From fd2822367ae3c4bcc451d2f82e4b1cee87a741d6 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 11 Apr 2012 00:08:35 +0200 Subject: [PATCH] Add more tests. --- MANIFEST | 3 +++ t/logs/bad | 2 ++ t/logs/buildd-dpkg-dev-missing | 13 +++++++++++++ t/logs/debian | 2 ++ t/logs/debian-cmake | 2 +- t/logs/debian-cmake-2 | 11 +++++++++++ t/logs/debian-cmake-ok | 11 +++++++++++ t/logs/good | 2 ++ t/logs/good-library | 1 + t/tests.t | 35 +++++++++++++++++++++++++++++++--- 10 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 t/logs/buildd-dpkg-dev-missing create mode 100644 t/logs/debian-cmake-2 create mode 100644 t/logs/debian-cmake-ok diff --git a/MANIFEST b/MANIFEST index 0102914..d6c38b3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -15,6 +15,7 @@ t/logs/bad-ldflags t/logs/bad-library t/logs/bad-multiline t/logs/buildd-dpkg-dev +t/logs/buildd-dpkg-dev-missing t/logs/buildd-dpkg-dev-old t/logs/buildd-package-details t/logs/buildd-verbose-build @@ -23,6 +24,8 @@ t/logs/cc t/logs/configure t/logs/debian t/logs/debian-cmake +t/logs/debian-cmake-2 +t/logs/debian-cmake-ok t/logs/debian-hardening-wrapper t/logs/empty t/logs/g++ diff --git a/t/logs/bad b/t/logs/bad index bac71a1..8457e9f 100644 --- a/t/logs/bad +++ b/t/logs/bad @@ -29,6 +29,8 @@ gcc -c -o test test.s gcc -E test.c +gcc -S test.c + gcc test.c gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o diff --git a/t/logs/buildd-dpkg-dev-missing b/t/logs/buildd-dpkg-dev-missing new file mode 100644 index 0000000..1f584f5 --- /dev/null +++ b/t/logs/buildd-dpkg-dev-missing @@ -0,0 +1,13 @@ +Toolchain package versions: ... +dpkg-buildpackage: source package test + +gcc -g -O2 -c test-a.c +gcc -g -O2 -c test-b.c +gcc -g -O2 -c test-c.c +gcc -o test test-a.o test-b.o test-c.o -ltest + +gcc -g -c test-a.c +gcc -g -c test-b.c +gcc -g -c test-c.c +gcc -g -c test-d.cpp +gcc -o test test-a.o test-b.o test-c.o test-d.cpp.o -ltest diff --git a/t/logs/debian b/t/logs/debian index ce91a13..e93b1c5 100644 --- a/t/logs/debian +++ b/t/logs/debian @@ -1,4 +1,6 @@ Build-Depends: .., gcc (>= 4:4.4.3), g++ (>= 4:4.4.3), ... +Toolchain package versions: ... +Package versions: ... dpkg-buildpackage: source package test diff --git a/t/logs/debian-cmake b/t/logs/debian-cmake index 20b4072..e91d1aa 100644 --- a/t/logs/debian-cmake +++ b/t/logs/debian-cmake @@ -1,4 +1,4 @@ -Package versions: ... cmake_2.8.7-2 cmake-data_2.8.7-2 ... +Package versions: ... cmake_2.8.7-1 cmake-data_2.8.7-1 ... dpkg-buildpackage: source package test diff --git a/t/logs/debian-cmake-2 b/t/logs/debian-cmake-2 new file mode 100644 index 0000000..20b4072 --- /dev/null +++ b/t/logs/debian-cmake-2 @@ -0,0 +1,11 @@ +Package versions: ... cmake_2.8.7-2 cmake-data_2.8.7-2 ... + +dpkg-buildpackage: source package test + +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-c.c +gcc -g -O3 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-d.c +gcc -Wl,-z,relro -o test test-a.o test-b.o test-c.o -ltest + +Build finished at 20120308-1648 diff --git a/t/logs/debian-cmake-ok b/t/logs/debian-cmake-ok new file mode 100644 index 0000000..8293666 --- /dev/null +++ b/t/logs/debian-cmake-ok @@ -0,0 +1,11 @@ +Package versions: ... cmake_2.8.7-3 cmake-data_2.8.7-3 ... + +dpkg-buildpackage: source package test + +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-c.c +gcc -g -O3 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-d.c +gcc -Wl,-z,relro -o test test-a.o test-b.o test-c.o -ltest + +Build finished at 20120308-1648 diff --git a/t/logs/good b/t/logs/good index 02f3b67..2519eea 100644 --- a/t/logs/good +++ b/t/logs/good @@ -30,6 +30,8 @@ gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-securit gcc -E -D_FORTIFY_SOURCE=2 test.c +gcc -S -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 test.c + gcc -Wl,-z,relro -o test test.cpp.o command --cc test diff --git a/t/logs/good-library b/t/logs/good-library index a52c84f..cdf9c76 100644 --- a/t/logs/good-library +++ b/t/logs/good-library @@ -3,6 +3,7 @@ dpkg-buildpackage: source package test # -fPIC and -fPIE conflict with each other and -fPIE is not necessary for # libraries. gcc -D_FORTIFY_SOURCE=2 -g -Wl,relro -Wl,now -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test.c -fPIC -DPIC -o libtest.so +gcc -D_FORTIFY_SOURCE=2 -g -Wl,relro -Wl,now -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test.cc -fPIC -DPIC -o libtest.so gcc -shared -fPIC -DPIC libtest.o -lpthread -O2 -Wl,relro -Wl,now -Wl,--as-needed -o libtest.so gcc -shared -fPIC test.o -Wl,-z -Wl,relro -Wl,now -o .libs/libtest.so.1.0.0 diff --git a/t/tests.t b/t/tests.t index c9a8649..d9c15c3 100644 --- a/t/tests.t +++ b/t/tests.t @@ -19,7 +19,7 @@ use strict; use warnings; -use Test::More tests => 112; +use Test::More tests => 122; sub is_blhc { @@ -42,7 +42,7 @@ sub is_blhc { } -# Usage. +# Usage, invalid arguments. my $usage = 'Usage: @@ -56,6 +56,7 @@ is_blhc '', '--invalid', 2, is_blhc '', '', 2, $usage; + # No compiler commands found. my $empty = "No compiler commands!\n"; @@ -63,6 +64,13 @@ is_blhc 'empty', '', 1, $empty; +# ANSI colored output. + +is_blhc 'arch-avr32', '--color', 8, + "\033[31mCFLAGS missing\033[0m (--param=ssp-buffer-size=4)\033[33m:\033[0m gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector -Wformat -Wformat-security -Werror=format-security -Wall -c test.c +"; + + # Correct build logs. is_blhc 'good', '', 0, @@ -111,6 +119,8 @@ LDFLAGS missing (-Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.a LDFLAGS missing (-Wl,-z,relro): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ../src/test/objs/test.o -o ../src/test/bin/test CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c -o test test.S CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -E test.c +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -S test.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -S test.c CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c LDFLAGS missing (-Wl,-z,relro): gcc test.c @@ -148,6 +158,8 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc -o test test-a.o test-b.o test-c. LDFLAGS missing (-fPIE -pie -Wl,-z,relro): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ../src/test/objs/test.o -o ../src/test/bin/test CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c -o test test.S CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -E test.c +CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -S test.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -S test.c CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc test.c @@ -185,6 +197,8 @@ LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -o test test-a.o test-b.o test-c. LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ../src/test/objs/test.o -o ../src/test/bin/test CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c -o test test.S CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -E test.c +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -S test.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -S test.c CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc test.c @@ -223,6 +237,8 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc -o test test-a.o test- LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ../src/test/objs/test.o -o ../src/test/bin/test CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c -o test test.S CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -E test.c +CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -S test.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -S test.c CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc test.c @@ -607,8 +623,13 @@ LDFLAGS missing (-Wl,-z,relro): gcc -o test test.o `dpkg-buildflags --get CFLAGS '; is_blhc 'debian-cmake', '', 32, + 'INVALID CMAKE: 2.8.7-1 +'; +is_blhc 'debian-cmake-2', '', 32, 'INVALID CMAKE: 2.8.7-2 '; +is_blhc 'debian-cmake-ok', '', 0, + ''; my $debian_hardening_wrapper = 'HARDENING WRAPPER: no checks possible, aborting @@ -634,6 +655,14 @@ is_blhc 'buildd-dpkg-dev-old', '--buildd', 8, 'W-dpkg-buildflags-missing CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing '; +is_blhc 'buildd-dpkg-dev-missing', '--buildd', 8, + 'W-dpkg-buildflags-missing CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing +'; + +is_blhc 'debian-hardening-wrapper', '--buildd', 16, + 'I-hardening-wrapper-used +'; + is_blhc 'buildd-verbose-build', '--buildd', 4, 'W-compiler-flags-hidden 1 (of 5) hidden '; @@ -643,7 +672,7 @@ is_blhc 'make', '--buildd', 1, '; is_blhc 'debian-cmake', '--buildd', 32, - 'W-invalid-cmake-used 2.8.7-2 + 'W-invalid-cmake-used 2.8.7-1 '; -- 2.45.2