From 4091148d2e1c58b9ab6b05a544418fc1de4dedff Mon Sep 17 00:00:00 2001 From: Gitea Date: Tue, 1 Dec 2020 20:59:33 -0600 Subject: [PATCH] Very basic "init" --- arch/i386/init.c | 106 ++++++++++++++++++++++++++++++++++++++++++ include/kernel/init.h | 9 ++++ 2 files changed, 115 insertions(+) create mode 100755 arch/i386/init.c create mode 100755 include/kernel/init.h diff --git a/arch/i386/init.c b/arch/i386/init.c new file mode 100755 index 0000000..454e159 --- /dev/null +++ b/arch/i386/init.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include + +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(); +} diff --git a/include/kernel/init.h b/include/kernel/init.h new file mode 100755 index 0000000..b411cd7 --- /dev/null +++ b/include/kernel/init.h @@ -0,0 +1,9 @@ +#ifndef _KERNEL_INIT +#define _KERNEL_INIT + +#include + +int test_libc(void); +int init(void); + +#endif