ARC: enable more options to satisfy build requirements of applications
[uclibc-ng.git] / test / testsuite.h
blob84c78156a5bbf163a23a54276c3e765ff7ab89ad
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Some simple macros for use in test applications.
4 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 */
9 #ifndef TESTSUITE_H
10 #define TESTSUITE_H
12 #ifdef __NO_TESTCODE__
13 extern size_t test_number;
14 #endif
16 extern void init_testsuite(const char* testname);
17 extern void done_testing(void) __attribute__((noreturn));
18 extern void success_msg(int result, const char* command);
19 extern void error_msg(int result, int line, const char* file, const char* command);
21 #ifndef __NO_TESTCODE__
23 size_t test_number = 0;
24 static int failures = 0;
26 void error_msg(int result, int line, const char* file, const char* command)
28 failures++;
30 printf("\nFAILED TEST %lu: \n\t%s\nResult: %d",
31 (unsigned long)test_number, command, result);
32 printf("AT LINE: %d, FILE: %s\n\n", line, file);
35 void success_msg(int result __attribute__((unused)), const char* command __attribute__((unused)))
37 #if 0
38 printf("passed test: %s == 0\n", command);
39 #endif
42 void done_testing(void)
44 if (0 < failures) {
45 printf("Failed %d tests\n", failures);
46 exit(EXIT_FAILURE);
47 } else {
48 printf("All functions tested sucessfully\n");
49 exit(EXIT_SUCCESS);
53 void init_testsuite(const char* testname)
55 printf("%s", testname);
56 test_number = 0;
57 failures = 0;
58 #if !defined(__UCLIBC__) || defined(__UCLIBC_DYNAMIC_ATEXIT__)
59 atexit(done_testing);
60 #endif
63 #endif /* __NO_TESTCODE__ */
66 #define TEST_STRING_OUTPUT(command, expected_result) \
67 do { \
68 int result = strcmp(command, expected_result); \
69 test_number++; \
70 if (result == expected_result) { \
71 success_msg(result, "command"); \
72 } else { \
73 error_msg(result, __LINE__, __FILE__, command); \
74 }; \
75 } while (0)
77 #define TEST_NUMERIC(command, expected_result) \
78 do { \
79 int result = (command); \
80 test_number++; \
81 if (result == expected_result) { \
82 success_msg(result, # command); \
83 } else { \
84 error_msg(result, __LINE__, __FILE__, # command); \
85 }; \
86 } while (0)
88 #define TEST(command) \
89 do { \
90 int result = (command); \
91 test_number++; \
92 if (result == 1) { \
93 success_msg(result, # command); \
94 } else { \
95 error_msg(result, __LINE__, __FILE__, # command); \
96 }; \
97 } while (0)
99 #define STR_CMD(cmd) cmd
101 #endif /* TESTSUITE_H */