]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-ukify: use systemd-measure and bootctl in build directory
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 Jul 2023 11:26:24 +0000 (20:26 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Jul 2023 13:32:02 +0000 (15:32 +0200)
And skip tests if systemd-measure is not found.
Then, we can safely run test_ukify.py directly.

src/ukify/test/test_ukify.py

index cff4ebe5ba81d3b53aa4e9feb7e438f243c92043..e0e85455c574250b2e022f5c9329db8849391151 100755 (executable)
@@ -36,6 +36,12 @@ except ImportError as e:
 sys.path.append(os.path.dirname(__file__) + '/..')
 import ukify
 
+build_root = os.getenv('PROJECT_BUILD_ROOT')
+arg_tools = ['--tools', build_root] if build_root else []
+
+def systemd_measure():
+    opts = ukify.create_parser().parse_args(arg_tools)
+    return ukify.find_tool('systemd-measure', opts=opts)
 
 def test_guess_efi_arch():
     arch = ukify.guess_efi_arch()
@@ -372,8 +378,13 @@ def test_help_error(capsys):
 
 @pytest.fixture(scope='session')
 def kernel_initrd():
+    opts = ukify.create_parser().parse_args(arg_tools)
+    bootctl = ukify.find_tool('bootctl', opts=opts)
+    if bootctl is None:
+        return None
+
     try:
-        text = subprocess.check_output(['bootctl', 'list', '--json=short'],
+        text = subprocess.check_output([bootctl, 'list', '--json=short'],
                                        text=True)
     except subprocess.CalledProcessError:
         return None
@@ -595,6 +606,8 @@ def test_efi_signing_pesign(kernel_initrd, tmpdir):
 def test_pcr_signing(kernel_initrd, tmpdir):
     if kernel_initrd is None:
         pytest.skip('linux+initrd not found')
+    if systemd_measure() is None:
+        pytest.skip('systemd-measure not found')
 
     ourdir = pathlib.Path(__file__).parent
     pub = unbase64(ourdir / 'example.tpm2-pcr-public.pem.base64')
@@ -610,7 +623,7 @@ def test_pcr_signing(kernel_initrd, tmpdir):
         '--os-release=ID=foobar\n',
         '--pcr-banks=sha1',   # use sha1 because it doesn't really matter
         f'--pcr-private-key={priv.name}',
-    ]
+    ] + arg_tools
 
     # If the public key is not explicitly specified, it is derived automatically. Let's make sure everything
     # works as expected both when the public keys is specified explicitly and when it is derived from the
@@ -656,6 +669,8 @@ def test_pcr_signing(kernel_initrd, tmpdir):
 def test_pcr_signing2(kernel_initrd, tmpdir):
     if kernel_initrd is None:
         pytest.skip('linux+initrd not found')
+    if systemd_measure() is None:
+        pytest.skip('systemd-measure not found')
 
     ourdir = pathlib.Path(__file__).parent
     pub = unbase64(ourdir / 'example.tpm2-pcr-public.pem.base64')
@@ -686,7 +701,7 @@ def test_pcr_signing2(kernel_initrd, tmpdir):
         f'--pcr-public-key={pub2.name}',
         f'--pcr-private-key={priv2.name}',
         '--phases=sysinit ready shutdown final',  # yes, those phase paths are not reachable
-    ])
+    ] + arg_tools)
 
     try:
         ukify.check_inputs(opts)