X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=t%2Ftests.t;h=0b98fe3648a00e9be9a70b02bbc605d6308642be;hb=f61763f97aa10059755d434556945465a4984aab;hp=326021334db0c81a970caaa1c122ae5675472c7c;hpb=4b7b1141cf7ced73a3ed2445068233e429987865;p=blhc%2Fblhc.git diff --git a/t/tests.t b/t/tests.t index 3260213..0b98fe3 100644 --- a/t/tests.t +++ b/t/tests.t @@ -19,12 +19,18 @@ use strict; use warnings; -use Test::More tests => 92; +use Test::More tests => 110; sub is_blhc { my ($file, $options, $exit, $expected) = @_; + # Multiple files as array references. + if (ref $file eq 'ARRAY') { + local $" = ' ./t/logs/'; + $file = "@{$file}"; + } + my $output = `./bin/blhc $options ./t/logs/$file 2>&1`; if ($options) { @@ -40,24 +46,16 @@ sub is_blhc { is_blhc 'empty', '--invalid', 2, 'Unknown option: invalid Usage: - blhc [options] - - --all force +all (+pie, +bindnow) check - --arch set architecture (autodetected) - --bindnow force +bindbow check - --buildd parser mode for buildds - --color use colored output - --pie force +pie check - --help available options - --version version number and license + blhc [*options*] *..* '; # No compiler commands found. +my $empty = "No compiler commands!\n"; is_blhc 'empty', '', 1, - "No compiler commands!\n"; + $empty; # Correct build logs. @@ -220,6 +218,8 @@ CFLAGS missing (-Wformat): gcc -fPIC -g -O2 -fstack-protector --param=ssp-buffer CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c -o test.output CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c -o test.output LDFLAGS missing (-Wl,-z,relro): gcc test.c -o test.output +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): (gcc -Wl,-z,relro -o test.output test.c) +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): (gcc -Wl,-z,relro -o test.output test.c) '; is_blhc 'bad-cflags', '--pie', 8, 'CFLAGS missing (-fPIE -Wformat): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c @@ -235,6 +235,9 @@ CFLAGS missing (-Wformat): gcc -fPIC -g -O2 -fstack-protector --param=ssp-buffer CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c -o test.output CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c -o test.output LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc test.c -o test.output +CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): (gcc -Wl,-z,relro -o test.output test.c) +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): (gcc -Wl,-z,relro -o test.output test.c) +LDFLAGS missing (-fPIE -pie): (gcc -Wl,-z,relro -o test.output test.c) '; is_blhc 'bad-cflags', '--bindnow', 8, 'CFLAGS missing (-Wformat): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c @@ -251,6 +254,9 @@ CFLAGS missing (-Wformat): gcc -fPIC -g -O2 -fstack-protector --param=ssp-buffer CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c -o test.output CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c -o test.output LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc test.c -o test.output +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): (gcc -Wl,-z,relro -o test.output test.c) +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): (gcc -Wl,-z,relro -o test.output test.c) +LDFLAGS missing (-Wl,-z,now): (gcc -Wl,-z,relro -o test.output test.c) '; is_blhc 'bad-cflags', '--pie --bindnow', 8, 'CFLAGS missing (-fPIE -Wformat): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c @@ -267,6 +273,9 @@ CFLAGS missing (-Wformat): gcc -fPIC -g -O2 -fstack-protector --param=ssp-buffer CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc test.c -o test.output CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c -o test.output LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc test.c -o test.output +CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): (gcc -Wl,-z,relro -o test.output test.c) +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): (gcc -Wl,-z,relro -o test.output test.c) +LDFLAGS missing (-fPIE -pie -Wl,-z,now): (gcc -Wl,-z,relro -o test.output test.c) '; is_blhc 'bad-cppflags', '', 8, @@ -277,9 +286,11 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -fPIC -g -O2 -fstack-protector --par CPPFLAGS missing (-D_FORTIFY_SOURCE=2): g++ -o test -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test-a.cxx test-b.o test-c.o -Wl,-z,relro '; -is_blhc 'bad-ldflags', '', 8, +my $bad_ldflags = 'LDFLAGS missing (-Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.o -ltest '; +is_blhc 'bad-ldflags', '', 8, + $bad_ldflags; is_blhc 'bad-ldflags', '--pie', 8, 'CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-a.c CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c @@ -328,7 +339,7 @@ LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -D_FORTIFY_SOURCE=2 -g -O2 --para LDFLAGS missing (-Wl,-z,now): gcc -shared -fPIC -DPIC libtest.o -lpthread -O2 -Wl,relro -Wl,--as-needed -o libtest.so LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -shared -fPIC -DPIC libtest.o -lpthread -O2 -Wl,--as-needed -o libtest.so LDFLAGS missing (-Wl,-z,now): gcc -shared -fPIC test.o -Wl,-z -Wl,relro -o .libs/libtest.so.1.0.0 -LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc -shared -o libtest.so.0d ./test-a.o test/./test-b.o -Wl,-z,now -lpthread -ldl +LDFLAGS missing (-Wl,-z,relro): gcc -shared -o libtest.so.0d ./test-a.o test/./test-b.o -Wl,-z,now -lpthread -ldl LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): /usr/bin/g++ -shared -fpic -o libtest-6.1.so.0 test.o -ltiff -lz LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc -Wl,--as-needed -fPIE -pie -o test.cgi test.o -lgcrypt CFLAGS missing (-fPIE): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security test.c -o lib`basename test/test`.so @@ -366,6 +377,8 @@ NONVERBOSE BUILD: [CC] src/test-b.o NONVERBOSE BUILD: [CC] src/test_c.o 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: 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 @@ -490,8 +503,7 @@ is_blhc 'libtool', '--bindnow', 8, CXXFLAGS missing (-fPIE -Wformat): /bin/bash ../../libtool --tag=CC --mode=compile x86_64-linux-gnu-g++ -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat-security -Werror=format-security -c test.cpp CFLAGS missing (-fPIE -Wformat): /bin/bash ../../libtool --tag=CC --mode=compile gcc-4.6 -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat-security -Werror=format-security -c test.c CFLAGS missing (-fPIE -Wformat): /bin/bash ../../libtool --tag=CXX --mode=compile g++-4.6 -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat-security -Werror=format-security -c test.c -LDFLAGS missing (-fPIE): libtool: link: g++ -shared test-a.o test-b.o test-b.o test-c.o -O2 -pie -Wl,relro -Wl,now -o test.so -LDFLAGS missing (-fPIE -pie -Wl,-z,now): libtool: link: g++ -shared test-a.o test-b.o test-b.o test-c.o -O2 -Wl,relro -o test.so +LDFLAGS missing (-Wl,-z,now): libtool: link: g++ -shared test-a.o test-b.o test-b.o test-c.o -O2 -Wl,relro -o test.so LDFLAGS missing (-fPIE -pie -Wl,-z,now): libtool: link: gcc -Wl,-z -Wl,relro -o test test.o LDFLAGS missing (-fPIE -pie -Wl,-z,now): /bin/bash ../../../libtool --mode=link cc -Wl,-z,relro -o test.so test.o LDFLAGS missing (-fPIE -pie -Wl,-z,now): /bin/bash ../../../libtool --mode=link gcc-4.6 -Wl,-z,relro -o test.so test.o @@ -513,19 +525,25 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,now): /bin/bash ../libtool --tag=CC --mode= # different architectures -is_blhc 'arch-avr32', '', 8, +my $arch_avr32 = 'CFLAGS missing (--param=ssp-buffer-size=4): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector -Wformat -Wformat-security -Werror=format-security -Wall -c test.c '; +is_blhc 'arch-avr32', '', 8, + $arch_avr32; -is_blhc 'arch-i386', '', 8, +my $arch_i386 = 'CFLAGS missing (-fstack-protector): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fPIE --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wall -c test.c LDFLAGS missing (-pie): gcc -fPIE -Wl,-z,relro -Wl,-z,now -o test test.o '; +is_blhc 'arch-i386', '', 8, + $arch_i386; -is_blhc 'arch-ia64', '', 8, +my $arch_ia64 = 'CFLAGS missing (-fPIE): gcc -D_FORTIFY_SOURCE=2 -g -O2 -Wformat -Wformat-security -Werror=format-security -Wall -c test.c LDFLAGS missing (-pie): gcc -fPIE -o test test.o '; +is_blhc 'arch-ia64', '', 8, + $arch_ia64; is_blhc 'arch-mipsel', '', 8, 'CFLAGS missing (-Werror=format-security): gcc -D_FORTIFY_SOURCE=2 -g -O2 -Wformat -Wformat-security -Wall -c test.c @@ -551,35 +569,61 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -c `dpkg-buildflags --get LDFLAGS` t LDFLAGS missing (-Wl,-z,relro): gcc -o test test.o `dpkg-buildflags --get CFLAGS` '; -is_blhc 'debian-hardening-wrapper', '', 16, +is_blhc 'debian-cmake', '', 32, + 'INVALID CMAKE: 2.8.7-2 +'; + +my $debian_hardening_wrapper = 'HARDENING WRAPPER: no checks possible, aborting '; +is_blhc 'debian-hardening-wrapper', '', 16, + $debian_hardening_wrapper; # buildd support +is_blhc 'empty', '--buildd', 1, + 'W-no-compiler-commands +'; + is_blhc 'buildd-package-details', '--buildd', 0, ''; is_blhc 'buildd-dpkg-dev', '--buildd', 8, - 'CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c -CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -c test-a.c -CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-b.c -CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -c test-b.c -CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-c.c -CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -c test-c.c -LDFLAGS missing (-Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.o -ltest -CFLAGS missing (-O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -c test-a.c -CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -c test-a.c -CFLAGS missing (-O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -c test-b.c -CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -c test-b.c -CFLAGS missing (-O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -c test-c.c -CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -c test-c.c -LDFLAGS missing (-Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.o -ltest + 'W-dpkg-buildflags-missing CPPFLAGS 7 (of 7), CFLAGS 6 (of 6), CXXFLAGS 1 (of 1), LDFLAGS 2 (of 2) missing '; is_blhc 'buildd-dpkg-dev-old', '--buildd', 8, - 'CFLAGS missing (-O2): gcc -g -c test-a.c -CFLAGS missing (-O2): gcc -g -c test-b.c -CFLAGS missing (-O2): gcc -g -c test-c.c + 'W-dpkg-buildflags-missing CFLAGS 3 (of 6), CXXFLAGS 1 (of 1) missing +'; + +is_blhc 'buildd-verbose-build', '--buildd', 4, + 'W-compiler-flags-hidden 1 (of 5) hidden +'; + +is_blhc 'make', '--buildd', 1, + 'W-no-compiler-commands '; + +is_blhc 'debian-cmake', '--buildd', 32, + 'W-invalid-cmake-used 2.8.7-2 +'; + + +# multiple files + +is_blhc ['good', 'good-pie', 'good-bindnow', 'good-all', 'good-multiline', 'good-library'], '', 0, + ''; +is_blhc ['good-all', 'good-library'], '--all', 0, + ''; + +is_blhc ['arch-i386', 'arch-ia64'], '', 8, + $arch_i386 . $arch_ia64; + +# No exit when multiple files are specified. +is_blhc ['bad-ldflags', 'empty', 'arch-avr32', 'debian-hardening-wrapper'], '', 25, + $bad_ldflags + . $empty + . $arch_avr32 + . $debian_hardening_wrapper + ;