blob: e64d19d69ec90a9dca081ee29a2eae3c70037489 [file] [log] [blame]
Andrew Geissler78b72792022-06-14 06:47:25 -05001# Copyright (C) 2019 - 2022 Armin Kuster <akuster808@gmail.com>
Brad Bishop19323692019-04-05 15:28:33 -04002#
3from oeqa.runtime.case import OERuntimeTestCase
4from oeqa.core.decorator.depends import OETestDepends
5from oeqa.runtime.decorator.package import OEHasPackage
Andrew Geissler78b72792022-06-14 06:47:25 -05006from oeqa.core.decorator.data import skipIfNotFeature
Brad Bishop19323692019-04-05 15:28:33 -04007
8class Tpm2Test(OERuntimeTestCase):
Andrew Geissler78b72792022-06-14 06:47:25 -05009 @classmethod
10 def setUpClass(cls):
11 cls.tc.target.run('mkdir /tmp/myvtpm2')
12
13 @classmethod
14 def tearDownClass(cls):
15 cls.tc.target.run('rm -fr /tmp/myvtpm2')
16
Brad Bishop19323692019-04-05 15:28:33 -040017 def check_endlines(self, results, expected_endlines):
18 for line in results.splitlines():
19 for el in expected_endlines:
20 if line == el:
21 expected_endlines.remove(el)
22 break
23
24 if expected_endlines:
25 self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines))
26
Brad Bishop26bdd442019-08-16 17:08:17 -040027 @OEHasPackage(['tpm2-tools'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050028 @OEHasPackage(['tpm2-abrmd'])
29 @OEHasPackage(['swtpm'])
Andrew Geissler78b72792022-06-14 06:47:25 -050030 @skipIfNotFeature('tpm2','Test tpm2_startup requires tpm2 to be in DISTRO_FEATURES')
Brad Bishop19323692019-04-05 15:28:33 -040031 @OETestDepends(['ssh.SSHTest.test_ssh'])
Andrew Geissler78b72792022-06-14 06:47:25 -050032 def test_tpm2_startup(self):
Brad Bishop19323692019-04-05 15:28:33 -040033 cmds = [
Andrew Geissler78b72792022-06-14 06:47:25 -050034 'swtpm socket -d --tpmstate dir=/tmp/myvtpm2 --tpm2 --ctrl type=tcp,port=2322 --server type=tcp,port=2321 --flags not-need-init',
35 'tpm2_startup -c -T "swtpm:port=2321"',
Brad Bishop19323692019-04-05 15:28:33 -040036 ]
37
38 for cmd in cmds:
39 status, output = self.target.run(cmd)
40 self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
41
Andrew Geissler78b72792022-06-14 06:47:25 -050042 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_startup'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050043 def test_tpm2_pcrread(self):
44 (status, output) = self.target.run('tpm2_pcrread')
Brad Bishop19323692019-04-05 15:28:33 -040045 expected_endlines = []
Andrew Geisslerd5838332022-05-27 11:33:10 -050046 expected_endlines.append(' sha1:')
47 expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000')
48 expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000')
49 expected_endlines.append(' sha256:')
50 expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000000000000000000000000000')
51 expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000000000000000000000000000')
52
Brad Bishop19323692019-04-05 15:28:33 -040053
54 self.check_endlines(output, expected_endlines)
55
Andrew Geisslerd5838332022-05-27 11:33:10 -050056
57 @OEHasPackage(['p11-kit'])
58 @OEHasPackage(['tpm2-pkcs11'])
Andrew Geissler78b72792022-06-14 06:47:25 -050059 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_pcrread'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050060 def test_tpm2_pkcs11(self):
61 (status, output) = self.target.run('p11-kit list-modules -v')
62 self.assertEqual(status, 0, msg="Modules missing: %s" % output)
63
64 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_pkcs11'])
65 def test_tpm2_swtpm_reset(self):
66 (status, output) = self.target.run('swtpm_ioctl -i --tcp :2322')
67 self.assertEqual(status, 0, msg="swtpm reset failed: %s" % output)