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