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