Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / irt_ext / libc / libc_test.h
1 /*
2  * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #ifndef NATIVE_CLIENT_TESTS_IRT_EXT_LIBC_TEST_H
8 #define NATIVE_CLIENT_TESTS_IRT_EXT_LIBC_TEST_H
9
10 #include "native_client/src/include/nacl_macros.h"
11 #include "native_client/tests/irt_ext/error_report.h"
12
13 /*
14  * This macro is used to expand macros for declaring and running the test
15  * functions. It also serves as a central location where all the tests are
16  * listed out. The test names must match the test name when defining tests
17  * using the "DEFINE_TEST" macro below.
18  *
19  * For example, having listed OP(Basic), we expect to have in another
20  * compiled .c file somewhere DEFINE_TEST(Basic, ...).
21  */
22 #define EXPAND_TEST_OPERATION(OP) \
23   OP(Basic);                      \
24   OP(File);                       \
25   OP(Mem);                        \
26   OP(Thread);
27
28 /* This macro specifies the format of our test function name. */
29 #define TEST_FUNC_NAME(TEST_NAME) run_##TEST_NAME##_tests
30
31 /* This macro is used to define the test body. */
32 #define DEFINE_TEST(TEST_NAME, TEST_FUNCS_ARRAY, ENV_TYPE, \
33                     SETUP_FUNC, TEARDOWN_FUNC) \
34   int TEST_FUNC_NAME(TEST_NAME)(void) { \
35     ENV_TYPE env_desc; \
36     int num_success = 0; \
37     irt_ext_test_print("Running %d " #TEST_NAME " Tests...\n", \
38                        NACL_ARRAY_SIZE(TEST_FUNCS_ARRAY)); \
39     for (int i = 0; i < NACL_ARRAY_SIZE(TEST_FUNCS_ARRAY); i++) { \
40       SETUP_FUNC(&env_desc); \
41       if (0 == TEST_FUNCS_ARRAY[i](&env_desc)) { \
42         num_success++; \
43       } \
44       TEARDOWN_FUNC(); \
45     } \
46     irt_ext_test_print(#TEST_NAME " Tests results - %d/%d succeeded.\n", \
47                        num_success, NACL_ARRAY_SIZE(TEST_FUNCS_ARRAY)); \
48     if (num_success < NACL_ARRAY_SIZE(TEST_FUNCS_ARRAY)) { \
49       irt_ext_test_print(#TEST_NAME " Test has Failed.\n"); \
50     } \
51     return NACL_ARRAY_SIZE(TEST_FUNCS_ARRAY) - num_success; \
52   }
53
54 /* The actual declaration of the test functions. */
55 #define TEST_DECLARATION(TEST_NAME) int TEST_FUNC_NAME(TEST_NAME)(void)
56 EXPAND_TEST_OPERATION(TEST_DECLARATION)
57
58 #endif /* NATIVE_CLIENT_TESTS_IRT_EXT_LIBC_TEST_H */