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.core.decorator.data import skipIfNotFeature
12from oeqa.runtime.decorator.package import OEHasPackage
13
14class KernelModuleTest(OERuntimeTestCase):
15
16    @classmethod
17    def setUp(cls):
18        src = os.path.join(cls.tc.runtime_files_dir, 'hellomod.c')
19        dst = '/tmp/hellomod.c'
20        cls.tc.target.copyTo(src, dst)
21
22        src = os.path.join(cls.tc.runtime_files_dir, 'hellomod_makefile')
23        dst = '/tmp/Makefile'
24        cls.tc.target.copyTo(src, dst)
25
26    @classmethod
27    def tearDown(cls):
28        files = '/tmp/Makefile /tmp/hellomod.c'
29        cls.tc.target.run('rm %s' % files)
30
31    @skipIfNotFeature('tools-sdk',
32                      'Test requires tools-sdk to be in IMAGE_FEATURES')
33    @OETestDepends(['gcc.GccCompileTest.test_gcc_compile'])
34    @OEHasPackage(['kernel-devsrc'])
35    @OEHasPackage(['make'])
36    @OEHasPackage(['gcc'])
37    def test_kernel_module(self):
38        cmds = [
39            'cd /usr/src/kernel && make scripts prepare',
40            'cd /tmp && make',
41            'cd /tmp && insmod hellomod.ko',
42            'lsmod | grep hellomod',
43            'dmesg | grep Hello',
44            'rmmod hellomod', 'dmesg | grep "Cleaning up hellomod"'
45            ]
46        for cmd in cmds:
47            status, output = self.target.run(cmd, 900)
48            self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
49