diff --git a/src/cmake/modules/CUnit.cmake b/src/cmake/modules/CUnit.cmake index 41d2c6d..85dbee2 100644 --- a/src/cmake/modules/CUnit.cmake +++ b/src/cmake/modules/CUnit.cmake @@ -11,11 +11,194 @@ # find_package(CUnit REQUIRED) -include(Glob) - set(CUNIT_DIR "${CMAKE_CURRENT_LIST_DIR}/CUnit") -function(add_cunit_executable target) + +function(get_cunit_header_file SOURCE_FILE HEADER_FILE) + # Return a unique (but consistent) filename where Theory macros can be + # written. The path that will be returned is the location to a header file + # located in the same relative directory, using the basename of the source + # file postfixed with .h. e.g. /foo/bar.h would be converted to + # /build/foo/bar.h. + get_filename_component(SOURCE_FILE "${SOURCE_FILE}" ABSOLUTE) + file(RELATIVE_PATH SOURCE_FILE "${PROJECT_SOURCE_DIR}" "${SOURCE_FILE}") + get_filename_component(basename "${SOURCE_FILE}" NAME_WE) + get_filename_component(dir "${SOURCE_FILE}" DIRECTORY) + set(${HEADER_FILE} "${CMAKE_BINARY_DIR}/${dir}/${basename}.h" PARENT_SCOPE) +endfunction() + +function(parse_cunit_fixtures INPUT TEST_DISABLED TEST_TIMEOUT) + if(INPUT MATCHES ".disabled${s}*=${s}*([tT][rR][uU][eE]|[0-9]+)") + set(${TEST_DISABLED} "TRUE" PARENT_SCOPE) + else() + set(${TEST_DISABLED} "FALSE" PARENT_SCOPE) + endif() + + if(INPUT MATCHES ".timeout${s}*=${s}*([0-9]+)") + set(${TEST_TIMEOUT} "${CMAKE_MATCH_1}" PARENT_SCOPE) + else() + set(${TEST_TIMEOUT} "0" PARENT_SCOPE) + endif() +endfunction() + +# Parse a single source file, generate a header file with theory definitions +# (if applicable) and return suite and test definitions. +function(process_cunit_source_file SOURCE_FILE HEADER_FILE SUITES TESTS) + set(x "\\*") + set(s "[ \t\r\n]") + set(s_or_x "[ \t\r\n\\*]") + set(w "[_a-zA-Z0-9]") + set(ident_expr "(${s}*${w}+${s}*)") + # Very basic type recognition, only things that contain word characters and + # pointers are handled. And since this script does not actually have to + # compile any code, type checking is left to the compiler. An error (or + # warning) will be thrown if something is off. + # + # The "type" regular expression below will match things like: + # - + # - * + # - * * + set(type_expr "(${s}*${w}+${x}*${s}+${s_or_x}*)+") + set(param_expr "${type_expr}${ident_expr}") + # Test fixture support (based on test fixtures as implemented in Criterion), + # to enable per-test (de)initializers, which is very different from + # per-suite (de)initializers, and timeouts. + # + # The following fixtures are supported: + # - init + # - fini + # - disabled + # - timeout + set(data_expr "(${s}*,${s}*\\.${w}+${s}*=[^,]+)*") + + set(suites_wo_init_n_clean) + set(suites_w_init) + set(suites_w_clean) + + file(READ "${SOURCE_FILE}" content) + + # CU_Init and CU_Clean + # + # Extract all suite initializers and deinitializers so that the list of + # suites can be probably populated when tests and theories are parsed. Suites + # are only registered if it contains at least one test or theory. + set(suite_expr "CU_(Init|Clean)${s}*\\(${ident_expr}\\)") + string(REGEX MATCHALL "${suite_expr}" matches "${content}") + foreach(match ${matches}) + string(REGEX REPLACE "${suite_expr}" "\\2" suite "${match}") + + if("${match}" MATCHES "CU_Init") + list(APPEND suites_w_init ${suite}) + elseif("${match}" MATCHES "CU_Clean") + list(APPEND suites_w_deinit ${suite}) + endif() + endforeach() + + # CU_Test + set(test_expr "CU_Test${s}*\\(${ident_expr},${ident_expr}${data_expr}\\)") + string(REGEX MATCHALL "${test_expr}" matches "${content}") + foreach(match ${matches}) + string(REGEX REPLACE "${test_expr}" "\\1" suite "${match}") + string(REGEX REPLACE "${test_expr}" "\\2" test "${match}") + # Remove leading and trailing whitespace + string(STRIP "${suite}" suite) + string(STRIP "${test}" test) + + # Extract fixtures that must be handled by CMake (.disabled and .timeout). + parse_cunit_fixtures("${match}" disabled timeout) + list(APPEND suites_wo_init_n_clean "${suite}") + list(APPEND tests "${suite}:${test}:${disabled}:${timeout}") + endforeach() + + # CU_Theory + # + # CU_Theory signatures must be recognized in order to generate structures to + # hold the CU_DataPoints declarations. The generated type is added to the + # compile definitions and inserted by the preprocessor when CU_TheoryDataPoints + # is expanded. + # + # NOTE: Since not all compilers support pushing function-style definitions + # from the command line (CMake will generate a warning too), a header + # file is generated instead. A define is pushed and expanded at + # compile time. It is included by CUnit/Theory.h. + get_cunit_header_file("${SOURCE_FILE}" header) + + set(theory_expr "CU_Theory${s}*\\(${s}*\\((${param_expr}(,${param_expr})*)\\)${s}*,${ident_expr},${ident_expr}${data_expr}\\)") + string(REGEX MATCHALL "${theory_expr}" matches "${content}") + foreach(match ${matches}) + if(NOT theories) + # Ensure generated header is truncated before anything is written. + file(WRITE "${header}" "") + endif() + string(REGEX REPLACE "${theory_expr}" "\\1" params "${match}") + string(REGEX REPLACE "${theory_expr}" "\\7" suite "${match}") + string(REGEX REPLACE "${theory_expr}" "\\8" test "${match}") + # Remove leading and trailing whitespace + string(STRIP "${params}" params) + string(STRIP "${suite}" suite) + string(STRIP "${test}" test) + # Convert parameters from a string to a list + string(REGEX REPLACE "${s}*,${s}*" ";" params "${params}") + + # Extract fixtures that must be handled by CMake (.disabled and .timeout) + parse_cunit_fixtures("${match}" disabled timeout) + list(APPEND suites_wo_init_n_clean "${suite}") + list(APPEND theories "${suite}:${test}:${disabled}:${timeout}") + + set(sep) + set(size "CU_TheoryDataPointsSize_${suite}_${test}(datapoints) (") + set(slice "CU_TheoryDataPointsSlice_${suite}_${test}(datapoints, index) (") + set(typedef "CU_TheoryDataPointsTypedef_${suite}_${test}() {") + foreach(param ${params}) + string( + REGEX REPLACE "(${type_expr})${ident_expr}" "\\3" name "${param}") + string( + REGEX REPLACE "(${type_expr})${ident_expr}" "\\1" type "${param}") + string(STRIP "${name}" name) + string(STRIP "${type}" type) + + set(slice "${slice}${sep} datapoints.${name}.p[index]") + if (NOT sep) + set(size "${size} datapoints.${name}.n") + set(sep ",") + endif() + set(typedef "${typedef} struct { size_t n; ${type} *p; } ${name};") + endforeach() + set(typedef "${typedef} }") + set(slice "${slice} )") + set(size "${size} )") + + file(APPEND "${header}" "#define ${size}\n") + file(APPEND "${header}" "#define ${slice}\n") + file(APPEND "${header}" "#define ${typedef}\n") + endforeach() + + # Propagate suites, tests and theories extracted from the source file. + list(REMOVE_DUPLICATES suites_wo_init_n_clean) + list(SORT suites_wo_init_n_clean) + foreach(suite ${suites_wo_init_n_clean}) + set(init "FALSE") + set(clean "FALSE") + if(${suite} IN_LIST suites_w_init) + set(init "TRUE") + endif() + if(${suite} IN_LIST suites_w_deinit) + set(clean "TRUE") + endif() + + list(APPEND suites "${suite}:${init}:${clean}") + endforeach() + + if(theories) + set(${HEADER_FILE} "${header}" PARENT_SCOPE) + else() + unset(${HEADER_FILE} PARENT_SCOPE) + endif() + set(${SUITES} ${suites} PARENT_SCOPE) + set(${TESTS} ${tests};${theories} PARENT_SCOPE) +endfunction() + +function(add_cunit_executable TARGET) # Retrieve location of shared libary, which is need to extend the PATH # environment variable on Microsoft Windows, so that the operating # system can locate the .dll that it was linked against. @@ -24,129 +207,103 @@ function(add_cunit_executable target) get_target_property(CUNIT_IMPORTED_LOCATION CUnit IMPORTED_LOCATION) get_filename_component(CUNIT_LIBRARY_DIR "${CUNIT_IMPORTED_LOCATION}" PATH) - # Generate semi-random filename to store the generated code in to avoid - # possible naming conflicts. - string(RANDOM random) - set(runner "${target}_${random}") + set(decls) + set(defns) + set(sources) - set(s "[ \t\r\n]") # space - set(w "[0-9a-zA-Z_]") # word - set(param "${s}*(${w}+)${s}*") - set(pattern "CUnit_${w}+${s}*\\(${param}(,${param}(,${param})?)?\\)") + foreach(source ${ARGN}) + if((EXISTS "${source}" OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")) + unset(suites) + unset(tests) - glob(filenames "c" ${ARGN}) + process_cunit_source_file("${source}" header suites tests) + if(header) + set_property( + SOURCE "${source}" + PROPERTY COMPILE_DEFINITIONS CU_THEORY_INCLUDE_FILE=\"${header}\") + endif() - foreach(filename ${filenames}) - file(READ "${filename}" contents) - string(REGEX MATCHALL "${pattern}" captures "${contents}") + # Disable missing-field-initializers warnings as not having to specify + # every member, aka fixture, is intended behavior. + if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR + ${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang" OR + ${CMAKE_C_COMPILER_ID} STREQUAL "GNU") + set_property( + SOURCE "${source}" + PROPERTY COMPILE_FLAGS -Wno-missing-field-initializers) + endif() - list(APPEND sources "${filename}") - list(LENGTH captures length) - if(length) - foreach(capture ${captures}) - string(REGEX REPLACE "${pattern}" "\\1" suite "${capture}") + foreach(suite ${suites}) + string(REPLACE ":" ";" suite ${suite}) + list(GET suite 2 clean) + list(GET suite 1 init) + list(GET suite 0 suite) + set(init_func "NULL") + set(clean_func "NULL") + if(init) + set(decls "${decls}\nCU_InitDecl(${suite});") + set(init_func "CU_InitName(${suite})") + endif() + if(clean) + set(decls "${decls}\nCU_CleanDecl(${suite});") + set(clean_func "CU_CleanName(${suite})") + endif() + set(defns "${defns}\nADD_SUITE(${suite}, ${init_func}, ${clean_func});") + endforeach() - if("${capture}" MATCHES "CUnit_Suite_Initialize") - list(APPEND suites ${suite}) - list(APPEND suites_w_init ${suite}) - elseif("${capture}" MATCHES "CUnit_Suite_Cleanup") - list(APPEND suites ${suite}) - list(APPEND suites_w_deinit ${suite}) - elseif("${capture}" MATCHES "CUnit_Test") - list(APPEND suites ${suite}) + foreach(test ${tests}) + string(REPLACE ":" ";" test ${test}) + list(GET test 3 timeout) + list(GET test 2 disabled) + list(GET test 0 suite) + list(GET test 1 test) - # Specifying a test name is mandatory - if("${capture}" MATCHES ",") - string(REGEX REPLACE "${pattern}" "\\3" test "${capture}") - else() - message(FATAL_ERROR "Bad CUnit_Test signature in ${filename}") - endif() + set(enable "true") + if(disabled) + set(enable "false") + endif() + if(NOT timeout) + set(timeout 10) + endif() - # Specifying if a test is enabled is optional - set(enable "true") - if("${capture}" MATCHES ",${param},") - string(REGEX REPLACE "${pattern}" "\\5" enable "${capture}") - endif() + set(decls "${decls}\nCU_TestDecl(${suite}, ${test});") + set(defns "${defns}\nADD_TEST(${suite}, ${test}, ${enable});") + set(ctest "CUnit_${suite}_${test}") - if((NOT "${enable}" STREQUAL "true") AND - (NOT "${enable}" STREQUAL "false")) - message(FATAL_ERROR "Bad CUnit_Test signature in ${filename}") - endif() - - list(APPEND tests "${suite}:${test}:${enable}") - else() - message(FATAL_ERROR "Bad CUnit signature in ${filename}") + add_test( + NAME ${ctest} + COMMAND ${TARGET} -a -r "${suite}-${test}" -s ${suite} -t ${test}) + set_property(TEST ${ctest} PROPERTY TIMEOUT ${timeout}) + set_property(TEST ${ctest} PROPERTY DISABLED ${disabled}) + if(APPLE) + set_property( + TEST ${ctest} + PROPERTY ENVIRONMENT + "DYLD_LIBRARY_PATH=${CUNIT_LIBRARY_DIR}:$ENV{DYLD_LIBRARY_PATH}") + elseif(WIN32 AND ${CUNIT_LIBRARY_TYPE} STREQUAL "SHARED_LIBRARY") + set_property( + TEST ${ctest} + PROPERTY ENVIRONMENT + "PATH=${CUNIT_LIBRARY_DIR};$ENV{PATH}") endif() endforeach() + + list(APPEND sources "${source}") endif() endforeach() - # Test suite signatures can be decided on only after everything is parsed. - set(lf "\n") - set(declf "") - set(deflf "") - - list(REMOVE_DUPLICATES suites) - list(SORT suites) - foreach(suite ${suites}) - set(init "NULL") - set(deinit "NULL") - if(${suite} IN_LIST suites_w_init) - set(init "CUnit_Suite_Initialize__(${suite})") - set(decls "${decls}${declf}CUnit_Suite_Initialize_Decl__(${suite});") - set(declf "${lf}") - endif() - if(${suite} IN_LIST suites_w_deinit) - set(deinit "CUnit_Suite_Cleanup__(${suite})") - set(decls "${decls}${declf}CUnit_Suite_Cleanup_Decl__(${suite});") - set(declf "${lf}") - endif() - - set(defs "${defs}${deflf}CUnit_Suite__(${suite}, ${init}, ${deinit});") - set(deflf "${lf}") - endforeach() - - list(REMOVE_DUPLICATES tests) - list(SORT tests) - foreach(entry ${tests}) - string(REPLACE ":" ";" entry ${entry}) - list(GET entry 0 suite) - list(GET entry 1 test) - list(GET entry 2 enable) - - set(decls "${decls}${declf}CUnit_Test_Decl__(${suite}, ${test});") - set(declf "${lf}") - set(defs "${defs}${deflf}CUnit_Test__(${suite}, ${test}, ${enable});") - set(deflf "${lf}") - - add_test( - NAME "CUnit_${suite}_${test}" - COMMAND ${target} -a -r "${suite}-${test}" -s ${suite} -t ${test}) - set_tests_properties("CUnit_${suite}_${test}" PROPERTIES TIMEOUT 10) - if(APPLE) - set_property( - TEST "CUnit_${suite}_${test}" - PROPERTY ENVIRONMENT "DYLD_LIBRARY_PATH=${CUNIT_LIBRARY_DIR}:$ENV{DYLD_LIBRARY_PATH}") - endif() - if(WIN32 AND ${CUNIT_LIBRARY_TYPE} STREQUAL "SHARED_LIBRARY") - set_property( - TEST "CUnit_${suite}_${test}" - PROPERTY ENVIRONMENT "PATH=${CUNIT_LIBRARY_DIR};$ENV{PATH}") - endif() - endforeach() - - set(root "${CUNIT_DIR}") - set(CUnit_Decls "${decls}") - set(CUnit_Defs "${defs}") - - configure_file("${root}/src/main.c.in" "${runner}.c" @ONLY) - add_executable(${target} "${runner}.c" "${root}/src/runner.c" ${sources}) - target_link_libraries(${target} CUnit) - target_include_directories(${target} PRIVATE "${root}/include") + configure_file( + "${CUNIT_DIR}/src/main.c.in" "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.c" @ONLY) if("2.1.3" VERSION_LESS_EQUAL "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}.${CUNIT_VERSION_PATCH}") - set_source_files_properties( - "${root}/src/runner.c" PROPERTIES COMPILE_DEFINITIONS HAVE_ENABLE_JUNIT_XML) + set_property( + SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.c" + PROPERTY COMPILE_DEFINITIONS HAVE_ENABLE_JUNIT_XML) endif() + + add_executable( + ${TARGET} "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.c" ${sources}) + target_link_libraries(${TARGET} CUnit) + target_include_directories(${TARGET} PRIVATE "${CUNIT_DIR}/include") endfunction() diff --git a/src/cmake/modules/CUnit/include/CUnit/Runner.h b/src/cmake/modules/CUnit/include/CUnit/Runner.h deleted file mode 100644 index e7cc113..0000000 --- a/src/cmake/modules/CUnit/include/CUnit/Runner.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License - * v. 1.0 which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ -#ifndef CUNIT_RUNNER_H -#define CUNIT_RUNNER_H - -#include -#include -#include - -#if defined (__cplusplus) -extern "C" { -#endif - -#define CUnit_Suite_Initialize_Name__(s) \ - s ## _Initialize -#define CUnit_Suite_Initialize(s) \ - int CUnit_Suite_Initialize_Name__(s)(void) -#define CUnit_Suite_Initialize_Decl__(s) \ - extern CUnit_Suite_Initialize(s) -#define CUnit_Suite_Initialize__(s) \ - CUnit_Suite_Initialize_Name__(s) - -#define CUnit_Suite_Cleanup_Name__(s) \ - s ## _Cleanup -#define CUnit_Suite_Cleanup(s) \ - int CUnit_Suite_Cleanup_Name__(s)(void) -#define CUnit_Suite_Cleanup_Decl__(s) \ - extern CUnit_Suite_Cleanup(s) -#define CUnit_Suite_Cleanup__(s) \ - CUnit_Suite_Cleanup_Name__(s) - -#define CUnit_Test_Name__(s, t) \ - s ## _ ## t -#define CUnit_Test(s, t, ...) \ - void CUnit_Test_Name__(s, t)(void) -#define CUnit_Test_Decl__(s, t) \ - extern CUnit_Test(s, t) - -#define CUnit_Suite__(s, c, d) \ - cu_runner_add_suite(#s, c, d) -#define CUnit_Test__(s, t, e) \ - cu_runner_add_test(#s, #t, CUnit_Test_Name__(s, t), e) - -CU_ErrorCode -cu_runner_init( - int argc, - char *argv[]); - -void -cu_runner_fini( - void); - -void -cu_runner_add_suite( - const char *suite, - CU_InitializeFunc pInitFunc, - CU_CleanupFunc pCleanFunc); - -void -cu_runner_add_test( - const char *suite, - const char *test, - CU_TestFunc pTestFunc, - bool enable); - -CU_ErrorCode -cu_runner_run( - void); - -#if defined (__cplusplus) -} -#endif - -#endif /* CUNIT_RUNNER_H */ diff --git a/src/cmake/modules/CUnit/include/CUnit/Test.h b/src/cmake/modules/CUnit/include/CUnit/Test.h new file mode 100644 index 0000000..4e9f2d4 --- /dev/null +++ b/src/cmake/modules/CUnit/include/CUnit/Test.h @@ -0,0 +1,93 @@ +#ifndef CUNIT_TEST_H +#define CUNIT_TEST_H + +#include +#include +#include + +#if defined (__cplusplus) +extern "C" { +#endif + +typedef void(*cu_test_init_func_t)(void); +typedef void(*cu_test_fini_func_t)(void); + +typedef struct { + cu_test_init_func_t init; + cu_test_fini_func_t fini; + int disabled; /* Parsed by CMake, used at test registration in main. */ + int timeout; /* Parsed by CMake, used at test registration in CMake. */ +} cu_data_t; + +#define CU_InitName(suite) \ + CU_Init_ ## suite +#define CU_CleanName(suite) \ + CU_Fini_ ## suite +#define CU_TestName(suite, test) \ + CU_Test_ ## suite ## _ ## test +#define CU_TestProxyName(suite, test) \ + CU_TestProxy_ ## suite ## _ ## test + +#define CU_Init(suite) \ + int CU_InitName(suite)(void) +#define CU_InitDecl(suite) \ + extern CU_Init(suite) + +#define CU_Clean(suite) \ + int CU_CleanName(suite)(void) +#define CU_CleanDecl(suite) \ + extern CU_Clean(suite) + +/* CU_Test generates a wrapper function that takes care of per-test + initialization and deinitialization, if provided in the CU_Test + signature. */ +#define CU_Test(suite, test, ...) \ + static void CU_TestName(suite, test)(void); \ + \ + void CU_TestProxyName(suite, test)(void) { \ + cu_data_t data = CU_Fixture(__VA_ARGS__); \ + \ + if (data.init != NULL) { \ + data.init(); \ + } \ + \ + CU_TestName(suite, test)(); \ + \ + if (data.fini != NULL) { \ + data.fini(); \ + } \ + } \ + \ + static void CU_TestName(suite, test)(void) + +#define CU_TestDecl(suite, test) \ + extern void CU_TestProxyName(suite, test)(void) + +/* Microsoft Visual Studio does not like empty struct initializers, i.e. + no fixtures are specified. To work around that issue CU_Fixture inserts a + NULL initializer as fall back. */ +#define CU_Comma() , +#define CU_Reduce(one, ...) one + +#ifdef _WIN32 +/* Microsoft Visual Studio does not expand __VA_ARGS__ correctly. */ +#define CU_Fixture__(...) CU_Fixture____((__VA_ARGS__)) +#define CU_Fixture____(tuple) CU_Fixture___ tuple +#else +#define CU_Fixture__(...) CU_Fixture___(__VA_ARGS__) +#endif /* _WIN32 */ + +#define CU_Fixture___(throw, away, value, ...) value + +#define CU_Fixture(...) \ + CU_Fixture_( CU_Comma CU_Reduce(__VA_ARGS__,) (), __VA_ARGS__ ) + +#define CU_Fixture_(throwaway, ...) \ + CU_Fixture__(throwaway, ((cu_data_t){ 0 }), ((cu_data_t){ __VA_ARGS__ })) + +#if defined (__cplusplus) +} +#endif + +#endif /* CUNIT_TEST_H */ + diff --git a/src/cmake/modules/CUnit/include/CUnit/Theory.h b/src/cmake/modules/CUnit/include/CUnit/Theory.h new file mode 100644 index 0000000..81dd7f7 --- /dev/null +++ b/src/cmake/modules/CUnit/include/CUnit/Theory.h @@ -0,0 +1,72 @@ +#ifndef CUNIT_THEORY_H +#define CUNIT_THEORY_H + +/* Function-style macros cannot be defined on the command line. */ +#ifdef CU_THEORY_INCLUDE_FILE +#include CU_THEORY_INCLUDE_FILE +#endif + +#include "CUnit/Test.h" + + +#if defined (__cplusplus) +extern "C" { +#endif + +#define CU_TheoryDataPointsName(suite, test) \ + CU_TheoryDataPoints_ ## suite ## _ ## test + +#define CU_TheoryDataPointsTypeName(suite, test) \ + CU_TheoryDataPointsType_ ## suite ## _ ## test + +#define CU_TheoryDataPointsSize(suite, test) \ + CU_TheoryDataPointsSize_ ## suite ## _ ## test ( \ + CU_TheoryDataPointsName(suite, test)) + +#define CU_TheoryDataPointsSlice(suite, test, index) \ + CU_TheoryDataPointsSlice_ ## suite ## _ ## test ( \ + CU_TheoryDataPointsName(suite, test), index) + +#define CU_TheoryDataPointsTypedef(suite, test) \ + CU_TheoryDataPointsTypedef_ ## suite ## _ ## test() + +#define CU_TheoryDataPoints(suite, test) \ + struct CU_TheoryDataPointsTypeName(suite, test) \ + CU_TheoryDataPointsTypedef(suite, test) ; \ + \ + static struct CU_TheoryDataPointsTypeName(suite, test) \ + CU_TheoryDataPointsName(suite, test) + +#define CU_DataPoints(type, ...) { \ + .p = (type[]) { __VA_ARGS__ }, \ + .n = (sizeof((type[]) { __VA_ARGS__ }) / sizeof(type)) \ + } + +#define CU_Theory(signature, suite, test, ...) \ + static void CU_TestName(suite, test) signature; \ + \ + void CU_TestProxyName(suite, test)(void) { \ + cu_data_t data = CU_Fixture(__VA_ARGS__); \ + size_t i, n; \ + \ + if (data.init != NULL) { \ + data.init(); \ + } \ + \ + for (i = 0, n = CU_TheoryDataPointsSize(suite, test); i < n; i++) { \ + CU_TestName(suite, test) CU_TheoryDataPointsSlice(suite, test, i) ; \ + } \ + \ + if (data.fini != NULL) { \ + data.fini(); \ + } \ + } \ + \ + static void CU_TestName(suite, test) signature + +#if defined (__cplusplus) +} +#endif + +#endif /* CUNIT_THEORY_H */ + diff --git a/src/cmake/modules/CUnit/src/main.c.in b/src/cmake/modules/CUnit/src/main.c.in index 8cf3042..2be3165 100644 --- a/src/cmake/modules/CUnit/src/main.c.in +++ b/src/cmake/modules/CUnit/src/main.c.in @@ -9,23 +9,235 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include +#include +#include -@CUnit_Decls@ +#ifndef _WIN32 +#include +#else +#define EX_USAGE (64) +#define EX_SOFTWARE (70) +#endif /* _WIN32 */ -int main (int argc, char *argv[]) +#include +#include +#include "CUnit/Test.h" + +static struct { + bool print_help; + bool automated; + bool junit; + const char *results; + CU_BasicRunMode mode; + CU_ErrorAction error_action; + const char *suite; + const char *test; +} opts = { + false, + false, + false, + NULL, + CU_BRM_NORMAL, + CUEA_IGNORE, + "*", + "*" +}; + +static int patmatch(const char *pat, const char *str) { - CU_ErrorCode err; - - if ((err = cu_runner_init(argc, argv))) { - goto err_init; + while (*pat) { + if (*pat == '?') { + /* any character will do */ + if (*str++ == 0) { + return 0; + } + pat++; + } else if (*pat == '*') { + /* collapse a sequence of wildcards, requiring as many + characters in str as there are ?s in the sequence */ + while (*pat == '*' || *pat == '?') { + if (*pat == '?' && *str++ == 0) { + return 0; + } + pat++; + } + /* try matching on all positions where str matches pat */ + while (*str) { + if (*str == *pat && patmatch(pat+1, str+1)) { + return 1; + } + str++; + } + return *pat == 0; + } else { + /* only an exact match */ + if (*str++ != *pat++) { + return 0; + } + } } -@CUnit_Defs@ - - err = cu_runner_run(); - cu_runner_fini(); -err_init: - return (int)err; + return *str == 0; +} + +static void usage(const char *name) +{ + fprintf(stderr, "Usage: %s OPTIONS\n", name); + fprintf(stderr, "Try '%s -h' for more information\n", name); +} + +static void help(const char *name) +{ + printf("Usage: %s [OPTIONS]\n", name); + printf("\n"); + printf("Possible options:\n"); + printf(" -a run in automated mode\n"); + printf(" -f fail fast\n"); + printf(" -h display this help and exit\n"); + printf(" -j junit format results \n"); + printf(" -r FILENAME results file for automated run\n"); + printf(" -s PATTERN run only tests in suites matching pattern\n"); + printf(" -t PATTERN run only test matching pattern\n"); + printf("\n"); + printf("Exit codes:\n"); + printf(" %-2d Successful termination\n", EXIT_SUCCESS); + printf(" %-2d One or more failing test cases\n", EXIT_FAILURE); + printf(" %-2d Command line usage error\n", EX_USAGE); + printf(" %-2d Internal software error\n", EX_SOFTWARE); +} + +static int parse_options(int argc, char *argv[]) +{ + int err = 0; + + for (int i = 1; err == 0 && i < argc; i++) { + switch ((argv[i][0] == '-') ? argv[i][1] : 0) { + case 'a': + opts.automated = true; + break; + case 'f': + opts.error_action = CUEA_FAIL; + break; + case 'h': + opts.print_help = true; + break; + case 'j': + opts.junit = true; + break; + case 'r': + if((i+1) < argc){ + opts.results = argv[++i]; + break; + } + /* FALLS THROUGH */ + case 's': + if ((i+1) < argc) { + opts.suite = argv[++i]; + break; + } + /* FALLS THROUGH */ + case 't': + if ((i+1) < argc) { + opts.test = argv[++i]; + break; + } + /* FALLS THROUGH */ + default: + err = 1; + break; + } + } + + return err; +} + +static void +add_suite( + const char *suite, + CU_InitializeFunc pInitFunc, + CU_CleanupFunc pCleanFunc) +{ + CU_pSuite pSuite; + + pSuite = CU_get_suite(suite); + if (pSuite == NULL) { + pSuite = CU_add_suite(suite, pInitFunc, pCleanFunc); + CU_set_suite_active(pSuite, patmatch(opts.suite, suite)); + } +} + +#define ADD_SUITE(suite, init, clean) \ + add_suite(#suite, init, clean) + +static void +add_test( + const char *suite, + const char *test, + CU_TestFunc pTestFunc, + bool enable) +{ + CU_pSuite pSuite; + CU_pTest pTest; + + pSuite = CU_get_suite(suite); + pTest = CU_add_test(pSuite, test, pTestFunc); + CU_set_test_active(pTest, enable && patmatch(opts.test, test)); +} + +#define ADD_TEST(suite, test, enable) \ + add_test(#suite, #test, CU_TestProxyName(suite, test), enable) + +/* CMake will expand the macro below to declare generated functions. */ +@decls@ + +int main(int argc, char *argv[]) +{ + int ret = EXIT_SUCCESS; + + if (parse_options(argc, argv) != 0) { + usage(argv[0]); + return EX_USAGE; + } else if (opts.print_help) { + help(argv[0]); + return ret; + } else if (CU_initialize_registry() != CUE_SUCCESS) { + fprintf(stderr, "CU_initialize_registry: %s\n", CU_get_error_msg()); + return EX_SOFTWARE; + } + +/* CMake will expand the macro below to register all suites and tests. */ +@defns@ + + CU_set_error_action(opts.error_action); + + if (opts.automated) { + if (opts.results != NULL) { + CU_set_output_filename(opts.results); + } + +#if defined(HAVE_ENABLE_JUNIT_XML) + if (opts.junit) { + CU_automated_enable_junit_xml(CU_TRUE); + } else +#endif + { + CU_list_tests_to_file(); + } + CU_automated_run_tests(); + } else { + CU_basic_set_mode(opts.mode); + CU_basic_run_tests(); + } + + if (CU_get_error() != CUE_SUCCESS) { + ret = EX_SOFTWARE; + } else if (CU_get_number_of_failures() != 0) { + ret = EXIT_FAILURE; + } + + CU_cleanup_registry(); + + return ret; } diff --git a/src/cmake/modules/CUnit/src/runner.c b/src/cmake/modules/CUnit/src/runner.c deleted file mode 100644 index 266d5b6..0000000 --- a/src/cmake/modules/CUnit/src/runner.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License - * v. 1.0 which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ -#include -#include - -#include "CUnit/Runner.h" - -static struct cunit_runner { - bool automated; - bool junit; - const char * results; - CU_BasicRunMode mode; - CU_ErrorAction error_action; - const char *suite; - const char *test; -} runner; - -static void -usage( - const char * name) -{ - fprintf(stderr, "usage: %s [flags]\n", name); - fprintf(stderr, "Supported flags:\n"); - fprintf(stderr, " -a run in automated mode\n"); - fprintf(stderr, " -r results file for automated run\n"); - fprintf(stderr, " -j junit format results \n"); - fprintf(stderr, " -f fail fast \n"); - fprintf(stderr, " -s suite\n"); - fprintf(stderr, " -t test\n"); -} - -int -patmatch( - const char *pat, - const char *str) -{ - while (*pat) { - if (*pat == '?') { - /* any character will do */ - if (*str++ == 0) { - return 0; - } - pat++; - } else if (*pat == '*') { - /* collapse a sequence of wildcards, requiring as many - characters in str as there are ?s in the sequence */ - while (*pat == '*' || *pat == '?') { - if (*pat == '?' && *str++ == 0) { - return 0; - } - pat++; - } - /* try matching on all positions where str matches pat */ - while (*str) { - if (*str == *pat && patmatch(pat+1, str+1)) { - return 1; - } - str++; - } - return *pat == 0; - } else { - /* only an exact match */ - if (*str++ != *pat++) { - return 0; - } - } - } - - return *str == 0; -} - -CU_ErrorCode -cu_runner_init( - int argc, - char* argv[]) -{ - int c, i; - CU_ErrorCode e = CUE_SUCCESS; - - runner.automated = false; - runner.junit = false; - runner.results = NULL; - runner.mode = CU_BRM_NORMAL; - runner.error_action = CUEA_IGNORE; - runner.suite = "*"; - runner.test = "*"; - - for (i = 1; e == CUE_SUCCESS && i < argc; i++) { - c = (argv[i][0] == '-') ? argv[i][1] : -1; - switch (c) { - case 'a': - runner.automated = true; - break; - case 'f': - runner.error_action = CUEA_FAIL; - break; - case 'j': - runner.junit = true; - break; - case 'r': - if((i+1) < argc){ - runner.results = argv[++i]; - break; - } - /* FALLS THROUGH */ - case 's': - if ((i+1) < argc) { - runner.suite = argv[++i]; - break; - } - /* FALLS THROUGH */ - case 't': - if ((i+1) < argc) { - runner.test = argv[++i]; - break; - } - /* FALLS THROUGH */ - default: - e = (CU_ErrorCode)256; - CU_set_error(e); /* Will print as "Undefined Errpr" */ - usage(argv[0]); - break; - } - } - - if (e == CUE_SUCCESS) { - if ((e = CU_initialize_registry()) != CUE_SUCCESS) { - fprintf( - stderr, "Test registry initialization failed: %s\n", CU_get_error_msg()); - } - } - - CU_set_error_action (runner.error_action); - - return e; -} - -void -cu_runner_fini( - void) -{ - CU_cleanup_registry(); -} - -void -cu_runner_add_suite( - const char *suite, - CU_InitializeFunc pInitFunc, - CU_CleanupFunc pCleanFunc) -{ - CU_pSuite pSuite; - - pSuite = CU_get_suite(suite); - if (pSuite == NULL) { - pSuite = CU_add_suite(suite, pInitFunc, pCleanFunc); - //assert(pSuite != NULL); - CU_set_suite_active(pSuite, patmatch(runner.suite, suite)); - } -} - -void -cu_runner_add_test( - const char *suite, - const char *test, - CU_TestFunc pTestFunc, - bool enable) -{ - CU_pSuite pSuite; - CU_pTest pTest; - - pSuite = CU_get_suite(suite); - //assert(pSuite != NULL); - pTest = CU_add_test(pSuite, test, pTestFunc); - //assert(pTest != NULL); - CU_set_test_active(pTest, enable && patmatch(runner.test, test)); -} - -CU_ErrorCode -cu_runner_run( - void) -{ - if (runner.automated) { - /* Generate CUnit or JUnit format results */ - if (runner.results != NULL) { - CU_set_output_filename(runner.results); - } - - if (runner.junit) { -#if defined(HAVE_ENABLE_JUNIT_XML) - CU_automated_enable_junit_xml(CU_TRUE); -#endif - } else { - CU_list_tests_to_file(); - } - CU_automated_run_tests(); - } else { - CU_basic_set_mode(runner.mode); - CU_basic_run_tests(); - } - - if (CU_get_error() == 0) { - return (CU_get_number_of_failures() != 0); - } - - return CU_get_error(); -} diff --git a/src/os/tests/CMakeLists.txt b/src/os/tests/CMakeLists.txt index 62feaa3..469c991 100644 --- a/src/os/tests/CMakeLists.txt +++ b/src/os/tests/CMakeLists.txt @@ -11,6 +11,22 @@ # include(CUnit) -add_cunit_executable(abstraction .) +set(sources + "atomics.c" + "error_no.c" + "heap.c" + "ifaddrs.c" + "iter.c" + "mutex.c" + "once.c" + "report.c" + "rwlock.c" + "stdlib.c" + "strtoll.c" + "thread.c" + "thread_cleanup.c" + "strcasecmp.c") + +add_cunit_executable(abstraction ${sources}) target_link_libraries(abstraction OSAPI) diff --git a/src/os/tests/atomics.c b/src/os/tests/atomics.c index 7f4b110..2683e68 100644 --- a/src/os/tests/atomics.c +++ b/src/os/tests/atomics.c @@ -10,7 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "os/os.h" -#include "CUnit/Runner.h" +#include "CUnit/Test.h" uint32_t _osuint32 = 0; uint64_t _osuint64 = 0; @@ -19,7 +19,7 @@ uintptr_t _osaddress = 0; ptrdiff_t _ptrdiff = 0; void * _osvoidp = (uintptr_t *)0; -CUnit_Test(os_atomics, load_store) +CU_Test(os_atomics, load_store) { volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(5); #if OS_ATOMIC64_SUPPORT @@ -57,7 +57,7 @@ CUnit_Test(os_atomics, load_store) printf ("Ending atomics_load_store\n"); } -CUnit_Test(os_atomics, compare_and_swap) +CU_Test(os_atomics, compare_and_swap) { /* Compare and Swap * if (ptr == expected) { ptr = newval; } @@ -115,7 +115,7 @@ CUnit_Test(os_atomics, compare_and_swap) printf ("Ending atomics_compare_and_swap\n"); } -CUnit_Test(os_atomics, increment) +CU_Test(os_atomics, increment) { volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(0); #if OS_ATOMIC64_SUPPORT @@ -164,7 +164,7 @@ CUnit_Test(os_atomics, increment) printf ("Ending atomics_increment\n"); } -CUnit_Test(os_atomics, decrement) +CU_Test(os_atomics, decrement) { volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(1); #if OS_ATOMIC64_SUPPORT @@ -213,7 +213,7 @@ CUnit_Test(os_atomics, decrement) printf ("Ending atomics_decrement\n"); } -CUnit_Test(os_atomics, add) +CU_Test(os_atomics, add) { volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(1); #if OS_ATOMIC64_SUPPORT @@ -273,7 +273,7 @@ CUnit_Test(os_atomics, add) printf ("Ending atomics_add\n"); } -CUnit_Test(os_atomics, subtract) +CU_Test(os_atomics, subtract) { volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(5); #if OS_ATOMIC64_SUPPORT @@ -333,7 +333,7 @@ CUnit_Test(os_atomics, subtract) printf ("Ending atomics_subtract\n"); } -CUnit_Test(os_atomics, and) +CU_Test(os_atomics, and) { /* AND Operation: @@ -399,7 +399,7 @@ CUnit_Test(os_atomics, and) printf ("Ending atomics_and\n"); } -CUnit_Test(os_atomics, or) +CU_Test(os_atomics, or) { /* OR Operation: diff --git a/src/os/tests/error_no.c b/src/os/tests/error_no.c index 8839917..a04b0e1 100644 --- a/src/os/tests/error_no.c +++ b/src/os/tests/error_no.c @@ -9,11 +9,11 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" -CUnit_Suite_Initialize(os_errno) +CU_Init(os_errno) { int result = 0; os_osInit(); @@ -22,7 +22,7 @@ CUnit_Suite_Initialize(os_errno) return result; } -CUnit_Suite_Cleanup(os_errno) +CU_Clean(os_errno) { int result = 0; os_osExit(); @@ -31,7 +31,7 @@ CUnit_Suite_Cleanup(os_errno) return result; } -CUnit_Test(os_errno, get_and_set) +CU_Test(os_errno, get_and_set) { printf ("Starting os_errno_get_and_set_001\n"); os_setErrno (0); diff --git a/src/os/tests/heap.c b/src/os/tests/heap.c index e64c61f..0468f1b 100644 --- a/src/os/tests/heap.c +++ b/src/os/tests/heap.c @@ -9,11 +9,11 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" -CUnit_Suite_Initialize(os_heap) +CU_Init(os_heap) { int result = 0; os_osInit(); @@ -22,7 +22,7 @@ CUnit_Suite_Initialize(os_heap) return result; } -CUnit_Suite_Cleanup(os_heap) +CU_Clean(os_heap) { int result = 0; os_osExit(); @@ -34,7 +34,7 @@ CUnit_Suite_Cleanup(os_heap) static const size_t allocsizes[] = {0, 1, 2, 3, 4, 5, 10, 20, 257, 1024}; static const size_t nof_allocsizes = sizeof allocsizes / sizeof *allocsizes; -CUnit_Test(os_heap, os_malloc) +CU_Test(os_heap, os_malloc) { for(size_t i = 0; i < nof_allocsizes; i++) { for(size_t j = 0; j < nof_allocsizes; j++) { @@ -48,7 +48,7 @@ CUnit_Test(os_heap, os_malloc) CU_PASS("os_malloc"); } -CUnit_Test(os_heap, os_malloc_0) +CU_Test(os_heap, os_malloc_0) { for(size_t i = 0; i < nof_allocsizes; i++) { for(size_t j = 0; j < nof_allocsizes; j++) { @@ -64,7 +64,7 @@ CUnit_Test(os_heap, os_malloc_0) CU_PASS("os_malloc_0"); } -CUnit_Test(os_heap, os_calloc) +CU_Test(os_heap, os_calloc) { for(size_t i = 0; i < nof_allocsizes; i++) { for(size_t j = 0; j < nof_allocsizes; j++) { @@ -79,7 +79,7 @@ CUnit_Test(os_heap, os_calloc) CU_PASS("os_calloc"); } -CUnit_Test(os_heap, os_realloc) +CU_Test(os_heap, os_realloc) { char *ptr = NULL; size_t unchanged, s, prevs = 0; @@ -105,7 +105,7 @@ CUnit_Test(os_heap, os_realloc) static const size_t allocsizes_s[] = {0, 1, 2, 3, 4, 5, 10, 20, 257, 1024, 8192}; static const size_t nof_allocsizes_s = sizeof allocsizes_s / sizeof *allocsizes_s; -CUnit_Test(os_heap, os_malloc_s) +CU_Test(os_heap, os_malloc_s) { for(size_t i = 0; i < nof_allocsizes_s; i++) { for(size_t j = 0; j < nof_allocsizes_s; j++) { @@ -124,7 +124,7 @@ CUnit_Test(os_heap, os_malloc_s) CU_PASS("os_malloc_s"); } -CUnit_Test(os_heap, os_malloc_0_s) +CU_Test(os_heap, os_malloc_0_s) { for(size_t i = 0; i < nof_allocsizes_s; i++) { for(size_t j = 0; j < nof_allocsizes_s; j++) { @@ -145,7 +145,7 @@ CUnit_Test(os_heap, os_malloc_0_s) CU_PASS("os_malloc_0_s"); } -CUnit_Test(os_heap, os_calloc_s) +CU_Test(os_heap, os_calloc_s) { for(size_t i = 0; i < nof_allocsizes_s; i++) { for(size_t j = 0; j < nof_allocsizes_s; j++) { @@ -166,7 +166,7 @@ CUnit_Test(os_heap, os_calloc_s) CU_PASS("os_calloc_s"); } -CUnit_Test(os_heap, os_realloc_s) +CU_Test(os_heap, os_realloc_s) { char *newptr, *ptr = NULL; size_t unchanged, s, prevs = 0; diff --git a/src/os/tests/ifaddrs.c b/src/os/tests/ifaddrs.c index 2f3266f..e978f29 100644 --- a/src/os/tests/ifaddrs.c +++ b/src/os/tests/ifaddrs.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" /* FIXME: It's not possible to predict what network interfaces are available @@ -24,7 +24,7 @@ static int ipv6_enabled = 1; #endif -CUnit_Suite_Initialize(os_getifaddrs) +CU_Init(os_getifaddrs) { os_osInit(); @@ -51,7 +51,7 @@ CUnit_Suite_Initialize(os_getifaddrs) return 0; } -CUnit_Suite_Cleanup(os_getifaddrs) +CU_Clean(os_getifaddrs) { os_osExit(); return 0; @@ -60,7 +60,7 @@ CUnit_Suite_Cleanup(os_getifaddrs) /* Assume every test machine has at least one IPv4 enabled interface. This simple test verifies an interface can at least be found and that the IFF_LOOPBACK flags are properly set. */ -CUnit_Test(os_getifaddrs, ipv4) +CU_Test(os_getifaddrs, ipv4) { int err; int seen = 0; @@ -87,7 +87,7 @@ CUnit_Test(os_getifaddrs, ipv4) os_freeifaddrs(ifa_root); } -CUnit_Test(os_getifaddrs, null_filter) +CU_Test(os_getifaddrs, null_filter) { int err; int cnt = 0; @@ -105,7 +105,7 @@ CUnit_Test(os_getifaddrs, null_filter) os_freeifaddrs(ifa_root); } -CUnit_Test(os_getifaddrs, empty_filter) +CU_Test(os_getifaddrs, empty_filter) { int err; os_ifaddrs_t *ifa_root; @@ -119,7 +119,7 @@ CUnit_Test(os_getifaddrs, empty_filter) } #ifdef OS_SOCKET_HAS_IPV6 -CUnit_Test(os_getifaddrs, ipv6) +CU_Test(os_getifaddrs, ipv6) { if (ipv6_enabled == 1) { int err; @@ -154,7 +154,7 @@ CUnit_Test(os_getifaddrs, ipv6) /* Assume at least one IPv4 and one IPv6 interface are available when IPv6 is available on the platform. */ -CUnit_Test(os_getifaddrs, ipv4_n_ipv6) +CU_Test(os_getifaddrs, ipv4_n_ipv6) { if (ipv6_enabled == 1) { int err; diff --git a/src/os/tests/iter.c b/src/os/tests/iter.c index f32761c..c58287f 100644 --- a/src/os/tests/iter.c +++ b/src/os/tests/iter.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" #include "assert.h" @@ -19,7 +19,7 @@ static int32_t three = 3; static int32_t four = 4; static int32_t five = 5; -CUnit_Test(os_iter, create) +CU_Test(os_iter, create) { os_iter *iter; @@ -31,7 +31,7 @@ CUnit_Test(os_iter, create) os_iterFree(iter, NULL); } -CUnit_Test(os_iter, prepend) +CU_Test(os_iter, prepend) { os_iter *iter; int32_t idx; @@ -51,7 +51,7 @@ CUnit_Test(os_iter, prepend) os_iterFree(iter, NULL); } -CUnit_Test(os_iter, append) +CU_Test(os_iter, append) { os_iter *iter; int32_t idx; @@ -71,7 +71,7 @@ CUnit_Test(os_iter, append) os_iterFree(iter, NULL); } -CUnit_Test(os_iter, insert) +CU_Test(os_iter, insert) { os_iter *iter; int32_t idx; @@ -104,7 +104,7 @@ iter_free_callback( (*(int32_t *)ptr)++; } -CUnit_Test(os_iter, free) +CU_Test(os_iter, free) { os_iter *iter; int32_t cnt = 0; @@ -126,7 +126,7 @@ iter_walk_callback( (*(int32_t *)arg)++; } -CUnit_Test(os_iter, walk) +CU_Test(os_iter, walk) { os_iter *iter; int32_t cnt = 0; @@ -166,7 +166,7 @@ iter_new( return iter; } -CUnit_Test(os_iter, object_indices) +CU_Test(os_iter, object_indices) { os_iter *iter; int32_t *num; @@ -198,7 +198,7 @@ CUnit_Test(os_iter, object_indices) os_iterFree(iter, NULL); } -CUnit_Test(os_iter, take_indices) +CU_Test(os_iter, take_indices) { os_iter *iter; int32_t *num, cnt = 0; diff --git a/src/os/tests/mutex.c b/src/os/tests/mutex.c index d4ddf1b..ea56be4 100644 --- a/src/os/tests/mutex.c +++ b/src/os/tests/mutex.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" #ifdef __VXWORKS__ @@ -157,7 +157,7 @@ uint32_t concurrent_trylock_thread (_In_opt_ void *arg) return 0; } -CUnit_Suite_Initialize(os_mutex) +CU_Init(os_mutex) { printf ( "Run os_mutex_Initialize\n" ); @@ -166,7 +166,7 @@ CUnit_Suite_Initialize(os_mutex) return 0; } -CUnit_Suite_Cleanup(os_mutex) +CU_Clean(os_mutex) { printf("Run os_mutex_Cleanup\n"); @@ -176,7 +176,7 @@ CUnit_Suite_Cleanup(os_mutex) } /* This test only checks a single-threaded use-case; just API availability.*/ -CUnit_Test(os_mutex, basic) +CU_Test(os_mutex, basic) { os_mutex m; os_result r; @@ -227,7 +227,7 @@ os_mutex_init_thr( return r != os_resultSuccess; /* Return true on faulure */ } -CUnit_Test(os_mutex, init_stress) +CU_Test(os_mutex, init_stress) { struct os_mutex_stress threads[NUM_THREADS]; os_threadAttr tattr; @@ -259,7 +259,7 @@ CUnit_Test(os_mutex, init_stress) printf("Ending os_mutex_init_stress\n"); } -CUnit_Test(os_mutex, lock, false) +CU_Test(os_mutex, lock, false) { /* Test critical section access with locking and PRIVATE scope */ printf ("Starting tc_os_mutex_lock_001\n"); @@ -330,7 +330,7 @@ CUnit_Test(os_mutex, lock, false) printf ("Ending os_mutex_lock\n"); } -CUnit_Test(os_mutex, trylock, false) +CU_Test(os_mutex, trylock, false) { os_result result; @@ -355,7 +355,7 @@ CUnit_Test(os_mutex, trylock, false) printf ("Ending os_mutex_trylock\n"); } -CUnit_Test(os_mutex, destroy, false) +CU_Test(os_mutex, destroy, false) { /* Deinitialize mutex with PRIVATE scope and Success result */ printf ("Starting os_mutex_destroy_001\n"); diff --git a/src/os/tests/once.c b/src/os/tests/once.c index 5ffafc7..7a04397 100644 --- a/src/os/tests/once.c +++ b/src/os/tests/once.c @@ -9,11 +9,11 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" /* Suite os_once*/ -CUnit_Suite_Initialize(os_once) +CU_Init(os_once) { printf("Run os_once_Initialize\n"); @@ -22,7 +22,7 @@ CUnit_Suite_Initialize(os_once) return 0; } -CUnit_Suite_Cleanup(os_once) +CU_Clean(os_once) { printf("Run os_once_Cleanup\n"); @@ -40,7 +40,7 @@ static void once_func(void) } /* This test only checks a single-threaded use-case; mostly API availability and mere basics.*/ -CUnit_Test(os_once, basic) +CU_Test(os_once, basic) { static os_once_t init = OS_ONCE_T_STATIC_INIT; @@ -127,7 +127,7 @@ os_once_parallel_thr( return 0; } -CUnit_Test(os_once, parallel) +CU_Test(os_once, parallel) { os_threadId threads[OS_ONCE_NUM_THREADS]; struct os_once_parallel state = { diff --git a/src/os/tests/report.c b/src/os/tests/report.c index 0fb4095..8032cb1 100644 --- a/src/os/tests/report.c +++ b/src/os/tests/report.c @@ -9,13 +9,13 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" #include "os/os_project.h" #include -CUnit_Suite_Initialize(os_report) +CU_Init(os_report) { os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_ERRORFILE=vdds_test_error"); os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_INFOFILE=vdds_test_info"); @@ -42,7 +42,7 @@ void check_existence(os_result error_log_existence, os_result info_log_existence CU_ASSERT(os_access(info_file_name, OS_ROK) == info_log_existence); } -CUnit_Suite_Cleanup(os_report) +CU_Clean(os_report) { remove_logs(); @@ -50,7 +50,7 @@ CUnit_Suite_Cleanup(os_report) } -CUnit_Test(os_report, re_init) +CU_Test(os_report, re_init) { os_reportInit(true); @@ -72,7 +72,7 @@ CUnit_Test(os_report, re_init) } -CUnit_Test(os_report, stack_critical) +CU_Test(os_report, stack_critical) { os_reportInit(true); @@ -93,7 +93,7 @@ CUnit_Test(os_report, stack_critical) } -CUnit_Test(os_report, stack_non_critical) +CU_Test(os_report, stack_non_critical) { os_reportInit(true); @@ -114,7 +114,7 @@ CUnit_Test(os_report, stack_non_critical) } -CUnit_Test(os_report, error_file_creation_critical) +CU_Test(os_report, error_file_creation_critical) { os_reportInit(true); @@ -128,7 +128,7 @@ CUnit_Test(os_report, error_file_creation_critical) } -CUnit_Test(os_report, error_file_creation_fatal) +CU_Test(os_report, error_file_creation_fatal) { os_reportInit(true); @@ -142,7 +142,7 @@ CUnit_Test(os_report, error_file_creation_fatal) } -CUnit_Test(os_report, info_file_creation_warning) +CU_Test(os_report, info_file_creation_warning) { os_reportInit(true); @@ -156,7 +156,7 @@ CUnit_Test(os_report, info_file_creation_warning) } -CUnit_Test(os_report, info_file_creation_info) +CU_Test(os_report, info_file_creation_info) { os_reportInit(true); @@ -170,7 +170,7 @@ CUnit_Test(os_report, info_file_creation_info) } -CUnit_Test(os_report, verbosity_low) +CU_Test(os_report, verbosity_low) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -187,7 +187,7 @@ CUnit_Test(os_report, verbosity_low) } -CUnit_Test(os_report, verbosity_high) +CU_Test(os_report, verbosity_high) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -205,7 +205,7 @@ CUnit_Test(os_report, verbosity_high) -CUnit_Test(os_report, verbosity_equal) +CU_Test(os_report, verbosity_equal) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -222,7 +222,7 @@ CUnit_Test(os_report, verbosity_equal) } -CUnit_Test(os_report, stack_verbosity_low) +CU_Test(os_report, stack_verbosity_low) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -241,7 +241,7 @@ CUnit_Test(os_report, stack_verbosity_low) } -CUnit_Test(os_report, stack_verbosity_high) +CU_Test(os_report, stack_verbosity_high) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -261,7 +261,7 @@ CUnit_Test(os_report, stack_verbosity_high) -CUnit_Test(os_report, stack_verbosity_equal) +CU_Test(os_report, stack_verbosity_equal) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -280,7 +280,7 @@ CUnit_Test(os_report, stack_verbosity_equal) } -CUnit_Test(os_report, no_log_append) +CU_Test(os_report, no_log_append) { os_reportInit(true); check_existence(os_resultFail, os_resultFail); @@ -305,7 +305,7 @@ CUnit_Test(os_report, no_log_append) } -CUnit_Test(os_report, log_dir) +CU_Test(os_report, log_dir) { os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_LOGPATH=."); @@ -324,7 +324,7 @@ CUnit_Test(os_report, log_dir) } -CUnit_Test(os_report, verbosity_env_value_info) +CU_Test(os_report, verbosity_env_value_info) { os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=0"); os_reportInit(true); @@ -344,7 +344,7 @@ CUnit_Test(os_report, verbosity_env_value_info) } -CUnit_Test(os_report, verbosity_env_value_error) +CU_Test(os_report, verbosity_env_value_error) { os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=3"); os_reportInit(true); @@ -364,7 +364,7 @@ CUnit_Test(os_report, verbosity_env_value_error) } -CUnit_Test(os_report, verbosity_env_value_error_as_string) +CU_Test(os_report, verbosity_env_value_error_as_string) { os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=ERROR"); os_reportInit(true); @@ -384,7 +384,7 @@ CUnit_Test(os_report, verbosity_env_value_error_as_string) } -CUnit_Test(os_report, verbosity_wrong_env_value) +CU_Test(os_report, verbosity_wrong_env_value) { os_putenv(OS_PROJECT_NAME_NOSPACE_CAPS"_VERBOSITY=WRONG"); os_reportInit(true); diff --git a/src/os/tests/rwlock.c b/src/os/tests/rwlock.c index 2041828..7b8f5ea 100644 --- a/src/os/tests/rwlock.c +++ b/src/os/tests/rwlock.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" #ifdef __VXWORKS__ @@ -256,7 +256,7 @@ uint32_t concurrent_tryread_thread (_In_ void *arg) return 0; } -CUnit_Suite_Initialize(os_rwlock) +CU_Init(os_rwlock) { int result = 0; os_osInit(); @@ -270,7 +270,7 @@ CUnit_Suite_Initialize(os_rwlock) return result; } -CUnit_Suite_Cleanup(os_rwlock) +CU_Clean(os_rwlock) { int result = 0; @@ -279,7 +279,7 @@ CUnit_Suite_Cleanup(os_rwlock) return result; } -CUnit_Test(os_rwlock, init) +CU_Test(os_rwlock, init) { /* Initilalize reader/writer lock with PRIVATE scope and Success result */ printf ("Starting os_rwlock_init_001\n"); @@ -292,7 +292,7 @@ CUnit_Test(os_rwlock, init) printf ("Ending os_rwlock_init\n"); } -CUnit_Test(os_rwlock, read, false) +CU_Test(os_rwlock, read, false) { os_time rdelay = { 3, 0 }; struct Par par[RWLOCK_THREADS]; @@ -438,7 +438,7 @@ CUnit_Test(os_rwlock, read, false) printf ("Ending os_rwlock_read\n"); } -CUnit_Test(os_rwlock, write, false) +CU_Test(os_rwlock, write, false) { /* Test critical section WRITE access with locking and PRIVATE scope */ printf ("Starting os_rwlock_write_001\n"); @@ -458,7 +458,7 @@ CUnit_Test(os_rwlock, write, false) printf ("Ending tc_rwlockWrite\n"); } -CUnit_Test(rwlock, tryread, false) +CU_Test(rwlock, tryread, false) { os_result result; /* Test critical section READ access with trylocking and PRIVATE scope */ @@ -488,7 +488,7 @@ CUnit_Test(rwlock, tryread, false) printf ("Ending os_rwlock_tryread\n"); } -CUnit_Test(os_rwlock, trywrite, false) +CU_Test(os_rwlock, trywrite, false) { os_result result; /* Test critical section WRITE access with trylocking and PRIVATE scope */ @@ -518,7 +518,7 @@ CUnit_Test(os_rwlock, trywrite, false) printf ("Ending os_rwlock_trywrite\n"); } -CUnit_Test(os_rwlock, unlock, false) +CU_Test(os_rwlock, unlock, false) { os_result result; /* Unlock rwlock with PRIVATE scope and Success result and claimed with read */ @@ -550,7 +550,7 @@ CUnit_Test(os_rwlock, unlock, false) printf ("Ending tc_rwlockUnlock\n"); } -CUnit_Test(os_rwlock, destroy, false) +CU_Test(os_rwlock, destroy, false) { /* Deinitialize rwlock with PRIVATE scope and Success result */ printf ("Starting os_rwlock_destroy_001\n"); @@ -563,7 +563,7 @@ CUnit_Test(os_rwlock, destroy, false) printf ("Ending tc_rwlockDestroy\n"); } -CUnit_Test(os_rwlock, destroy_shared) +CU_Test(os_rwlock, destroy_shared) { os_rwlock mylock; diff --git a/src/os/tests/stdlib.c b/src/os/tests/stdlib.c index 303f4bb..81ae916 100644 --- a/src/os/tests/stdlib.c +++ b/src/os/tests/stdlib.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" #ifndef WINCE @@ -283,14 +283,14 @@ vsnprintfTest( return result; } -CUnit_Suite_Initialize(os_stdlib) +CU_Init(os_stdlib) { int result = 0; os_osInit(); return result; } -CUnit_Suite_Cleanup(os_stdlib) +CU_Clean(os_stdlib) { /* Remove files used to test permissions */ remove ("exec_only"); @@ -303,119 +303,7 @@ CUnit_Suite_Cleanup(os_stdlib) return 0; } -CUnit_Test(os_stdlib, strcasecmp) -{ - int res; - char *s1, *s2; - - s1 = "a"; - s2 = "a"; - printf ("Starting os_stdlib_strcasecmp_001\n"); - res = os_strcasecmp (s1,s2); - CU_ASSERT (res == 0); - - printf ("Starting os_stdlib_strcasecmp_002\n"); - s1 = "aa"; - s2 = "a"; - res = os_strcasecmp (s1,s2); - CU_ASSERT (res > 0); - - printf ("Starting os_stdlib_strcasecmp_003\n"); - s1 = "a"; - s2 = "aa"; - res = os_strcasecmp (s1,s2); - CU_ASSERT (res < 0); - - printf ("Starting os_stdlib_strcasecmp_004\n"); - s1 = "a"; - s2 = "A"; - res = os_strcasecmp (s1,s2); - CU_ASSERT (res == 0); - - printf ("Starting os_stdlib_strcasecmp_005\n"); - s1 = "A"; - s2 = "a"; - res = os_strcasecmp (s1,s2); - CU_ASSERT (res == 0); - - printf ("Starting os_stdlib_strcasecmp_006\n"); - s1 = "a"; - s2 = "b"; - res = os_strcasecmp (s1,s2); - CU_ASSERT (res < 0); - - printf ("Starting os_stdlib_strcasecmp_007\n"); - s1 = "b"; - s2 = "a"; - res = os_strcasecmp (s1,s2); - CU_ASSERT (res > 0); - - printf ("Ending os_stdlib_strcasecmp\n"); -} - -CUnit_Test(os_stdlib, strncasecmp) -{ - int res; - char *s1, *s2; - - s1 = "a"; - s2 = "a"; - printf ("Starting os_stdlib_strncasecmp_001\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res == 0); - - s1 = "aa"; - s2 = "a"; - printf ("Starting os_stdlib_strncasecmp_002\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res > 0); - - s1 = "a"; - s2 = "aa"; - printf ("Starting os_stdlib_strncasecmp_003\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res < 0); - - s1 = "a"; - s2 = "A"; - printf ("Starting os_stdlib_strncasecmp_004\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res == 0); - - s1 = "A"; - s2 = "a"; - printf ("Starting os_stdlib_strncasecmp_005\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res == 0); - - s1 = "a"; - s2 = "b"; - printf ("Starting os_stdlib_strncasecmp_006\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res < 0); - - s1 = "b"; - s2 = "a"; - printf ("Starting os_stdlib_strncasecmp_007\n"); - res = os_strncasecmp (s1,s2,2); - CU_ASSERT (res > 0); - - s1 = "abcdefghijkl"; - s2 = "AbCdEaGhIjKl"; - printf ("Starting os_stdlib_strncasecmp_008\n"); - res = os_strncasecmp (s1,s2,5); - CU_ASSERT (res == 0); - - s1 = "abcdefghijkl"; - s2 = "AbCdEaGhIjKl"; - printf ("Starting os_stdlib_strncasecmp_009\n"); - res = os_strncasecmp (s1,s2,6); - CU_ASSERT (res > 0); - - printf ("Ending os_stdlib_strncasecmp\n"); -} - -CUnit_Test(os_stdlib, gethostname) +CU_Test(os_stdlib, gethostname) { int res; os_result os_res; @@ -437,7 +325,7 @@ CUnit_Test(os_stdlib, gethostname) printf ("Ending os_stdlib_gethostname\n"); } -CUnit_Test(os_stdlib, putenv) +CU_Test(os_stdlib, putenv) { os_result os_res; @@ -448,7 +336,7 @@ CUnit_Test(os_stdlib, putenv) printf ("Ending os_stdlib_putenv\n"); } -CUnit_Test(os_stdlib, getenv) +CU_Test(os_stdlib, getenv) { const char *env; os_result res; @@ -468,7 +356,7 @@ CUnit_Test(os_stdlib, getenv) printf ("Ending os_stdlib_getenv\n"); } -CUnit_Test(os_stdlib, fileSep) +CU_Test(os_stdlib, fileSep) { #if defined WIN32 const char *wanted= "\\"; @@ -480,7 +368,7 @@ CUnit_Test(os_stdlib, fileSep) printf ("Ending os_stdlib_fileSep\n"); } -CUnit_Test(os_stdlib, access) +CU_Test(os_stdlib, access) { os_result os_res; os_result wanted; @@ -716,7 +604,7 @@ CUnit_Test(os_stdlib, access) printf ("Ending stdlib_os_access\n"); } -CUnit_Test(os_stdlib, vsnprintf) +CU_Test(os_stdlib, vsnprintf) { printf ("Starting os_stdlib_vsnprintf_001\n"); CU_ASSERT (vsnprintfTest("%s","test") == 4); @@ -726,7 +614,7 @@ CUnit_Test(os_stdlib, vsnprintf) printf ("Ending os_stdlib_vsnprintf\n"); } -CUnit_Test(os_stdlib, strtok_r) +CU_Test(os_stdlib, strtok_r) { char * res; char *strtok_r_ts1; @@ -781,7 +669,7 @@ CUnit_Test(os_stdlib, strtok_r) printf ("Ending os_stdlib_strtok_r\n"); } -CUnit_Test(os_stdlib, index) +CU_Test(os_stdlib, index) { char * res; char *index_ts1; @@ -806,7 +694,7 @@ CUnit_Test(os_stdlib, index) printf ("Ending os_stdlib_index\n"); } -CUnit_Test(os_stdlib, flockfile) +CU_Test(os_stdlib, flockfile) { bool result = false; @@ -827,7 +715,7 @@ CUnit_Test(os_stdlib, flockfile) os_osExit(); } -CUnit_Test(os_stdlib, getopt) +CU_Test(os_stdlib, getopt) { int c = 0; int argc = 3; diff --git a/src/os/tests/strcasecmp.c b/src/os/tests/strcasecmp.c new file mode 100644 index 0000000..a6f9035 --- /dev/null +++ b/src/os/tests/strcasecmp.c @@ -0,0 +1,56 @@ +#include "os/os.h" +#include "CUnit/Theory.h" + +typedef enum { eq, lt, gt } eq_t; + +CU_TheoryDataPoints(os_strcasecmp, basic) = { + CU_DataPoints(const char *, "a", "aa", "a", "a", "A", "a", "b", "a", "B", "A", "", "a"), + CU_DataPoints(const char *, "a", "a", "aa", "A", "a", "b", "a", "b", "A", "B", "a", ""), + CU_DataPoints(eq_t, eq, gt, lt, eq, eq, lt, gt, lt, gt, lt, lt, gt) +}; + +CU_Theory((const char *s1, const char *s2, eq_t e), os_strcasecmp, basic) +{ + int r = os_strcasecmp(s1, s2); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_TheoryDataPoints(os_strncasecmp, basic) = { + CU_DataPoints(const char *, "a", "aa", "a", "A", "a", "b", "a", "B", "A", "", "a"), + CU_DataPoints(const char *, "a", "a", "aa", "a", "A", "a", "b", "A", "B", "a", ""), + CU_DataPoints(size_t, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1), + CU_DataPoints(eq_t, eq, gt, lt, eq, eq, gt, lt, gt, lt, lt, gt) +}; + +CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), os_strncasecmp, basic) +{ + int r = os_strncasecmp(s1, s2, n); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_TheoryDataPoints(os_strncasecmp, empty) = { + CU_DataPoints(const char *, "a", "", "a", "", "a", ""), + CU_DataPoints(const char *, "", "a", "", "a", "", "a"), + CU_DataPoints(size_t, 1, 1, 0, 0, 2, 2), + CU_DataPoints(eq_t, gt, lt, eq, eq, gt, lt) +}; + +CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), os_strncasecmp, empty) +{ + int r = os_strncasecmp(s1, s2, n); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_TheoryDataPoints(os_strncasecmp, length) = { + CU_DataPoints(const char *, "aBcD", "AbCX", "aBcD", "AbCX", "aBcD"), + CU_DataPoints(const char *, "AbCX", "aBcD", "AbCX", "aBcD", "AbCd"), + CU_DataPoints(size_t, 3, 3, 4, 4, 5, 5), + CU_DataPoints(eq_t, eq, eq, lt, gt, eq, eq) +}; + +CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), os_strncasecmp, length) +{ + int r = os_strncasecmp(s1, s2, n); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + diff --git a/src/os/tests/strtoll.c b/src/os/tests/strtoll.c index d8468ed..3859ec3 100644 --- a/src/os/tests/strtoll.c +++ b/src/os/tests/strtoll.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" long long ll; @@ -31,7 +31,7 @@ long long llmin = OS_MIN_INTEGER(long long); long long llmax = OS_MAX_INTEGER(long long); unsigned long long ullmax = OS_MAX_INTEGER(unsigned long long); -CUnit_Suite_Initialize(os_str_convert) +CU_Init(os_str_convert) { int result = 0; os_osInit(); @@ -48,7 +48,7 @@ CUnit_Suite_Initialize(os_str_convert) return result; } -CUnit_Suite_Cleanup(os_str_convert) +CU_Clean(os_str_convert) { int result = 0; @@ -57,7 +57,7 @@ CUnit_Suite_Cleanup(os_str_convert) return result; } -CUnit_Test(os_str_convert, strtoll) +CU_Test(os_str_convert, strtoll) { printf ("Starting os_strtoll_001a\n"); str = "gibberish"; @@ -223,7 +223,7 @@ CUnit_Test(os_str_convert, strtoll) printf ("Ending os_strtoll\n"); } -CUnit_Test(os_str_convert, strtoull) +CU_Test(os_str_convert, strtoull) { printf ("Starting os_strtoull_001a\n"); str = "0xffffffffffffffff"; @@ -243,7 +243,7 @@ CUnit_Test(os_str_convert, strtoull) printf ("Ending os_strtoull\n"); } -CUnit_Test(os_str_convert, atoll) +CU_Test(os_str_convert, atoll) { printf ("Starting os_atoll_001\n"); str = "10"; @@ -253,7 +253,7 @@ CUnit_Test(os_str_convert, atoll) printf ("Ending os_atoll\n"); } -CUnit_Test(os_str_convert, atoull) +CU_Test(os_str_convert, atoull) { printf ("Starting os_atoull_001\n"); str = "10"; @@ -263,7 +263,7 @@ CUnit_Test(os_str_convert, atoull) printf ("Ending tc_os_atoull\n"); } -CUnit_Test(os_str_convert, lltostr) +CU_Test(os_str_convert, lltostr) { printf ("Starting os_lltostr_001\n"); ll = llmax; @@ -304,7 +304,7 @@ CUnit_Test(os_str_convert, lltostr) printf ("Ending os_lltostr\n"); } -CUnit_Test(os_str_convert, ulltostr) +CU_Test(os_str_convert, ulltostr) { printf ("Starting os_ulltostr_001\n"); ull = ullmax; diff --git a/src/os/tests/thread.c b/src/os/tests/thread.c index aaf5644..6f2d5fa 100644 --- a/src/os/tests/thread.c +++ b/src/os/tests/thread.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "CUnit/Runner.h" +#include "CUnit/Test.h" #include "os/os.h" #include "assert.h" @@ -107,7 +107,7 @@ uint32_t threadMemory_thread (_In_opt_ void *args) return 0; } -CUnit_Suite_Initialize(os_thread) +CU_Init(os_thread) { int result = 0; os_osInit(); @@ -116,7 +116,7 @@ CUnit_Suite_Initialize(os_thread) return result; } -CUnit_Suite_Cleanup(os_thread) +CU_Clean(os_thread) { int result = 0; @@ -125,7 +125,7 @@ CUnit_Suite_Cleanup(os_thread) return result; } -CUnit_Test(os_thread, create) +CU_Test(os_thread, create) { int result; os_result osResult; @@ -452,7 +452,7 @@ CUnit_Test(os_thread, create) printf ("Ending os_thread_create\n"); } -CUnit_Test(os_thread, idself) +CU_Test(os_thread, idself) { os_threadId thread_os_threadId; os_threadAttr thread_os_threadAttr; @@ -486,7 +486,7 @@ CUnit_Test(os_thread, idself) printf ("Ending tc_threadIdSelf\n"); } -CUnit_Test(os_thread, join) +CU_Test(os_thread, join) { os_threadId thread_os_threadId; os_threadAttr thread_os_threadAttr; @@ -612,7 +612,7 @@ CUnit_Test(os_thread, join) printf ("Ending tc_threadWaitExit\n"); } -CUnit_Test(os_thread, figure_identity) +CU_Test(os_thread, figure_identity) { #if !defined(_WIN32) os_threadId thread_os_threadId; @@ -718,7 +718,7 @@ CUnit_Test(os_thread, figure_identity) printf ("Ending os_thread_figure_identity\n"); } -CUnit_Test(os_thread, attr_init) +CU_Test(os_thread, attr_init) { os_threadAttr thread_os_threadAttr; /* Check default attributes: schedClass */ @@ -744,7 +744,7 @@ CUnit_Test(os_thread, attr_init) printf ("Ending os_thread_attr_init\n"); } -CUnit_Test(os_thread, memmalloc) +CU_Test(os_thread, memmalloc) { /* Check os_threadMemMalloc with success result for main thread */ printf ("Starting os_thread_memmalloc_001\n"); @@ -772,7 +772,7 @@ CUnit_Test(os_thread, memmalloc) printf ("Ending tc_thread_memmalloc\n"); } -CUnit_Test(os_thread, memget) +CU_Test(os_thread, memget) { /* Check os_threadMemGet for main thread and non allocated index */ printf ("Starting os_thread_memget_001\n"); @@ -793,7 +793,7 @@ CUnit_Test(os_thread, memget) printf ("Ending tc_thread_memget\n"); } -CUnit_Test(os_thread, memfree) +CU_Test(os_thread, memfree) { /* Check os_threadMemFree for main thread and non allocated index */ printf ("Starting os_thread_memfree_001\n"); @@ -814,7 +814,7 @@ CUnit_Test(os_thread, memfree) printf ("Ending os_thread_memfree\n"); } -CUnit_Test(os_thread, module) +CU_Test(os_thread, module) { os_threadId tid; os_threadAttr tattr; diff --git a/src/os/tests/thread_cleanup.c b/src/os/tests/thread_cleanup.c index afd07b5..9314361 100644 --- a/src/os/tests/thread_cleanup.c +++ b/src/os/tests/thread_cleanup.c @@ -13,15 +13,15 @@ #include #include "os/os.h" -#include "CUnit/Runner.h" +#include "CUnit/Test.h" -CUnit_Suite_Initialize(os_thread_cleanup) +CU_Init(os_thread_cleanup) { os_osInit(); return 0; } -CUnit_Suite_Cleanup(os_thread_cleanup) +CU_Clean(os_thread_cleanup) { os_osExit(); return 0; @@ -137,7 +137,7 @@ setup( } /* verify the cleanup routine is called */ -CUnit_Test(os_thread_cleanup, push_one) +CU_Test(os_thread_cleanup, push_one) { int flags = THREAD_RESET_1; struct thread_argument *targ = make_thread_argument(flags, 0, 1, 2); @@ -152,7 +152,7 @@ CUnit_Test(os_thread_cleanup, push_one) } /* verify all cleanup routines are called if multiple are registered */ -CUnit_Test(os_thread_cleanup, push_two) +CU_Test(os_thread_cleanup, push_two) { int flags = THREAD_RESET_1 | THREAD_RESET_2; struct thread_argument *targ = make_thread_argument(flags, 0, 1, 2); @@ -167,7 +167,7 @@ CUnit_Test(os_thread_cleanup, push_two) } /* verify the first cleanup routine is still called if second got popped */ -CUnit_Test(os_thread_cleanup, push_two_pop_one_no_exec) +CU_Test(os_thread_cleanup, push_two_pop_one_no_exec) { int flags = THREAD_RESET_1 | THREAD_RESET_2; struct thread_argument *targ = make_thread_argument(flags, 1, 1, 2); @@ -181,7 +181,7 @@ CUnit_Test(os_thread_cleanup, push_two_pop_one_no_exec) free(targ); } -CUnit_Test(os_thread_cleanup, push_two_pop_one_exec) +CU_Test(os_thread_cleanup, push_two_pop_one_exec) { int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1; struct thread_argument *targ = make_thread_argument(flags, 1, 1, 2); @@ -196,7 +196,7 @@ CUnit_Test(os_thread_cleanup, push_two_pop_one_exec) } /* verify no cleanup routines are called if all got popped */ -CUnit_Test(os_thread_cleanup, push_two_pop_two_no_exec) +CU_Test(os_thread_cleanup, push_two_pop_two_no_exec) { int flags = THREAD_RESET_1 | THREAD_RESET_2; struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); @@ -210,7 +210,7 @@ CUnit_Test(os_thread_cleanup, push_two_pop_two_no_exec) free(targ); } -CUnit_Test(os_thread_cleanup, push_two_pop_two_exec_one) +CU_Test(os_thread_cleanup, push_two_pop_two_exec_one) { int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1; struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); @@ -224,7 +224,7 @@ CUnit_Test(os_thread_cleanup, push_two_pop_two_exec_one) free(targ); } -CUnit_Test(os_thread_cleanup, push_two_pop_two_exec_both) +CU_Test(os_thread_cleanup, push_two_pop_two_exec_both) { int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1 | THREAD_RUN_2; struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); @@ -238,7 +238,7 @@ CUnit_Test(os_thread_cleanup, push_two_pop_two_exec_both) free(targ); } -CUnit_Test(os_thread_cleanup, no_interference) +CU_Test(os_thread_cleanup, no_interference) { int flags = THREAD_RESET_1 | THREAD_RESET_2; struct thread_argument *targ1 = make_thread_argument(flags, 0, 1, 2);