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