blob: bd56b2f6e77d91bcad808daa0ebeb00abe678655 [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
Patrick Williams2a254922023-08-11 09:48:11 -05007import time
Brad Bishop79641f22019-09-10 07:20:22 -04008import contextlib
9from oeqa.core.decorator import OETestTag
Brad Bishopa34c0302019-09-23 22:34:48 -040010from oeqa.core.case import OEPTestResultTestCase
Brad Bishop79641f22019-09-10 07:20:22 -040011from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -050012from oeqa.utils.commands import bitbake, get_bb_var, runqemu
Brad Bishop79641f22019-09-10 07:20:22 -040013from oeqa.utils.nfs import unfs_server
14
15def 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 Bishopa34c0302019-09-23 22:34:48 -040022class GlibcSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
Brad Bishop79641f22019-09-10 07:20:22 -040023 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 Geissler8f840682023-07-21 09:09:43 -050032 features.append('EGLIBCPARALLELISM:task-check:pn-glibc-testsuite = "PARALLELMFLAGS="-j1""')
Brad Bishop79641f22019-09-10 07:20:22 -040033 self.write_config("\n".join(features))
34
Patrick Williams2a254922023-08-11 09:48:11 -050035 start_time = time.time()
36
Brad Bishop79641f22019-09-10 07:20:22 -040037 bitbake("glibc-testsuite -c check")
38
Patrick Williams2a254922023-08-11 09:48:11 -050039 end_time = time.time()
40
Brad Bishop79641f22019-09-10 07:20:22 -040041 builddir = get_bb_var("B", "glibc-testsuite")
42
43 ptestsuite = "glibc-user" if ssh is None else "glibc"
Patrick Williams2a254922023-08-11 09:48:11 -050044 self.ptest_section(ptestsuite, duration = int(end_time - start_time))
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050045 with open(os.path.join(builddir, "tests.sum"), "r", errors='replace') as f:
Brad Bishop79641f22019-09-10 07:20:22 -040046 for test, result in parse_values(f):
Brad Bishopa34c0302019-09-23 22:34:48 -040047 self.ptest_result(ptestsuite, test, result)
Brad Bishop79641f22019-09-10 07:20:22 -040048
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 Williams2a254922023-08-11 09:48:11 -050053 nfsport, mountport = s.enter_context(unfs_server(tmpdir, udp = False))
Brad Bishop79641f22019-09-10 07:20:22 -040054
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 Williams2a254922023-08-11 09:48:11 -050073 qemu = s.enter_context(runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 1024"))
Brad Bishop79641f22019-09-10 07:20:22 -040074
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 Williams2a254922023-08-11 09:48:11 -050082 mountcmd = "mount -o noac,nfsvers=3,port={0},mountport={1} \"{2}:{3}\" \"{3}\"".format(nfsport, mountport, qemu.server_ip, tmpdir)
Brad Bishop79641f22019-09-10 07:20:22 -040083 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")
90class GlibcSelfTest(GlibcSelfTestBase):
91 def test_glibc(self):
92 self.run_check()
93
94@OETestTag("toolchain-system")
Patrick Williams45852732022-04-02 08:58:32 -050095@OETestTag("runqemu")
Brad Bishop79641f22019-09-10 07:20:22 -040096class GlibcSelfTestSystemEmulated(GlibcSelfTestBase):
97 def test_glibc(self):
98 self.run_check_emulated()
99