xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/runtime/cases/kernelmodule.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# SPDX-License-Identifier: MIT
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun
5*4882a593Smuzhiyunimport os
6*4882a593Smuzhiyun
7*4882a593Smuzhiyunfrom oeqa.runtime.case import OERuntimeTestCase
8*4882a593Smuzhiyunfrom oeqa.core.decorator.depends import OETestDepends
9*4882a593Smuzhiyunfrom oeqa.core.decorator.data import skipIfNotFeature
10*4882a593Smuzhiyunfrom oeqa.runtime.decorator.package import OEHasPackage
11*4882a593Smuzhiyun
12*4882a593Smuzhiyunclass KernelModuleTest(OERuntimeTestCase):
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun    @classmethod
15*4882a593Smuzhiyun    def setUp(cls):
16*4882a593Smuzhiyun        src = os.path.join(cls.tc.runtime_files_dir, 'hellomod.c')
17*4882a593Smuzhiyun        dst = '/tmp/hellomod.c'
18*4882a593Smuzhiyun        cls.tc.target.copyTo(src, dst)
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun        src = os.path.join(cls.tc.runtime_files_dir, 'hellomod_makefile')
21*4882a593Smuzhiyun        dst = '/tmp/Makefile'
22*4882a593Smuzhiyun        cls.tc.target.copyTo(src, dst)
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun    @classmethod
25*4882a593Smuzhiyun    def tearDown(cls):
26*4882a593Smuzhiyun        files = '/tmp/Makefile /tmp/hellomod.c'
27*4882a593Smuzhiyun        cls.tc.target.run('rm %s' % files)
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun    @skipIfNotFeature('tools-sdk',
30*4882a593Smuzhiyun                      'Test requires tools-sdk to be in IMAGE_FEATURES')
31*4882a593Smuzhiyun    @OETestDepends(['gcc.GccCompileTest.test_gcc_compile'])
32*4882a593Smuzhiyun    @OEHasPackage(['kernel-devsrc'])
33*4882a593Smuzhiyun    @OEHasPackage(['make'])
34*4882a593Smuzhiyun    @OEHasPackage(['gcc'])
35*4882a593Smuzhiyun    def test_kernel_module(self):
36*4882a593Smuzhiyun        cmds = [
37*4882a593Smuzhiyun            'cd /usr/src/kernel && make scripts prepare',
38*4882a593Smuzhiyun            'cd /tmp && make',
39*4882a593Smuzhiyun            'cd /tmp && insmod hellomod.ko',
40*4882a593Smuzhiyun            'lsmod | grep hellomod',
41*4882a593Smuzhiyun            'dmesg | grep Hello',
42*4882a593Smuzhiyun            'rmmod hellomod', 'dmesg | grep "Cleaning up hellomod"'
43*4882a593Smuzhiyun            ]
44*4882a593Smuzhiyun        for cmd in cmds:
45*4882a593Smuzhiyun            status, output = self.target.run(cmd, 900)
46*4882a593Smuzhiyun            self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
47