00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00038 #include <unistd.h>
00039 #include <stdio.h>
00040 #include <str.h>
00041 #include "tester.h"
00042
00043 bool test_quiet;
00044 int test_argc;
00045 char **test_argv;
00046
00047 test_t tests[] = {
00048 #include "thread/thread1.def"
00049 #include "print/print1.def"
00050 #include "print/print2.def"
00051 #include "print/print3.def"
00052 #include "print/print4.def"
00053 #include "print/print5.def"
00054 #include "console/console1.def"
00055 #include "stdio/stdio1.def"
00056 #include "stdio/stdio2.def"
00057 #include "fault/fault1.def"
00058 #include "fault/fault2.def"
00059 #include "fault/fault3.def"
00060 #include "vfs/vfs1.def"
00061 #include "ipc/ping_pong.def"
00062 #include "loop/loop1.def"
00063 #include "mm/malloc1.def"
00064 #include "mm/malloc2.def"
00065 #include "mm/malloc3.def"
00066 #include "mm/mapping1.def"
00067 #include "hw/serial/serial1.def"
00068 #include "hw/misc/virtchar1.def"
00069 #include "devs/devman1.def"
00070 #include "devs/devman2.def"
00071 {NULL, NULL, NULL, false}
00072 };
00073
00074 static bool run_test(test_t *test)
00075 {
00076
00077 const char *ret = test->entry();
00078
00079 if (ret == NULL) {
00080 printf("\nTest passed\n");
00081 return true;
00082 }
00083
00084 printf("\n%s\n", ret);
00085 return false;
00086 }
00087
00088 static void run_safe_tests(void)
00089 {
00090 test_t *test;
00091 unsigned int i = 0;
00092 unsigned int n = 0;
00093
00094 printf("\n*** Running all safe tests ***\n\n");
00095
00096 for (test = tests; test->name != NULL; test++) {
00097 if (test->safe) {
00098 printf("%s (%s)\n", test->name, test->desc);
00099 if (run_test(test))
00100 i++;
00101 else
00102 n++;
00103 }
00104 }
00105
00106 printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
00107 }
00108
00109 static void list_tests(void)
00110 {
00111 size_t len = 0;
00112 test_t *test;
00113 for (test = tests; test->name != NULL; test++) {
00114 if (str_length(test->name) > len)
00115 len = str_length(test->name);
00116 }
00117
00118 unsigned int _len = (unsigned int) len;
00119 if ((_len != len) || (((int) _len) < 0)) {
00120 printf("Command length overflow\n");
00121 return;
00122 }
00123
00124 for (test = tests; test->name != NULL; test++)
00125 printf("%-*s %s%s\n", _len, test->name, test->desc,
00126 (test->safe ? "" : " (unsafe)"));
00127
00128 printf("%-*s Run all safe tests\n", _len, "*");
00129 }
00130
00131 int main(int argc, char *argv[])
00132 {
00133 if (argc < 2) {
00134 printf("Usage:\n\n");
00135 printf("%s <test> [args ...]\n\n", argv[0]);
00136 list_tests();
00137 return 0;
00138 }
00139
00140 test_quiet = false;
00141 test_argc = argc - 2;
00142 test_argv = argv + 2;
00143
00144 if (str_cmp(argv[1], "*") == 0) {
00145 run_safe_tests();
00146 return 0;
00147 }
00148
00149 test_t *test;
00150 for (test = tests; test->name != NULL; test++) {
00151 if (str_cmp(argv[1], test->name) == 0) {
00152 return (run_test(test) ? 0 : -1);
00153 }
00154 }
00155
00156 printf("Unknown test \"%s\"\n", argv[1]);
00157 return -2;
00158 }
00159