blob: 8e90dc9dc9fc2f28e046386cae2dda2ca11cdc49 [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):
Andrew Geissler615f2f12022-07-15 14:00:58 -050011 cls.tc.target.run('swtpm_ioctl -s --tcp :2322')
Andrew Geissler78b72792022-06-14 06:47:25 -050012 cls.tc.target.run('mkdir /tmp/myvtpm2')
13
14 @classmethod
15 def tearDownClass(cls):
Andrew Geissler615f2f12022-07-15 14:00:58 -050016 cls.tc.target.run('swtpm_ioctl -s --tcp :2322')
Andrew Geissler78b72792022-06-14 06:47:25 -050017 cls.tc.target.run('rm -fr /tmp/myvtpm2')
18
Brad Bishop19323692019-04-05 15:28:33 -040019 def check_endlines(self, results, expected_endlines):
20 for line in results.splitlines():
21 for el in expected_endlines:
22 if line == el:
23 expected_endlines.remove(el)
24 break
25
26 if expected_endlines:
27 self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines))
28
Brad Bishop26bdd442019-08-16 17:08:17 -040029 @OEHasPackage(['tpm2-tools'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050030 @OEHasPackage(['tpm2-abrmd'])
31 @OEHasPackage(['swtpm'])
Andrew Geissler78b72792022-06-14 06:47:25 -050032 @skipIfNotFeature('tpm2','Test tpm2_startup requires tpm2 to be in DISTRO_FEATURES')
Brad Bishop19323692019-04-05 15:28:33 -040033 @OETestDepends(['ssh.SSHTest.test_ssh'])
Andrew Geissler78b72792022-06-14 06:47:25 -050034 def test_tpm2_startup(self):
Brad Bishop19323692019-04-05 15:28:33 -040035 cmds = [
Andrew Geissler78b72792022-06-14 06:47:25 -050036 'swtpm socket -d --tpmstate dir=/tmp/myvtpm2 --tpm2 --ctrl type=tcp,port=2322 --server type=tcp,port=2321 --flags not-need-init',
37 'tpm2_startup -c -T "swtpm:port=2321"',
Brad Bishop19323692019-04-05 15:28:33 -040038 ]
39
40 for cmd in cmds:
41 status, output = self.target.run(cmd)
42 self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
43
Andrew Geissler78b72792022-06-14 06:47:25 -050044 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_startup'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050045 def test_tpm2_pcrread(self):
46 (status, output) = self.target.run('tpm2_pcrread')
Brad Bishop19323692019-04-05 15:28:33 -040047 expected_endlines = []
Andrew Geisslerd5838332022-05-27 11:33:10 -050048 expected_endlines.append(' sha1:')
49 expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000')
50 expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000')
51 expected_endlines.append(' sha256:')
52 expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000000000000000000000000000')
53 expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000000000000000000000000000')
54
Brad Bishop19323692019-04-05 15:28:33 -040055
56 self.check_endlines(output, expected_endlines)
57
Andrew Geisslerd5838332022-05-27 11:33:10 -050058
59 @OEHasPackage(['p11-kit'])
60 @OEHasPackage(['tpm2-pkcs11'])
Andrew Geissler78b72792022-06-14 06:47:25 -050061 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_pcrread'])
Andrew Geisslerd5838332022-05-27 11:33:10 -050062 def test_tpm2_pkcs11(self):
63 (status, output) = self.target.run('p11-kit list-modules -v')
64 self.assertEqual(status, 0, msg="Modules missing: %s" % output)
65
66 @OETestDepends(['tpm2.Tpm2Test.test_tpm2_pkcs11'])
67 def test_tpm2_swtpm_reset(self):
68 (status, output) = self.target.run('swtpm_ioctl -i --tcp :2322')
69 self.assertEqual(status, 0, msg="swtpm reset failed: %s" % output)