blob: c2c95e71597a82709884df6baa06269ff37f0837 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001# Copyright (C) 2019 Armin Kuster <akuster808@gmail.com>
2#
3from oeqa.runtime.case import OERuntimeTestCase
4from oeqa.core.decorator.depends import OETestDepends
5from oeqa.runtime.decorator.package import OEHasPackage
6
7
8class Tpm2Test(OERuntimeTestCase):
9 def check_endlines(self, results, expected_endlines):
10 for line in results.splitlines():
11 for el in expected_endlines:
12 if line == el:
13 expected_endlines.remove(el)
14 break
15
16 if expected_endlines:
17 self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines))
18
Brad Bishop26bdd442019-08-16 17:08:17 -040019 @OEHasPackage(['tpm2-tools'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050020 @OEHasPackage(['tpm2-abrmd'])
21 @OEHasPackage(['swtpm'])
Brad Bishop19323692019-04-05 15:28:33 -040022 @OETestDepends(['ssh.SSHTest.test_ssh'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050023 def test_tpm2_swtpm_socket(self):
Brad Bishop19323692019-04-05 15:28:33 -040024 cmds = [
Andrew Geisslerd5838332022-05-27 11:33:10 -050025 'mkdir /tmp/myvtpm',
26 'swtpm socket --tpmstate dir=/tmp/myvtpm --tpm2 --ctrl type=tcp,port=2322 --server type=tcp,port=2321 --flags not-need-init &',
27 'export TPM2TOOLS_TCTI="swtpm:port=2321"',
28 'tpm2_startup -c'
Brad Bishop19323692019-04-05 15:28:33 -040029 ]
30
31 for cmd in cmds:
32 status, output = self.target.run(cmd)
33 self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
34
Andrew Geisslerd5838332022-05-27 11:33:10 -050035 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_swtpm_socket'])
36 def test_tpm2_pcrread(self):
37 (status, output) = self.target.run('tpm2_pcrread')
Brad Bishop19323692019-04-05 15:28:33 -040038 expected_endlines = []
Andrew Geisslerd5838332022-05-27 11:33:10 -050039 expected_endlines.append(' sha1:')
40 expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000')
41 expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000')
42 expected_endlines.append(' sha256:')
43 expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000000000000000000000000000')
44 expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000000000000000000000000000')
45
Brad Bishop19323692019-04-05 15:28:33 -040046
47 self.check_endlines(output, expected_endlines)
48
Andrew Geisslerd5838332022-05-27 11:33:10 -050049
50 @OEHasPackage(['p11-kit'])
51 @OEHasPackage(['tpm2-pkcs11'])
52 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_swtpm_socket'])
53 def test_tpm2_pkcs11(self):
54 (status, output) = self.target.run('p11-kit list-modules -v')
55 self.assertEqual(status, 0, msg="Modules missing: %s" % output)
56
57 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_pkcs11'])
58 def test_tpm2_swtpm_reset(self):
59 (status, output) = self.target.run('swtpm_ioctl -i --tcp :2322')
60 self.assertEqual(status, 0, msg="swtpm reset failed: %s" % output)