tester.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Ondrej Palkovsky
00003  * Copyright (c) 2007 Martin Decky
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * - Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * - The name of the author may not be used to endorse or promote products
00016  *   derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00019  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00020  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00021  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00023  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00024  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00025  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00027  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         /* Execute the test */
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 

Generated on Thu Jun 2 07:45:43 2011 for HelenOS/USB by  doxygen 1.4.7