source: mainline/uspace/app/tester/tester.c@ 7bce1fc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7bce1fc was 12f9f0d0, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Notifications on changes in loc categories. Limitations:

  • cannot specify single category to watch
  • max one task can register notifications with loc service
  • max one user callback function can be registered with C library

Remove devman tests as they are not applicable anymore.

  • Property mode set to 100644
File size: 4.0 KB
Line 
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 User space tester
31 * @brief User space testing infrastructure.
32 * @{
33 */
34/**
35 * @file
36 */
37
38#include <unistd.h>
39#include <stdio.h>
40#include <str.h>
41#include "tester.h"
42
43bool test_quiet;
44int test_argc;
45char **test_argv;
46
47test_t tests[] = {
48#include "thread/thread1.def"
49#include "print/print1.def"
50#include "print/print2.def"
51#include "print/print3.def"
52#include "print/print4.def"
53#include "print/print5.def"
54#include "console/console1.def"
55#include "stdio/stdio1.def"
56#include "stdio/stdio2.def"
57#include "fault/fault1.def"
58#include "fault/fault2.def"
59#include "fault/fault3.def"
60#include "vfs/vfs1.def"
61#include "ipc/ping_pong.def"
62#include "loop/loop1.def"
63#include "mm/malloc1.def"
64#include "mm/malloc2.def"
65#include "mm/malloc3.def"
66#include "mm/mapping1.def"
67#include "hw/serial/serial1.def"
68#include "hw/misc/virtchar1.def"
69#include "libext2/libext2_1.def"
70 {NULL, NULL, NULL, false}
71};
72
73static bool run_test(test_t *test)
74{
75 /* Execute the test */
76 const char *ret = test->entry();
77
78 if (ret == NULL) {
79 printf("\nTest passed\n");
80 return true;
81 }
82
83 printf("\n%s\n", ret);
84 return false;
85}
86
87static void run_safe_tests(void)
88{
89 test_t *test;
90 unsigned int i = 0;
91 unsigned int n = 0;
92
93 printf("\n*** Running all safe tests ***\n\n");
94
95 for (test = tests; test->name != NULL; test++) {
96 if (test->safe) {
97 printf("%s (%s)\n", test->name, test->desc);
98 if (run_test(test))
99 i++;
100 else
101 n++;
102 }
103 }
104
105 printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
106}
107
108static void list_tests(void)
109{
110 size_t len = 0;
111 test_t *test;
112 for (test = tests; test->name != NULL; test++) {
113 if (str_length(test->name) > len)
114 len = str_length(test->name);
115 }
116
117 unsigned int _len = (unsigned int) len;
118 if ((_len != len) || (((int) _len) < 0)) {
119 printf("Command length overflow\n");
120 return;
121 }
122
123 for (test = tests; test->name != NULL; test++)
124 printf("%-*s %s%s\n", _len, test->name, test->desc,
125 (test->safe ? "" : " (unsafe)"));
126
127 printf("%-*s Run all safe tests\n", _len, "*");
128}
129
130int main(int argc, char *argv[])
131{
132 if (argc < 2) {
133 printf("Usage:\n\n");
134 printf("%s <test> [args ...]\n\n", argv[0]);
135 list_tests();
136 return 0;
137 }
138
139 test_quiet = false;
140 test_argc = argc - 2;
141 test_argv = argv + 2;
142
143 if (str_cmp(argv[1], "*") == 0) {
144 run_safe_tests();
145 return 0;
146 }
147
148 test_t *test;
149 for (test = tests; test->name != NULL; test++) {
150 if (str_cmp(argv[1], test->name) == 0) {
151 return (run_test(test) ? 0 : -1);
152 }
153 }
154
155 printf("Unknown test \"%s\"\n", argv[1]);
156 return -2;
157}
158
159/** @}
160 */
Note: See TracBrowser for help on using the repository browser.