X-Git-Url: https://ruderich.org/simon/gitweb/?p=blhc%2Fblhc.git;a=blobdiff_plain;f=t%2Ftests.t;h=02c3d3c38206f6144063ddb581c9ed7fb96435eb;hp=eff3d2bea0d703ec13005c2f7e43165cf479adca;hb=3feff7d79bac4bdf991e8fbcd672c5156f12c019;hpb=737a0dd159dfba58a7e66fef5e49b731e3d9bbb2 diff --git a/t/tests.t b/t/tests.t index eff3d2b..02c3d3c 100644 --- a/t/tests.t +++ b/t/tests.t @@ -19,7 +19,7 @@ use strict; use warnings; -use Test::More tests => 138; +use Test::More tests => 194; sub is_blhc { @@ -38,7 +38,11 @@ sub is_blhc { $options = ' '. $options; } is $? >> 8, $exit, "$file$options (exit code)"; - is $output, $expected, "$file$options (output)"; + # Perform regex or string match. + my $cmd = (ref $expected eq 'Regexp') + ? \&like + : \&is; + &$cmd($output, $expected, "$file$options (output)"); } @@ -57,7 +61,7 @@ is_blhc '', '', 2, $usage; is_blhc '', '--version', 0, - 'blhc 0.02 Copyright (C) 2012 Simon Ruderich + 'blhc 0.03 Copyright (C) 2012 Simon Ruderich This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -73,6 +77,16 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . '; +is_blhc '', '--help', 1, + qr/^Usage: + blhc \[\*options\*\] \*\.\.\* + +Options: +/s; + +is_blhc 'doesnt-exist', '', 2, + qr{^No such file or directory at \./bin/blhc line \d+\.$}; + # No compiler commands found. @@ -97,6 +111,60 @@ is_blhc 'ignore-flag', '--ignore-flag -g', 8, is_blhc 'ignore-flag', '--ignore-flag -g --ignore-flag -O2', 0, ''; +is_blhc 'ignore-flag-ldflags', '--ignore-flag -fPIE', 0, + ''; + +# Ignore missing compiler flags for specific architectures. + +# Invalid option. +is_blhc 'ignore-flag', '--ignore-arch-flag -g', 2, + 'Value "-g" invalid for option ignore-arch-flag ("arch:flag" expected) +Usage: + blhc [*options*] *..* + +'; +is_blhc 'ignore-flag', '--ignore-arch-flag -g:', 2, + 'Value "-g:" invalid for option ignore-arch-flag ("arch:flag" expected) +Usage: + blhc [*options*] *..* + +'; +is_blhc 'ignore-flag', '--ignore-arch-flag :amd64', 2, + 'Value ":amd64" invalid for option ignore-arch-flag ("arch:flag" expected) +Usage: + blhc [*options*] *..* + +'; + +# Wrong architecture. +is_blhc 'ignore-flag', '--ignore-arch-flag amd64:-g', 8, + 'CFLAGS missing (-g): gcc -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c +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 'arch-i386', '--ignore-arch-flag i386:-fstack-protector', 8, + 'LDFLAGS missing (-pie): gcc -fPIE -Wl,-z,relro -Wl,-z,now -o test test.o +'; +is_blhc 'arch-i386', '--ignore-arch-flag i386:-pie', 8, + '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 +'; +is_blhc 'arch-i386', '--ignore-arch-flag i386:-fstack-protector --ignore-arch-flag i386:-pie', 0, + ''; + +# Wrong architecture. +is_blhc 'arch-i386', '--ignore-arch-flag amd64:-fstack-protector', 8, + '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', '--ignore-arch-flag amd64:-pie', 8, + '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', '--ignore-arch-flag amd64:-fstack-protector --ignore-arch-flag amd64:-pie', 8, + '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 +'; + # Ignore certain lines. @@ -109,6 +177,73 @@ LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-a.c test-b.c test- is_blhc 'ignore-line', '--ignore-line "\./prepare-script gcc test-[a-z]\.c" --ignore-line "\s*\./prepare-script gcc test-[a-z]\.c .+"', 0, ''; +# Ignore certain lines for specific architectures. + +# Invalid option. +is_blhc 'ignore-line', '--ignore-arch-line .+', 2, + 'Value ".+" invalid for option ignore-arch-line ("arch:line" expected) +Usage: + blhc [*options*] *..* + +'; +is_blhc 'ignore-line', '--ignore-arch-line .+:', 2, + 'Value ".+:" invalid for option ignore-arch-line ("arch:line" expected) +Usage: + blhc [*options*] *..* + +'; +is_blhc 'ignore-line', '--ignore-arch-line :amd64', 2, + 'Value ":amd64" invalid for option ignore-arch-line ("arch:line" expected) +Usage: + blhc [*options*] *..* + +'; + +# Wrong architecture. +is_blhc 'ignore-line', '--ignore-arch-line "amd64:.+"', 8, + 'CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -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 +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): ./prepare-script gcc test-a.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-a.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-a.c +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): ./prepare-script gcc test-b.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-b.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-b.c +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): ./prepare-script gcc test-c.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-c.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-c.c +'; + +# Line regex anchored at beginning/end of the line. +is_blhc 'arch-i386', '--ignore-arch-line "i386:-fPIE --param=ssp-buffer-size=4"', 8, + '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', '--ignore-arch-line "i386:gcc .+ -fPIE --param=ssp-buffer-size=4 .+ test\.c"', 8, + 'LDFLAGS missing (-pie): gcc -fPIE -Wl,-z,relro -Wl,-z,now -o test test.o +'; +is_blhc 'arch-i386', '--ignore-arch-line "i386:gcc .+ -Wl,-z,relro -Wl,-z,now .+"', 8, + '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 +'; +is_blhc 'arch-i386', '--ignore-arch-line "i386:gcc .+ -fPIE --param=ssp-buffer-size=4 .+ test\.c" --ignore-arch-line "i386:gcc .+ -Wl,-z,relro -Wl,-z,now .+"', 0, + ''; + +# Wrong architecture. +is_blhc 'arch-i386', '--ignore-arch-line "amd64:gcc .+ -fPIE --param=ssp-buffer-size=4 .+ test\.c"', 8, + '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', '--ignore-arch-line "amd64:gcc .+ -Wl,-z,relro -Wl,-z,now .+"', 8, + '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', '--ignore-arch-line "amd64:gcc .+ -fPIE --param=ssp-buffer-size=4 .+ test\.c" --ignore-arch-line "amd64:gcc .+ -Wl,-z,relro -Wl,-z,now .+"', 8, + '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 +'; + # Correct build logs. @@ -376,7 +511,19 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -fstack-protector --param=ssp CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c test-c.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c ../../../../src/test/test.c -o test.so.o 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 -'; +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=0 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c test-a.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=1 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c test-b.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-c.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=0 -c test-d.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=0 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-e.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=1 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-f.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -U_FORTIFY_SOURCE -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c test-g.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -U_FORTIFY_SOURCE -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-h.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -c test-i.c +'; + +is_blhc 'bad-cppflags', '--ignore-flag -D_FORTIFY_SOURCE=2', 0, + ''; my $bad_ldflags = 'LDFLAGS missing (-Wl,-z,relro): gcc -o test test-a.o test-b.o test-c.o -ltest @@ -500,6 +647,11 @@ is_blhc 'make', '', 1, $empty; +# qt4 + +is_blhc 'qt4', '', 1, + $empty; + # cc @@ -772,3 +924,44 @@ is_blhc ['bad-ldflags', 'empty', 'arch-avr32', 'debian-hardening-wrapper'], '', . "checking './t/logs/debian-hardening-wrapper'...\n" . $debian_hardening_wrapper ; + +# Ignore works correctly with multiple architectures. +is_blhc ['arch-i386', 'arch-amd64', 'arch-avr32', 'ignore-flag'], + '--ignore-arch-flag i386:-fstack-protector --ignore-arch-flag mipsel:-Werror=format-security', 8, + "checking './t/logs/arch-i386'... +LDFLAGS missing (-pie): gcc -fPIE -Wl,-z,relro -Wl,-z,now -o test test.o +checking './t/logs/arch-amd64'... +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 +checking './t/logs/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 +checking './t/logs/ignore-flag'... +CFLAGS missing (-g): gcc -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -c test-b.c +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 ['arch-i386', 'arch-amd64', 'arch-avr32', 'ignore-line'], + '--ignore-arch-line "i386:gcc .+ -fPIE --param=ssp-buffer-size=4 .+" --ignore-arch-line "mipsel:gcc .+ -Wl,-z,relro -Wl,-z,now .+"', 8, + "checking './t/logs/arch-i386'... +LDFLAGS missing (-pie): gcc -fPIE -Wl,-z,relro -Wl,-z,now -o test test.o +checking './t/logs/arch-amd64'... +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 +checking './t/logs/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 +checking './t/logs/ignore-line'... +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -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 +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): ./prepare-script gcc test-a.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-a.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-a.c +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): ./prepare-script gcc test-b.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-b.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-b.c +CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security): ./prepare-script gcc test-c.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): ./prepare-script gcc test-c.c +LDFLAGS missing (-Wl,-z,relro): ./prepare-script gcc test-c.c +" + ;