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.
7 #ifndef NATIVE_CLIENT_TESTS_IRT_EXT_LIBC_TEST_H
8 #define NATIVE_CLIENT_TESTS_IRT_EXT_LIBC_TEST_H
10 #include "native_client/src/include/nacl_macros.h"
11 #include "native_client/tests/irt_ext/error_report.h"
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.
19 * For example, having listed OP(Basic), we expect to have in another
20 * compiled .c file somewhere DEFINE_TEST(Basic, ...).
22 #define EXPAND_TEST_OPERATION(OP) \
28 /* This macro specifies the format of our test function name. */
29 #define TEST_FUNC_NAME(TEST_NAME) run_##TEST_NAME##_tests
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) { \
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)) { \
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"); \
51 return NACL_ARRAY_SIZE(TEST_FUNCS_ARRAY) - num_success; \
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)
58 #endif /* NATIVE_CLIENT_TESTS_IRT_EXT_LIBC_TEST_H */