[b2951e2] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[dd655970] | 3 | * Copyright (c) 2007 Martin Decky
|
---|
[b2951e2] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[2d11a7d8] | 30 | /** @addtogroup tester User space tester
|
---|
| 31 | * @brief User space testing infrastructure.
|
---|
[b2951e2] | 32 | * @{
|
---|
[2d11a7d8] | 33 | */
|
---|
[b2951e2] | 34 | /**
|
---|
| 35 | * @file
|
---|
| 36 | */
|
---|
| 37 |
|
---|
[dd655970] | 38 | #include <unistd.h>
|
---|
[51dbadf3] | 39 | #include <stdio.h>
|
---|
[19f857a] | 40 | #include <str.h>
|
---|
[dd655970] | 41 | #include "tester.h"
|
---|
| 42 |
|
---|
[2d11a7d8] | 43 | bool test_quiet;
|
---|
| 44 | int test_argc;
|
---|
| 45 | char **test_argv;
|
---|
[dd655970] | 46 |
|
---|
| 47 | test_t tests[] = {
|
---|
| 48 | #include "thread/thread1.def"
|
---|
| 49 | #include "print/print1.def"
|
---|
[2d11a7d8] | 50 | #include "print/print2.def"
|
---|
| 51 | #include "print/print3.def"
|
---|
[7a2c479] | 52 | #include "print/print4.def"
|
---|
[855e0d8] | 53 | #include "print/print5.def"
|
---|
[2d11a7d8] | 54 | #include "console/console1.def"
|
---|
| 55 | #include "stdio/stdio1.def"
|
---|
| 56 | #include "stdio/stdio2.def"
|
---|
[be66dee] | 57 | #include "fault/fault1.def"
|
---|
| 58 | #include "fault/fault2.def"
|
---|
[d91a20c] | 59 | #include "fault/fault3.def"
|
---|
[2d11a7d8] | 60 | #include "vfs/vfs1.def"
|
---|
| 61 | #include "ipc/ping_pong.def"
|
---|
[ce4a3dae] | 62 | #include "loop/loop1.def"
|
---|
[2d11a7d8] | 63 | #include "mm/malloc1.def"
|
---|
[ffdd2b9] | 64 | #include "hw/serial/serial1.def"
|
---|
[3f45993] | 65 | #include "adt/usbaddrkeep.def"
|
---|
[424558a] | 66 | #include "hw/misc/virtchar1.def"
|
---|
[2d11a7d8] | 67 | {NULL, NULL, NULL, false}
|
---|
[dd655970] | 68 | };
|
---|
| 69 |
|
---|
| 70 | static bool run_test(test_t *test)
|
---|
[51dbadf3] | 71 | {
|
---|
[dd655970] | 72 | /* Execute the test */
|
---|
[a000878c] | 73 | const char *ret = test->entry();
|
---|
[dd655970] | 74 |
|
---|
| 75 | if (ret == NULL) {
|
---|
[2d11a7d8] | 76 | printf("\nTest passed\n");
|
---|
[dd655970] | 77 | return true;
|
---|
[51dbadf3] | 78 | }
|
---|
[2d11a7d8] | 79 |
|
---|
| 80 | printf("\n%s\n", ret);
|
---|
[dd655970] | 81 | return false;
|
---|
[51dbadf3] | 82 | }
|
---|
| 83 |
|
---|
[dd655970] | 84 | static void run_safe_tests(void)
|
---|
[51dbadf3] | 85 | {
|
---|
[047aa46] | 86 | test_t *test;
|
---|
[e190a89b] | 87 | unsigned int i = 0;
|
---|
| 88 | unsigned int n = 0;
|
---|
[2d11a7d8] | 89 |
|
---|
[e190a89b] | 90 | printf("\n*** Running all safe tests ***\n\n");
|
---|
[2d11a7d8] | 91 |
|
---|
[047aa46] | 92 | for (test = tests; test->name != NULL; test++) {
|
---|
| 93 | if (test->safe) {
|
---|
[2d11a7d8] | 94 | printf("%s (%s)\n", test->name, test->desc);
|
---|
[047aa46] | 95 | if (run_test(test))
|
---|
| 96 | i++;
|
---|
| 97 | else
|
---|
| 98 | n++;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
[2d11a7d8] | 101 |
|
---|
| 102 | printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
|
---|
[51dbadf3] | 103 | }
|
---|
| 104 |
|
---|
[dd655970] | 105 | static void list_tests(void)
|
---|
[51dbadf3] | 106 | {
|
---|
[2d11a7d8] | 107 | size_t len = 0;
|
---|
[dd655970] | 108 | test_t *test;
|
---|
[2d11a7d8] | 109 | for (test = tests; test->name != NULL; test++) {
|
---|
| 110 | if (str_length(test->name) > len)
|
---|
| 111 | len = str_length(test->name);
|
---|
| 112 | }
|
---|
[51dbadf3] | 113 |
|
---|
[855e0d8] | 114 | unsigned int _len = (unsigned int) len;
|
---|
| 115 | if ((_len != len) || (((int) _len) < 0)) {
|
---|
| 116 | printf("Command length overflow\n");
|
---|
| 117 | return;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[2d11a7d8] | 120 | for (test = tests; test->name != NULL; test++)
|
---|
[855e0d8] | 121 | printf("%-*s %s%s\n", _len, test->name, test->desc,
|
---|
| 122 | (test->safe ? "" : " (unsafe)"));
|
---|
[51dbadf3] | 123 |
|
---|
[855e0d8] | 124 | printf("%-*s Run all safe tests\n", _len, "*");
|
---|
[51dbadf3] | 125 | }
|
---|
| 126 |
|
---|
[2d11a7d8] | 127 | int main(int argc, char *argv[])
|
---|
[51dbadf3] | 128 | {
|
---|
[2d11a7d8] | 129 | if (argc < 2) {
|
---|
| 130 | printf("Usage:\n\n");
|
---|
| 131 | printf("%s <test> [args ...]\n\n", argv[0]);
|
---|
[dd655970] | 132 | list_tests();
|
---|
[2d11a7d8] | 133 | return 0;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | test_quiet = false;
|
---|
| 137 | test_argc = argc - 2;
|
---|
| 138 | test_argv = argv + 2;
|
---|
| 139 |
|
---|
| 140 | if (str_cmp(argv[1], "*") == 0) {
|
---|
| 141 | run_safe_tests();
|
---|
| 142 | return 0;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | test_t *test;
|
---|
| 146 | for (test = tests; test->name != NULL; test++) {
|
---|
| 147 | if (str_cmp(argv[1], test->name) == 0) {
|
---|
| 148 | return (run_test(test) ? 0 : -1);
|
---|
[51b966b] | 149 | }
|
---|
[51dbadf3] | 150 | }
|
---|
[2d11a7d8] | 151 |
|
---|
| 152 | printf("Unknown test \"%s\"\n", argv[1]);
|
---|
| 153 | return -2;
|
---|
[51dbadf3] | 154 | }
|
---|
[b2951e2] | 155 |
|
---|
| 156 | /** @}
|
---|
| 157 | */
|
---|