1#
2# SPDX-License-Identifier: MIT
3#
4
5import os
6
7from oeqa.runtime.case import OERuntimeTestCase
8from oeqa.core.decorator.depends import OETestDepends
9from oeqa.runtime.decorator.package import OEHasPackage
10
11class GccCompileTest(OERuntimeTestCase):
12
13    @classmethod
14    def setUp(cls):
15        dst = '/tmp/'
16        src = os.path.join(cls.tc.files_dir, 'test.c')
17        cls.tc.target.copyTo(src, dst)
18
19        src = os.path.join(cls.tc.runtime_files_dir, 'testmakefile')
20        cls.tc.target.copyTo(src, dst)
21
22        src = os.path.join(cls.tc.files_dir, 'test.cpp')
23        cls.tc.target.copyTo(src, dst)
24
25    @classmethod
26    def tearDown(cls):
27        files = '/tmp/test.c /tmp/test.o /tmp/test /tmp/testmakefile'
28        cls.tc.target.run('rm %s' % files)
29
30    @OETestDepends(['ssh.SSHTest.test_ssh'])
31    @OEHasPackage(['gcc'])
32    def test_gcc_compile(self):
33        status, output = self.target.run('gcc /tmp/test.c -o /tmp/test -lm')
34        msg = 'gcc compile failed, output: %s' % output
35        self.assertEqual(status, 0, msg=msg)
36
37        status, output = self.target.run('/tmp/test')
38        msg = 'running compiled file failed, output: %s' % output
39        self.assertEqual(status, 0, msg=msg)
40
41    @OETestDepends(['ssh.SSHTest.test_ssh'])
42    @OEHasPackage(['g++'])
43    def test_gpp_compile(self):
44        status, output = self.target.run('g++ /tmp/test.c -o /tmp/test -lm')
45        msg = 'g++ compile failed, output: %s' % output
46        self.assertEqual(status, 0, msg=msg)
47
48        status, output = self.target.run('/tmp/test')
49        msg = 'running compiled file failed, output: %s' % output
50        self.assertEqual(status, 0, msg=msg)
51
52    @OETestDepends(['ssh.SSHTest.test_ssh'])
53    @OEHasPackage(['g++'])
54    def test_gpp2_compile(self):
55        status, output = self.target.run('g++ /tmp/test.cpp -o /tmp/test -lm')
56        msg = 'g++ compile failed, output: %s' % output
57        self.assertEqual(status, 0, msg=msg)
58
59        status, output = self.target.run('/tmp/test')
60        msg = 'running compiled file failed, output: %s' % output
61        self.assertEqual(status, 0, msg=msg)
62
63    @OETestDepends(['ssh.SSHTest.test_ssh'])
64    @OEHasPackage(['gcc'])
65    @OEHasPackage(['make'])
66    def test_make(self):
67        status, output = self.target.run('cd /tmp; make -f testmakefile')
68        msg = 'running make failed, output %s' % output
69        self.assertEqual(status, 0, msg=msg)
70