unix: Add build script for tests

This commit is contained in:
doyle 2021-09-12 18:49:49 +10:00
parent 3f7b586ca2
commit e5e83fff5c
4 changed files with 44 additions and 12 deletions

View File

@ -9,15 +9,18 @@ where /q cl || (
) )
REM MSVC cl build 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 pushd build
cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TP %script_dir%\intc_tests.h /Fe:intc_tests_msvc /link cl -nologo -O2 -D INTC_TESTS_WITH_MAIN -I %script_dir% -TP %script_dir%\intc_tests.c /Fe:intc_tests_cpp_msvc /link
popd build
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 REM Optional clang-cl build if we have the compiler on the path
where /q clang-cl || goto :eof 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 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 popd build

15
build_tests.sh Normal file
View File

@ -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

11
intc.h
View File

@ -152,6 +152,9 @@
#endif #endif
#define INTC_ZERO_INIT {} #define INTC_ZERO_INIT {}
#else #else
#if !defined(INTC_NO_CPP_FEATURES)
#define INTC_NO_CPP_FEATURES
#endif
#define INTC_BEGIN_EXTERN_C #define INTC_BEGIN_EXTERN_C
#define INTC_END_EXTERN_C #define INTC_END_EXTERN_C
#define INTC_ZERO_INIT {0} #define INTC_ZERO_INIT {0}
@ -638,10 +641,10 @@ INTC_API intc_u256 operator--(intc_u256 &lhs, int);
#endif // INTC_H #endif // INTC_H
#if defined(INTC_IMPLEMENTATION) #if defined(INTC_IMPLEMENTATION)
static bool const INTC__U8_IS_8_BITS [sizeof(intc_u8) == 1 ? 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] = {}; 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] = {}; 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] = {}; static bool const INTC__U64_IS_64_BITS[sizeof(intc_u64) == 8 ? 1 : -1] = INTC_ZERO_INIT;
INTC_BEGIN_EXTERN_C INTC_BEGIN_EXTERN_C
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -1,5 +1,6 @@
#if !defined(INTC_TESTS_H) #if !defined(INTC_TESTS_H)
#define INTC_TESTS_H #define INTC_TESTS_H
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// NOTE: Overview // NOTE: Overview
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -142,7 +143,17 @@ intc_u64 const INTC_TESTS_MAX_UNSIGNED_VALUES[] = {
} \ } \
} while (0) } 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) #if defined(INTC_TESTS_NO_COLORS)
#define INTC_TESTS_COLOR_RED #define INTC_TESTS_COLOR_RED
@ -630,8 +641,8 @@ struct intc_test_state intc_u128_unit_tests(void)
bool f = false; bool f = false;
intc_u8 u8 = 0xffULL; intc_u8 u8 = 0xffULL;
intc_u16 u16 = 0xffffULL; intc_u16 u16 = 0xffffULL;
intc_u32 u32 = 0xffffffffULL; intc_u32 u32 = 0xffffffff;
intc_u64 u64 = 0xffffffffffffffffULL; intc_u64 u64 = 0xffffffffffffffff;
struct intc_u128 const u128 = INTC_U128(0xffffffffffffffffULL, 0xffffffffffffffffULL); 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))); INTC_TESTS_ASSERT(intc_u128_eq(intc_u128_lshift(INTC_U64_TO_U128(u8), 7), INTC_U64_TO_U128(0x7f80ULL)));