source: mainline/uspace/app/tester/tester.c@ 992ffa6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 992ffa6 was d9be488, checked in by Martin Decky <martin@…>, 11 years ago

refactor floating point support

  • implement IA-32 and AMD64 specific trunc(), sin(), cos() using x87
  • implement generic trunc() (generic sin(), cos() still missing)
  • trunc(), sin(), cos() tests
  • Property mode set to 100644
File size: 4.2 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 <io/log.h>
42#include "tester.h"
43
44bool test_quiet;
45int test_argc;
46char **test_argv;
47
48test_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 "float/softfloat1.def"
68#include "vfs/vfs1.def"
69#include "ipc/ping_pong.def"
70#include "ipc/starve.def"
71#include "loop/loop1.def"
72#include "mm/malloc1.def"
73#include "mm/malloc2.def"
74#include "mm/malloc3.def"
75#include "mm/mapping1.def"
76#include "hw/serial/serial1.def"
77#include "hw/misc/virtchar1.def"
78 {NULL, NULL, NULL, false}
79};
80
81static bool run_test(test_t *test)
82{
83 /* Execute the test */
84 const char *ret = test->entry();
85
86 if (ret == NULL) {
87 printf("\nTest passed\n");
88 return true;
89 }
90
91 printf("\n%s\n", ret);
92 return false;
93}
94
95static void run_safe_tests(void)
96{
97 test_t *test;
98 unsigned int i = 0;
99 unsigned int n = 0;
100
101 printf("\n*** Running all safe tests ***\n\n");
102
103 for (test = tests; test->name != NULL; test++) {
104 if (test->safe) {
105 printf("%s (%s)\n", test->name, test->desc);
106 if (run_test(test))
107 i++;
108 else
109 n++;
110 }
111 }
112
113 printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
114}
115
116static void list_tests(void)
117{
118 size_t len = 0;
119 test_t *test;
120 for (test = tests; test->name != NULL; test++) {
121 if (str_length(test->name) > len)
122 len = str_length(test->name);
123 }
124
125 unsigned int _len = (unsigned int) len;
126 if ((_len != len) || (((int) _len) < 0)) {
127 printf("Command length overflow\n");
128 return;
129 }
130
131 for (test = tests; test->name != NULL; test++)
132 printf("%-*s %s%s\n", _len, test->name, test->desc,
133 (test->safe ? "" : " (unsafe)"));
134
135 printf("%-*s Run all safe tests\n", _len, "*");
136}
137
138int main(int argc, char *argv[])
139{
140 if (argc < 2) {
141 printf("Usage:\n\n");
142 printf("%s <test> [args ...]\n\n", argv[0]);
143 list_tests();
144 return 0;
145 }
146
147 log_init("tester");
148
149 test_quiet = false;
150 test_argc = argc - 2;
151 test_argv = argv + 2;
152
153 if (str_cmp(argv[1], "*") == 0) {
154 run_safe_tests();
155 return 0;
156 }
157
158 test_t *test;
159 for (test = tests; test->name != NULL; test++) {
160 if (str_cmp(argv[1], test->name) == 0) {
161 return (run_test(test) ? 0 : -1);
162 }
163 }
164
165 printf("Unknown test \"%s\"\n", argv[1]);
166 return -2;
167}
168
169/** @}
170 */
Note: See TracBrowser for help on using the repository browser.