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