From e5e83fff5c8e5b8231c98300c85da8db7ddc3bec Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 12 Sep 2021 18:49:49 +1000 Subject: [PATCH] unix: Add build script for tests --- build_tests.bat | 13 ++++++++----- build_tests.sh | 15 +++++++++++++++ intc.h | 11 +++++++---- intc_tests.h => intc_tests.c | 17 ++++++++++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 build_tests.sh rename intc_tests.h => intc_tests.c (98%) diff --git a/build_tests.bat b/build_tests.bat index b398726..b53a8a2 100644 --- a/build_tests.bat +++ b/build_tests.bat @@ -9,15 +9,18 @@ where /q cl || ( ) REM MSVC cl build -echo [SCRIPT] Building tests via cl to build\intc_tests_msvc.exe +echo [SCRIPT] Building tests via cl to build\intc_tests_cpp_msvc.exe pushd build -cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TP %script_dir%\intc_tests.h /Fe:intc_tests_msvc /link -popd build +cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TP %script_dir%\intc_tests.c /Fe:intc_tests_cpp_msvc /link + +echo [SCRIPT] Building tests via cl to build\intc_tests_c_msvc.exe +cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TC %script_dir%\intc_tests.c /Fe:intc_tests_c_msvc /link +popd REM Optional clang-cl build if we have the compiler on the path where /q clang-cl || goto :eof -echo [SCRIPT] Building tests via clang-cl to build\intc_tests_clang.exe +echo [SCRIPT] Building tests via clang-cl to build\intc_tests_cpp_clang.exe pushd build -clang-cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TP %script_dir%\intc_tests.h /Fe:intc_tests_clang /link +clang-cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TP %script_dir%\intc_tests.c /Fe:intc_tests_cpp_clang /link popd build diff --git a/build_tests.sh b/build_tests.sh new file mode 100644 index 0000000..d435845 --- /dev/null +++ b/build_tests.sh @@ -0,0 +1,15 @@ +#!/bin/bash +script_dir="$(cd "$(dirname "$BASH_SOURCE")" && pwd)" +mkdir --parents build + +# GCC build +echo "[SCRIPT] Building tests via gcc to build/intc_tests_cpp_gcc" +pushd build +g++ -O2 -D INTC_TESTS_WITH_MAIN -I ${script_dir} ${script_dir}/intc_tests.c -o intc_tests_cpp_gcc +popd + +echo "[SCRIPT] Building tests via gcc to build/intc_tests_c_gcc" +pushd build +gcc -O2 -D INTC_TESTS_WITH_MAIN -I ${script_dir} ${script_dir}/intc_tests.c -o intc_tests_c_gcc +popd + diff --git a/intc.h b/intc.h index a0196aa..e31d0da 100644 --- a/intc.h +++ b/intc.h @@ -152,6 +152,9 @@ #endif #define INTC_ZERO_INIT {} #else + #if !defined(INTC_NO_CPP_FEATURES) + #define INTC_NO_CPP_FEATURES + #endif #define INTC_BEGIN_EXTERN_C #define INTC_END_EXTERN_C #define INTC_ZERO_INIT {0} @@ -638,10 +641,10 @@ INTC_API intc_u256 operator--(intc_u256 &lhs, int); #endif // INTC_H #if defined(INTC_IMPLEMENTATION) -static bool const INTC__U8_IS_8_BITS [sizeof(intc_u8) == 1 ? 1 : -1] = {}; -static bool const INTC__U16_IS_16_BITS[sizeof(intc_u16) == 2 ? 1 : -1] = {}; -static bool const INTC__U32_IS_32_BITS[sizeof(intc_u32) == 4 ? 1 : -1] = {}; -static bool const INTC__U64_IS_64_BITS[sizeof(intc_u64) == 8 ? 1 : -1] = {}; +static bool const INTC__U8_IS_8_BITS [sizeof(intc_u8) == 1 ? 1 : -1] = INTC_ZERO_INIT; +static bool const INTC__U16_IS_16_BITS[sizeof(intc_u16) == 2 ? 1 : -1] = INTC_ZERO_INIT; +static bool const INTC__U32_IS_32_BITS[sizeof(intc_u32) == 4 ? 1 : -1] = INTC_ZERO_INIT; +static bool const INTC__U64_IS_64_BITS[sizeof(intc_u64) == 8 ? 1 : -1] = INTC_ZERO_INIT; INTC_BEGIN_EXTERN_C // ----------------------------------------------------------------------------- diff --git a/intc_tests.h b/intc_tests.c similarity index 98% rename from intc_tests.h rename to intc_tests.c index 4c5f6bb..ba853f4 100644 --- a/intc_tests.h +++ b/intc_tests.c @@ -1,5 +1,6 @@ #if !defined(INTC_TESTS_H) #define INTC_TESTS_H + // ----------------------------------------------------------------------------- // NOTE: Overview // ----------------------------------------------------------------------------- @@ -142,7 +143,17 @@ intc_u64 const INTC_TESTS_MAX_UNSIGNED_VALUES[] = { } \ } while (0) -#define INTC_TESTS_ASSERT(expr) INTC_TESTS_ASSERT_MSG(expr, 0, "") +#define INTC_TESTS_ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + test_case_.failed = true; \ + char const *file = intc_strip_path_to_file(__FILE__); \ + printf(" +--Test failed at %s:%d, expression was: %s\n", file, __LINE__, #expr); \ + printf(" V\n"); \ + } \ + } while (0) #if defined(INTC_TESTS_NO_COLORS) #define INTC_TESTS_COLOR_RED @@ -630,8 +641,8 @@ struct intc_test_state intc_u128_unit_tests(void) bool f = false; intc_u8 u8 = 0xffULL; intc_u16 u16 = 0xffffULL; - intc_u32 u32 = 0xffffffffULL; - intc_u64 u64 = 0xffffffffffffffffULL; + intc_u32 u32 = 0xffffffff; + intc_u64 u64 = 0xffffffffffffffff; struct intc_u128 const u128 = INTC_U128(0xffffffffffffffffULL, 0xffffffffffffffffULL); INTC_TESTS_ASSERT(intc_u128_eq(intc_u128_lshift(INTC_U64_TO_U128(u8), 7), INTC_U64_TO_U128(0x7f80ULL)));