File: test_tpm2_chroot_socket

package info (click to toggle)
swtpm 0.10.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,008 kB
  • sloc: ansic: 20,787; sh: 14,667; makefile: 760; python: 173
file content (76 lines) | stat: -rwxr-xr-x 1,548 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash

# For the license, see the LICENSE file in the root directory.

if [ "$(id -u)" -ne 0 ]; then
        echo "Need to be root to run this test."
        exit 77
fi

if [ "$(uname -s)" != "Linux" ]; then
	# Due to using /proc/<pid>/root
	echo "This test only runs only Linux."
	exit 77
fi

ROOT=${abs_top_builddir:-$(dirname "$0")/..}
TESTDIR=${abs_top_testdir:=$(dirname "$0")}

PID_FILE=/swtpm.pid

source "${TESTDIR}/common"
source "${TESTDIR}/test_common"
skip_test_no_chardev "${SWTPM_EXE}"
skip_test_no_tpm20 "${SWTPM_EXE}"

trap "cleanup" SIGTERM EXIT

function cleanup()
{
	rm -rf "$TPMDIR"
	if [ -n "$PID" ]; then
		kill_quiet -SIGTERM "$PID" 2>/dev/null
	fi
}

PORT=65468

export TCSD_TCP_DEVICE_HOSTNAME=localhost
export TCSD_TCP_DEVICE_PORT=$PORT
export TCSD_USE_TCP_DEVICE=1

for OPTION in --chroot -R; do
	TPMDIR="$(mktemp -d)" || exit 1
	mkdir "$TPMDIR/dev"
	mknod -m 0666 "$TPMDIR/dev/urandom" c 1 9

	$SWTPM_EXE socket \
		-p $PORT \
		"$OPTION" "$TPMDIR" \
		--tpmstate dir=/ \
		--pid "file=$PID_FILE" \
		--tpm2 \
		--flags not-need-init \
		${SWTPM_TEST_SECCOMP_OPT:+${SWTPM_TEST_SECCOMP_OPT}} &
	PID=$!

	if wait_for_file "$TPMDIR/$PID_FILE" 3; then
		echo "Error: socket TPM did not write pidfile."
		exit 1
	fi

	validate_pidfile "$PID" "$TPMDIR/$PID_FILE"

	if [ "$(readlink /proc/$PID/root)" != "$TPMDIR" ]; then
		echo "Test 1 failed: Unexpected chroot dir"
		exit 1
	fi

	if [ ! -f "${TPMDIR}/tpm2-00.permall" ]; then
		echo "Missing state file"
		exit 1
	fi

	echo "Test $OPTION passed"
	cleanup
done