X-Git-Url: https://ruderich.org/simon/gitweb/?p=blhc%2Fblhc.git;a=blobdiff_plain;f=t%2Ftests.t;h=cfe2f9dbb082724ddf068ca4f48f3b4564feaf81;hp=95a8f40c830c43588b7686aab209851a4b35fac0;hb=f0ae7b1580cd26bcf44dc5b780f1c2e081314479;hpb=c2dd74aada8d92258b14727c057e5d02a4c8c7a4 diff --git a/t/tests.t b/t/tests.t index 95a8f40..cfe2f9d 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 => 136; 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,35 @@ 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 +"; + + +# Ignore missing compiler flags. + +is_blhc 'ignore-flag', '--ignore-flag -g', 8, + 'CFLAGS missing (-O2): gcc -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-c.c +'; + +is_blhc 'ignore-flag', '--ignore-flag -g --ignore-flag -O2', 0, + ''; + + +# Ignore certain lines. + +is_blhc 'ignore-line', '--ignore-line "\./prepare-script gcc test-[a-z]\.c"', 8, + 'CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): ./prepare-script gcc test-a.c test-b.c test-c.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-a.c test-b.c test-c.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-a.c test-b.c test-c.c +'; + +is_blhc 'ignore-line', '--ignore-line "\./prepare-script gcc test-[a-z]\.c" --ignore-line "\s*\./prepare-script gcc test-[a-z]\.c .+"', 0, + ''; + + # Correct build logs. is_blhc 'good', '', 0, @@ -109,8 +139,10 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): g++ -g -O2 -fstack-protector --param=ss LDFLAGS missing (-Wl,-z,relro): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -pthread -o ./testProgram ../src/test/testProgram.cpp 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 -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 @@ -146,8 +178,10 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro): g++ -g -O2 -fstack-protector --param LDFLAGS missing (-fPIE -pie): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -pthread -Wl,-z,relro -o ../src/test/bin/test ../src/test/objs/test.o LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.a 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 -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 @@ -183,8 +217,10 @@ LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): g++ -g -O2 -fstack-protector --param LDFLAGS missing (-Wl,-z,now): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -pthread -Wl,-z,relro -o ../src/test/bin/test ../src/test/objs/test.o LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -o test test-a.o test-b.o test-c.a 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 -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 @@ -221,8 +257,10 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): g++ -g -O2 -fstack-protec LDFLAGS missing (-fPIE -pie -Wl,-z,now): g++ -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -pthread -Wl,-z,relro -o ../src/test/bin/test ../src/test/objs/test.o LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc -o test test-a.o test-b.o test-c.a 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 -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 @@ -416,6 +454,8 @@ NONVERBOSE BUILD: [LD] src/test.o NONVERBOSE BUILD: CC modules/server/test.c NONVERBOSE BUILD: C++ test/test.o NONVERBOSE BUILD: C++ test.cpp +NONVERBOSE BUILD: Building program ../build/bin/test +NONVERBOSE BUILD: Compiling test/test.cc to ../build/test/test.o NONVERBOSE BUILD: Compiling test/test.cc to ../build/test/test.o NONVERBOSE BUILD: Building shared library ../build/test/libtest.so.1.2.3 NONVERBOSE BUILD: Compiling test.cc to ../build/test/test.o @@ -437,12 +477,10 @@ CFLAGS missing (-Werror=format-security): cd /tmp/test/src && /usr/bin/gcc -g -O # configure/make is_blhc 'configure', '', 1, - 'No compiler commands! -'; + $empty; is_blhc 'make', '', 1, - 'No compiler commands! -'; + $empty; @@ -595,6 +633,25 @@ LDFLAGS missing (-pie -Wl,-z,relro): gcc -fPIE -o test test.o '; +# ignore architecture + +is_blhc ['arch-avr32', 'arch-i386', 'empty', 'arch-mipsel'], + '--ignore-arch avr32 --ignore-arch mipsel', + 9, + "checking './t/logs/arch-avr32'...\n" + . "ignoring architecture 'avr32'\n" + . "checking './t/logs/arch-i386'...\n" + . $arch_i386 + . "checking './t/logs/empty'...\n" + . $empty + . "checking './t/logs/arch-mipsel'...\n" + . "ignoring architecture 'mipsel'\n" + ; + +is_blhc 'buildd-dpkg-dev', '--ignore-arch i386', 0, + "ignoring architecture 'i386'\n"; + + # debian is_blhc 'debian', '', 8, @@ -607,8 +664,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 @@ -617,6 +679,12 @@ is_blhc 'debian-hardening-wrapper', '', 16, $debian_hardening_wrapper; +# false positives + +is_blhc 'false-positives', '', 1, + $empty; + + # buildd support is_blhc 'empty', '--buildd', 1, @@ -634,6 +702,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 +719,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 ';