| 1 | /*
|
|---|
| 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
|---|
| 3 | * Copyright (c) 2007 Martin Decky
|
|---|
| 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 |
|
|---|
| 30 | /** @addtogroup tester
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /**
|
|---|
| 34 | * @file
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <stdio.h>
|
|---|
| 38 | #include <stddef.h>
|
|---|
| 39 | #include <stdlib.h>
|
|---|
| 40 | #include <str.h>
|
|---|
| 41 | #include <io/log.h>
|
|---|
| 42 | #include "tester.h"
|
|---|
| 43 |
|
|---|
| 44 | bool test_quiet;
|
|---|
| 45 | int test_argc;
|
|---|
| 46 | char **test_argv;
|
|---|
| 47 |
|
|---|
| 48 | test_t tests[] = {
|
|---|
| 49 | #include "thread/thread1.def"
|
|---|
| 50 | #include "thread/setjmp1.def"
|
|---|
| 51 | #include "print/print1.def"
|
|---|
| 52 | #include "print/print2.def"
|
|---|
| 53 | #include "print/print3.def"
|
|---|
| 54 | #include "print/print4.def"
|
|---|
| 55 | #include "print/print5.def"
|
|---|
| 56 | #include "print/print6.def"
|
|---|
| 57 | #include "console/console1.def"
|
|---|
| 58 | #include "stdio/stdio1.def"
|
|---|
| 59 | #include "stdio/stdio2.def"
|
|---|
| 60 | #include "stdio/logger1.def"
|
|---|
| 61 | #include "stdio/logger2.def"
|
|---|
| 62 | #include "fault/fault1.def"
|
|---|
| 63 | #include "fault/fault2.def"
|
|---|
| 64 | #include "fault/fault3.def"
|
|---|
| 65 | #include "float/float1.def"
|
|---|
| 66 | #include "float/float2.def"
|
|---|
| 67 | #include "vfs/vfs1.def"
|
|---|
| 68 | #include "ipc/starve.def"
|
|---|
| 69 | #include "loop/loop1.def"
|
|---|
| 70 | #include "mm/malloc1.def"
|
|---|
| 71 | #include "mm/malloc2.def"
|
|---|
| 72 | #include "mm/malloc3.def"
|
|---|
| 73 | #include "mm/mapping1.def"
|
|---|
| 74 | #include "mm/pager1.def"
|
|---|
| 75 | #include "hw/serial/serial1.def"
|
|---|
| 76 | #include "chardev/chardev1.def"
|
|---|
| 77 | { NULL, NULL, NULL, false }
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | static bool run_test(test_t *test)
|
|---|
| 81 | {
|
|---|
| 82 | /* Execute the test */
|
|---|
| 83 | const char *ret = test->entry();
|
|---|
| 84 |
|
|---|
| 85 | if (ret == NULL) {
|
|---|
| 86 | printf("\nTest passed\n");
|
|---|
| 87 | return true;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | printf("\n%s\n", ret);
|
|---|
| 91 | return false;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | static int run_safe_tests(void)
|
|---|
| 95 | {
|
|---|
| 96 | test_t *test;
|
|---|
| 97 | unsigned int i = 0;
|
|---|
| 98 | unsigned int n = 0;
|
|---|
| 99 |
|
|---|
| 100 | char *failed_names = NULL;
|
|---|
| 101 |
|
|---|
| 102 | printf("\n*** Running all safe tests ***\n\n");
|
|---|
| 103 |
|
|---|
| 104 | for (test = tests; test->name != NULL; test++) {
|
|---|
| 105 | if (!test->safe)
|
|---|
| 106 | continue;
|
|---|
| 107 |
|
|---|
| 108 | printf("%s (%s)\n", test->name, test->desc);
|
|---|
| 109 | if (run_test(test)) {
|
|---|
| 110 | i++;
|
|---|
| 111 | continue;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | if (!failed_names) {
|
|---|
| 115 | failed_names = str_dup(test->name);
|
|---|
| 116 | } else {
|
|---|
| 117 | char *f = NULL;
|
|---|
| 118 | asprintf(&f, "%s, %s", failed_names, test->name);
|
|---|
| 119 | if (!f) {
|
|---|
| 120 | printf("Out of memory.\n");
|
|---|
| 121 | abort();
|
|---|
| 122 | }
|
|---|
| 123 | free(failed_names);
|
|---|
| 124 | failed_names = f;
|
|---|
| 125 | }
|
|---|
| 126 | n++;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
|
|---|
| 130 | if (failed_names)
|
|---|
| 131 | printf("Failed tests: %s\n", failed_names);
|
|---|
| 132 |
|
|---|
| 133 | return n;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | static void list_tests(void)
|
|---|
| 137 | {
|
|---|
| 138 | size_t len = 0;
|
|---|
| 139 | test_t *test;
|
|---|
| 140 | for (test = tests; test->name != NULL; test++) {
|
|---|
| 141 | if (str_length(test->name) > len)
|
|---|
| 142 | len = str_length(test->name);
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | unsigned int _len = (unsigned int) len;
|
|---|
| 146 | if ((_len != len) || (((int) _len) < 0)) {
|
|---|
| 147 | printf("Command length overflow\n");
|
|---|
| 148 | return;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | for (test = tests; test->name != NULL; test++)
|
|---|
| 152 | printf("%-*s %s%s\n", _len, test->name, test->desc,
|
|---|
| 153 | (test->safe ? "" : " (unsafe)"));
|
|---|
| 154 |
|
|---|
| 155 | printf("%-*s Run all safe tests\n", _len, "*");
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | int main(int argc, char *argv[])
|
|---|
| 159 | {
|
|---|
| 160 | if (argc < 2) {
|
|---|
| 161 | printf("Usage:\n\n");
|
|---|
| 162 | printf("%s <test> [args ...]\n\n", argv[0]);
|
|---|
| 163 | list_tests();
|
|---|
| 164 | return 0;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | log_init("tester");
|
|---|
| 168 |
|
|---|
| 169 | test_quiet = false;
|
|---|
| 170 | test_argc = argc - 2;
|
|---|
| 171 | test_argv = argv + 2;
|
|---|
| 172 |
|
|---|
| 173 | if (str_cmp(argv[1], "*") == 0) {
|
|---|
| 174 | return run_safe_tests();
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | test_t *test;
|
|---|
| 178 | for (test = tests; test->name != NULL; test++) {
|
|---|
| 179 | if (str_cmp(argv[1], test->name) == 0) {
|
|---|
| 180 | return (run_test(test) ? 0 : -1);
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | printf("Unknown test \"%s\"\n", argv[1]);
|
|---|
| 185 | return -2;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | /** @}
|
|---|
| 189 | */
|
|---|