test.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. name: TaskScheduler Unit Tests
  2. on:
  3. push:
  4. branches: [ master, main ]
  5. pull_request:
  6. branches: [ master, main ]
  7. workflow_dispatch:
  8. jobs:
  9. test-basic:
  10. name: Tests of Basic Functionality
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout
  14. uses: actions/checkout@v4
  15. - name: Install dependencies
  16. run: |
  17. sudo apt-get update
  18. sudo apt-get install -y cmake build-essential libgtest-dev pkg-config
  19. - name: Build and install Google Test
  20. run: |
  21. cd /usr/src/gtest
  22. sudo cmake .
  23. sudo cmake --build . --target all
  24. sudo cp lib/*.a /usr/lib || sudo cp *.a /usr/lib
  25. - name: Create CMakeLists.txt for Basic Tests
  26. run: |
  27. cat > CMakeLists.txt << 'EOF'
  28. cmake_minimum_required(VERSION 3.10)
  29. project(TaskSchedulerBasicTests VERSION 1.0.0)
  30. set(CMAKE_CXX_STANDARD 14)
  31. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  32. # Find required packages
  33. find_package(PkgConfig REQUIRED)
  34. find_package(Threads REQUIRED)
  35. # Include directories
  36. include_directories(${CMAKE_SOURCE_DIR}/src)
  37. include_directories(${CMAKE_SOURCE_DIR}/tests)
  38. # Gather source files
  39. file(GLOB TASKSCHEDULER_SOURCES
  40. "${CMAKE_SOURCE_DIR}/src/*.cpp"
  41. "${CMAKE_SOURCE_DIR}/src/*.c"
  42. )
  43. # Create the basic test executable
  44. add_executable(test_basic
  45. tests/test-scheduler-basic.cpp
  46. ${TASKSCHEDULER_SOURCES}
  47. )
  48. # Link libraries
  49. target_link_libraries(test_basic
  50. gtest
  51. gtest_main
  52. pthread
  53. )
  54. # Compiler definitions for Arduino compatibility
  55. target_compile_definitions(test_basic PRIVATE
  56. ARDUINO=300
  57. )
  58. # Compiler flags
  59. target_compile_options(test_basic PRIVATE
  60. -Wall
  61. -Wextra
  62. -O2
  63. )
  64. # Enable testing
  65. enable_testing()
  66. add_test(NAME BasicTests COMMAND test_basic)
  67. EOF
  68. - name: Build basic tests
  69. run: |
  70. cmake .
  71. make -j$(nproc)
  72. - name: Run basic tests
  73. run: |
  74. echo "=== Running Basic Scheduler Tests ==="
  75. ./test_basic
  76. test-thorough:
  77. name: Thorough Scheduler Tests
  78. runs-on: ubuntu-latest
  79. steps:
  80. - name: Checkout
  81. uses: actions/checkout@v4
  82. - name: Install dependencies
  83. run: |
  84. sudo apt-get update
  85. sudo apt-get install -y cmake build-essential libgtest-dev pkg-config
  86. - name: Build and install Google Test
  87. run: |
  88. cd /usr/src/gtest
  89. sudo cmake .
  90. sudo cmake --build . --target all
  91. sudo cp lib/*.a /usr/lib || sudo cp *.a /usr/lib
  92. - name: Create CMakeLists.txt for Thorough Tests
  93. run: |
  94. cat > CMakeLists.txt << 'EOF'
  95. cmake_minimum_required(VERSION 3.10)
  96. project(TaskSchedulerThoroughTests VERSION 1.0.0)
  97. set(CMAKE_CXX_STANDARD 14)
  98. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  99. # Find required packages
  100. find_package(PkgConfig REQUIRED)
  101. find_package(Threads REQUIRED)
  102. # Include directories
  103. include_directories(${CMAKE_SOURCE_DIR}/src)
  104. include_directories(${CMAKE_SOURCE_DIR}/tests)
  105. # Gather source files
  106. file(GLOB TASKSCHEDULER_SOURCES
  107. "${CMAKE_SOURCE_DIR}/src/*.cpp"
  108. "${CMAKE_SOURCE_DIR}/src/*.c"
  109. )
  110. # Create the thorough test executable
  111. add_executable(test_thorough
  112. tests/test-scheduler-basic-thorough.cpp
  113. ${TASKSCHEDULER_SOURCES}
  114. )
  115. # Link libraries
  116. target_link_libraries(test_thorough
  117. gtest
  118. gtest_main
  119. pthread
  120. )
  121. # Compiler definitions for Arduino compatibility
  122. target_compile_definitions(test_thorough PRIVATE
  123. ARDUINO=300
  124. )
  125. # Compiler flags
  126. target_compile_options(test_thorough PRIVATE
  127. -Wall
  128. -Wextra
  129. -O2
  130. )
  131. # Enable testing
  132. enable_testing()
  133. add_test(NAME ThoroughTests COMMAND test_thorough)
  134. EOF
  135. - name: Build thorough tests
  136. run: |
  137. cmake .
  138. make -j$(nproc)
  139. - name: Run thorough tests
  140. run: |
  141. echo "=== Running Thorough Tests ==="
  142. ./test_thorough
  143. test-advanced:
  144. name: Tests of Advanced Functionality
  145. runs-on: ubuntu-latest
  146. steps:
  147. - name: Checkout
  148. uses: actions/checkout@v4
  149. - name: Install dependencies
  150. run: |
  151. sudo apt-get update
  152. sudo apt-get install -y cmake build-essential libgtest-dev pkg-config
  153. - name: Build and install Google Test
  154. run: |
  155. cd /usr/src/gtest
  156. sudo cmake .
  157. sudo cmake --build . --target all
  158. sudo cp lib/*.a /usr/lib || sudo cp *.a /usr/lib
  159. - name: Create CMakeLists.txt for Advanced Tests
  160. run: |
  161. cat > CMakeLists.txt << 'EOF'
  162. cmake_minimum_required(VERSION 3.10)
  163. project(TaskSchedulerAdvancedTests VERSION 1.0.0)
  164. set(CMAKE_CXX_STANDARD 14)
  165. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  166. # Find required packages
  167. find_package(PkgConfig REQUIRED)
  168. find_package(Threads REQUIRED)
  169. # Include directories
  170. include_directories(${CMAKE_SOURCE_DIR}/src)
  171. include_directories(${CMAKE_SOURCE_DIR}/tests)
  172. # Gather source files
  173. file(GLOB TASKSCHEDULER_SOURCES
  174. "${CMAKE_SOURCE_DIR}/src/*.cpp"
  175. "${CMAKE_SOURCE_DIR}/src/*.c"
  176. )
  177. # Create the advanced test executable
  178. add_executable(test_advanced
  179. tests/test-scheduler-advanced-features.cpp
  180. ${TASKSCHEDULER_SOURCES}
  181. )
  182. # Link libraries
  183. target_link_libraries(test_advanced
  184. gtest
  185. gtest_main
  186. pthread
  187. )
  188. # Compiler definitions for Arduino compatibility
  189. target_compile_definitions(test_advanced PRIVATE
  190. ARDUINO=300
  191. )
  192. # Compiler flags
  193. target_compile_options(test_advanced PRIVATE
  194. -Wall
  195. -Wextra
  196. -O2
  197. )
  198. # Enable testing
  199. enable_testing()
  200. add_test(NAME AdvancedTests COMMAND test_advanced)
  201. EOF
  202. - name: Build advanced tests
  203. run: |
  204. cmake .
  205. make -j$(nproc)
  206. - name: Run advanced tests
  207. run: |
  208. echo "=== Running Advanced Tests ==="
  209. ./test_advanced
  210. test-blink-example:
  211. name: Tests Based on Blink Example
  212. runs-on: ubuntu-latest
  213. steps:
  214. - name: Checkout
  215. uses: actions/checkout@v4
  216. - name: Install dependencies
  217. run: |
  218. sudo apt-get update
  219. sudo apt-get install -y cmake build-essential libgtest-dev pkg-config
  220. - name: Build and install Google Test
  221. run: |
  222. cd /usr/src/gtest
  223. sudo cmake .
  224. sudo cmake --build . --target all
  225. sudo cp lib/*.a /usr/lib || sudo cp *.a /usr/lib
  226. - name: Create CMakeLists.txt for Blink Example Tests
  227. run: |
  228. cat > CMakeLists.txt << 'EOF'
  229. cmake_minimum_required(VERSION 3.10)
  230. project(TaskSchedulerBlinkExampleTests VERSION 1.0.0)
  231. set(CMAKE_CXX_STANDARD 14)
  232. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  233. # Find required packages
  234. find_package(PkgConfig REQUIRED)
  235. find_package(Threads REQUIRED)
  236. # Include directories
  237. include_directories(${CMAKE_SOURCE_DIR}/src)
  238. include_directories(${CMAKE_SOURCE_DIR}/tests)
  239. # Gather source files
  240. file(GLOB TASKSCHEDULER_SOURCES
  241. "${CMAKE_SOURCE_DIR}/src/*.cpp"
  242. "${CMAKE_SOURCE_DIR}/src/*.c"
  243. )
  244. # Create the blink example test executable
  245. add_executable(test_blink_example
  246. tests/test-scheduler-blink-example.cpp
  247. ${TASKSCHEDULER_SOURCES}
  248. )
  249. # Link libraries
  250. target_link_libraries(test_blink_example
  251. gtest
  252. gtest_main
  253. pthread
  254. )
  255. # Compiler definitions for Arduino compatibility
  256. target_compile_definitions(test_blink_example PRIVATE
  257. ARDUINO=300
  258. _TASK_SLEEP_ON_IDLE_RUN
  259. _TASK_STATUS_REQUEST
  260. )
  261. # Compiler flags
  262. target_compile_options(test_blink_example PRIVATE
  263. -Wall
  264. -Wextra
  265. -O2
  266. )
  267. # Enable testing
  268. enable_testing()
  269. add_test(NAME BlinkExampleTests COMMAND test_blink_example)
  270. EOF
  271. - name: Build blink example tests
  272. run: |
  273. cmake .
  274. make -j$(nproc)
  275. - name: Run blink example tests
  276. run: |
  277. echo "=== Running Blink Example Tests ==="
  278. ./test_blink_example
  279. test-priority:
  280. name: Tests with Layered Priority
  281. runs-on: ubuntu-latest
  282. steps:
  283. - name: Checkout
  284. uses: actions/checkout@v4
  285. - name: Install dependencies
  286. run: |
  287. sudo apt-get update
  288. sudo apt-get install -y cmake build-essential libgtest-dev pkg-config
  289. - name: Build and install Google Test
  290. run: |
  291. cd /usr/src/gtest
  292. sudo cmake .
  293. sudo cmake --build . --target all
  294. sudo cp lib/*.a /usr/lib || sudo cp *.a /usr/lib
  295. - name: Create CMakeLists.txt for Priority Tests
  296. run: |
  297. cat > CMakeLists.txt << 'EOF'
  298. cmake_minimum_required(VERSION 3.10)
  299. project(TaskSchedulerPriorityTests VERSION 1.0.0)
  300. set(CMAKE_CXX_STANDARD 14)
  301. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  302. # Find required packages
  303. find_package(PkgConfig REQUIRED)
  304. find_package(Threads REQUIRED)
  305. # Include directories
  306. include_directories(${CMAKE_SOURCE_DIR}/src)
  307. include_directories(${CMAKE_SOURCE_DIR}/tests)
  308. # Gather source files
  309. file(GLOB TASKSCHEDULER_SOURCES
  310. "${CMAKE_SOURCE_DIR}/src/*.cpp"
  311. "${CMAKE_SOURCE_DIR}/src/*.c"
  312. )
  313. # Create the priority test executable
  314. add_executable(test_priority
  315. tests/test-scheduler-priority.cpp
  316. ${TASKSCHEDULER_SOURCES}
  317. )
  318. # Link libraries
  319. target_link_libraries(test_priority
  320. gtest
  321. gtest_main
  322. pthread
  323. )
  324. # Compiler definitions for Arduino compatibility and priority support
  325. target_compile_definitions(test_priority PRIVATE
  326. ARDUINO=300
  327. _TASK_PRIORITY
  328. )
  329. # Compiler flags
  330. target_compile_options(test_priority PRIVATE
  331. -Wall
  332. -Wextra
  333. -O2
  334. )
  335. # Enable testing
  336. enable_testing()
  337. add_test(NAME PriorityTests COMMAND test_priority)
  338. EOF
  339. - name: Build priority tests
  340. run: |
  341. cmake .
  342. make -j$(nproc)
  343. - name: Run priority tests
  344. run: |
  345. echo "=== Running Priority Tests ==="
  346. ./test_priority