Skip to content
Snippets Groups Projects
Commit 0f44c81e authored by Simon McVittie's avatar Simon McVittie
Browse files

tests: Test --copy-runtime-into and --only-prepare


To make this a little faster, we only generate locales in two of the six
tests (combining them asymmetrically so that we generate locales once
with and once without --copy-runtime-into, and once for each runtime
we are running from), and skip checking that locales were generated
correctly in the other tests.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 3d79c339
No related branches found
No related tags found
No related merge requests found
...@@ -83,6 +83,7 @@ import os ...@@ -83,6 +83,7 @@ import os
import shutil import shutil
import subprocess import subprocess
import sys import sys
import tempfile
import unittest import unittest
try: try:
...@@ -122,9 +123,8 @@ class TestContainers(BaseTest): ...@@ -122,9 +123,8 @@ class TestContainers(BaseTest):
stdout=2, stdout=2,
stderr=2, stderr=2,
).returncode != 0: ).returncode != 0:
# Right now this means we will skip all the tests, but in # We can only do tests that just do setup and don't actually
# future we will be able to do some tests that just do the # try to run the container.
# setup and do not actually go as far as running the container.
cls.bwrap = None cls.bwrap = None
else: else:
cls.bwrap = bwrap cls.bwrap = bwrap
...@@ -334,9 +334,11 @@ class TestContainers(BaseTest): ...@@ -334,9 +334,11 @@ class TestContainers(BaseTest):
test_name: str, test_name: str,
scout: str, scout: str,
*, *,
locales: bool = False copy: bool = False,
locales: bool = False,
only_prepare: bool = False
) -> None: ) -> None:
if self.bwrap is None: if self.bwrap is None and not only_prepare:
self.skipTest('Unable to run bwrap (in a container?)') self.skipTest('Unable to run bwrap (in a container?)')
if not os.path.isdir(scout): if not os.path.isdir(scout):
...@@ -354,30 +356,65 @@ class TestContainers(BaseTest): ...@@ -354,30 +356,65 @@ class TestContainers(BaseTest):
'--verbose', '--verbose',
] ]
var = os.path.join(self.containers_dir, 'var')
os.makedirs(var, exist_ok=True)
if not locales: if not locales:
argv.append('--no-generate-locales') argv.append('--no-generate-locales')
argv.extend([ with tempfile.TemporaryDirectory(prefix='test-', dir=var) as temp:
'--', if copy:
'env', argv.extend(['--copy-runtime-into', temp])
'TEST_INSIDE_SCOUT_ARTIFACTS=' + artifacts,
'TEST_INSIDE_SCOUT_LOCALES=' + ('1' if locales else ''), if only_prepare:
'python3.5', argv.append('--only-prepare')
os.path.join(self.artifacts, 'tmp', 'inside-scout.py'), else:
]) argv.extend([
'--',
with tee_file_and_stderr( 'env',
os.path.join(artifacts, 'inside-scout.log') 'TEST_INSIDE_SCOUT_ARTIFACTS=' + artifacts,
) as tee: 'TEST_INSIDE_SCOUT_LOCALES=' + ('1' if locales else ''),
completed = self.run_subprocess( 'python3.5',
argv, os.path.join(self.artifacts, 'tmp', 'inside-scout.py'),
cwd=self.artifacts, ])
stdout=tee.stdin,
stderr=tee.stdin, with tee_file_and_stderr(
universal_newlines=True, os.path.join(artifacts, 'inside-scout.log')
) ) as tee:
completed = self.run_subprocess(
argv,
cwd=self.artifacts,
stdout=tee.stdin,
stderr=tee.stdin,
universal_newlines=True,
)
self.assertEqual(completed.returncode, 0) self.assertEqual(completed.returncode, 0)
if copy:
members = set(os.listdir(temp))
members.discard('.ref')
self.assertEqual(len(members), 1)
tree = os.path.join(temp, members.pop())
with open(
os.path.join(artifacts, 'contents.txt'),
'w',
) as writer:
self.run_subprocess([
'find',
'.',
'-ls',
], cwd=tree, stderr=2, stdout=writer)
self.assertTrue(os.path.isdir(os.path.join(tree, 'bin')))
self.assertTrue(os.path.isdir(os.path.join(tree, 'etc')))
self.assertTrue(os.path.isdir(os.path.join(tree, 'lib')))
self.assertTrue(os.path.isdir(os.path.join(tree, 'usr')))
self.assertFalse(
os.path.isdir(os.path.join(tree, 'usr', 'usr'))
)
self.assertTrue(os.path.isdir(os.path.join(tree, 'sbin')))
def test_scout_sysroot(self) -> None: def test_scout_sysroot(self) -> None:
scout = os.path.join(self.containers_dir, 'scout_sysroot') scout = os.path.join(self.containers_dir, 'scout_sysroot')
...@@ -385,12 +422,29 @@ class TestContainers(BaseTest): ...@@ -385,12 +422,29 @@ class TestContainers(BaseTest):
if os.path.isdir(os.path.join(scout, 'files')): if os.path.isdir(os.path.join(scout, 'files')):
scout = os.path.join(scout, 'files') scout = os.path.join(scout, 'files')
self._test_scout('scout_sysroot', scout, locales=True) with self.subTest('only-prepare'):
self._test_scout(
'scout_sysroot_prep', scout,
copy=True, only_prepare=True,
)
with self.subTest('copy'):
self._test_scout('scout_sysroot_copy', scout, copy=True)
with self.subTest('transient'):
self._test_scout('scout_sysroot', scout, locales=True)
def test_scout_usr(self) -> None: def test_scout_usr(self) -> None:
scout = os.path.join(self.containers_dir, 'scout', 'files') scout = os.path.join(self.containers_dir, 'scout', 'files')
self._test_scout('scout', scout, locales=True) with self.subTest('only-prepare'):
self._test_scout('scout_prep', scout, copy=True, only_prepare=True)
with self.subTest('copy'):
self._test_scout('scout_copy', scout, copy=True, locales=True)
with self.subTest('transient'):
self._test_scout('scout', scout)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -64,6 +64,14 @@ class TestInvocation(BaseTest): ...@@ -64,6 +64,14 @@ class TestInvocation(BaseTest):
) )
self.assertEqual(completed.returncode, 2) self.assertEqual(completed.returncode, 2)
def test_only_prepare_exclusive(self) -> None:
completed = run_subprocess(
[self.pv_wrap, '--only-prepare', '--test'],
stdout=2,
stderr=2,
)
self.assertEqual(completed.returncode, 2)
if __name__ == '__main__': if __name__ == '__main__':
assert sys.version_info >= (3, 4), \ assert sys.version_info >= (3, 4), \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment