Skip to content

Commit c5ce678

Browse files
committed
test: add test workflow
1 parent b9d0cab commit c5ce678

File tree

6 files changed

+74
-213
lines changed

6 files changed

+74
-213
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Windows CMake Build & Test
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
pull_request:
8+
branches:
9+
- develop
10+
11+
jobs:
12+
build:
13+
runs-on: windows-latest
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install MinGW
20+
run: |
21+
choco install mingw --version=12.2.0 -y
22+
echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" >> $GITHUB_PATH
23+
gcc --version
24+
25+
- name: Build
26+
run: |
27+
mkdir __build__
28+
cd __build__
29+
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=gcc -S.. -G Ninja
30+
cmake --build .
31+
32+
- name: Run Tests
33+
working-directory: __build__
34+
run: |
35+
ctest . --output-on-failure

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project(LwLibPROJECT C)
66
if(NOT PROJECT_IS_TOP_LEVEL)
77
add_subdirectory(lwrb)
88
else()
9+
enable_testing()
910
add_executable(${PROJECT_NAME})
1011
target_sources(${PROJECT_NAME} PRIVATE
1112
${CMAKE_CURRENT_LIST_DIR}/dev/main.c
@@ -23,4 +24,7 @@ else()
2324
# Add compile options to the library, which will propagate options to executable through public link
2425
target_compile_definitions(lwrb PUBLIC WIN32 _DEBUG CONSOLE LWRB_DEV)
2526
target_compile_options(lwrb PUBLIC -Wall -Wextra -Wpedantic)
27+
28+
# Add test
29+
add_test(NAME Test COMMAND $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
2630
endif()

dev/lwrb_dev.sln

Lines changed: 0 additions & 31 deletions
This file was deleted.

dev/lwrb_dev.vcxproj

Lines changed: 0 additions & 149 deletions
This file was deleted.

dev/lwrb_dev.vcxproj.filters

Lines changed: 0 additions & 25 deletions
This file was deleted.

dev/main.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ main() {
3636

3737
#define RW_TEST(_w_exp_, _r_exp_, _rw_len_, _rw_exp_len_) \
3838
do { \
39+
uint8_t is_as_expected = (buff.w_ptr == (_w_exp_) && buff.r_ptr == (_r_exp_) && (_rw_len_) == (_rw_exp_len_)); \
3940
printf("W ptr: %u, R ptr: %u, R/W len: %u, as_expected: %u\r\n", (unsigned)buff.w_ptr, (unsigned)buff.r_ptr, \
40-
(unsigned)(_rw_len_), \
41-
(unsigned)(buff.w_ptr == (_w_exp_) && buff.r_ptr == (_r_exp_) && (_rw_len_) == (_rw_exp_len_))); \
41+
(unsigned)(_rw_len_), (unsigned)is_as_expected); \
42+
if (!is_as_expected) { \
43+
printf("Test failed on line %u", (unsigned)__LINE__); \
44+
return -1; \
45+
} \
4246
} while (0)
4347

4448
lwrb_reset(&buff);
@@ -65,9 +69,13 @@ main() {
6569

6670
#define RW_TEST(_w_exp_, _r_exp_, _success_, _rw_len_, _rw_exp_len_) \
6771
do { \
72+
uint8_t is_as_expected = (buff.w_ptr == (_w_exp_) && buff.r_ptr == (_r_exp_) && (_rw_len_) == (_rw_exp_len_)); \
6873
printf("W ptr: %u, R ptr: %u, R/W success: %u, R/W len: %u, as_expected: %u\r\n", (unsigned)buff.w_ptr, \
69-
(unsigned)buff.r_ptr, (unsigned)(_success_), (unsigned)(_rw_len_), \
70-
(unsigned)(buff.w_ptr == (_w_exp_) && buff.r_ptr == (_r_exp_) && (_rw_len_) == (_rw_exp_len_))); \
74+
(unsigned)buff.r_ptr, (unsigned)(_success_), (unsigned)(_rw_len_), (unsigned)is_as_expected); \
75+
if (!is_as_expected) { \
76+
printf("Test failed on line %u", (unsigned)__LINE__); \
77+
return -1; \
78+
} \
7179
} while (0)
7280

7381
lwrb_reset(&buff);
@@ -98,8 +106,13 @@ main() {
98106
#define OVERWRITE_TEST(_exp_content_, _exp_len_) \
99107
do { \
100108
len = lwrb_peek(&buff, 0, tmp, buff.size); \
109+
uint32_t is_as_expected = (strncmp((_exp_content_), (const void*)tmp, len) == 0 && len == (_exp_len_)); \
101110
printf("overwrite data read: %.*s, len: %u, as_expected: %u\r\n", (int)len, tmp, (unsigned)len, \
102-
(unsigned)(strncmp((_exp_content_), (const void*)tmp, len) == 0 && len == (_exp_len_))); \
111+
(unsigned)is_as_expected); \
112+
if (!is_as_expected) { \
113+
printf("Test failed on line %u", (unsigned)__LINE__); \
114+
return -1; \
115+
} \
103116
} while (0)
104117

105118
/* Test overwrite */
@@ -138,9 +151,15 @@ main() {
138151
lwrb_sz_t move_len; \
139152
move_len = lwrb_move(&dst, &src); \
140153
len = lwrb_peek(&dst, 0, tmp, dst.size); \
154+
\
155+
uint32_t is_as_expected = (strncmp((_exp_content_), (const void*)tmp, len) == 0 \
156+
&& move_len == (_exp_move_len_) && len == (_exp_buff_len_)); \
141157
printf("move data: len: %d, dest data: %.*s, as_expected: %u\r\n", (int)len, (int)len, tmp, \
142-
(unsigned)(strncmp((_exp_content_), (const void*)tmp, len) == 0 && move_len == (_exp_move_len_) \
143-
&& len == (_exp_buff_len_))); \
158+
(unsigned)is_as_expected); \
159+
if (!is_as_expected) { \
160+
printf("Test failed on line %u", (unsigned)__LINE__); \
161+
return -1; \
162+
} \
144163
} while (0)
145164

146165
lwrb_t src, dst;
@@ -176,8 +195,14 @@ main() {
176195
lwrb_sz_t found_idx; \
177196
uint8_t found; \
178197
found = lwrb_find(&buff, (_bts_), (_bts_len_), (_start_offset_), &found_idx); \
198+
\
199+
uint32_t is_as_expected = (!!found == !!(_exp_result_)); \
179200
printf("Find \"%s\" (len %d), start_offset: %d, found_index: %d; Found: %d; As expected: %d\r\n", (_bts_), \
180-
(_bts_len_), (_start_offset_), (int)found_idx, (int)found, (int)(!!found == !!(_exp_result_))); \
201+
(_bts_len_), (_start_offset_), (int)found_idx, (int)found, (int)is_as_expected); \
202+
if (!is_as_expected) { \
203+
printf("Test failed on line %u", (unsigned)__LINE__); \
204+
return -1; \
205+
} \
181206
} while (0)
182207

183208
/* Prepare buffer and write data */
@@ -210,5 +235,7 @@ main() {
210235

211236
#undef FIND_TEST
212237
}
238+
239+
printf("All completed!\r\n");
213240
return 0;
214241
}

0 commit comments

Comments
 (0)