Commit Graph

31 Commits

Author SHA1 Message Date
Stefan Berger
d4c60e44ce tests: Allow 'ss' as an alternative to 'netstat'
Some distros (openSUSE) have deprecated the 'net-tools' package,
so we allow for 'ss' as an alternative tool from the
iproute/iproute2 package. This is only relevant for test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-02 15:56:42 -04:00
Stefan Berger
88c7bdc9e3 swtpm_cert: Add support for --print-capabilities option
Add support for the --print-capabilities option to display newly
added capabilities. Adpat the man page and related test case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-30 08:52:58 -05:00
Stefan Berger
b291eb83ed samples: Protect variables in swtpm-create-tpmca
Address several issues reported by shellcheck and protect
variables with quotes so we now can have filenames with spaces.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-27 09:16:16 -05:00
Stefan Berger
930c7ba16e tests: Allow seccomp override w/ SWTPM_TEST_SECCOMP_OPT env var
The Ubuntu (PPA) build system executes the build on an environment that
has problems with seccomp profiles. It does not allow us to run the test
suite with swtpm applying its seccomp profile since it fails with a
'bad system call' error. To work around this we introduce the env. variable
SWTPM_TEST_SECCOMP_OPT that we can set to "--seccomp action=none" to avoid
having swtpm apply it seccomp profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-15 15:49:51 -05:00
Stefan Berger
c5748a5354 tests: Move local functions to common file and handle errors better
Move wait_port_open and wait_port_closed to common file and handle
the timeout errors in test_commandline.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
996ad55fbc tests: delay reading of pidfile if found empty
Delay the reading of the PID file if it is found to be empty.
This can happend if swtpm is run by valgrind.

Also, use the passed parameters rather than the global ones to check
the PID file contents against the expected pid. So far this worked
because PID and PID_FILE were variables used by every caller.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-01-13 15:03:01 -05:00
Stefan Berger
1ce7293d3c tests: Skip seccomp check if env. sets up seccomp profile
If the test environment is running in a seccomp profile do not check
that the seccomp profile of the swtpm process runs with the action
provided in --seccomp action=... since the environment may override
this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-08-08 09:36:04 -04:00
Stefan Berger
01ad1d03f1 tests: Get swtpm PID from shell and validate against pidfile after
Get the PID of the started swtpm from the shell and validate it
against the contents of the pidfile afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-13 12:48:36 -04:00
Stefan Berger
0db8249cf1 tests: Extend --print-capabilities tests with test of swtpm_setup
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-07-12 14:18:20 -04:00
Stefan Berger
86e8f60584 tests: wait for file content in wait_for_file
When the PID_FILE is passed to swtpm as a file descriptor in one test,
we already create a file without content when running
'exec 100<>$PID_FILE'. So we have to extend wait_for_file to also
wait for file content since the 0.2 seconds delay are sometimes not
enough for content to have been written. Otherwise we do not get the
PID of the process. We can extend the function in this way since all
its usages imply that some content should become available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-08 10:17:32 -04:00
Stefan Berger
bb0aa2ad5a tests: Pass file ownership using uid and gid
Pass file ownership using the uid= and gid= parameters when run
as root and check the result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
f487473cf6 tests: Use mode= to set file mode bits in test and check them
Use the mode= parameter of the TPM's state file and a unix
socket to have swtpm set the file mode bits and check that
they are set as expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-04-02 18:08:06 -04:00
Stefan Berger
a3820b8634 tests: Extend tests cases with test for active seccomp profiles
Extend existing test cases to test for active seccomp profiles.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2019-03-18 15:43:44 -04:00
Stefan Berger
08c8820a74 tests: Return a string from get_file_hash if file not found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-08 06:43:30 -04:00
Stefan Berger
03c7fe4566 tests: Get the IBM TSS2 test suite and run it
Get the IBM TSS2 test suite from its git repo, compile it, and run
its test suite if SWTPM_TEST_EXPENSIVE=1 is set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-05 13:34:22 -04:00
Stefan Berger
c46d6717ae tests: Add delay after finding file for process to write into it
Add a delay of 0.2s after a file is found in wait_for_file so that the
process can also write into it. Sometimes we are also interested in the
content and don't seem to get the content since we didn't wait for
the file to have been written to. It happens occasionally when the system
is under load that we don't seem to be able to read the file content
afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-01 12:52:20 -04:00
Stefan Berger
100317d541 tests: Call function rather than running 'ps aux' to display proceses
Call a function display_processes_by_name that displays all processes
if needed. The function is quiet, though.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-27 10:19:09 -04:00
Stefan Berger
80f985897c tests: Implement support for OS/X (Darwin)
If the file descriptor 100 is open prior to trying to open
it, it must be closed first on OS/X, otherwise we get test
case failures due to interrupted connections.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:44:24 -04:00
Stefan Berger
47c7ea7783 tests: Make the killing of processes less noisy
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
313cf75c42 tests: Enable running tests in out-of-source builds
Pass the top_builddir and top_srcdir via TESTS_ENVIRONMENT
variable in Makefile.am.

Use TESTDIR for the path to the test directory and replace
previously used DIR in all occurences.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
142a2974ae tests: Poll for 1 second after PID file was found to be gone
Poll for process to be gone for 1 seconds after a shutdown was requested
and it was found that the PID file had been removed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-04 16:10:27 -04:00
Stefan Berger
ee40c13aaf tests: Extend encrypted state test to check for unmodified state
Extend the encrypted state test with a test case using a wrong key
for decrypting the state and make sure that the init fails and the
state files remain unmodified.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-14 07:59:04 -05:00
Stefan Berger
6098d7baae tests: implement missing wait_file_gone function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-17 17:33:23 -04:00
Stefan Berger
6d33f6eb08 tests: increase socat timeout for slow machines
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
bd8f3581ef tests: Wait for previous socket or device to have disappeared
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
35e571b43c tests: Wait for swtpm to open socket or chardev
Rather than waiting for some time poll for the swtpm to either
open a socket or chardev.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
597d06eeef tests: wrap sha1 and file size tools
OpenBSD uses different tools for sha1 and file size calculations,
so we wrap them in functions and check which one to call by using
uname -s.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
27aad7283c tests: write binary string into file and then cat into device
Rather than using the non-bash echo tool, which doesn't seem to
support -e on OpenBSD, use the bash echo tool to write the binary
code into a file and cat the file into the device. This also works
around a problem when a sequence contains \x0a, which then seems
to be the last character written to the device if bash's echo is
used. It does this correctly when writing to a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
a19a868316 tests: convert test_ctrlchannel to use functions
Convert the test_ctrlchannel to use the functions from tests/common.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-11 18:57:16 -04:00
Stefan Berger
19e05751c7 tests: Allow to specify SWTPM_EXE, SWTPM_IOCTL and SWTPM_BIOS for tests
To enable the test suite to for example run a mixture of 32- and
64bit executables, allow users to specify the executables to use by
setting the variables SWTPM_EXE, SWTPM_IOCTL, and SWTPM_BIOS via
command line.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 07:17:25 -04:00
Stefan Berger
f3a149175c tests: add functions for running swtpm and swtpm_ioctl
To be able to run tests with either one of the interfaces, add function
for running swtpm and swtpm_ioctl commands and form the command line
parameters dependent on the type of interface being passed. We rely on
environment variables to provide the specific parameters that are needed
to run the program with the appropriate parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00