summaryrefslogtreecommitdiff
path: root/testing/testing.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-15 17:53:27 +0200
committerMiguel <m.i@gmx.at>2018-09-15 17:53:27 +0200
commitcd50c8d1047832bbb0798b368fde0428ef749422 (patch)
treefcacf85f58fefeffa482630f31ef208a8bc9d03a /testing/testing.c
parent0b010d22dbf845ad030e2e7320f9c5935b2604a4 (diff)
improved in-kernel alloc/dealloc. addded colorless logging and struggling with mouse and kb
Diffstat (limited to 'testing/testing.c')
-rw-r--r--testing/testing.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/testing/testing.c b/testing/testing.c
new file mode 100644
index 0000000..fc95054
--- /dev/null
+++ b/testing/testing.c
@@ -0,0 +1,85 @@
+#include <stdint.h>
+#include "log.h"
+#include "kmalloc.h"
+
+void testing_kmalloc_alloc(uint32_t size)
+{
+ uint32_t addr=kballoc(size);
+ testlog("kballoc(%d) returned 0x%08x",size,addr);
+}
+
+void testing_kmalloc_alloc_free(uint32_t size)
+{
+ uint32_t addr=kballoc(size);
+ testlog("kballoc(%d) returned 0x%08x",size,addr);
+ kbfree(addr);
+ testlog("kbfree(0x%08X)",addr);
+}
+
+// only free even
+void testing_kmalloc_alloc_free_even(uint32_t size)
+{
+ uint32_t addr=kballoc(size);
+ testlog("kballoc(%d) returned 0x%08x",size,addr);
+ if(!(size%2))
+ {
+ kbfree(addr);
+ testlog("kbfree(0x%08X)",addr);
+ }
+}
+
+// only free first
+void testing_kmalloc_alloc_two_free_first(uint32_t size)
+{
+ uint32_t addr1=kballoc(size);
+ testlog("kballoc(%d) returned 0x%08x",size,addr1);
+
+ uint32_t addr2=kballoc(size);
+ testlog("kballoc(%d) returned 0x%08x",size,addr2);
+
+ kbfree(addr1);
+ testlog("kbfree(0x%08X)",addr1);
+}
+
+void testing_kmalloc()
+{
+ #ifndef FOOLOS_UNIT_TESTING
+ return;
+ #endif
+ fixme("[TESTING] Create multiple independent tests that start from scratch");
+ fixme("[TESTING] Check the test results automatically!");
+
+ testlog("= UNIT TESTING KMALLOC =");
+
+ testlog("* allocating blocks different sizes (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc(i+1);
+
+ testlog("* allocating and freeing different sizes (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc_free(i+1);
+
+ testlog("* allocating blocks different sizes (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc(i+1);
+
+ testlog("* allocating and freeing odd sizes only (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc_free_even(i+1);
+
+ testlog("* allocating two but freeing first only (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(i+1);
+
+ testlog("* allocating two but freeing first only (10-1 blocks)");
+ for(int i=9;i>=0;i--)testing_kmalloc_alloc_two_free_first(i+1);
+
+ testlog("* allocating blocks different sizes (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc(i+1);
+
+ testlog("* allocating and freeing mega blocks");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(255);
+
+ testlog("* allocating two but freeing first only (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(255-i);
+
+ testlog("* allocating two but freeing first only (1-10 blocks)");
+ for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(255-i);
+
+}
+