diff --git a/.github/workflows/posix.yml b/.github/workflows/posix.yml new file mode 100644 index 00000000..e096ed0d --- /dev/null +++ b/.github/workflows/posix.yml @@ -0,0 +1,19 @@ +name: Posix examples + +on: + pull_request: + +jobs: + ci: + name: Build zephyr examples + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + - name: Build and run Posix examples + run: | + cd examples/posix + ./buildAll.sh + diff --git a/CMakeLists.txt b/CMakeLists.txt index 86df9763..c73f9b69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.9) project(reactor-uc LANGUAGES C) # Command line options for the build -set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples") set(BUILD_TESTS OFF CACHE BOOL "Build all tests") set(BUILD_LF_TESTS OFF CACHE BOOL "Build lf tests") set(BUILD_UNIT_TESTS OFF CACHE BOOL "Build unit tests") @@ -18,6 +17,7 @@ if(TEST_COVERAGE) set(CMAKE_BUILD_TYPE "Debug") include(external/cmake/CodeCoverage.cmake) append_coverage_compiler_flags() + add_compile_options(-fprofile-update=atomic) endif() # Setup AddressSanitizer for chasing memory bugs. @@ -52,9 +52,6 @@ if (PLATFORM STREQUAL "POSIX") set_target_properties(nanopb PROPERTIES C_CLANG_TIDY "") # Disable clang-tidy for this external lib. target_link_libraries(reactor-uc PRIVATE pthread nanopb) - if(BUILD_EXAMPLES) - add_subdirectory(examples/posix) - endif () elseif (PLATFORM STREQUAL "ZEPHYR") zephyr_library_named(reactor-uc) zephyr_library_sources(${SOURCES}) diff --git a/Makefile b/Makefile index 99e7d4d9..b82d4a84 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,10 @@ lib: cmake --build build make -C build -# Build examples +# Build federated example examples: - cmake -Bbuild -DBUILD_EXAMPLES=ON . - cmake --build build - make examples -C build + cmake -Bbuild/posix/federated/ examples/posix/federated + make -C build/posix/federated/ # Build and run the unit tests unit-test: diff --git a/examples/posix/CMakeLists.txt b/examples/posix/CMakeLists.txt deleted file mode 100644 index 2bbf8bca..00000000 --- a/examples/posix/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.20.0) - -# TODO: Make this more nicer -target_compile_definitions(reactor-uc PRIVATE NETWORK_POSIX_TCP) - -# Find all .c files in the src directory -file(GLOB C_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.c") - -# Create a list to store all executable names -set(EXECUTABLES) - -# Loop through each .c file and create an executable -foreach(C_FILE ${C_FILES}) - # Get the filename without the extension - get_filename_component(EXEC_NAME ${C_FILE} NAME_WE) - - # Add the executable - add_executable(${EXEC_NAME} ${C_FILE}) - - # Link the necessary libraries - target_link_libraries(${EXEC_NAME} PUBLIC reactor-uc nanopb) - - # Add the executable name to the list - list(APPEND EXECUTABLES ${EXEC_NAME}) -endforeach() diff --git a/examples/posix/buildAll.sh b/examples/posix/buildAll.sh new file mode 100755 index 00000000..f64dbfff --- /dev/null +++ b/examples/posix/buildAll.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +# List of folders +FOLDERS=("hello" "federated") + +# Iterate over each folder and execute the command +for dir in "${FOLDERS[@]}"; do + echo "Entering $dir" + pushd $dir + cmake -Bbuild + make -C build + popd +done \ No newline at end of file diff --git a/examples/posix/federated/CMakeLists.txt b/examples/posix/federated/CMakeLists.txt new file mode 100644 index 00000000..c7379fb6 --- /dev/null +++ b/examples/posix/federated/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.20.0) +project(reactor-uc-posix-hello) + +set(PLATFORM "POSIX" CACHE STRING "") +set(NETWORK_POSIX_TCP ON CACHE STRING "") +add_subdirectory(../../../ reactor-uc) + +add_executable(sender sender.c) +target_link_libraries(sender PRIVATE reactor-uc) + +add_executable(receiver receiver.c) +target_link_libraries(receiver PRIVATE reactor-uc) \ No newline at end of file diff --git a/examples/posix/testing_fed_conn_receiver.c b/examples/posix/federated/receiver.c similarity index 100% rename from examples/posix/testing_fed_conn_receiver.c rename to examples/posix/federated/receiver.c diff --git a/examples/posix/testing_fed_conn_sender.c b/examples/posix/federated/sender.c similarity index 100% rename from examples/posix/testing_fed_conn_sender.c rename to examples/posix/federated/sender.c diff --git a/examples/posix/hello/CMakeLists.txt b/examples/posix/hello/CMakeLists.txt new file mode 100644 index 00000000..7483d6e5 --- /dev/null +++ b/examples/posix/hello/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.20.0) +project(reactor-uc-posix-hello) + +set(PLATFORM "POSIX" CACHE STRING "Platform to target") +add_subdirectory(../../../ reactor-uc) + +add_executable(app timer_ex.c) +target_link_libraries(app PRIVATE reactor-uc) \ No newline at end of file diff --git a/examples/posix/timer_ex.c b/examples/posix/hello/timer_ex.c similarity index 100% rename from examples/posix/timer_ex.c rename to examples/posix/hello/timer_ex.c diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index cb76fb66..adcfe6e7 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -32,8 +32,7 @@ if(TEST_COVERAGE) NAME coverage EXECUTABLE ctest EXCLUDE - "external/Unity/**" - "examples/**" + "external/**" "test/**" LCOV_ARGS --rc lcov_branch_coverage=1 GENHTML_ARGS --rc lcov_branch_coverage=1