source: mainline/uspace/app/tester/tester.c@ 51b966b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 51b966b was 51b966b, checked in by Jiri Svoboda <jirik.svoboda@…>, 17 years ago

Make getchar() and tester behave sanely when there's no console.

  • Property mode set to 100644
File size: 3.4 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
[dd655970]30/** @addtogroup tester User space Tester
31 * @brief User space testing infrastructure.
[b2951e2]32 * @{
33 */
34/**
35 * @file
36 */
37
[dd655970]38#include <unistd.h>
[51dbadf3]39#include <stdio.h>
[dd655970]40#include "tester.h"
41
42int myservice = 0;
43int phones[MAX_PHONES];
44int connections[MAX_CONNECTIONS];
45ipc_callid_t callids[MAX_CONNECTIONS];
46
47test_t tests[] = {
48#include "thread/thread1.def"
49#include "print/print1.def"
[be66dee]50#include "fault/fault1.def"
51#include "fault/fault2.def"
[dd655970]52#include "ipc/register.def"
53#include "ipc/connect.def"
[be66dee]54#include "ipc/send_async.def"
55#include "ipc/send_sync.def"
56#include "ipc/answer.def"
57#include "ipc/hangup.def"
[798f364]58#include "devmap/devmap1.def"
[6344851]59#include "vfs/vfs1.def"
[dd655970]60 {NULL, NULL, NULL}
61};
62
63static bool run_test(test_t *test)
[51dbadf3]64{
[dd655970]65 printf("%s\t\t%s\n", test->name, test->desc);
[51dbadf3]66
[dd655970]67 /* Execute the test */
68 char * ret = test->entry(false);
69
70 if (ret == NULL) {
71 printf("Test passed\n\n");
72 return true;
[51dbadf3]73 }
74
[dd655970]75 printf("%s\n\n", ret);
76 return false;
[51dbadf3]77}
78
[dd655970]79static void run_safe_tests(void)
[51dbadf3]80{
[047aa46]81 test_t *test;
[e190a89b]82 unsigned int i = 0;
83 unsigned int n = 0;
[047aa46]84
[e190a89b]85 printf("\n*** Running all safe tests ***\n\n");
[047aa46]86
87 for (test = tests; test->name != NULL; test++) {
88 if (test->safe) {
89 if (run_test(test))
90 i++;
91 else
92 n++;
93 }
94 }
95
[e190a89b]96 printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i);
[51dbadf3]97}
98
[dd655970]99static void list_tests(void)
[51dbadf3]100{
[dd655970]101 test_t *test;
102 char c = 'a';
[51dbadf3]103
[dd655970]104 for (test = tests; test->name != NULL; test++, c++)
105 printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
[51dbadf3]106
[dd655970]107 printf("*\t\t\tRun all safe tests\n");
[51dbadf3]108}
109
110int main(void)
111{
112 while (1) {
[dd655970]113 char c;
114 test_t *test;
115
116 list_tests();
117 printf("> ");
118
[51dbadf3]119 c = getchar();
[dd655970]120 printf("%c\n", c);
121
122 if ((c >= 'a') && (c <= 'z')) {
123 for (test = tests; test->name != NULL; test++, c--)
124 if (c == 'a')
125 break;
126
127 if (c > 'a')
128 printf("Unknown test\n\n");
129 else
130 run_test(test);
[51b966b]131 } else if (c == '*') {
[dd655970]132 run_safe_tests();
[51b966b]133 } else if (c < 0) {
134 /* got EOF */
135 break;
136 } else {
[dd655970]137 printf("Invalid test\n\n");
[51b966b]138 }
139
[51dbadf3]140 }
141}
[b2951e2]142
143/** @}
144 */
Note: See TracBrowser for help on using the repository browser.