Subversion Repositories HelenOS

Rev

Rev 3022 | Rev 4296 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
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 "tester.h"
40
#include "tester.h"
41
 
41
 
42
int myservice = 0;
42
int myservice = 0;
43
int phones[MAX_PHONES];
43
int phones[MAX_PHONES];
44
int connections[MAX_CONNECTIONS];
44
int connections[MAX_CONNECTIONS];
45
ipc_callid_t callids[MAX_CONNECTIONS];
45
ipc_callid_t callids[MAX_CONNECTIONS];
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 "fault/fault1.def"
50
#include "fault/fault1.def"
51
#include "fault/fault2.def"
51
#include "fault/fault2.def"
52
#include "ipc/register.def"
52
#include "ipc/register.def"
53
#include "ipc/connect.def"
53
#include "ipc/connect.def"
54
#include "ipc/send_async.def"
54
#include "ipc/send_async.def"
55
#include "ipc/send_sync.def"
55
#include "ipc/send_sync.def"
56
#include "ipc/answer.def"
56
#include "ipc/answer.def"
57
#include "ipc/hangup.def"
57
#include "ipc/hangup.def"
58
#include "devmap/devmap1.def"
58
#include "devmap/devmap1.def"
-
 
59
#include "loop/loop1.def"
59
#include "vfs/vfs1.def"
60
#include "vfs/vfs1.def"
-
 
61
#include "console/console1.def"
-
 
62
#include "stdio/stdio1.def"
-
 
63
#include "stdio/stdio2.def"
60
    {NULL, NULL, NULL}
64
    {NULL, NULL, NULL}
61
};
65
};
62
 
66
 
63
static bool run_test(test_t *test)
67
static bool run_test(test_t *test)
64
{
68
{
65
    printf("%s\t\t%s\n", test->name, test->desc);
69
    printf("%s\t\t%s\n", test->name, test->desc);
66
   
70
   
67
    /* Execute the test */
71
    /* Execute the test */
68
    char * ret = test->entry(false);
72
    char * ret = test->entry(false);
69
   
73
   
70
    if (ret == NULL) {
74
    if (ret == NULL) {
71
        printf("Test passed\n\n");
75
        printf("Test passed\n\n");
72
        return true;
76
        return true;
73
    }
77
    }
74
 
78
 
75
    printf("%s\n\n", ret);
79
    printf("%s\n\n", ret);
76
    return false;
80
    return false;
77
}
81
}
78
 
82
 
79
static void run_safe_tests(void)
83
static void run_safe_tests(void)
80
{
84
{
81
    test_t *test;
85
    test_t *test;
82
    unsigned int i = 0;
86
    unsigned int i = 0;
83
    unsigned int n = 0;
87
    unsigned int n = 0;
84
 
88
 
85
    printf("\n*** Running all safe tests ***\n\n");
89
    printf("\n*** Running all safe tests ***\n\n");
86
 
90
 
87
    for (test = tests; test->name != NULL; test++) {
91
    for (test = tests; test->name != NULL; test++) {
88
        if (test->safe) {
92
        if (test->safe) {
89
            if (run_test(test))
93
            if (run_test(test))
90
                i++;
94
                i++;
91
            else
95
            else
92
                n++;
96
                n++;
93
        }
97
        }
94
    }
98
    }
95
 
99
 
96
    printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i);
100
    printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i);
97
}
101
}
98
 
102
 
99
static void list_tests(void)
103
static void list_tests(void)
100
{
104
{
101
    test_t *test;
105
    test_t *test;
102
    char c = 'a';
106
    char c = 'a';
103
   
107
   
104
    for (test = tests; test->name != NULL; test++, c++)
108
    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)"));
109
        printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
106
   
110
   
107
    printf("*\t\t\tRun all safe tests\n");
111
    printf("*\t\t\tRun all safe tests\n");
108
}
112
}
109
 
113
 
110
int main(void)
114
int main(int argc, char **argv)
111
{
115
{
-
 
116
    printf("Number of arguments: %d\n", argc);
-
 
117
    if (argv) {
-
 
118
        printf("Arguments:");
-
 
119
        while (*argv) {
-
 
120
            printf(" '%s'", *argv++);
-
 
121
        }
-
 
122
        printf("\n");
-
 
123
    }
-
 
124
 
112
    while (1) {
125
    while (1) {
113
        char c;
126
        char c;
114
        test_t *test;
127
        test_t *test;
115
       
128
       
116
        list_tests();
129
        list_tests();
117
        printf("> ");
130
        printf("> ");
118
       
131
       
119
        c = getchar();
132
        c = getchar();
120
        printf("%c\n", c);
133
        printf("%c\n", c);
121
       
134
       
122
        if ((c >= 'a') && (c <= 'z')) {
135
        if ((c >= 'a') && (c <= 'z')) {
123
            for (test = tests; test->name != NULL; test++, c--)
136
            for (test = tests; test->name != NULL; test++, c--)
124
                if (c == 'a')
137
                if (c == 'a')
125
                    break;
138
                    break;
126
           
139
           
127
            if (c > 'a')
140
            if (test->name == NULL)
128
                printf("Unknown test\n\n");
141
                printf("Unknown test\n\n");
129
            else
142
            else
130
                run_test(test);
143
                run_test(test);
131
        } else if (c == '*')
144
        } else if (c == '*') {
132
            run_safe_tests();
145
            run_safe_tests();
-
 
146
        } else if (c < 0) {
-
 
147
            /* got EOF */
-
 
148
            break;
133
        else
149
        } else {
134
            printf("Invalid test\n\n");
150
            printf("Invalid test\n\n");
-
 
151
        }
-
 
152
           
135
    }
153
    }
-
 
154
 
-
 
155
    return 0;
136
}
156
}
137
 
157
 
138
/** @}
158
/** @}
139
 */
159
 */
140
 
160