3 # For the license, see the LICENSE file in the root directory.
6 ROOT
=${abs_top_builddir:-$(pwd)/..}
7 TESTDIR
=${abs_top_testdir:-$(dirname "$0")}
9 VTPM_NAME
="vtpm-test-tpm2-init"
10 SWTPM_DEV_NAME
="/dev/${VTPM_NAME}"
11 export TPM_PATH
="$(mktemp -d)" ||
exit 1
12 STATE_FILE
=$TPM_PATH/tpm2-00.permall
13 VOLATILE_STATE_FILE
=$TPM_PATH/tpm2-00.volatilestate
14 SWTPM_INTERFACE
=${SWTPM_INTERFACE:-cuse}
15 SWTPM_CMD_UNIX_PATH
=${TPM_PATH}/unix-cmd.sock
16 SWTPM_CTRL_UNIX_PATH
=${TPM_PATH}/unix-ctrl.sock
21 if [ -n "$pid" ]; then
29 [ "${SWTPM_INTERFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
30 source ${TESTDIR}/common
32 rm -f $STATE_FILE $VOLATILE_STATE_FILE 2>/dev
/null
34 if has_seccomp_support
"${SWTPM_EXE}"; then
35 SWTPM_TEST_SECCOMP_OPT
="--seccomp action=none"
38 run_swtpm
${SWTPM_INTERFACE} --tpm2
40 display_processes_by_name
"$SWTPM"
42 kill_quiet
-0 ${SWTPM_PID}
44 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
49 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
51 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
55 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
57 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
61 # Init the TPM again but make its state file inaccessible; this only
62 # works if the TPM runs as non-rootchmod 000 "${STATE_FILE}"
63 if [ "$(id -u)" != "0" ]; then
64 chmod 000 "${STATE_FILE}"
65 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
67 echo "Error: Unexpected initialization success of the ${SWTPM_INTERFACE} TPM."
73 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
75 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after failed INIT."
78 chmod 664 "${STATE_FILE}"
80 # Init the TPM again; now with state file accessible again
81 run_swtpm_ioctl
${SWTPM_INTERFACE} -i
83 echo "Error: Could not initialize the ${SWTPM_INTERFACE} TPM."
89 kill_quiet
-0 ${SWTPM_PID} 2>/dev
/null
91 echo "Error: ${SWTPM_INTERFACE} TPM not running anymore after INIT."
96 check_seccomp_profile
"${SWTPM_EXE}" ${SWTPM_PID} 0
102 run_swtpm_ioctl
${SWTPM_INTERFACE} -s
103 if [ $?
-ne 0 ]; then
104 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
108 if wait_process_gone
${SWTPM_PID} 4; then
109 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
113 if [ ! -e $STATE_FILE ]; then
114 echo "Error: TPM state file $STATE_FILE does not exist."