1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

Merge pull request #9558 from gilles-peskine-arm/run-test-suites-on-subproject

Run test suites on subproject
This commit is contained in:
Gilles Peskine
2024-09-28 08:31:30 +00:00
committed by GitHub
3 changed files with 27 additions and 58 deletions

View File

@ -281,7 +281,6 @@ endif
# Test suites caught by SKIP_TEST_SUITES are built but not executed. # Test suites caught by SKIP_TEST_SUITES are built but not executed.
check: $(BINARIES) $(CRYPTO_BINARIES) check: $(BINARIES) $(CRYPTO_BINARIES)
perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES) 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 test: check

View File

@ -35,8 +35,6 @@ if [ -d library -a -d include -a -d tests ]; then :; else
exit 1 exit 1
fi fi
MBEDTLS_ROOT_DIR="$PWD"
: ${OPENSSL:="openssl"} : ${OPENSSL:="openssl"}
: ${GNUTLS_CLI:="gnutls-cli"} : ${GNUTLS_CLI:="gnutls-cli"}
: ${GNUTLS_SERV:="gnutls-serv"} : ${GNUTLS_SERV:="gnutls-serv"}
@ -81,26 +79,21 @@ make
# Step 2 - Execute the tests # Step 2 - Execute the tests
TEST_OUTPUT=out_${PPID} TEST_OUTPUT=out_${PPID}
cd $MBEDTLS_ROOT_DIR/tests cd tests
if [ ! -f "seedfile" ]; then if [ ! -f "seedfile" ]; then
dd if=/dev/urandom of="seedfile" bs=64 count=1 dd if=/dev/urandom of="seedfile" bs=64 count=1
fi fi
cd $MBEDTLS_ROOT_DIR/tf-psa-crypto/tests if [ ! -f "../tf-psa-crypto/tests/seedfile" ]; then
if [ ! -f "seedfile" ]; then cp "seedfile" "../tf-psa-crypto/tests/seedfile"
dd if=/dev/urandom of="seedfile" bs=64 count=1
fi fi
echo echo
# Step 2a - Unit Tests (keep going even if some tests fail) # Step 2a - Unit Tests (keep going even if some tests fail)
echo '################ Unit tests ################' echo '################ Unit tests ################'
cd $MBEDTLS_ROOT_DIR/tests perl scripts/run-test-suites.pl -v 2 |tee unit-test-$TEST_OUTPUT
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
echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^' echo '^^^^^^^^^^^^^^^^ Unit tests ^^^^^^^^^^^^^^^^'
echo echo
cd $MBEDTLS_ROOT_DIR/tests
# Step 2b - System Tests (keep going even if some tests fail) # Step 2b - System Tests (keep going even if some tests fail)
echo echo
echo '################ ssl-opt.sh ################' echo '################ ssl-opt.sh ################'
@ -151,13 +144,13 @@ rm -f "tests/basic-build-test-$$.ok"
cd tests cd tests
# Step 4a - TLS and x509 unit tests # Step 4a - Unit tests
echo "TLS and x509 unit tests - tests/scripts/run-test-suites.pl" 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 ' ') 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 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/skipped :[ \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 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) .*, [0-9]* tests run)/\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 tls-x509-unit-test-$TEST_OUTPUT|sed -n -e 's/failed :[\t]*\([0-9]*\)/\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 "No test suites : $TOTAL_SUITES"
echo "Passed : $PASSED_TESTS" echo "Passed : $PASSED_TESTS"
@ -173,29 +166,7 @@ rm -f "tests/basic-build-test-$$.ok"
TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS)) TOTAL_AVAIL=$(($PASSED_TESTS + $FAILED_TESTS + $SKIPPED_TESTS))
TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS)) TOTAL_EXED=$(($PASSED_TESTS + $FAILED_TESTS))
# Step 4b - Crypto unit tests # Step 4b - TLS Options 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
echo "TLS Options tests - tests/ssl-opt.sh" 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') PASSED_TESTS=$(tail -n5 sys-test-$TEST_OUTPUT|sed -n -e 's/.* (\([0-9]*\) \/ [0-9]* tests ([0-9]* skipped))$/\1/p')
@ -217,7 +188,7 @@ rm -f "tests/basic-build-test-$$.ok"
TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS)) TOTAL_EXED=$(($TOTAL_EXED + $TOTAL_TESTS))
# Step 4d - System Compatibility tests # Step 4c - System Compatibility tests
echo "System/Compatibility tests - tests/compat.sh" 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 }') 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 +210,7 @@ rm -f "tests/basic-build-test-$$.ok"
TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS)) TOTAL_EXED=$(($TOTAL_EXED + $EXED_TESTS))
# Step 4e - Grand totals # Step 4d - Grand totals
echo "-------------------------------------------------------------------------" echo "-------------------------------------------------------------------------"
echo "Total tests" echo "Total tests"
@ -251,13 +222,12 @@ rm -f "tests/basic-build-test-$$.ok"
echo echo
# Step 4f - Coverage report # Step 4e - Coverage report
echo "Coverage statistics:" echo "Coverage statistics:"
sed -n '1,/^Overall coverage/d; /%/p' cov-$TEST_OUTPUT sed -n '1,/^Overall coverage/d; /%/p' cov-$TEST_OUTPUT
echo echo
rm tls-x509-unit-test-$TEST_OUTPUT rm unit-test-$TEST_OUTPUT
rm crypto-unit-test-$TEST_OUTPUT
rm sys-test-$TEST_OUTPUT rm sys-test-$TEST_OUTPUT
rm compat-test-$TEST_OUTPUT rm compat-test-$TEST_OUTPUT
rm cov-$TEST_OUTPUT rm cov-$TEST_OUTPUT

