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