From ef2dd74a86e2125215fadf5a6f376086d689c214 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Sep 2024 12:48:16 +0200 Subject: [PATCH 1/5] Run test suites with a single call to run-test-suites.pl Before this commit, `make test` stopped after running the TLS tests if there was a failure. Have `run-test-suites.pl` take care of looking in all the directories, so that the last line of output from `make test` is an accurate report of all the test suites, not just the test suites from the last run of `run-test-suites.pl`. Signed-off-by: Gilles Peskine --- tests/Makefile | 1 - tests/scripts/run-test-suites.pl | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 3f1a6dfcfd..635816b50f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -270,7 +270,6 @@ endif # Test suites caught by SKIP_TEST_SUITES are built but not executed. check: $(BINARIES) $(CRYPTO_BINARIES) perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES) - cd ../tf-psa-crypto/tests && perl ../../tests/scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES) test: check diff --git a/tests/scripts/run-test-suites.pl b/tests/scripts/run-test-suites.pl index 408deaf13b..8274210e6f 100755 --- a/tests/scripts/run-test-suites.pl +++ b/tests/scripts/run-test-suites.pl @@ -40,7 +40,8 @@ GetOptions( # All test suites = executable files with a .datax file. my @suites = (); -for my $data_file (glob 'test_suite_*.datax') { +my @test_dirs = qw(../tf-psa-crypto/tests .); +for my $data_file (map {glob "$_/test_suite_*.datax"} @test_dirs) { (my $base = $data_file) =~ s/\.datax$//; push @suites, $base if -x $base; push @suites, "$base.exe" if -e "$base.exe"; @@ -82,8 +83,10 @@ sub pad_print_center { print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n"; } -for my $suite (@suites) +for my $suite_path (@suites) { + my $suite = $suite_path; + $suite =~ s!.*/!!; print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; if( $suite =~ /$skip_re/o ) { print "SKIP\n"; @@ -91,7 +94,7 @@ for my $suite (@suites) next; } - my $command = "$prefix$suite"; + my $command = "$prefix$suite_path"; if( $verbose ) { $command .= ' -v'; } From 24515f9b713949c07a598cca6f60996ebc8c15a1 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Sep 2024 12:46:08 +0200 Subject: [PATCH 2/5] Revert "Adapt basic-build-test.sh" This reverts commit 0866936d26436401cb5976b9c2a93ceb1110e1cf. Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 59 +++++++------------------------ 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index b850147738..d2e955f1eb 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -35,8 +35,6 @@ if [ -d library -a -d include -a -d tests ]; then :; else exit 1 fi -MBEDTLS_ROOT_DIR="$PWD" - : ${OPENSSL:="openssl"} : ${GNUTLS_CLI:="gnutls-cli"} : ${GNUTLS_SERV:="gnutls-serv"} @@ -81,11 +79,7 @@ make # Step 2 - Execute the tests TEST_OUTPUT=out_${PPID} -cd $MBEDTLS_ROOT_DIR/tests -if [ ! -f "seedfile" ]; then - dd if=/dev/urandom of="seedfile" bs=64 count=1 -fi -cd $MBEDTLS_ROOT_DIR/tf-psa-crypto/tests +cd tests if [ ! -f "seedfile" ]; then dd if=/dev/urandom of="seedfile" bs=64 count=1 fi @@ -93,14 +87,10 @@ echo # Step 2a - Unit Tests (keep going even if some tests fail) echo '################ Unit tests ################' -cd $MBEDTLS_ROOT_DIR/tests -perl scripts/run-test-suites.pl -v 2 |tee tls-x509-unit-test-$TEST_OUTPUT -cd $MBEDTLS_ROOT_DIR/tf-psa-crypto/tests -perl $MBEDTLS_ROOT_DIR/tests/scripts/run-test-suites.pl -v 2 |tee ../../tests/crypto-unit-test-$TEST_OUTPUT +perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^' echo -cd $MBEDTLS_ROOT_DIR/tests # Step 2b - System Tests (keep going even if some tests fail) echo echo '################ ssl-opt.sh ################' @@ -151,13 +141,13 @@ rm -f "tests/basic-build-test-$$.ok" cd tests - # Step 4a - TLS and x509 unit tests - echo "TLS and x509 unit tests - tests/scripts/run-test-suites.pl" + # Step 4a - Unit tests + echo "Unit tests - tests/scripts/run-test-suites.pl" - PASSED_TESTS=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') - SKIPPED_TESTS=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') - TOTAL_SUITES=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') - FAILED_TESTS=$(tail -n6 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') + PASSED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') + SKIPPED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') + TOTAL_SUITES=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') + FAILED_TESTS=$(tail -n6 unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') echo "No test suites : $TOTAL_SUITES" echo "Passed : $PASSED_TESTS" @@ -173,29 +163,7 @@ rm -f "tests/basic-build-test-$$.ok" TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) - # Step 4b - Crypto unit tests - echo "Crypto unit tests - tests/scripts/run-test-suites.pl" - - PASSED_TESTS=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/test cases passed :[\t]*\([0-9]*\)/\1/p'| tr -d ' ') - SKIPPED_TESTS=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \t]*\([0-9]*\)/\1/p'| tr -d ' ') - TOTAL_SUITES=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\1/p'| tr -d ' ') - FAILED_TESTS=$(tail -n6 crypto-unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\1/p' |tr -d ' ') - - echo "No test suites : $TOTAL_SUITES" - echo "Passed : $PASSED_TESTS" - echo "Failed : $FAILED_TESTS" - echo "Skipped : $SKIPPED_TESTS" - echo "Total exec'd tests : $(($PASSED_TESTS + $FAILED_TESTS))" - echo "Total avail tests : $(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))" - echo - - TOTAL_PASS=$(($TOTAL_PASS+$PASSED_TESTS)) - TOTAL_FAIL=$(($TOTAL_FAIL+$FAILED_TESTS)) - TOTAL_SKIP=$(($TOTAL_SKIP+$SKIPPED_TESTS)) - TOTAL_AVAIL=$(($TOTAL_AVAIL + $PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) - TOTAL_EXED=$(($TOTAL_EXED + $PASSED_TESTS + $FAILED_TESTS)) - - # Step 4c - TLS Options tests + # Step 4b - TLS Options tests echo "TLS Options tests - tests/ssl-opt.sh" PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p') @@ -217,7 +185,7 @@ rm -f "tests/basic-build-test-$$.ok" TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) - # Step 4d - System Compatibility tests + # Step 4c - System Compatibility tests echo "System/Compatibility tests - tests/compat.sh" PASSED_TESTS=$(cat compat-test-$TEST_OUTPUT | sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p' | awk 'BEGIN{ s = 0 } { s += $1 } END{ print s }') @@ -239,7 +207,7 @@ rm -f "tests/basic-build-test-$$.ok" TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) - # Step 4e - Grand totals + # Step 4d - Grand totals echo "-------------------------------------------------------------------------" echo "Total tests" @@ -251,13 +219,12 @@ rm -f "tests/basic-build-test-$$.ok" echo - # Step 4f - Coverage report + # Step 4e - Coverage report echo "Coverage statistics:" sed -n '1,/^Overall coverage/d; /%/p' cov-$TEST_OUTPUT echo - rm tls-x509-unit-test-$TEST_OUTPUT - rm crypto-unit-test-$TEST_OUTPUT + rm unit-test-$TEST_OUTPUT rm sys-test-$TEST_OUTPUT rm compat-test-$TEST_OUTPUT rm cov-$TEST_OUTPUT From 282abb507dd61222c8ecaea463729ce8e561428a Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Sep 2024 12:49:50 +0200 Subject: [PATCH 3/5] Create seedfile in the tf-psa-crypto subproject Signed-off-by: Gilles Peskine --- tests/scripts/basic-build-test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh index d2e955f1eb..4adae9adcc 100755 --- a/tests/scripts/basic-build-test.sh +++ b/tests/scripts/basic-build-test.sh @@ -83,6 +83,9 @@ cd tests if [ ! -f "seedfile" ]; then dd if=/dev/urandom of="seedfile" bs=64 count=1 fi +if [ ! -f "../tf-psa-crypto/tests/seedfile" ]; then + cp "seedfile" "../tf-psa-crypto/tests/seedfile" +fi echo # Step 2a - Unit Tests (keep going even if some tests fail) From 71a53b5cc09481eb3c35b36d65dce6fabedeb4bf Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Sep 2024 13:21:50 +0200 Subject: [PATCH 4/5] Fix test suites invoked in the wrong directory Running test suites from another directory only works when the auto-chdir code in host_test.function is enabled, which is platform-dependent and configuration-dependent. Signed-off-by: Gilles Peskine --- tests/scripts/run-test-suites.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/scripts/run-test-suites.pl b/tests/scripts/run-test-suites.pl index 8274210e6f..7f20ae00ee 100755 --- a/tests/scripts/run-test-suites.pl +++ b/tests/scripts/run-test-suites.pl @@ -85,8 +85,11 @@ sub pad_print_center { for my $suite_path (@suites) { - my $suite = $suite_path; - $suite =~ s!.*/!!; + my ($dir, $suite) = ('.', $suite_path); + if ($suite =~ m!(.*)/([^/]*)!) { + $dir = $1; + $suite = $2; + } print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; if( $suite =~ /$skip_re/o ) { print "SKIP\n"; @@ -94,7 +97,7 @@ for my $suite_path (@suites) next; } - my $command = "$prefix$suite_path"; + my $command = "cd $dir && $prefix$suite"; if( $verbose ) { $command .= ' -v'; } From 9fa8dc44d6b3263e1b569852a8172234a8b7bcc4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Sep 2024 16:07:09 +0200 Subject: [PATCH 5/5] Fix shared library builds Signed-off-by: Gilles Peskine --- tests/scripts/run-test-suites.pl | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/scripts/run-test-suites.pl b/tests/scripts/run-test-suites.pl index 7f20ae00ee..e01d44f6e1 100755 --- a/tests/scripts/run-test-suites.pl +++ b/tests/scripts/run-test-suites.pl @@ -28,6 +28,7 @@ use strict; use utf8; use open qw(:std utf8); +use Cwd qw(getcwd); use Getopt::Long qw(:config auto_help gnu_compat); use Pod::Usage; @@ -60,15 +61,8 @@ my $skip_re = ')(\z|\.)' ); # in case test suites are linked dynamically -if (-d '../../tf-psa-crypto') { - $ENV{'LD_LIBRARY_PATH'} = '../../library'; - $ENV{'DYLD_LIBRARY_PATH'} = '../../library'; -} -else -{ - $ENV{'LD_LIBRARY_PATH'} = '../library'; - $ENV{'DYLD_LIBRARY_PATH'} = '../library'; -} +$ENV{'LD_LIBRARY_PATH'} = getcwd() . "/../library"; +$ENV{'DYLD_LIBRARY_PATH'} = $ENV{'LD_LIBRARY_PATH'}; # For macOS my $prefix = $^O eq "MSWin32" ? '' : './';