source: mainline/uspace/app/tester/tester.c@ 82ff0a1

Last change on this file since 82ff0a1 was 82ff0a1, checked in by Jiri Svoboda <jiri@…>, 6 months ago

Add deadlock detector to tester.

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[b2951e2]1/*
[82ff0a1]2 * Copyright (c) 2025 Jiri Svoboda
[df4ed85]3 * Copyright (c) 2006 Ondrej Palkovsky
[dd655970]4 * Copyright (c) 2007 Martin Decky
[b2951e2]5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
[a63966d]31/** @addtogroup tester
[b2951e2]32 * @{
[2d11a7d8]33 */
[b2951e2]34/**
35 * @file
36 */
37
[713ba400]38#include <assert.h>
[51dbadf3]39#include <stdio.h>
[582a0b8]40#include <stddef.h>
[c45dc5e1]41#include <stdlib.h>
[19f857a]42#include <str.h>
[f47c70d4]43#include <io/log.h>
[713ba400]44#include <types/casting.h>
[dd655970]45#include "tester.h"
46
[2d11a7d8]47bool test_quiet;
48int test_argc;
49char **test_argv;
[dd655970]50
51test_t tests[] = {
[82ff0a1]52#include "thread/deadlock.def"
[dd655970]53#include "thread/thread1.def"
[6a5b999]54#include "thread/setjmp1.def"
[dd655970]55#include "print/print1.def"
[2d11a7d8]56#include "print/print2.def"
57#include "print/print3.def"
[7a2c479]58#include "print/print4.def"
[855e0d8]59#include "print/print5.def"
[34b9299]60#include "print/print6.def"
[2d11a7d8]61#include "console/console1.def"
62#include "stdio/stdio1.def"
63#include "stdio/stdio2.def"
[f47c70d4]64#include "stdio/logger1.def"
[9a53e00]65#include "stdio/logger2.def"
[be66dee]66#include "fault/fault1.def"
67#include "fault/fault2.def"
[d91a20c]68#include "fault/fault3.def"
[b6636dc]69#include "float/float1.def"
[d9be488]70#include "float/float2.def"
[2d11a7d8]71#include "vfs/vfs1.def"
[d53a5ab0]72#include "ipc/readwrite.def"
[3b3fcf36]73#include "ipc/sharein.def"
[3191c01]74#include "ipc/starve.def"
[ce4a3dae]75#include "loop/loop1.def"
[2d11a7d8]76#include "mm/malloc1.def"
[9e953bda]77#include "mm/malloc2.def"
[013a5d7]78#include "mm/malloc3.def"
[b93d637]79#include "mm/mapping1.def"
[dd5f703]80#include "mm/pager1.def"
[ffdd2b9]81#include "hw/serial/serial1.def"
[57914494]82#include "chardev/chardev1.def"
[1433ecda]83 { NULL, NULL, NULL, false }
[dd655970]84};
85
86static bool run_test(test_t *test)
[51dbadf3]87{
[dd655970]88 /* Execute the test */
[a000878c]89 const char *ret = test->entry();
[a35b458]90
[dd655970]91 if (ret == NULL) {
[2d11a7d8]92 printf("\nTest passed\n");
[dd655970]93 return true;
[51dbadf3]94 }
[a35b458]95
[2d11a7d8]96 printf("\n%s\n", ret);
[dd655970]97 return false;
[51dbadf3]98}
99
[209cd41]100static int run_safe_tests(void)
[51dbadf3]101{
[047aa46]102 test_t *test;
[e190a89b]103 unsigned int i = 0;
104 unsigned int n = 0;
[a35b458]105
[c45dc5e1]106 char *failed_names = NULL;
107
[e190a89b]108 printf("\n*** Running all safe tests ***\n\n");
[a35b458]109
[047aa46]110 for (test = tests; test->name != NULL; test++) {
[c45dc5e1]111 if (!test->safe)
112 continue;
113
114 printf("%s (%s)\n", test->name, test->desc);
115 if (run_test(test)) {
116 i++;
117 continue;
118 }
119
120 if (!failed_names) {
121 failed_names = str_dup(test->name);
122 } else {
123 char *f = NULL;
124 asprintf(&f, "%s, %s", failed_names, test->name);
125 if (!f) {
126 printf("Out of memory.\n");
127 abort();
128 }
129 free(failed_names);
130 failed_names = f;
[047aa46]131 }
[c45dc5e1]132 n++;
[047aa46]133 }
[a35b458]134
[2d11a7d8]135 printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
[c45dc5e1]136 if (failed_names)
137 printf("Failed tests: %s\n", failed_names);
[209cd41]138
139 return n;
[51dbadf3]140}
141
[dd655970]142static void list_tests(void)
[51dbadf3]143{
[2d11a7d8]144 size_t len = 0;
[dd655970]145 test_t *test;
[2d11a7d8]146 for (test = tests; test->name != NULL; test++) {
147 if (str_length(test->name) > len)
148 len = str_length(test->name);
149 }
[a35b458]150
[713ba400]151 assert(can_cast_size_t_to_int(len) && "test name length overflow");
[a35b458]152
[2d11a7d8]153 for (test = tests; test->name != NULL; test++)
[713ba400]154 printf("%-*s %s%s\n", (int) len, test->name, test->desc,
[855e0d8]155 (test->safe ? "" : " (unsafe)"));
[a35b458]156
[713ba400]157 printf("%-*s Run all safe tests\n", (int) len, "*");
[51dbadf3]158}
159
[2d11a7d8]160int main(int argc, char *argv[])
[51dbadf3]161{
[2d11a7d8]162 if (argc < 2) {
163 printf("Usage:\n\n");
164 printf("%s <test> [args ...]\n\n", argv[0]);
[dd655970]165 list_tests();
[2d11a7d8]166 return 0;
167 }
[a35b458]168
[267f235]169 log_init("tester");
[f47c70d4]170
[2d11a7d8]171 test_quiet = false;
172 test_argc = argc - 2;
173 test_argv = argv + 2;
[a35b458]174
[2d11a7d8]175 if (str_cmp(argv[1], "*") == 0) {
[209cd41]176 return run_safe_tests();
[2d11a7d8]177 }
[a35b458]178
[2d11a7d8]179 test_t *test;
180 for (test = tests; test->name != NULL; test++) {
181 if (str_cmp(argv[1], test->name) == 0) {
182 return (run_test(test) ? 0 : -1);
[51b966b]183 }
[51dbadf3]184 }
[a35b458]185
[2d11a7d8]186 printf("Unknown test \"%s\"\n", argv[1]);
187 return -2;
[51dbadf3]188}
[b2951e2]189
190/** @}
191 */
Note: See TracBrowser for help on using the repository browser.