Changes devether's Max Trans Unit to 1500
[akaros.git] / kern / include / ktest.h
index a3d46ac..46496bd 100644 (file)
@@ -13,9 +13,7 @@
 #include <kmalloc.h>
 #include <arch/arch.h>
 #include <time.h>
-
-/* Global string used to report info about the last completed test */
-extern char ktest_msg[1024];
+#include <sys/queue.h>
 
 /* Macros for assertions. 
  */
@@ -38,36 +36,31 @@ struct ktest {
        bool enabled; // Whether to run or not the test.
 };
 
-/* Macro for registering a kernel test. */
+struct ktest_suite {
+    SLIST_ENTRY(ktest_suite) link;
+       char name[256];
+       struct ktest *ktests;
+       int num_ktests;
+};
+
+#define KTEST_SUITE(name) \
+       static struct ktest_suite ktest_suite = {{}, name, NULL, 0};
+
 #define KTEST_REG(name, config) \
        {"test_" #name, test_##name, is_defined(config)}
 
-static void run_ktests(char *suite_name, struct ktest tests[], int num_tests)
-{
-       extern char ktest_msg[];
-       printk("<-- BEGIN_KERNEL_%s_TESTS -->\n", suite_name);
-
-       for (int i=0; i<num_tests; i++) {
-               struct ktest *test = &tests[i];
-               if (test->enabled) {
-                       uint64_t start = read_tsc();
-                       bool result = test->func();
-                       uint64_t end = read_tsc();
-                       uint64_t et_us = tsc2usec(end - start) % 1000000;
-                       uint64_t et_s = tsc2sec(end - start);
+#define REGISTER_KTESTS(ktests, num_ktests)                                      \
+       do {                                                                         \
+               ktest_suite.ktests = ktests;                                             \
+               ktest_suite.num_ktests = num_ktests;                                     \
+               register_ktest_suite(&ktest_suite);                                      \
+       } while (0)
 
-                       char fmt[] = "\t%s   [%s](%llu.%06llus)   %s\n";
-                       if (result) {
-                               printk(fmt, "PASSED", test->name, et_s, et_us, "");
-                       } else {
-                               printk(fmt, "FAILED", test->name, et_s, et_us, ktest_msg);
-                       }
-               } else {
-                       printk("\tDISABLED [%s]\n", test->name);
-               }
-       }
+/* Global string used to report info about the last completed test */
+extern char ktest_msg[1024];
 
-       printk("<-- END_KERNEL_%s_TESTS -->\n", suite_name);
-}
+void register_ktest_suite(struct ktest_suite *suite);
+void run_ktest_suite(struct ktest_suite *suite);
+void run_registered_ktest_suites();
 
 #endif // ROS_INC_KTEST_H