diff options
| -rw-r--r-- | tests/matrix/main_test.go | 114 | ||||
| -rw-r--r-- | tests/matrix/matrix_test.go | 104 | 
2 files changed, 114 insertions, 104 deletions
| diff --git a/tests/matrix/main_test.go b/tests/matrix/main_test.go new file mode 100644 index 0000000..fb2b273 --- /dev/null +++ b/tests/matrix/main_test.go @@ -0,0 +1,114 @@ +// Tests run for (almost all) combinations of openssl, aessiv, plaintextnames. +// +// File reading, writing, modification, truncate, ... +// +// Runs all tests N times, for the combinations of different flags specified +// in the `matrix` variable. + +package matrix + +import ( +	"flag" +	"fmt" +	"os" +	"testing" +	"time" + +	"github.com/rfjakob/gocryptfs/v2/internal/stupidgcm" +	"github.com/rfjakob/gocryptfs/v2/tests/test_helpers" +) + +// Several tests need to be aware if plaintextnames is active or not, so make this +// a global variable +var testcase testcaseMatrix + +type testcaseMatrix struct { +	plaintextnames bool +	openssl        string +	aessiv         bool +	raw64          bool +	extraArgs      []string +} + +// isSet finds out if `extraArg` is set in `tc.extraArgs` +func (tc *testcaseMatrix) isSet(extraArg string) bool { +	for _, v := range tc.extraArgs { +		if v == extraArg { +			return true +		} +	} +	return false +} + +var matrix = []testcaseMatrix{ +	// Normal +	{false, "auto", false, false, nil}, +	{false, "true", false, false, nil}, +	{false, "false", false, false, nil}, +	// Plaintextnames +	{true, "true", false, false, nil}, +	{true, "false", false, false, nil}, +	// AES-SIV (does not use openssl, no need to test permutations) +	{false, "auto", true, false, nil}, +	{true, "auto", true, false, nil}, +	// Raw64 +	{false, "auto", false, true, nil}, +	// -serialize_reads +	{false, "auto", false, false, []string{"-serialize_reads"}}, +	{false, "auto", false, false, []string{"-sharedstorage"}}, +	{false, "auto", false, false, []string{"-deterministic-names"}}, +	// Test xchacha with and without openssl +	{false, "true", false, true, []string{"-xchacha"}}, +	{false, "false", false, true, []string{"-xchacha"}}, +} + +// This is the entry point for the tests +func TestMain(m *testing.M) { +	// Make "testing.Verbose()" return the correct value +	flag.Parse() +	var i int +	for i, testcase = range matrix { +		if testcase.openssl == "true" && stupidgcm.BuiltWithoutOpenssl { +			continue +		} +		if testing.Verbose() { +			fmt.Printf("matrix: testcase = %#v\n", testcase) +		} +		createDirIV := true +		if testcase.plaintextnames { +			createDirIV = false +		} else if testcase.isSet("-deterministic-names") { +			createDirIV = false +		} +		test_helpers.ResetTmpDir(createDirIV) +		opts := []string{"-zerokey"} +		//opts = append(opts, "-fusedebug") +		opts = append(opts, fmt.Sprintf("-openssl=%v", testcase.openssl)) +		opts = append(opts, fmt.Sprintf("-plaintextnames=%v", testcase.plaintextnames)) +		opts = append(opts, fmt.Sprintf("-aessiv=%v", testcase.aessiv)) +		opts = append(opts, fmt.Sprintf("-raw64=%v", testcase.raw64)) +		opts = append(opts, testcase.extraArgs...) +		test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...) +		before := test_helpers.ListFds(0, test_helpers.TmpDir) +		t0 := time.Now() +		r := m.Run() +		if testing.Verbose() { +			fmt.Printf("matrix: run took %v\n", time.Since(t0)) +		} +		// Catch fd leaks in the tests. NOTE: this does NOT catch leaks in +		// the gocryptfs FUSE process, but only in the tests that access it! +		// All fds that point outside TmpDir are not interesting (the Go test +		// infrastucture creates temporary log files we don't care about). +		after := test_helpers.ListFds(0, test_helpers.TmpDir) +		if len(before) != len(after) { +			fmt.Printf("fd leak in test process? before, after:\n%v\n%v\n", before, after) +			os.Exit(1) +		} +		test_helpers.UnmountPanic(test_helpers.DefaultPlainDir) +		if r != 0 { +			fmt.Printf("TestMain: matrix[%d] = %#v failed\n", i, testcase) +			os.Exit(r) +		} +	} +	os.Exit(0) +} diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index b406517..d32d3d8 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -1,14 +1,7 @@ -// Tests run for (almost all) combinations of openssl, aessiv, plaintextnames.  package matrix -// File reading, writing, modification, truncate, ... -// -// Runs all tests N times, for the combinations of different flags specified -// in the `matrix` variable. -  import (  	"bytes" -	"flag"  	"fmt"  	"math/rand"  	"os" @@ -19,109 +12,12 @@ import (  	"sync"  	"syscall"  	"testing" -	"time"  	"golang.org/x/sys/unix" -	"github.com/rfjakob/gocryptfs/v2/internal/stupidgcm"  	"github.com/rfjakob/gocryptfs/v2/tests/test_helpers"  ) -// Several tests need to be aware if plaintextnames is active or not, so make this -// a global variable -var testcase testcaseMatrix - -type testcaseMatrix struct { -	plaintextnames bool -	openssl        string -	aessiv         bool -	raw64          bool -	extraArgs      []string -} - -// isSet finds out if `extraArg` is set in `tc.extraArgs` -func (tc *testcaseMatrix) isSet(extraArg string) bool { -	for _, v := range tc.extraArgs { -		if v == extraArg { -			return true -		} -	} -	return false -} - -var matrix = []testcaseMatrix{ -	// Normal -	{false, "auto", false, false, nil}, -	{false, "true", false, false, nil}, -	{false, "false", false, false, nil}, -	// Plaintextnames -	{true, "true", false, false, nil}, -	{true, "false", false, false, nil}, -	// AES-SIV (does not use openssl, no need to test permutations) -	{false, "auto", true, false, nil}, -	{true, "auto", true, false, nil}, -	// Raw64 -	{false, "auto", false, true, nil}, -	// -serialize_reads -	{false, "auto", false, false, []string{"-serialize_reads"}}, -	{false, "auto", false, false, []string{"-sharedstorage"}}, -	{false, "auto", false, false, []string{"-deterministic-names"}}, -	// Test xchacha with and without openssl -	{false, "true", false, true, []string{"-xchacha"}}, -	{false, "false", false, true, []string{"-xchacha"}}, -} - -// This is the entry point for the tests -func TestMain(m *testing.M) { -	// Make "testing.Verbose()" return the correct value -	flag.Parse() -	var i int -	for i, testcase = range matrix { -		if testcase.openssl == "true" && stupidgcm.BuiltWithoutOpenssl { -			continue -		} -		if testing.Verbose() { -			fmt.Printf("matrix: testcase = %#v\n", testcase) -		} -		createDirIV := true -		if testcase.plaintextnames { -			createDirIV = false -		} else if testcase.isSet("-deterministic-names") { -			createDirIV = false -		} -		test_helpers.ResetTmpDir(createDirIV) -		opts := []string{"-zerokey"} -		//opts = append(opts, "-fusedebug") -		opts = append(opts, fmt.Sprintf("-openssl=%v", testcase.openssl)) -		opts = append(opts, fmt.Sprintf("-plaintextnames=%v", testcase.plaintextnames)) -		opts = append(opts, fmt.Sprintf("-aessiv=%v", testcase.aessiv)) -		opts = append(opts, fmt.Sprintf("-raw64=%v", testcase.raw64)) -		opts = append(opts, testcase.extraArgs...) -		test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...) -		before := test_helpers.ListFds(0, test_helpers.TmpDir) -		t0 := time.Now() -		r := m.Run() -		if testing.Verbose() { -			fmt.Printf("matrix: run took %v\n", time.Since(t0)) -		} -		// Catch fd leaks in the tests. NOTE: this does NOT catch leaks in -		// the gocryptfs FUSE process, but only in the tests that access it! -		// All fds that point outside TmpDir are not interesting (the Go test -		// infrastucture creates temporary log files we don't care about). -		after := test_helpers.ListFds(0, test_helpers.TmpDir) -		if len(before) != len(after) { -			fmt.Printf("fd leak in test process? before, after:\n%v\n%v\n", before, after) -			os.Exit(1) -		} -		test_helpers.UnmountPanic(test_helpers.DefaultPlainDir) -		if r != 0 { -			fmt.Printf("TestMain: matrix[%d] = %#v failed\n", i, testcase) -			os.Exit(r) -		} -	} -	os.Exit(0) -} -  // Write `n` random bytes to filename `fn`, read again, compare hash  func testWriteN(t *testing.T, fn string, n int) string {  	file, err := os.Create(test_helpers.DefaultPlainDir + "/" + fn) | 
