1# 2# SPDX-License-Identifier: MIT 3# 4 5import os 6import shutil 7import unittest 8 9from oeqa.core.utils.path import remove_safe 10from oeqa.sdk.case import OESDKTestCase 11 12from oeqa.utils.subprocesstweak import errors_have_output 13errors_have_output() 14 15class GccCompileTest(OESDKTestCase): 16 td_vars = ['MACHINE'] 17 18 @classmethod 19 def setUpClass(self): 20 files = {'test.c' : self.tc.files_dir, 'test.cpp' : self.tc.files_dir, 21 'testsdkmakefile' : self.tc.sdk_files_dir} 22 for f in files: 23 shutil.copyfile(os.path.join(files[f], f), 24 os.path.join(self.tc.sdk_dir, f)) 25 26 def setUp(self): 27 machine = self.td.get("MACHINE") 28 if not (self.tc.hasHostPackage("packagegroup-cross-canadian-%s" % machine) or 29 self.tc.hasHostPackage("^gcc-", regex=True)): 30 raise unittest.SkipTest("GccCompileTest class: SDK doesn't contain a cross-canadian toolchain") 31 32 def test_gcc_compile(self): 33 self._run('$CC %s/test.c -o %s/test -lm' % (self.tc.sdk_dir, self.tc.sdk_dir)) 34 35 def test_gpp_compile(self): 36 self._run('$CXX %s/test.c -o %s/test -lm' % (self.tc.sdk_dir, self.tc.sdk_dir)) 37 38 def test_gpp2_compile(self): 39 self._run('$CXX %s/test.cpp -o %s/test -lm' % (self.tc.sdk_dir, self.tc.sdk_dir)) 40 41 def test_make(self): 42 self._run('cd %s; make -f testsdkmakefile' % self.tc.sdk_dir) 43 44 @classmethod 45 def tearDownClass(self): 46 files = [os.path.join(self.tc.sdk_dir, f) \ 47 for f in ['test.c', 'test.cpp', 'test.o', 'test', 48 'testsdkmakefile']] 49 for f in files: 50 remove_safe(f) 51