Rev 4602 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4602 | Rev 4687 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2007 Martin Decky |
3 | * Copyright (c) 2007 Martin Decky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup tester User space tester |
30 | /** @addtogroup tester User space tester |
31 | * @brief User space testing infrastructure. |
31 | * @brief User space testing infrastructure. |
32 | * @{ |
32 | * @{ |
33 | */ |
33 | */ |
34 | /** |
34 | /** |
35 | * @file |
35 | * @file |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <unistd.h> |
38 | #include <unistd.h> |
39 | #include <stdio.h> |
39 | #include <stdio.h> |
40 | #include <string.h> |
40 | #include <string.h> |
41 | #include "tester.h" |
41 | #include "tester.h" |
42 | 42 | ||
43 | bool test_quiet; |
43 | bool test_quiet; |
44 | int test_argc; |
44 | int test_argc; |
45 | char **test_argv; |
45 | char **test_argv; |
46 | 46 | ||
47 | test_t tests[] = { |
47 | test_t tests[] = { |
48 | #include "thread/thread1.def" |
48 | #include "thread/thread1.def" |
49 | #include "print/print1.def" |
49 | #include "print/print1.def" |
50 | #include "print/print2.def" |
50 | #include "print/print2.def" |
51 | #include "print/print3.def" |
51 | #include "print/print3.def" |
52 | #include "print/print4.def" |
52 | #include "print/print4.def" |
53 | #include "console/console1.def" |
53 | #include "console/console1.def" |
54 | #include "stdio/stdio1.def" |
54 | #include "stdio/stdio1.def" |
55 | #include "stdio/stdio2.def" |
55 | #include "stdio/stdio2.def" |
56 | #include "fault/fault1.def" |
56 | #include "fault/fault1.def" |
57 | #include "fault/fault2.def" |
57 | #include "fault/fault2.def" |
58 | #include "vfs/vfs1.def" |
58 | #include "vfs/vfs1.def" |
59 | #include "ipc/ping_pong.def" |
59 | #include "ipc/ping_pong.def" |
60 | #include "ipc/register.def" |
60 | #include "ipc/register.def" |
61 | #include "ipc/connect.def" |
61 | #include "ipc/connect.def" |
62 | #include "loop/loop1.def" |
62 | #include "loop/loop1.def" |
63 | #include "mm/malloc1.def" |
63 | #include "mm/malloc1.def" |
64 | {NULL, NULL, NULL, false} |
64 | {NULL, NULL, NULL, false} |
65 | }; |
65 | }; |
66 | 66 | ||
67 | static bool run_test(test_t *test) |
67 | static bool run_test(test_t *test) |
68 | { |
68 | { |
69 | /* Execute the test */ |
69 | /* Execute the test */ |
70 | char *ret = test->entry(); |
70 | char *ret = test->entry(); |
71 | 71 | ||
72 | if (ret == NULL) { |
72 | if (ret == NULL) { |
73 | printf("\nTest passed\n"); |
73 | printf("\nTest passed\n"); |
74 | return true; |
74 | return true; |
75 | } |
75 | } |
76 | 76 | ||
77 | printf("\n%s\n", ret); |
77 | printf("\n%s\n", ret); |
78 | return false; |
78 | return false; |
79 | } |
79 | } |
80 | 80 | ||
81 | static void run_safe_tests(void) |
81 | static void run_safe_tests(void) |
82 | { |
82 | { |
83 | test_t *test; |
83 | test_t *test; |
84 | unsigned int i = 0; |
84 | unsigned int i = 0; |
85 | unsigned int n = 0; |
85 | unsigned int n = 0; |
86 | 86 | ||
87 | printf("\n*** Running all safe tests ***\n\n"); |
87 | printf("\n*** Running all safe tests ***\n\n"); |
88 | 88 | ||
89 | for (test = tests; test->name != NULL; test++) { |
89 | for (test = tests; test->name != NULL; test++) { |
90 | if (test->safe) { |
90 | if (test->safe) { |
91 | printf("%s (%s)\n", test->name, test->desc); |
91 | printf("%s (%s)\n", test->name, test->desc); |
92 | if (run_test(test)) |
92 | if (run_test(test)) |
93 | i++; |
93 | i++; |
94 | else |
94 | else |
95 | n++; |
95 | n++; |
96 | } |
96 | } |
97 | } |
97 | } |
98 | 98 | ||
99 | printf("\nCompleted, %u tests run, %u passed.\n", i + n, i); |
99 | printf("\nCompleted, %u tests run, %u passed.\n", i + n, i); |
100 | } |
100 | } |
101 | 101 | ||
102 | static void list_tests(void) |
102 | static void list_tests(void) |
103 | { |
103 | { |
104 | size_t len = 0; |
104 | size_t len = 0; |
105 | test_t *test; |
105 | test_t *test; |
106 | for (test = tests; test->name != NULL; test++) { |
106 | for (test = tests; test->name != NULL; test++) { |
107 | if (str_length(test->name) > len) |
107 | if (str_length(test->name) > len) |
108 | len = str_length(test->name); |
108 | len = str_length(test->name); |
109 | } |
109 | } |
110 | 110 | ||
111 | for (test = tests; test->name != NULL; test++) |
111 | for (test = tests; test->name != NULL; test++) |
112 | printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
112 | printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
113 | 113 | ||
114 | printf("%-*s Run all safe tests\n", len, "*"); |
114 | printf("%-*s Run all safe tests\n", len, "*"); |
115 | } |
115 | } |
116 | 116 | ||
117 | int main(int argc, char *argv[]) |
117 | int main(int argc, char *argv[]) |
118 | { |
118 | { |
119 | if (argc < 2) { |
119 | if (argc < 2) { |
120 | printf("Usage:\n\n"); |
120 | printf("Usage:\n\n"); |
121 | printf("%s <test> [args ...]\n\n", argv[0]); |
121 | printf("%s <test> [args ...]\n\n", argv[0]); |
122 | list_tests(); |
122 | list_tests(); |
123 | return 0; |
123 | return 0; |
124 | } |
124 | } |
125 | 125 | ||
126 | test_quiet = false; |
126 | test_quiet = false; |
127 | test_argc = argc - 2; |
127 | test_argc = argc - 2; |
128 | test_argv = argv + 2; |
128 | test_argv = argv + 2; |
129 | 129 | ||
130 | if (str_cmp(argv[1], "*") == 0) { |
130 | if (str_cmp(argv[1], "*") == 0) { |
131 | run_safe_tests(); |
131 | run_safe_tests(); |
132 | return 0; |
132 | return 0; |
133 | } |
133 | } |
134 | 134 | ||
135 | test_t *test; |
135 | test_t *test; |
136 | for (test = tests; test->name != NULL; test++) { |
136 | for (test = tests; test->name != NULL; test++) { |
137 | if (str_cmp(argv[1], test->name) == 0) { |
137 | if (str_cmp(argv[1], test->name) == 0) { |
138 | return (run_test(test) ? 0 : -1); |
138 | return (run_test(test) ? 0 : -1); |
139 | } |
139 | } |
140 | } |
140 | } |
141 | 141 | ||
142 | printf("Unknown test \"%s\"\n", argv[1]); |
142 | printf("Unknown test \"%s\"\n", argv[1]); |
143 | return -2; |
143 | return -2; |
144 | } |
144 | } |
145 | 145 | ||
146 | /** @} |
146 | /** @} |
147 | */ |
147 | */ |
148 | 148 |