OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [testsuite.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* vi: set sw=4 ts=4: */
2
/*
3
 * Some simple macros for use in test applications.
4
 *
5
 * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
6
 * Copyright (C) 2000,2001 by Erik Andersen <andersen@uclibc.org>
7
 * Written by Erik Andersen <andersen@uclibc.org>
8
 *
9
 * This program is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU Library General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or (at your
12
 * option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
17
 * for more details.
18
 *
19
 * You should have received a copy of the GNU Library General Public License
20
 * along with this program; if not, write to the Free Software Foundation,
21
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
 *
23
 */
24
 
25
#ifndef TESTSUITE_H
26
#define TESTSUITE_H
27
 
28
#ifdef __NO_TESTCODE__
29
 
30
extern size_t test_number;
31
 
32
 
33
extern void init_testsuite(const char* testname);
34
extern void done_testing(void) __attribute__((noreturn));
35
extern void success_msg(int result, const char* command);
36
extern void error_msg(int result, int line, const char* file, const char* command);
37
 
38
#else
39
 
40
 
41
size_t test_number = 0;
42
static int failures = 0;
43
 
44
void error_msg(int result, int line, const char* file, const char* command)
45
{
46
        failures++;
47
 
48
        printf("\nFAILED TEST %d: \n\t%s\n", test_number, command);
49
        printf("AT LINE: %d, FILE: %s\n\n", line, file);
50
}
51
 
52
void success_msg(int result, const char* command)
53
{
54
#if 0
55
        printf("passed test: %s == 0\n", command);
56
#endif  
57
}
58
 
59
void done_testing(void)
60
{
61
    if (0 < failures) {
62
                printf("Failed %d tests\n", failures);
63
                exit(EXIT_FAILURE);
64
        } else {
65
                printf("All functions tested sucessfully\n");
66
                exit( EXIT_SUCCESS );
67
        }
68
}
69
 
70
void init_testsuite(const char* testname)
71
{
72
        printf("%s", testname);
73
        test_number = 0;
74
        failures = 0;
75
        atexit(done_testing);
76
}
77
 
78
#endif
79
 
80
 
81
 
82
#define TEST_STRING_OUTPUT( command, expected_result ) \
83
        do { \
84
                int result=strcmp( command, expected_result); \
85
                test_number++; \
86
                if ( result == expected_result ) { \
87
                        success_msg( result, "command"); \
88
                } else { \
89
                        error_msg(result, __LINE__, __FILE__, command); \
90
                }; \
91
        } while (0)
92
 
93
#define TEST_NUMERIC( command, expected_result ) \
94
        do { \
95
                int result=(command); \
96
                test_number++; \
97
                if ( result == expected_result ) { \
98
                        success_msg( result, # command); \
99
                } else { \
100
                        error_msg(result, __LINE__, __FILE__, # command); \
101
                }; \
102
        } while (0)
103
 
104
#define TEST(command) \
105
        do { \
106
                int result=(command); \
107
                test_number++; \
108
                if ( result == 1) { \
109
                        success_msg( result, # command); \
110
                } else { \
111
                        error_msg(result, __LINE__, __FILE__,  # command ); \
112
                }; \
113
        } while (0)
114
 
115
#define STR_CMD(cmd)    cmd
116
 
117
#endif  /* TESTSUITE_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.