Subversion Repositories HelenOS

Rev

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

Rev 2787 Rev 2799
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 "vfs/vfs1.def"
59
#include "vfs/vfs1.def"
60
#include "tdebug/tdebug1.def"
-
 
61
    {NULL, NULL, NULL}
60
    {NULL, NULL, NULL}
62
};
61
};
63
 
62
 
64
static bool run_test(test_t *test)
63
static bool run_test(test_t *test)
65
{
64
{
66
    printf("%s\t\t%s\n", test->name, test->desc);
65
    printf("%s\t\t%s\n", test->name, test->desc);
67
   
66
   
68
    /* Execute the test */
67
    /* Execute the test */
69
    char * ret = test->entry(false);
68
    char * ret = test->entry(false);
70
   
69
   
71
    if (ret == NULL) {
70
    if (ret == NULL) {
72
        printf("Test passed\n\n");
71
        printf("Test passed\n\n");
73
        return true;
72
        return true;
74
    }
73
    }
75
 
74
 
76
    printf("%s\n\n", ret);
75
    printf("%s\n\n", ret);
77
    return false;
76
    return false;
78
}
77
}
79
 
78
 
80
static void run_safe_tests(void)
79
static void run_safe_tests(void)
81
{
80
{
82
    test_t *test;
81
    test_t *test;
83
    unsigned int i = 0;
-
 
84
    unsigned int n = 0;
82
    int i = 0, n = 0;
85
 
83
 
86
    printf("\n*** Running all safe tests ***\n\n");
84
    printf("\n*** Running all safe tests\n\n");
87
 
85
 
88
    for (test = tests; test->name != NULL; test++) {
86
    for (test = tests; test->name != NULL; test++) {
89
        if (test->safe) {
87
        if (test->safe) {
90
            if (run_test(test))
88
            if (run_test(test))
91
                i++;
89
                i++;
92
            else
90
            else
93
                n++;
91
                n++;
94
        }
92
        }
95
    }
93
    }
96
 
94
 
97
    printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i);
95
    printf("\nSafe tests completed, %d tests run, %d passed.\n\n", i + n, i);
98
}
96
}
99
 
97
 
100
static void list_tests(void)
98
static void list_tests(void)
101
{
99
{
102
    test_t *test;
100
    test_t *test;
103
    char c = 'a';
101
    char c = 'a';
104
   
102
   
105
    for (test = tests; test->name != NULL; test++, c++)
103
    for (test = tests; test->name != NULL; test++, c++)
106
        printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
104
        printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
107
   
105
   
108
    printf("*\t\t\tRun all safe tests\n");
106
    printf("*\t\t\tRun all safe tests\n");
109
}
107
}
110
 
108
 
111
int main(void)
109
int main(void)
112
{
110
{
113
    while (1) {
111
    while (1) {
114
        char c;
112
        char c;
115
        test_t *test;
113
        test_t *test;
116
       
114
       
117
        list_tests();
115
        list_tests();
118
        printf("> ");
116
        printf("> ");
119
       
117
       
120
        c = getchar();
118
        c = getchar();
121
        printf("%c\n", c);
119
        printf("%c\n", c);
122
       
120
       
123
        if ((c >= 'a') && (c <= 'z')) {
121
        if ((c >= 'a') && (c <= 'z')) {
124
            for (test = tests; test->name != NULL; test++, c--)
122
            for (test = tests; test->name != NULL; test++, c--)
125
                if (c == 'a')
123
                if (c == 'a')
126
                    break;
124
                    break;
127
           
125
           
128
            if (c > 'a')
126
            if (c > 'a')
129
                printf("Unknown test\n\n");
127
                printf("Unknown test\n\n");
130
            else
128
            else
131
                run_test(test);
129
                run_test(test);
132
        } else if (c == '*')
130
        } else if (c == '*')
133
            run_safe_tests();
131
            run_safe_tests();
134
        else
132
        else
135
            printf("Invalid test\n\n");
133
            printf("Invalid test\n\n");
136
    }
134
    }
137
}
135
}
138
 
136
 
139
/** @}
137
/** @}
140
 */
138
 */
141
 
139