[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 |
|
---|
[51dbadf3] | 38 | #include <stdio.h>
|
---|
[582a0b8] | 39 | #include <stddef.h>
|
---|
[19f857a] | 40 | #include <str.h>
|
---|
[f47c70d4] | 41 | #include <io/log.h>
|
---|
[dd655970] | 42 | #include "tester.h"
|
---|
| 43 |
|
---|
[2d11a7d8] | 44 | bool test_quiet;
|
---|
| 45 | int test_argc;
|
---|
| 46 | char **test_argv;
|
---|
[dd655970] | 47 |
|
---|
| 48 | test_t tests[] = {
|
---|
| 49 | #include "thread/thread1.def"
|
---|
[6a5b999] | 50 | #include "thread/setjmp1.def"
|
---|
[dd655970] | 51 | #include "print/print1.def"
|
---|
[2d11a7d8] | 52 | #include "print/print2.def"
|
---|
| 53 | #include "print/print3.def"
|
---|
[7a2c479] | 54 | #include "print/print4.def"
|
---|
[855e0d8] | 55 | #include "print/print5.def"
|
---|
[34b9299] | 56 | #include "print/print6.def"
|
---|
[2d11a7d8] | 57 | #include "console/console1.def"
|
---|
| 58 | #include "stdio/stdio1.def"
|
---|
| 59 | #include "stdio/stdio2.def"
|
---|
[f47c70d4] | 60 | #include "stdio/logger1.def"
|
---|
[9a53e00] | 61 | #include "stdio/logger2.def"
|
---|
[be66dee] | 62 | #include "fault/fault1.def"
|
---|
| 63 | #include "fault/fault2.def"
|
---|
[d91a20c] | 64 | #include "fault/fault3.def"
|
---|
[b6636dc] | 65 | #include "float/float1.def"
|
---|
[d9be488] | 66 | #include "float/float2.def"
|
---|
[b6636dc] | 67 | #include "float/softfloat1.def"
|
---|
[2d11a7d8] | 68 | #include "vfs/vfs1.def"
|
---|
| 69 | #include "ipc/ping_pong.def"
|
---|
[3191c01] | 70 | #include "ipc/starve.def"
|
---|
[ce4a3dae] | 71 | #include "loop/loop1.def"
|
---|
[2d11a7d8] | 72 | #include "mm/malloc1.def"
|
---|
[9e953bda] | 73 | #include "mm/malloc2.def"
|
---|
[013a5d7] | 74 | #include "mm/malloc3.def"
|
---|
[b93d637] | 75 | #include "mm/mapping1.def"
|
---|
[dd5f703] | 76 | #include "mm/pager1.def"
|
---|
[ffdd2b9] | 77 | #include "hw/serial/serial1.def"
|
---|
[424558a] | 78 | #include "hw/misc/virtchar1.def"
|
---|
[57914494] | 79 | #include "chardev/chardev1.def"
|
---|
[2d11a7d8] | 80 | {NULL, NULL, NULL, false}
|
---|
[dd655970] | 81 | };
|
---|
| 82 |
|
---|
| 83 | static bool run_test(test_t *test)
|
---|
[51dbadf3] | 84 | {
|
---|
[dd655970] | 85 | /* Execute the test */
|
---|
[a000878c] | 86 | const char *ret = test->entry();
|
---|
[dd655970] | 87 |
|
---|
| 88 | if (ret == NULL) {
|
---|
[2d11a7d8] | 89 | printf("\nTest passed\n");
|
---|
[dd655970] | 90 | return true;
|
---|
[51dbadf3] | 91 | }
|
---|
[2d11a7d8] | 92 |
|
---|
| 93 | printf("\n%s\n", ret);
|
---|
[dd655970] | 94 | return false;
|
---|
[51dbadf3] | 95 | }
|
---|
| 96 |
|
---|
[dd655970] | 97 | static void run_safe_tests(void)
|
---|
[51dbadf3] | 98 | {
|
---|
[047aa46] | 99 | test_t *test;
|
---|
[e190a89b] | 100 | unsigned int i = 0;
|
---|
| 101 | unsigned int n = 0;
|
---|
[2d11a7d8] | 102 |
|
---|
[e190a89b] | 103 | printf("\n*** Running all safe tests ***\n\n");
|
---|
[2d11a7d8] | 104 |
|
---|
[047aa46] | 105 | for (test = tests; test->name != NULL; test++) {
|
---|
| 106 | if (test->safe) {
|
---|
[2d11a7d8] | 107 | printf("%s (%s)\n", test->name, test->desc);
|
---|
[047aa46] | 108 | if (run_test(test))
|
---|
| 109 | i++;
|
---|
| 110 | else
|
---|
| 111 | n++;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
[2d11a7d8] | 114 |
|
---|
| 115 | printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
|
---|
[51dbadf3] | 116 | }
|
---|
| 117 |
|
---|
[dd655970] | 118 | static void list_tests(void)
|
---|
[51dbadf3] | 119 | {
|
---|
[2d11a7d8] | 120 | size_t len = 0;
|
---|
[dd655970] | 121 | test_t *test;
|
---|
[2d11a7d8] | 122 | for (test = tests; test->name != NULL; test++) {
|
---|
| 123 | if (str_length(test->name) > len)
|
---|
| 124 | len = str_length(test->name);
|
---|
| 125 | }
|
---|
[51dbadf3] | 126 |
|
---|
[855e0d8] | 127 | unsigned int _len = (unsigned int) len;
|
---|
| 128 | if ((_len != len) || (((int) _len) < 0)) {
|
---|
| 129 | printf("Command length overflow\n");
|
---|
| 130 | return;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[2d11a7d8] | 133 | for (test = tests; test->name != NULL; test++)
|
---|
[855e0d8] | 134 | printf("%-*s %s%s\n", _len, test->name, test->desc,
|
---|
| 135 | (test->safe ? "" : " (unsafe)"));
|
---|
[51dbadf3] | 136 |
|
---|
[855e0d8] | 137 | printf("%-*s Run all safe tests\n", _len, "*");
|
---|
[51dbadf3] | 138 | }
|
---|
| 139 |
|
---|
[2d11a7d8] | 140 | int main(int argc, char *argv[])
|
---|
[51dbadf3] | 141 | {
|
---|
[2d11a7d8] | 142 | if (argc < 2) {
|
---|
| 143 | printf("Usage:\n\n");
|
---|
| 144 | printf("%s <test> [args ...]\n\n", argv[0]);
|
---|
[dd655970] | 145 | list_tests();
|
---|
[2d11a7d8] | 146 | return 0;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[267f235] | 149 | log_init("tester");
|
---|
[f47c70d4] | 150 |
|
---|
[2d11a7d8] | 151 | test_quiet = false;
|
---|
| 152 | test_argc = argc - 2;
|
---|
| 153 | test_argv = argv + 2;
|
---|
| 154 |
|
---|
| 155 | if (str_cmp(argv[1], "*") == 0) {
|
---|
| 156 | run_safe_tests();
|
---|
| 157 | return 0;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | test_t *test;
|
---|
| 161 | for (test = tests; test->name != NULL; test++) {
|
---|
| 162 | if (str_cmp(argv[1], test->name) == 0) {
|
---|
| 163 | return (run_test(test) ? 0 : -1);
|
---|
[51b966b] | 164 | }
|
---|
[51dbadf3] | 165 | }
|
---|
[2d11a7d8] | 166 |
|
---|
| 167 | printf("Unknown test \"%s\"\n", argv[1]);
|
---|
| 168 | return -2;
|
---|
[51dbadf3] | 169 | }
|
---|
[b2951e2] | 170 |
|
---|
| 171 | /** @}
|
---|
| 172 | */
|
---|