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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d91a20c was d91a20c, checked in by Jakub Jermar <jakub@…>, 16 years ago

Add a simple test which abort()'s.

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