1# SPDX-License-Identifier: MIT 2import os 3from oeqa.core.decorator import OETestTag 4from oeqa.core.case import OEPTestResultTestCase 5from oeqa.selftest.case import OESelftestTestCase 6from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars, runqemu, Command 7 8def parse_values(content): 9 for i in content: 10 for v in ["PASS", "FAIL", "XPASS", "XFAIL", "UNRESOLVED", "UNSUPPORTED", "UNTESTED", "ERROR", "WARNING"]: 11 if i.startswith(v + ": "): 12 yield i[len(v) + 2:].strip(), v 13 break 14 15class GccSelfTestBase(OESelftestTestCase, OEPTestResultTestCase): 16 def check_skip(self, suite): 17 targets = get_bb_var("RUNTIMETARGET", "gcc-runtime").split() 18 if suite not in targets: 19 self.skipTest("Target does not use {0}".format(suite)) 20 21 def run_check(self, *suites, ssh = None): 22 targets = set() 23 for s in suites: 24 if s == "gcc": 25 targets.add("check-gcc-c") 26 elif s == "g++": 27 targets.add("check-gcc-c++") 28 else: 29 targets.add("check-target-{}".format(s)) 30 31 # configure ssh target 32 features = [] 33 features.append('MAKE_CHECK_TARGETS = "{0}"'.format(" ".join(targets))) 34 if ssh is not None: 35 features.append('TOOLCHAIN_TEST_TARGET = "ssh"') 36 features.append('TOOLCHAIN_TEST_HOST = "{0}"'.format(ssh)) 37 features.append('TOOLCHAIN_TEST_HOST_USER = "root"') 38 features.append('TOOLCHAIN_TEST_HOST_PORT = "22"') 39 self.write_config("\n".join(features)) 40 41 recipe = "gcc-runtime" 42 bitbake("{} -c check".format(recipe)) 43 44 bb_vars = get_bb_vars(["B", "TARGET_SYS"], recipe) 45 builddir, target_sys = bb_vars["B"], bb_vars["TARGET_SYS"] 46 47 for suite in suites: 48 sumspath = os.path.join(builddir, "gcc", "testsuite", suite, "{0}.sum".format(suite)) 49 if not os.path.exists(sumspath): # check in target dirs 50 sumspath = os.path.join(builddir, target_sys, suite, "testsuite", "{0}.sum".format(suite)) 51 if not os.path.exists(sumspath): # handle libstdc++-v3 -> libstdc++ 52 sumspath = os.path.join(builddir, target_sys, suite, "testsuite", "{0}.sum".format(suite.split("-")[0])) 53 logpath = os.path.splitext(sumspath)[0] + ".log" 54 55 ptestsuite = "gcc-{}".format(suite) if suite != "gcc" else suite 56 ptestsuite = ptestsuite + "-user" if ssh is None else ptestsuite 57 self.ptest_section(ptestsuite, logfile = logpath) 58 with open(sumspath, "r") as f: 59 for test, result in parse_values(f): 60 self.ptest_result(ptestsuite, test, result) 61 62 def run_check_emulated(self, *args, **kwargs): 63 # build core-image-minimal with required packages 64 default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"] 65 features = [] 66 features.append('IMAGE_FEATURES += "ssh-server-openssh"') 67 features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages))) 68 self.write_config("\n".join(features)) 69 bitbake("core-image-minimal") 70 71 # wrap the execution with a qemu instance 72 with runqemu("core-image-minimal", runqemuparams = "nographic") as qemu: 73 # validate that SSH is working 74 status, _ = qemu.run("uname") 75 self.assertEqual(status, 0) 76 77 return self.run_check(*args, ssh=qemu.ip, **kwargs) 78 79@OETestTag("toolchain-user") 80class GccCrossSelfTest(GccSelfTestBase): 81 def test_cross_gcc(self): 82 self.run_check("gcc") 83 84@OETestTag("toolchain-user") 85class GxxCrossSelfTest(GccSelfTestBase): 86 def test_cross_gxx(self): 87 self.run_check("g++") 88 89@OETestTag("toolchain-user") 90class GccLibAtomicSelfTest(GccSelfTestBase): 91 def test_libatomic(self): 92 self.run_check("libatomic") 93 94@OETestTag("toolchain-user") 95class GccLibGompSelfTest(GccSelfTestBase): 96 def test_libgomp(self): 97 self.run_check("libgomp") 98 99@OETestTag("toolchain-user") 100class GccLibStdCxxSelfTest(GccSelfTestBase): 101 def test_libstdcxx(self): 102 self.run_check("libstdc++-v3") 103 104@OETestTag("toolchain-user") 105class GccLibSspSelfTest(GccSelfTestBase): 106 def test_libssp(self): 107 self.check_skip("libssp") 108 self.run_check("libssp") 109 110@OETestTag("toolchain-user") 111class GccLibItmSelfTest(GccSelfTestBase): 112 def test_libitm(self): 113 self.check_skip("libitm") 114 self.run_check("libitm") 115 116@OETestTag("toolchain-system") 117class GccCrossSelfTestSystemEmulated(GccSelfTestBase): 118 def test_cross_gcc(self): 119 self.run_check_emulated("gcc") 120 121@OETestTag("toolchain-system") 122class GxxCrossSelfTestSystemEmulated(GccSelfTestBase): 123 def test_cross_gxx(self): 124 self.run_check_emulated("g++") 125 126@OETestTag("toolchain-system") 127class GccLibAtomicSelfTestSystemEmulated(GccSelfTestBase): 128 def test_libatomic(self): 129 self.run_check_emulated("libatomic") 130 131@OETestTag("toolchain-system") 132class GccLibGompSelfTestSystemEmulated(GccSelfTestBase): 133 def test_libgomp(self): 134 self.run_check_emulated("libgomp") 135 136@OETestTag("toolchain-system") 137class GccLibStdCxxSelfTestSystemEmulated(GccSelfTestBase): 138 def test_libstdcxx(self): 139 self.run_check_emulated("libstdc++-v3") 140 141@OETestTag("toolchain-system") 142class GccLibSspSelfTestSystemEmulated(GccSelfTestBase): 143 def test_libssp(self): 144 self.check_skip("libssp") 145 self.run_check_emulated("libssp") 146 147@OETestTag("toolchain-system") 148class GccLibItmSelfTestSystemEmulated(GccSelfTestBase): 149 def test_libitm(self): 150 self.check_skip("libitm") 151 self.run_check_emulated("libitm") 152 153