Subversion Repositories HelenOS

Rev

Rev 4377 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1653 cejka 1
/*
2071 jermar 2
 * Copyright (c) 2006 Ondrej Palkovsky
2188 decky 3
 * Copyright (c) 2007 Martin Decky
1653 cejka 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
 
4692 svoboda 30
/** @addtogroup tester User space tester
31
 * @brief User space testing infrastructure.
1653 cejka 32
 * @{
4692 svoboda 33
 */
1653 cejka 34
/**
35
 * @file
36
 */
37
 
2188 decky 38
#include <unistd.h>
1596 palkovsky 39
#include <stdio.h>
4692 svoboda 40
#include <string.h>
2188 decky 41
#include "tester.h"
1596 palkovsky 42
 
4692 svoboda 43
bool test_quiet;
44
int test_argc;
45
char **test_argv;
1596 palkovsky 46
 
2188 decky 47
test_t tests[] = {
48
#include "thread/thread1.def"
49
#include "print/print1.def"
4692 svoboda 50
#include "print/print2.def"
51
#include "print/print3.def"
4377 svoboda 52
#include "print/print4.def"
4692 svoboda 53
#include "console/console1.def"
54
#include "stdio/stdio1.def"
55
#include "stdio/stdio2.def"
2193 decky 56
#include "fault/fault1.def"
57
#include "fault/fault2.def"
4692 svoboda 58
#include "vfs/vfs1.def"
59
#include "ipc/ping_pong.def"
2188 decky 60
#include "ipc/register.def"
61
#include "ipc/connect.def"
3612 svoboda 62
#include "loop/loop1.def"
4692 svoboda 63
#include "mm/malloc1.def"
2801 svoboda 64
#include "debug/debug1.def"
4692 svoboda 65
    {NULL, NULL, NULL, false}
2188 decky 66
};
1596 palkovsky 67
 
2188 decky 68
static bool run_test(test_t *test)
1596 palkovsky 69
{
2188 decky 70
    /* Execute the test */
4692 svoboda 71
    char *ret = test->entry();
2188 decky 72
 
73
    if (ret == NULL) {
4692 svoboda 74
        printf("\nTest passed\n");
2188 decky 75
        return true;
1596 palkovsky 76
    }
4692 svoboda 77
 
78
    printf("\n%s\n", ret);
2188 decky 79
    return false;
1596 palkovsky 80
}
81
 
2188 decky 82
static void run_safe_tests(void)
1596 palkovsky 83
{
2785 jermar 84
    test_t *test;
2925 svoboda 85
    unsigned int i = 0;
86
    unsigned int n = 0;
4692 svoboda 87
 
2925 svoboda 88
    printf("\n*** Running all safe tests ***\n\n");
4692 svoboda 89
 
2785 jermar 90
    for (test = tests; test->name != NULL; test++) {
91
        if (test->safe) {
4692 svoboda 92
            printf("%s (%s)\n", test->name, test->desc);
2785 jermar 93
            if (run_test(test))
94
                i++;
95
            else
96
                n++;
97
        }
98
    }
4692 svoboda 99
 
100
    printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
1596 palkovsky 101
}
102
 
2188 decky 103
static void list_tests(void)
1596 palkovsky 104
{
4692 svoboda 105
    size_t len = 0;
2188 decky 106
    test_t *test;
4692 svoboda 107
    for (test = tests; test->name != NULL; test++) {
108
        if (str_length(test->name) > len)
109
            len = str_length(test->name);
110
    }
1596 palkovsky 111
 
4692 svoboda 112
    for (test = tests; test->name != NULL; test++)
113
        printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
1596 palkovsky 114
 
4692 svoboda 115
    printf("%-*s Run all safe tests\n", len, "*");
1596 palkovsky 116
}
117
 
4692 svoboda 118
int main(int argc, char *argv[])
1596 palkovsky 119
{
4692 svoboda 120
    if (argc < 2) {
121
        printf("Usage:\n\n");
122
        printf("%s <test> [args ...]\n\n", argv[0]);
123
        list_tests();
124
        return 0;
3425 svoboda 125
    }
4692 svoboda 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);
3424 svoboda 140
        }
1596 palkovsky 141
    }
4692 svoboda 142
 
143
    printf("Unknown test \"%s\"\n", argv[1]);
144
    return -2;
1596 palkovsky 145
}
1653 cejka 146
 
147
/** @}
148
 */