Very basic "init"
This commit is contained in:
parent
ed1241341b
commit
4091148d2e
2 changed files with 115 additions and 0 deletions
106
arch/i386/init.c
Executable file
106
arch/i386/init.c
Executable file
|
@ -0,0 +1,106 @@
|
|||
#include <kernel/init.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int test_libc(void) {
|
||||
int failed = 0;
|
||||
|
||||
printf("==Testing stdio.h==\n");
|
||||
|
||||
printf("printf(\"%%d\", 10): %d (expected 10)\n", 10);
|
||||
printf("printf(\"%%d\", -10): %d (expected -10)\n", -10);
|
||||
printf("printf(\"%%i\", 10): %d (expected 10)\n", 10);
|
||||
printf("printf(\"%%o\", 014): %o (expected 14)\n", 014);
|
||||
printf("printf(\"%%o\", 14): %o (expected 16)\n", 14);
|
||||
printf("printf(\"%%u\", 10): %u (expected 10)\n", 10);
|
||||
printf("printf(\"%%x\", 0xC9A): %x (expected c9a)\n", 0xC9A);
|
||||
printf("printf(\"%%x\", 26): %x (expected 1a)\n", 26);
|
||||
printf("printf(\"%%X\", 0xC9A): %x (expected C9A)\n", 0xC9A);
|
||||
printf("printf(\"%%p\", &i): %p (expected 0x[hex])\n", &failed);
|
||||
printf("printf(\"%%n\"): %n (expected 14)\n");
|
||||
|
||||
printf("==Testing math.h==\n");
|
||||
if(cos(0) == 1.0) {
|
||||
printf("[");
|
||||
/* I want the status to be coloured. How do I do that? */
|
||||
printf("OK");
|
||||
printf("] cos()\n");
|
||||
}
|
||||
else {
|
||||
printf("[");
|
||||
printf("FAIL");
|
||||
printf("] cos()\n");
|
||||
failed++;
|
||||
}
|
||||
|
||||
if(fabs(-2.3) == 2.3) {
|
||||
printf("[");
|
||||
printf("OK");
|
||||
printf("] fabs()\n");
|
||||
}
|
||||
else {
|
||||
printf("[");
|
||||
printf("FAIL");
|
||||
printf("] fabs()\n");
|
||||
failed++;
|
||||
}
|
||||
|
||||
printf("==Testing time.h==\n");
|
||||
printf("time(0): Current UNIX time: %d\n", time(0));
|
||||
|
||||
printf("==Testing stdlib.h==\n");
|
||||
|
||||
if(abs(-5) == 5) {
|
||||
printf("[");
|
||||
printf("OK");
|
||||
printf("] abs()\n");
|
||||
}
|
||||
else {
|
||||
printf("[");
|
||||
printf("FAIL");
|
||||
printf("] abs(); expected 5, got %d\n", abs(-5));
|
||||
failed++;
|
||||
}
|
||||
|
||||
srand(time(0));
|
||||
int rand_test = rand();
|
||||
printf("rand() output with seed time(0): %d\n", rand_test);
|
||||
|
||||
printf("==Testing string.h==\n");
|
||||
|
||||
if(strcmp("Hi", "Hi") == 0 && strcmp("Hi", "Hello") != 0) {
|
||||
printf("[");
|
||||
printf("OK");
|
||||
printf("] strcmp()\n");
|
||||
}
|
||||
else {
|
||||
printf("[");
|
||||
printf("FAIL");
|
||||
printf("] strcmp()\n");
|
||||
failed++;
|
||||
}
|
||||
|
||||
if(strcspn("Hello!", "!e") == 1) {
|
||||
printf("[");
|
||||
printf("OK");
|
||||
printf("] strcspn()\n");
|
||||
}
|
||||
else {
|
||||
printf("[");
|
||||
printf("FAIL");
|
||||
printf("] strcspn(); expected 1, got %d\n", strcspn("Hello!", "!e"));
|
||||
failed++;
|
||||
}
|
||||
|
||||
printf("Tests failed: %d\n", failed);
|
||||
printf("One final test: If you can see this, the TTY can scroll.");
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
int init(void) {
|
||||
printf("Fenix Dev Pre-release v0.0.3\n");
|
||||
return test_libc();
|
||||
}
|
9
include/kernel/init.h
Executable file
9
include/kernel/init.h
Executable file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _KERNEL_INIT
|
||||
#define _KERNEL_INIT
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int test_libc(void);
|
||||
int init(void);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue