Skip to content

Commit 5b95a26

Browse files
committed
Testing: thread safe unit test
1 parent f6776d7 commit 5b95a26

2 files changed

Lines changed: 648 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,90 @@ jobs:
432432
run: |
433433
echo "=== Running Priority Tests ==="
434434
./test_priority
435+
436+
test-thread-safe:
437+
name: Tests of Thread-Safe Functionality
438+
runs-on: ubuntu-latest
439+
440+
steps:
441+
- name: Checkout
442+
uses: actions/checkout@v4
443+
444+
- name: Install dependencies
445+
run: |
446+
sudo apt-get update
447+
sudo apt-get install -y cmake build-essential libgtest-dev pkg-config
448+
449+
- name: Build and install Google Test
450+
run: |
451+
cd /usr/src/gtest
452+
sudo cmake .
453+
sudo cmake --build . --target all
454+
sudo cp lib/*.a /usr/lib || sudo cp *.a /usr/lib
455+
456+
- name: Create CMakeLists.txt for Thread-Safe Tests
457+
run: |
458+
cat > CMakeLists.txt << 'EOF'
459+
cmake_minimum_required(VERSION 3.10)
460+
project(TaskSchedulerThreadSafeTests VERSION 1.0.0)
461+
462+
set(CMAKE_CXX_STANDARD 14)
463+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
464+
465+
# Find required packages
466+
find_package(PkgConfig REQUIRED)
467+
find_package(Threads REQUIRED)
468+
469+
# Include directories
470+
include_directories(${CMAKE_SOURCE_DIR}/src)
471+
include_directories(${CMAKE_SOURCE_DIR}/tests)
472+
473+
# Gather source files
474+
file(GLOB TASKSCHEDULER_SOURCES
475+
"${CMAKE_SOURCE_DIR}/src/*.cpp"
476+
"${CMAKE_SOURCE_DIR}/src/*.c"
477+
)
478+
479+
# Create the thread-safe test executable
480+
add_executable(test_thread_safe
481+
tests/test-scheduler-thread-safe.cpp
482+
${TASKSCHEDULER_SOURCES}
483+
)
484+
485+
# Link libraries
486+
target_link_libraries(test_thread_safe
487+
gtest
488+
gtest_main
489+
pthread
490+
)
491+
492+
# Compiler definitions for Arduino compatibility and thread safety
493+
target_compile_definitions(test_thread_safe PRIVATE
494+
ARDUINO=300
495+
_TASK_THREAD_SAFE
496+
_TASK_STATUS_REQUEST
497+
_TASK_TIMEOUT
498+
)
499+
500+
# Compiler flags
501+
target_compile_options(test_thread_safe PRIVATE
502+
-Wall
503+
-Wextra
504+
-O2
505+
-pthread
506+
)
507+
508+
# Enable testing
509+
enable_testing()
510+
add_test(NAME ThreadSafeTests COMMAND test_thread_safe)
511+
EOF
512+
513+
- name: Build thread-safe tests
514+
run: |
515+
cmake .
516+
make -j$(nproc)
517+
518+
- name: Run thread-safe tests
519+
run: |
520+
echo "=== Running Thread-Safe Tests ==="
521+
./test_thread_safe

0 commit comments

Comments
 (0)