Skip to content

Commit 11e4676

Browse files
committed
Coverage with gcov and gcovr
1 parent 48a7c7d commit 11e4676

File tree

8 files changed

+128
-26
lines changed

8 files changed

+128
-26
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ rdkafka*.pc
1111
*.dylib
1212
*.a
1313
*.d
14+
*.gcno
15+
*.gcda
1416
librdkafka*.lds
1517
core
1618
vgcore.*
@@ -23,10 +25,13 @@ gmon.out
2325
*.bz2
2426
*.deb
2527
*.rpm
28+
coverage/json/*
29+
coverage/html/*
2630
staging-docs
2731
tmp
2832
stats*.json
2933
test_report*.json
34+
tests/coverage.json
3035
cov-int
3136
gdbrun*.gdb
3237
TAGS

.semaphore/run-all-tests.yml

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@ name: run-all-tests
33

44
agent:
55
machine:
6-
type: s1-prod-ubuntu24-04-amd64-1
6+
type: s1-prod-ubuntu24-04-arm64-1
77

88
execution_time_limit:
99
hours: 3
1010

1111
global_job_config:
12+
env_vars:
13+
- name: TEST_COVERAGE
14+
value: "True"
1215
prologue:
1316
commands:
1417
- checkout
1518
- '[[ -z "$GIT_REF" ]] || git checkout $GIT_REF'
16-
- wget -O rapidjson-dev.deb https://launchpad.net/ubuntu/+archive/primary/+files/rapidjson-dev_1.1.0+dfsg2-3_all.deb
17-
- sudo dpkg -i rapidjson-dev.deb
1819
- sudo apt update
1920
- sudo apt remove -y needrestart
20-
- sudo apt install -y valgrind
21-
- python3 -m pip install -U pip
22-
- python3 -m pip -V
23-
- (cd tests && python3 -m pip install -r requirements.txt)
24-
- ./configure --install-deps --enable-werror --enable-devel
25-
- make -j all
26-
- make -j -C tests build
21+
- sudo apt install -y gcovr
2722
- sem-version java 17
2823

2924
blocks:
@@ -35,22 +30,28 @@ blocks:
3530
type: s1-prod-ubuntu24-04-amd64-2
3631
prologue:
3732
commands:
38-
- if [[ "$TEST_ARCHES" != *"x86_64"* ]]; then exit 0; fi
33+
- if [[ "$TEST_ARCHES" != *"x86_64"* ]]; then
34+
return 130;
35+
fi
3936
jobs:
4037
- name: "PLAINTEXT cluster (x86_64)"
4138
env_vars:
4239
- name: TEST_SSL
4340
value: "False"
4441
commands:
45-
- if [[ "$TEST_TYPE" != *"plaintext"* ]]; then exit 0; fi
46-
- ./tests/run-all-tests.sh
42+
- if [[ "$TEST_TYPE" != *"plaintext"* ]]; then
43+
return 130;
44+
fi
45+
- ./tests/run-all-tests.sh x86_64_plaintext
4746
- name: "SSL cluster (x86_64)"
4847
env_vars:
4948
- name: TEST_SSL
5049
value: "True"
5150
commands:
52-
- if [[ "$TEST_TYPE" != *"ssl"* ]]; then exit 0; fi
53-
- ./tests/run-all-tests.sh
51+
- if [[ "$TEST_TYPE" != *"ssl"* ]]; then
52+
return 130;
53+
fi
54+
- ./tests/run-all-tests.sh x86_64_ssl
5455
- name: "Run all tests (aarch64)"
5556
dependencies: []
5657
task:
@@ -59,19 +60,44 @@ blocks:
5960
type: s1-prod-ubuntu24-04-arm64-2
6061
prologue:
6162
commands:
62-
- if [[ "$TEST_ARCHES" != *"aarch64"* ]]; then exit 0; fi
63+
- if [[ "$TEST_ARCHES" != *"aarch64"* ]]; then
64+
return 130;
65+
fi
6366
jobs:
6467
- name: "PLAINTEXT cluster (aarch64)"
6568
env_vars:
6669
- name: TEST_SSL
6770
value: "False"
6871
commands:
69-
- if [[ "$TEST_TYPE" != *"plaintext"* ]]; then exit 0; fi
70-
- ./tests/run-all-tests.sh
72+
- if [[ "$TEST_TYPE" != *"plaintext"* ]]; then
73+
return 130;
74+
fi
75+
- ./tests/run-all-tests.sh aarch64_plaintext
7176
- name: "SSL cluster (aarch64)"
7277
env_vars:
7378
- name: TEST_SSL
7479
value: "True"
7580
commands:
76-
- if [[ "$TEST_TYPE" != *"ssl"* ]]; then exit 0; fi
77-
- ./tests/run-all-tests.sh
81+
- if [[ "$TEST_TYPE" != *"ssl"* ]]; then
82+
return 130;
83+
fi
84+
- ./tests/run-all-tests.sh aarch64_ssl
85+
86+
after_pipeline:
87+
task:
88+
env_vars:
89+
- name: TEST_COVERAGE
90+
value: "True"
91+
jobs:
92+
- name: Coverage report
93+
commands:
94+
- if [[ "$TEST_COVERAGE" != "True" ]]; then
95+
return 130;
96+
fi
97+
- checkout
98+
- '[[ -z "$GIT_REF" ]] || git checkout $GIT_REF'
99+
- sudo apt update
100+
- sudo apt remove -y needrestart
101+
- sudo apt install -y gcovr
102+
- sem-version java 17
103+
- ./tests/run-all-tests.sh coverage_report

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ TAGS: .PHONY
9797
cmp $@ $@.tmp || mv $@.tmp $@ ; rm -f $@.tmp ; \
9898
fi)
9999

100+
gcovr-build:
101+
@(export CFLAGS="$$CFLAGS -O0 -fprofile-arcs -ftest-coverage" LDFLAGS="-lgcov --coverage" && \
102+
make libs && make -C tests build)
103+
104+
gcovr-report:
105+
@(gcovr --json tests/coverage.json --gcov-ignore-parse-errors \
106+
--exclude src/nanopb/ \
107+
--exclude src/cJSON\.c \
108+
--exclude src/crc32c\.c \
109+
--exclude src/snappy\.c ./src)
110+
100111
coverity: Makefile.config
101112
@(which cov-build >/dev/null 2>&1 || echo "Make sure coverity../bin is in your PATH")
102113
@(cd src && \

mklove/Makefile.base

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ MKL_BLUE?= \033[034m
88
MKL_CLR_RESET?= \033[0m
99

1010
DEPS= $(OBJS:%.o=%.d)
11+
GCNOS= $(OBJS:%.o=%.gcno)
12+
GCDAS= $(OBJS:%.o=%.gcda)
1113

1214
# TOPDIR is "TOPDIR/mklove/../" i.e., TOPDIR.
1315
# We do it with two dir calls instead of /.. to support mklove being symlinked.
@@ -316,7 +318,7 @@ doc-uninstall:
316318
rmdir $$DESTDIR$(docdir) || true
317319

318320
generic-clean:
319-
rm -f $(OBJS) $(DEPS)
321+
rm -f $(OBJS) $(DEPS) $(GCNOS) $(GCDAS)
320322

321323
lib-clean: generic-clean lib-clean-pkg-config
322324
rm -f $(LIBNAME)*.a $(LIBFILENAME) $(LIBFILENAMEDBG) \

src/rdkafka_range_assignor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ static int setupRackAwareAssignment0(rd_kafka_t *rk,
967967
rd_kafka_metadata_get_internal(*metadata));
968968

969969
for (i = 0; i < member_cnt; i++) {
970-
char member_id[10];
971-
snprintf(member_id, 10, "consumer%d", (int)(i + 1));
970+
char member_id[20];
971+
snprintf(member_id, 20, "consumer%d", (int)(i + 1));
972972
ut_init_member_with_rack(
973973
&members[i], member_id, ALL_RACKS[consumer_racks[i]],
974974
subscriptions[i], subscriptions_count[i]);

src/rdkafka_sticky_assignor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,8 +4200,8 @@ setupRackAwareAssignment0(rd_kafka_t *rk,
42004200
rd_kafka_metadata_get_internal(*metadata));
42014201

42024202
for (i = 0; initialize_members && i < member_cnt; i++) {
4203-
char member_id[10];
4204-
snprintf(member_id, 10, "consumer%d", (int)(i + 1));
4203+
char member_id[20];
4204+
snprintf(member_id, 20, "consumer%d", (int)(i + 1));
42054205
ut_init_member_with_rack(
42064206
&members[i], member_id, ALL_RACKS[consumer_racks[i]],
42074207
subscriptions[i], subscriptions_count[i]);

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ rdlist.o: ../src/rdlist.c
124124

125125

126126
clean:
127-
rm -f *.test $(OBJS) $(BIN)
127+
rm -f *.test $(OBJS) $(BIN) $(GCNOS) $(GCDAS) coverage.json
128128
$(MAKE) -C interceptor_test clean
129129

130130
# Remove test reports, temporary test files, crash dumps, etc.

tests/run-all-tests.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ set -e
1414
# - no assertions
1515
# - following AK and CP versions
1616

17+
if [ "$1" = "coverage_report" ]; then
18+
artifact pull workflow coverage
19+
mkdir -p coverage/html
20+
gcovr --gcov-ignore-parse-errors --exclude src/nanopb/ \
21+
--exclude src/lz4.*\.c --exclude src/cJSON\.c \
22+
--exclude src/crc32c\.c --exclude src/snappy\.c \
23+
--json-add-tracefile "coverage/json/*.json" \
24+
--html-details coverage/html/coverage.html \
25+
--html-self-contained
26+
tar -czf coverage/coverage_report_html.tar.gz coverage/html
27+
artifact push workflow coverage/coverage_report_html.tar.gz \
28+
--destination "coverage/coverage_report_html.tar.gz"
29+
exit 0;
30+
fi
31+
1732
export TEST_KAFKA_GIT_REF=${TEST_KAFKA_GIT_REF:-4.0.0}
1833
export TEST_CP_VERSION=${TEST_CP_VERSION:-7.9.0}
1934

@@ -26,6 +41,18 @@ TEST_CONF_ARG=""
2641
TEST_QUICK_ARG=""
2742
TEST_ASSERT_ARG=""
2843
TEST_PARALLEL_ARG=""
44+
45+
if [ "$TEST_COVERAGE" = "True" ]; then
46+
if [ "$1" = "aarch64_plaintext" ]; then
47+
export TEST_CONSUMER_GROUP_PROTOCOL="consumer"
48+
TEST_SASL="PLAIN"
49+
elif [ "$1" = "aarch64_ssl" ]; then
50+
export TEST_CONSUMER_GROUP_PROTOCOL="consumer"
51+
TEST_SASL="OAUTHBEARER"
52+
TEST_TRIVUP_PARAMETERS="$TEST_TRIVUP_PARAMETERS --oidc"
53+
fi
54+
fi
55+
2956
if [ "$TEST_SSL" = "True" ]; then
3057
TEST_SSL_ARG="--ssl"
3158
fi
@@ -73,7 +100,38 @@ echo "kafka version: $TEST_KAFKA_VERSION"
73100
echo "CP version: $TEST_CP_VERSION"
74101
echo "configuration: $TEST_CONFIGURATION"
75102
echo "arguments: $TEST_ARGS"
103+
104+
# Install requirements for running the tests
105+
wget -O rapidjson-dev.deb https://launchpad.net/ubuntu/+archive/primary/+files/rapidjson-dev_1.1.0+dfsg2-3_all.deb
106+
sudo dpkg -i rapidjson-dev.deb
107+
sudo apt install -y valgrind
108+
python3 -m pip install -U pip
109+
python3 -m pip -V
110+
(cd tests && python3 -m pip install -r requirements.txt)
111+
./configure --install-deps --enable-werror --enable-devel
112+
if [ "$TEST_COVERAGE" = "True" ]; then
113+
make -j gcovr-build
114+
else
115+
make -j
116+
fi
117+
118+
# Disable exit on error
119+
set +e
76120
(cd tests && python3 -m trivup.clusters.KafkaCluster $TEST_CONFIGURATION \
77121
--version "$TEST_KAFKA_GIT_REF" \
78122
--cpversion "$TEST_CP_VERSION" \
79123
--cmd "python run-test-batches.py $TEST_ARGS")
124+
RESULT=$?
125+
126+
if [ ! -z "$1" -a "$TEST_COVERAGE" = "True" ]; then
127+
make gcovr-report
128+
artifact push workflow tests/coverage.json --destination "coverage/json/coverage_$1.json"
129+
fi
130+
131+
if [ $RESULT -eq 0 ]; then
132+
echo "All tests passed"
133+
exit 0
134+
else
135+
echo "Some tests failed"
136+
exit 1
137+
fi

0 commit comments

Comments
 (0)