From 0e8e1dd20cf89dc0ac603a151452ca5b40a29580 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 20 Oct 2014 19:59:08 +0200 Subject: [PATCH] tests: Move perl tests to tests/, make them callable from top-level Makefile Use "make test" or "make test-verbose" to run. Note that "make test" seems to be more common than "make tests", hence the change. Also, use a new clean directory directory as a working area for each run Created using mkdtemp and deleted in cleanup() --- Makefile.am | 8 ++++++ encfs/Makefile.am | 6 ---- encfs/tests.t => tests/normal.pl | 47 +++++++++++++++++--------------- 3 files changed, 33 insertions(+), 28 deletions(-) rename encfs/tests.t => tests/normal.pl (90%) diff --git a/Makefile.am b/Makefile.am index 05cb17d..020fa7a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,3 +14,11 @@ MAINTAINERCLEANFILES = aclocal.m4 ACLOCAL_AMFLAGS = -I m4 + +.PHONY: test +test: + perl -MTest::Harness -e '$$Test::Harness::verbose=0; runtests @ARGV;' tests/*.pl + +.PHONY: test-verbose +test-verbose: + perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' tests/*.pl diff --git a/encfs/Makefile.am b/encfs/Makefile.am index 778df1f..9174a60 100644 --- a/encfs/Makefile.am +++ b/encfs/Makefile.am @@ -141,9 +141,3 @@ encfs-man.html: encfs.pod @POD2HTML@ encfs.pod > $@ endif -tests: - perl -MTest::Harness -e '$$Test::Harness::verbose=0; runtests @ARGV;' *.t - -tests-verbose: - perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' *.t - diff --git a/encfs/tests.t b/tests/normal.pl similarity index 90% rename from encfs/tests.t rename to tests/normal.pl index 1d18cfe..0820030 100644 --- a/encfs/tests.t +++ b/tests/normal.pl @@ -3,26 +3,25 @@ use Test::More qw( no_plan ); use File::Path; use File::Copy; +use File::Temp; use IO::Handle; use Digest::MD5 qw(md5_hex); my $tempDir = $ENV{'TMPDIR'} || "/tmp"; -my $raw = "$tempDir/crypt-raw-$$"; -my $crypt = "$tempDir/crypt-$$"; - # test filesystem in standard config mode &runTests('standard'); # test in paranoia mode &runTests('paranoia'); - # Wrapper function - runs all tests in the specified mode sub runTests { my $mode = shift; + &newWorkingDir; + my $hardlinks = 1; if($mode eq 'standard') { @@ -48,6 +47,17 @@ sub runTests &cleanup; } +# Helper function +# Create a new empty working directory +sub newWorkingDir +{ + our $workingDir = mkdtemp("$tempDir/encfs-tests-XXXX") + || BAIL_OUT("Could not create temporary directory"); + + our $raw = "$workingDir/raw"; + our $crypt = "$workingDir/crypt"; +} + # Test Corruption # Modify the encrypted file and verify that the MAC check detects it sub corruption @@ -71,7 +81,7 @@ sub corruption # (like a database would do) sub internalModification { - $ofile = "$tempDir/crypt-internal-$$"; + $ofile = "$workingDir/crypt-internal-$$"; qx(dd if=/dev/urandom of=$ofile bs=2k count=2 2> /dev/null); ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file"); @@ -177,7 +187,7 @@ sub fileCreation # create a file qx(df -ah > "$crypt/df.txt"); ok( -f "$crypt/df.txt", "file created" ); - + # ensure there is an encrypted version. my $c = encName("df.txt"); cmp_ok( length($c), '>', 8, "encrypted name ok" ); @@ -196,7 +206,7 @@ sub fileCreation sub grow { open(my $fh_a, "+>$crypt/grow"); - open(my $fh_b, "+>$tempDir/grow"); + open(my $fh_b, "+>$workingDir/grow"); my $d = "1234567"; # Length 7 so we are not aligned to the block size my $len = 7; @@ -248,7 +258,7 @@ sub checkContents sub encName { my $plain = shift; - my $enc = qx(./encfsctl encode --extpass="echo test" $raw $plain); + my $enc = qx(./encfs/encfsctl encode --extpass="echo test" $raw $plain); chomp($enc); return $enc; } @@ -285,7 +295,7 @@ sub links SKIP: { skip "No hardlink support" unless $hardlinkTests; - + ok( link("$crypt/data", "$crypt/data.2"), "hard link"); checkContents("$crypt/data.2", $contents, "hardlink read"); }; @@ -297,15 +307,11 @@ sub mount { my $args = shift; - ok( ! -d $raw, "no existing dir"); - ok( ! -d $crypt, "no existing dir"); + # When these fail, the rest of the tests makes no sense + mkdir($raw) || BAIL_OUT("Could not create $raw: $!"); + mkdir($crypt) || BAIL_OUT("Could not create $crypt: $!"); - mkdir $raw; - ok( -d $raw, "created dir" ); - mkdir $crypt; - ok( -d $crypt, "created dir" ); - - qx(./encfs --extpass="echo test" $args $raw $crypt); + qx(./encfs/encfs --extpass="echo test" $args $raw $crypt); ok( -f "$raw/.encfs6.xml", "created control file"); } @@ -327,10 +333,7 @@ sub cleanup rmdir $crypt; ok( ! -d $crypt, "unmount ok, mount point removed"); - if(-d $raw) - { - rmtree($raw); - } - ok( ! -d $raw, "encrypted directory removed"); + rmtree($workingDir); + ok( ! -d $workingDir, "working dir removed"); }