Skip to content

Commit 543a6b8

Browse files
authored
Ensure the daily workflow uses gtest-parallel to run unit tests in isolation (valkey-io#3375)
The daily workflow was directly invoking the `valkey-unit-gtests` executable. The intended invocation is to use `gtest-parallel` to ensure that the tests are executed in isolation. Signed-off-by: harrylin98 <harrylin980107@gmail.com>
1 parent afe6ee1 commit 543a6b8

File tree

5 files changed

+39
-32
lines changed

5 files changed

+39
-32
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
if [[ ! -z "$dirty" ]]; then echo "$dirty"; exit 1; fi
5353
- name: unit tests
5454
run: |
55-
./src/unit/valkey-unit-gtests
55+
make test-unit
5656
5757
test-ubuntu-latest-compatibility:
5858
runs-on: ubuntu-latest
@@ -116,8 +116,7 @@ jobs:
116116
./utils/gen-test-certs.sh
117117
./build-release/runtest --verbose --tags -slow --dump-logs --tls
118118
- name: unit tests
119-
run: |
120-
./build-release/bin/valkey-unit-gtests
119+
run: make -C build-release test-unit
121120

122121
test-sanitizer-address:
123122
runs-on: ubuntu-latest
@@ -144,7 +143,7 @@ jobs:
144143
run: CFLAGS='-Werror' ./runtest-moduleapi --verbose --dump-logs
145144
- name: unit tests
146145
run: |
147-
./src/unit/valkey-unit-gtests
146+
make test-unit
148147
149148
test-rdma:
150149
runs-on: ubuntu-latest
@@ -283,7 +282,9 @@ jobs:
283282
GTEST_LIBS="/usr/lib32/libgtest.a /usr/lib32/libgmock.a"
284283
- name: unit tests
285284
run: |
286-
./src/unit/valkey-unit-gtests
285+
make test-unit \
286+
GTEST_CFLAGS="-I/usr/src/googletest/googletest/include -I/usr/src/googletest/googlemock/include" \
287+
GTEST_LIBS="/usr/lib32/libgtest.a /usr/lib32/libgmock.a"
287288
288289
build-libc-malloc:
289290
runs-on: ubuntu-latest

.github/workflows/daily.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
if: true && !contains(github.event.inputs.skiptests, 'unittest')
133133
run: |
134134
if [ -f ./src/unit/valkey-unit-gtests ]; then
135-
./src/unit/valkey-unit-gtests --accurate
135+
make test-unit accurate=1
136136
elif [ -f ./src/valkey-unit-tests ]; then
137137
./src/valkey-unit-tests --accurate
138138
fi
@@ -218,7 +218,7 @@ jobs:
218218
if: true && !contains(github.event.inputs.skiptests, 'unittest')
219219
run: |
220220
if [ -f ./src/unit/valkey-unit-gtests ]; then
221-
./src/unit/valkey-unit-gtests --accurate
221+
make test-unit accurate=1
222222
elif [ -f ./src/valkey-unit-tests ]; then
223223
./src/valkey-unit-tests --accurate
224224
fi
@@ -283,7 +283,7 @@ jobs:
283283
if: true && !contains(github.event.inputs.skiptests, 'unittest')
284284
run: |
285285
if [ -f ./src/unit/valkey-unit-gtests ]; then
286-
./src/unit/valkey-unit-gtests --accurate
286+
make test-unit accurate=1
287287
elif [ -f ./src/valkey-unit-tests ]; then
288288
./src/valkey-unit-tests --accurate
289289
fi
@@ -464,7 +464,9 @@ jobs:
464464
if: true && !contains(github.event.inputs.skiptests, 'unittest')
465465
run: |
466466
if [ -f ./src/unit/valkey-unit-gtests ]; then
467-
./src/unit/valkey-unit-gtests --accurate
467+
make test-unit accurate=1 \
468+
GTEST_CFLAGS="-I/usr/src/googletest/googletest/include -I/usr/src/googletest/googlemock/include" \
469+
GTEST_LIBS="/usr/lib32/libgtest.a /usr/lib32/libgmock.a"
468470
elif [ -f ./src/valkey-unit-tests ]; then
469471
./src/valkey-unit-tests --accurate
470472
fi
@@ -843,8 +845,8 @@ jobs:
843845
if: true && !contains(github.event.inputs.skiptests, 'unittest')
844846
run: |
845847
if [ -f ./src/unit/valkey-unit-gtests ]; then
846-
valgrind --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.txt ./src/unit/valkey-unit-gtests --valgrind
847-
if grep -q 0x err.txt; then cat err.txt; exit 1; fi
848+
./deps/gtest-parallel/gtest-parallel valgrind -- --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.%p.txt ./src/unit/valkey-unit-gtests --valgrind
849+
if grep -qlE '0x[0-9A-Fa-f]+:' err.*.txt 2>/dev/null; then grep -lE '0x[0-9A-Fa-f]+:' err.*.txt | xargs cat; exit 1; fi
848850
elif [ -f ./src/valkey-unit-tests ]; then
849851
valgrind --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.txt ./src/valkey-unit-tests --valgrind
850852
if grep -q 0x err.txt; then cat err.txt; exit 1; fi
@@ -931,8 +933,8 @@ jobs:
931933
if: true && !contains(github.event.inputs.skiptests, 'unittest')
932934
run: |
933935
if [ -f ./src/unit/valkey-unit-gtests ]; then
934-
valgrind --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.txt ./src/unit/valkey-unit-gtests --valgrind
935-
if grep -q 0x err.txt; then cat err.txt; exit 1; fi
936+
./deps/gtest-parallel/gtest-parallel valgrind -- --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.%p.txt ./src/unit/valkey-unit-gtests --valgrind
937+
if grep -qlE '0x[0-9A-Fa-f]+:' err.*.txt 2>/dev/null; then grep -lE '0x[0-9A-Fa-f]+:' err.*.txt | xargs cat; exit 1; fi
936938
elif [ -f ./src/valkey-unit-tests ]; then
937939
valgrind --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.txt ./src/valkey-unit-tests --valgrind
938940
if grep -q 0x err.txt; then cat err.txt; exit 1; fi
@@ -996,7 +998,7 @@ jobs:
996998
if: true && !contains(github.event.inputs.skiptests, 'unittest')
997999
run: |
9981000
if [ -f ./src/unit/valkey-unit-gtests ]; then
999-
./src/unit/valkey-unit-gtests
1001+
make test-unit
10001002
elif [ -f ./src/valkey-unit-tests ]; then
10011003
./src/valkey-unit-tests
10021004
fi
@@ -1055,7 +1057,7 @@ jobs:
10551057
if: true && !contains(github.event.inputs.skiptests, 'unittest')
10561058
run: |
10571059
if [ -f ./src/unit/valkey-unit-gtests ]; then
1058-
./src/unit/valkey-unit-gtests --large-memory
1060+
make test-unit large_memory=1
10591061
elif [ -f ./src/valkey-unit-tests ]; then
10601062
./src/valkey-unit-tests --large-memory
10611063
fi
@@ -1134,7 +1136,7 @@ jobs:
11341136
if: true && !contains(github.event.inputs.skiptests, 'unittest')
11351137
run: |
11361138
if [ -f ./src/unit/valkey-unit-gtests ]; then
1137-
./src/unit/valkey-unit-gtests --accurate
1139+
make test-unit accurate=1
11381140
elif [ -f ./src/valkey-unit-tests ]; then
11391141
./src/valkey-unit-tests --accurate
11401142
fi
@@ -1193,7 +1195,7 @@ jobs:
11931195
if: true && !contains(github.event.inputs.skiptests, 'unittest')
11941196
run: |
11951197
if [ -f ./src/unit/valkey-unit-gtests ]; then
1196-
./src/unit/valkey-unit-gtests --accurate --large-memory
1198+
make test-unit accurate=1 large_memory=1
11971199
elif [ -f ./src/valkey-unit-tests ]; then
11981200
./src/valkey-unit-tests --accurate --large-memory
11991201
fi
@@ -1268,7 +1270,7 @@ jobs:
12681270
if: true && !contains(github.event.inputs.skiptests, 'unittest')
12691271
run: |
12701272
if [ -f ./src/unit/valkey-unit-gtests ]; then
1271-
./src/unit/valkey-unit-gtests
1273+
make test-unit
12721274
elif [ -f ./src/valkey-unit-tests ]; then
12731275
./src/valkey-unit-tests
12741276
fi

src/unit/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ gtest_discover_tests(valkey-unit-gtests)
157157

158158
# Add custom test target using gtest-parallel
159159
add_custom_target(test-unit
160-
COMMAND python3 ${CMAKE_SOURCE_DIR}/deps/gtest-parallel/gtest_parallel.py $<TARGET_FILE:valkey-unit-gtests>
160+
COMMAND sh -c "TEST_ARGS=''; \
161+
[ -n \"$accurate\" ] && TEST_ARGS=\"$TEST_ARGS --accurate\"; \
162+
[ -n \"$large_memory\" ] && TEST_ARGS=\"$TEST_ARGS --large-memory\"; \
163+
[ -n \"$valgrind\" ] && TEST_ARGS=\"$TEST_ARGS --valgrind\"; \
164+
[ -n \"$seed\" ] && TEST_ARGS=\"$TEST_ARGS --seed $seed\"; \
165+
python3 ${CMAKE_SOURCE_DIR}/deps/gtest-parallel/gtest_parallel.py $<TARGET_FILE:valkey-unit-gtests> --gtest_filter=\"$UNIT_TEST_PATTERN\"* -- $TEST_ARGS"
161166
DEPENDS valkey-unit-gtests
162167
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
163168
COMMENT "Running tests with gtest-parallel"
169+
VERBATIM
164170
)

src/unit/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ endif
217217
all: valkey-unit-gtests
218218

219219
.PHONY: test-unit
220+
TEST_ARGS = $(if $(accurate),--accurate) $(if $(large_memory),--large-memory) $(if $(valgrind),--valgrind) $(if $(seed),--seed $(seed))
220221
test-unit: valkey-unit-gtests
221-
python3 ../../deps/gtest-parallel/gtest_parallel.py ./valkey-unit-gtests
222+
python3 ../../deps/gtest-parallel/gtest_parallel.py ./valkey-unit-gtests --gtest_filter=$(UNIT_TEST_PATTERN)* -- $(TEST_ARGS)
222223
@printf '\033[32mAll UNIT TESTS PASSED!\033[0m\n'
223224

224225
.PHONY: valgrind

src/unit/README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,23 @@ gtest unit tests that you can filter/play with:
6262
expected test class name
6363

6464
```bash
65-
make valkey-unit-gtests
66-
./src/unit/valkey-unit-gtests --gtest_filter='TEST_CLASS_NAME.*'
65+
make test-unit UNIT_TEST_PATTERN='TEST_CLASS_NAME.*'
6766
```
6867

6968
4. Running a subset of gtest unit tests in the test class, replace
7069
TEST_CLASS_NAME with expected test class name, and replace TEST_NAME_PREFIX
7170
with test name
7271

7372
```bash
74-
make valkey-unit-gtests
75-
./src/unit/valkey-unit-gtests --gtest_filter='TEST_CLASS_NAME.TEST_NAME_PREFIX*'
73+
make test-unit UNIT_TEST_PATTERN='TEST_CLASS_NAME.TEST_NAME_PREFIX*'
7674
```
7775

7876
5. Building and running with CMake
7977

8078
```bash
8179
mkdir build-release && cd $_
8280
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/valkey -DBUILD_UNIT_GTESTS=yes
83-
make valkey-unit-gtests
84-
./bin/valkey-unit-gtests
81+
make test-unit
8582
```
8683

8784
6. Running disabled tests
@@ -99,13 +96,13 @@ gtest unit tests that you can filter/play with:
9996

10097
The gtest framework supports several command-line flags to control test behavior:
10198

102-
* `--accurate`: Indicates the test should use extra computation to more accurately validate the tests.
103-
* `--large-memory`: Indicates whether tests should use more than 100mb of memory.
104-
* `--valgrind`: A hint passed to tests to indicate that we are running under valgrind.
105-
* `--seed <number>`: Sets a specific random seed for reproducible test runs. All `rand()` calls will produce the same sequence with the same seed.
99+
* `accurate=1`: Indicates the test should use extra computation to more accurately validate the tests.
100+
* `large_memory=1`: Indicates whether tests should use more than 100mb of memory.
101+
* `valgrind=1`: A hint passed to tests to indicate that we are running under valgrind.
102+
* `seed=<number>`: Sets a specific random seed for reproducible test runs. All `rand()` calls will produce the same sequence with the same seed.
106103

107104
Example usage:
108105

109106
```bash
110-
./src/unit/valkey-unit-gtests --accurate --large-memory --seed 12345
111-
```
107+
make test-unit accurate=1 large_memory=1 seed=12345
108+
```

0 commit comments

Comments
 (0)