source: mainline/uspace/app/tester/tester.c@ d53a5ab0

topic/simplify-dev-export
Last change on this file since d53a5ab0 was d53a5ab0, checked in by Jiri Svoboda <jiri@…>, 19 months ago

Add IPC read/write test to libipctest/ipc test server + tester

Now really if IPC read/write didn't work, nothing would work.
Tester's readwrite test is mostly for sanity checking that
the read/write test in libipctest / ipc-test server work as intended.

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[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
[a63966d]30/** @addtogroup tester
[b2951e2]31 * @{
[2d11a7d8]32 */
[b2951e2]33/**
34 * @file
35 */
36
[713ba400]37#include <assert.h>
[51dbadf3]38#include <stdio.h>
[582a0b8]39#include <stddef.h>
[c45dc5e1]40#include <stdlib.h>
[19f857a]41#include <str.h>
[f47c70d4]42#include <io/log.h>
[713ba400]43#include <types/casting.h>
[dd655970]44#include "tester.h"
45
[2d11a7d8]46bool test_quiet;
47int test_argc;
48char **test_argv;
[dd655970]49
50test_t tests[] = {
51#include "thread/thread1.def"
[6a5b999]52#include "thread/setjmp1.def"
[dd655970]53#include "print/print1.def"
[2d11a7d8]54#include "print/print2.def"
55#include "print/print3.def"
[7a2c479]56#include "print/print4.def"
[855e0d8]57#include "print/print5.def"
[34b9299]58#include "print/print6.def"
[2d11a7d8]59#include "console/console1.def"
60#include "stdio/stdio1.def"
61#include "stdio/stdio2.def"
[f47c70d4]62#include "stdio/logger1.def"
[9a53e00]63#include "stdio/logger2.def"
[be66dee]64#include "fault/fault1.def"
65#include "fault/fault2.def"
[d91a20c]66#include "fault/fault3.def"
[b6636dc]67#include "float/float1.def"
[d9be488]68#include "float/float2.def"
[2d11a7d8]69#include "vfs/vfs1.def"
[d53a5ab0]70#include "ipc/readwrite.def"
[3b3fcf36]71#include "ipc/sharein.def"
[3191c01]72#include "ipc/starve.def"
[ce4a3dae]73#include "loop/loop1.def"
[2d11a7d8]74#include "mm/malloc1.def"
[9e953bda]75#include "mm/malloc2.def"
[013a5d7]76#include "mm/malloc3.def"
[b93d637]77#include "mm/mapping1.def"
[dd5f703]78#include "mm/pager1.def"
[ffdd2b9]79#include "hw/serial/serial1.def"
[57914494]80#include "chardev/chardev1.def"
[1433ecda]81 { NULL, NULL, NULL, false }
[dd655970]82};
83
84static bool run_test(test_t *test)
[51dbadf3]85{
[dd655970]86 /* Execute the test */
[a000878c]87 const char *ret = test->entry();
[a35b458]88
[dd655970]89 if (ret == NULL) {
[2d11a7d8]90 printf("\nTest passed\n");
[dd655970]91 return true;
[51dbadf3]92 }
[a35b458]93
[2d11a7d8]94 printf("\n%s\n", ret);
[dd655970]95 return false;
[51dbadf3]96}
97
[209cd41]98static int run_safe_tests(void)
[51dbadf3]99{
[047aa46]100 test_t *test;
[e190a89b]101 unsigned int i = 0;
102 unsigned int n = 0;
[a35b458]103
[c45dc5e1]104 char *failed_names = NULL;
105
[e190a89b]106 printf("\n*** Running all safe tests ***\n\n");
[a35b458]107
[047aa46]108 for (test = tests; test->name != NULL; test++) {
[c45dc5e1]109 if (!test->safe)
110 continue;
111
112 printf("%s (%s)\n", test->name, test->desc);
113 if (run_test(test)) {
114 i++;
115 continue;
116 }
117
118 if (!failed_names) {
119 failed_names = str_dup(test->name);
120 } else {
121 char *f = NULL;
122 asprintf(&f, "%s, %s", failed_names, test->name);
123 if (!f) {
124 printf("Out of memory.\n");
125 abort();
126 }
127 free(failed_names);
128 failed_names = f;
[047aa46]129 }
[c45dc5e1]130 n++;
[047aa46]131 }
[a35b458]132
[2d11a7d8]133 printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
[c45dc5e1]134 if (failed_names)
135 printf("Failed tests: %s\n", failed_names);
[209cd41]136
137 return n;
[51dbadf3]138}
139
[dd655970]140static void list_tests(void)
[51dbadf3]141{
[2d11a7d8]142 size_t len = 0;
[dd655970]143 test_t *test;
[2d11a7d8]144 for (test = tests; test->name != NULL; test++) {
145 if (str_length(test->name) > len)
146 len = str_length(test->name);
147 }
[a35b458]148
[713ba400]149 assert(can_cast_size_t_to_int(len) && "test name length overflow");
[a35b458]150
[2d11a7d8]151 for (test = tests; test->name != NULL; test++)
[713ba400]152 printf("%-*s %s%s\n", (int) len, test->name, test->desc,
[855e0d8]153 (test->safe ? "" : " (unsafe)"));
[a35b458]154
[713ba400]155 printf("%-*s Run all safe tests\n", (int) len, "*");
[51dbadf3]156}
157
[2d11a7d8]158int main(int argc, char *argv[])
[51dbadf3]159{
[2d11a7d8]160 if (argc < 2) {
161 printf("Usage:\n\n");
162 printf("%s <test> [args ...]\n\n", argv[0]);
[dd655970]163 list_tests();
[2d11a7d8]164 return 0;
165 }
[a35b458]166
[267f235]167 log_init("tester");
[f47c70d4]168
[2d11a7d8]169 test_quiet = false;
170 test_argc = argc - 2;
171 test_argv = argv + 2;
[a35b458]172
[2d11a7d8]173 if (str_cmp(argv[1], "*") == 0) {
[209cd41]174 return run_safe_tests();
[2d11a7d8]175 }
[a35b458]176
[2d11a7d8]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);
[51b966b]181 }
[51dbadf3]182 }
[a35b458]183
[2d11a7d8]184 printf("Unknown test \"%s\"\n", argv[1]);
185 return -2;
[51dbadf3]186}
[b2951e2]187
188/** @}
189 */
Note: See TracBrowser for help on using the repository browser.