View File

@ -28,6 +28,7 @@ use strict;
use utf8; use utf8;
use open qw(:std utf8); use open qw(:std utf8);
use Cwd qw(getcwd);
use Getopt::Long qw(:config auto_help gnu_compat); use Getopt::Long qw(:config auto_help gnu_compat);
use Pod::Usage; use Pod::Usage;
@ -40,7 +41,8 @@ GetOptions(
# All test suites = executable files with a .datax file. # All test suites = executable files with a .datax file.
my @suites = (); 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$//; (my $base = $data_file) =~ s/\.datax$//;
push @suites, $base if -x $base; push @suites, $base if -x $base;
push @suites, "$base.exe" if -e "$base.exe"; push @suites, "$base.exe" if -e "$base.exe";
@ -59,15 +61,8 @@ my $skip_re =
')(\z|\.)' ); ')(\z|\.)' );
# in case test suites are linked dynamically # in case test suites are linked dynamically
if (-d '../../tf-psa-crypto') { $ENV{'LD_LIBRARY_PATH'} = getcwd() . "/../library";
$ENV{'LD_LIBRARY_PATH'} = '../../library'; $ENV{'DYLD_LIBRARY_PATH'} = $ENV{'LD_LIBRARY_PATH'}; # For macOS
$ENV{'DYLD_LIBRARY_PATH'} = '../../library';
}
else
{
$ENV{'LD_LIBRARY_PATH'} = '../library';
$ENV{'DYLD_LIBRARY_PATH'} = '../library';
}
my $prefix = $^O eq "MSWin32" ? '' : './'; my $prefix = $^O eq "MSWin32" ? '' : './';
@ -82,8 +77,13 @@ sub pad_print_center {
print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n"; print $padchar x( $padlen ), " $string ", $padchar x( $padlen ), "\n";
} }
for my $suite (@suites) for my $suite_path (@suites)
{ {
my ($dir, $suite) = ('.', $suite_path);
if ($suite =~ m!(.*)/([^/]*)!) {
$dir = $1;
$suite = $2;
}
print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " ";
if( $suite =~ /$skip_re/o ) { if( $suite =~ /$skip_re/o ) {
print "SKIP\n"; print "SKIP\n";
@ -91,7 +91,7 @@ for my $suite (@suites)
next; next;
} }
my $command = "$prefix$suite"; my $command = "cd $dir && $prefix$suite";
if( $verbose ) { if( $verbose ) {
$command .= ' -v'; $command .= ' -v';
} }