Skip to content

Commit

Permalink
test: add test for C++ applications (#1254)
Browse files Browse the repository at this point in the history
* test: add test for C++ applications

* cmake: move some compile options to C only

* cmake: move -Wshorten-64-to-32 to C-only

* sanitizer: add clang++

* test: move compile options to C only

* test: fix cmake lint

* ci: rename job

* atomic: attempt to fix __iso_volatile_load8() compile error

* atomic: change unsigned to volatile
  • Loading branch information
alfredh authored Jan 9, 2025
1 parent 169f642 commit 063865b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake_win.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake and Windows
name: Windows

on:
push:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
sanitizer: [thread, address, undefined]
env:
CC: clang-18
CXX: clang++-18
CMAKE_GENERATOR: Ninja
CFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function"
CXXFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function"
ASAN_OPTIONS: fast_unwind_on_malloc=0

steps:
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ endif()

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(
-Wshorten-64-to-32
-Wno-gnu-zero-variadic-macro-arguments
-Wno-c2x-extensions
)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wshorten-64-to-32>")
endif()

check_c_compiler_flag("-Watomic-implicit-seq-cst" COMPILER_SUPPORTS_WATOMIC)
if(COMPILER_SUPPORTS_WATOMIC)
add_compile_options(-Watomic-implicit-seq-cst)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Watomic-implicit-seq-cst>")
endif()

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
Expand Down
12 changes: 10 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ include(sanitizer)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 11)

if(MSVC)
add_compile_options("/W3")
else()
add_compile_options(

set(c_flags
-Wall
-Wbad-function-cast
-Wcast-align
Expand All @@ -49,10 +51,14 @@ else()
-Wuninitialized
-Wvla
)

add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
)
endif()

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wshorten-64-to-32)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wshorten-64-to-32>")
endif()

include_directories(
Expand Down Expand Up @@ -153,6 +159,8 @@ if(USE_OPENSSL)
)
endif()

list(APPEND SRCS cplusplus.cpp)


##############################################################################
#
Expand Down
25 changes: 25 additions & 0 deletions test/cplusplus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @file cplusplus.cpp Emulate C++ applications
*
* Copyright (C) 2025 Alfred E. Heggestad
*/

#include <iostream>
#include <re_atomic.h>
#include <re.h>
#include "test.h"


#define DEBUG_MODULE "cplusplus"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


int test_cplusplus(void)
{
std::cout << "test\n";

DEBUG_NOTICE("%H\n", sys_kernel_get, nullptr);

return 0;
}
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ static const struct test tests_integration[] = {
TEST(test_tmr_jiffies_usec),
TEST(test_turn_thread),
TEST(test_thread_cnd_timedwait),
TEST(test_cplusplus),
};


Expand Down
10 changes: 10 additions & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ int test_integration(const char *name, bool verbose);
int test_sipevent_network(void);
int test_sip_drequestf_network(void);

#ifdef __cplusplus
extern "C" {
#endif

int test_cplusplus(void);

#ifdef __cplusplus
}
#endif

/* High-level API */
int test_reg(const char *name, bool verbose);
int test_oom(const char *name, bool verbose);
Expand Down

0 comments on commit 063865b

Please sign in to comment.