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