Skip to content

Commit 91576a3

Browse files
committed
Refactor testsuite
- include a `config.mk` if it exists. This is useful to set local cflags while debugging. For example: echo "CFLAGS+=-U_FORTIFY_SOURCE" > config.mk - Remove 'gcc' and 'clang' targets. Let user set that via CC. - Add a `check` target, so user can run the test suite with `make check`. - set -nostdinc always to avoid pull in system headers
1 parent b0809da commit 91576a3

3 files changed

Lines changed: 21 additions & 21 deletions

File tree

.github/workflows/testsuite.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
matrix:
1313
version: [9, 10, 11, 12, 13]
1414
use_native_chk: [true, false]
15+
env:
16+
CC: ../x86_64-linux-musl-native/bin/gcc
17+
SYS_INCLUDES: -I/usr/include/x86_64-linux-musl -I../x86_64-linux-musl-native/include/ -Ix86_64-linux-musl-native/include/
1518
steps:
1619
- name: Checking out the code
1720
uses: actions/checkout@v3
@@ -36,18 +39,19 @@ jobs:
3639
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.version }} 100
3740
- name: Build with native chk
3841
if: ${{ matrix.use_native_chk == true }}
39-
run: make CFLAGS=-DFORTIFY_USE_NATIVE_CHK -C tests gcc CC=../x86_64-linux-musl-native/bin/gcc
42+
run: make TARGET_DIR=out.gcc.native_chk CFLAGS=-DFORTIFY_USE_NATIVE_CHK -C tests
4043
- name: Build without native chk, and run the testsuite
4144
if: ${{ matrix.use_native_chk == false }}
4245
shell: bash
4346
run: |
44-
make -C tests clean gcc run CC=../x86_64-linux-musl-native/bin/gcc > ./results.txt
47+
make -C tests check > ./results.txt
4548
grep -zvq 'FAIL' ./results.txt
4649
4750
clang:
4851
runs-on: ubuntu-latest
4952
env:
50-
SYS_INCLUDES: -I/usr/include/x86_64-linux-musl -I../x86_64-linux-musl-native/include/ -Ix86_64-linux-musl-native/include/ -nostdinc
53+
SYS_INCLUDES: -I/usr/include/x86_64-linux-musl -I../x86_64-linux-musl-native/include/ -Ix86_64-linux-musl-native/include/
54+
CC: clang
5155
strategy:
5256
matrix:
5357
version: [13, 14, 15]
@@ -73,12 +77,12 @@ jobs:
7377
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${{ matrix.version }} 100
7478
- name: Build with native chk
7579
if: ${{ matrix.use_native_chk == true }}
76-
run: make CFLAGS=-DFORTIFY_USE_NATIVE_CHK SYS_INCLUDES="$SYS_INCLUDES" -C tests clang
80+
run: make CFLAGS=-DFORTIFY_USE_NATIVE_CHK SYS_INCLUDES="$SYS_INCLUDES" CC=clang -C tests clang
7781
- name: Building and running without native chk
7882
if: ${{ matrix.use_native_chk == false }}
7983
shell: bash
8084
run: |
81-
make SYS_INCLUDES="$SYS_INCLUDES" -C tests clean clang run > ./results.txt
85+
make SYS_INCLUDES="$SYS_INCLUDES" CC=clang TARGET_DIR=out.clang -C tests check > ./results.txt
8286
grep -zvq 'FAIL' ./results.txt
8387
8488
c_versions:

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ dist: clean
1717
gzip fortify-headers-$(VERSION).tar
1818
rm -rf fortify-headers-$(VERSION)
1919

20+
check:
21+
$(MAKE) -C tests check
2022
clean:
2123
rm -f fortify-headers-$(VERSION).tar.gz
2224

tests/Makefile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
FORTIFY_CFLAGS= -D_FORTIFY_SOURCE=3
2-
CFLAGS+=-I../include/ $(FORTIFY_CFLAGS) -static -O2 -DFORTIFY_PEDANTIC_CHECKS -Wno-format -Werror=pointer-arith
1+
-include config.mk
2+
3+
FORTIFY_LEVEL=3
4+
FORTIFY_CFLAGS= -D_FORTIFY_SOURCE=$(FORTIFY_LEVEL)
5+
SYS_INCLUDES= -nostdinc -I/usr/include
6+
CFLAGS+=-I../include/ $(FORTIFY_CFLAGS) -static -O2 -DFORTIFY_PEDANTIC_CHECKS -Wno-format -Werror=pointer-arith -nostdinc
37

48
COMPTIME_BINS= \
59
test_memcpy_overwrite_under \
@@ -149,33 +153,23 @@ RUNTIME_BINS= \
149153
test_write_dynamic \
150154
test_write_static \
151155

152-
TARGET_DIR=out
156+
TARGET_DIR=out.$(notdir $(CC))
153157
RUNTIME_TARGETS = $(addprefix $(TARGET_DIR)/,$(RUNTIME_BINS))
154158
COMPTIME_TARGETS = $(addprefix $(TARGET_DIR)/,$(COMPTIME_BINS))
155159

156160
.SILENT:
157161

158-
gcc: CC=gcc
159-
gcc: $(RUNTIME_TARGETS)
160-
161-
clang: CC=clang
162-
clang: CXX=clang++
163-
clang: CXXFLAGS+=-I/usr/include/x86_64-linux-musl
164-
clang: CXXFLAGS+=-I../x86_64-linux-musl-native/include/
165-
clang: CXXFLAGS+=-Ix86_64-linux-musl-native/include/
166-
clang: CXXFLAGS+=-nostdinc
167-
clang: comptime $(RUNTIME_TARGETS) cpp
162+
check: run comptime cpp
168163

169164
coverage: CFLAGS += -fprofile-arcs -ftest-coverage
170-
coverage: CC=../x86_64-linux-musl-native/bin/gcc
171-
coverage: GCOV=../x86_64-linux-musl-native/bin/gcov
165+
coverage: CC=gcc
166+
coverage: GCOV=gcov
172167
coverage: $(RUNTIME_TARGETS) run
173168
$(GCOV) *.c
174169
lcov --capture --directory . --output-file coverage.info
175170
lcov --remove ./coverage.info "*/tests/*" --output-file cleaned-coverage.info
176171
genhtml cleaned-coverage.info --output-directory coverage
177172

178-
all: gcc
179173

180174
$(TARGET_DIR):
181175
mkdir -p $@

0 commit comments

Comments
 (0)