Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: MIT |
| 2 | import os |
| 3 | import contextlib |
| 4 | from oeqa.core.decorator import OETestTag |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 5 | from oeqa.core.case import OEPTestResultTestCase |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 6 | from oeqa.selftest.case import OESelftestTestCase |
| 7 | from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars, runqemu, Command |
| 8 | from oeqa.utils.nfs import unfs_server |
| 9 | |
| 10 | def parse_values(content): |
| 11 | for i in content: |
| 12 | for v in ["PASS", "FAIL", "XPASS", "XFAIL", "UNRESOLVED", "UNSUPPORTED", "UNTESTED", "ERROR", "WARNING"]: |
| 13 | if i.startswith(v + ": "): |
| 14 | yield i[len(v) + 2:].strip(), v |
| 15 | break |
| 16 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 17 | class GlibcSelfTestBase(OESelftestTestCase, OEPTestResultTestCase): |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 18 | def run_check(self, ssh = None): |
| 19 | # configure ssh target |
| 20 | features = [] |
| 21 | if ssh is not None: |
| 22 | features.append('TOOLCHAIN_TEST_TARGET = "ssh"') |
| 23 | features.append('TOOLCHAIN_TEST_HOST = "{0}"'.format(ssh)) |
| 24 | features.append('TOOLCHAIN_TEST_HOST_USER = "root"') |
| 25 | features.append('TOOLCHAIN_TEST_HOST_PORT = "22"') |
| 26 | # force single threaded test execution |
| 27 | features.append('EGLIBCPARALLELISM_task-check_pn-glibc-testsuite = "PARALLELMFLAGS="-j1""') |
| 28 | self.write_config("\n".join(features)) |
| 29 | |
| 30 | bitbake("glibc-testsuite -c check") |
| 31 | |
| 32 | builddir = get_bb_var("B", "glibc-testsuite") |
| 33 | |
| 34 | ptestsuite = "glibc-user" if ssh is None else "glibc" |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 35 | self.ptest_section(ptestsuite) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 36 | with open(os.path.join(builddir, "tests.sum"), "r") as f: |
| 37 | for test, result in parse_values(f): |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 38 | self.ptest_result(ptestsuite, test, result) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 39 | |
| 40 | def run_check_emulated(self): |
| 41 | with contextlib.ExitStack() as s: |
| 42 | # use the base work dir, as the nfs mount, since the recipe directory may not exist |
| 43 | tmpdir = get_bb_var("BASE_WORKDIR") |
| 44 | nfsport, mountport = s.enter_context(unfs_server(tmpdir)) |
| 45 | |
| 46 | # build core-image-minimal with required packages |
| 47 | default_installed_packages = [ |
| 48 | "glibc-charmaps", |
| 49 | "libgcc", |
| 50 | "libstdc++", |
| 51 | "libatomic", |
| 52 | "libgomp", |
| 53 | # "python3", |
| 54 | # "python3-pexpect", |
| 55 | "nfs-utils", |
| 56 | ] |
| 57 | features = [] |
| 58 | features.append('IMAGE_FEATURES += "ssh-server-openssh"') |
| 59 | features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages))) |
| 60 | self.write_config("\n".join(features)) |
| 61 | bitbake("core-image-minimal") |
| 62 | |
| 63 | # start runqemu |
| 64 | qemu = s.enter_context(runqemu("core-image-minimal", runqemuparams = "nographic")) |
| 65 | |
| 66 | # validate that SSH is working |
| 67 | status, _ = qemu.run("uname") |
| 68 | self.assertEqual(status, 0) |
| 69 | |
| 70 | # setup nfs mount |
| 71 | if qemu.run("mkdir -p \"{0}\"".format(tmpdir))[0] != 0: |
| 72 | raise Exception("Failed to setup NFS mount directory on target") |
| 73 | mountcmd = "mount -o noac,nfsvers=3,port={0},udp,mountport={1} \"{2}:{3}\" \"{3}\"".format(nfsport, mountport, qemu.server_ip, tmpdir) |
| 74 | status, output = qemu.run(mountcmd) |
| 75 | if status != 0: |
| 76 | raise Exception("Failed to setup NFS mount on target ({})".format(repr(output))) |
| 77 | |
| 78 | self.run_check(ssh = qemu.ip) |
| 79 | |
| 80 | @OETestTag("toolchain-user") |
| 81 | class GlibcSelfTest(GlibcSelfTestBase): |
| 82 | def test_glibc(self): |
| 83 | self.run_check() |
| 84 | |
| 85 | @OETestTag("toolchain-system") |
| 86 | class GlibcSelfTestSystemEmulated(GlibcSelfTestBase): |
| 87 | def test_glibc(self): |
| 88 | self.run_check_emulated() |
| 89 | |