blob: a446543a1718bb0104862a489179dac0ee2b7b5e [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
Brad Bishop79641f22019-09-10 07:20:22 -04004# SPDX-License-Identifier: MIT
Patrick Williams92b42cb2022-09-03 06:53:57 -05005#
Brad Bishop79641f22019-09-10 07:20:22 -04006import os
7import contextlib
8from oeqa.core.decorator import OETestTag
Brad Bishopa34c0302019-09-23 22:34:48 -04009from oeqa.core.case import OEPTestResultTestCase
Brad Bishop79641f22019-09-10 07:20:22 -040010from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -050011from oeqa.utils.commands import bitbake, get_bb_var, runqemu
Brad Bishop79641f22019-09-10 07:20:22 -040012from 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
Brad Bishopa34c0302019-09-23 22:34:48 -040021class GlibcSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
Brad Bishop79641f22019-09-10 07:20:22 -040022 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
Patrick Williams213cb262021-08-07 19:21:33 -050031 features.append('EGLIBCPARALLELISM_task-check:pn-glibc-testsuite = "PARALLELMFLAGS="-j1""')
Brad Bishop79641f22019-09-10 07:20:22 -040032 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"
Brad Bishopa34c0302019-09-23 22:34:48 -040039 self.ptest_section(ptestsuite)
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050040 with open(os.path.join(builddir, "tests.sum"), "r", errors='replace') as f:
Brad Bishop79641f22019-09-10 07:20:22 -040041 for test, result in parse_values(f):
Brad Bishopa34c0302019-09-23 22:34:48 -040042 self.ptest_result(ptestsuite, test, result)
Brad Bishop79641f22019-09-10 07:20:22 -040043
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")
Patrick Williams45852732022-04-02 08:58:32 -050090@OETestTag("runqemu")
Brad Bishop79641f22019-09-10 07:20:22 -040091class GlibcSelfTestSystemEmulated(GlibcSelfTestBase):
92 def test_glibc(self):
93 self.run_check_emulated()
94