blob: 47fd2f850c01baccb8a7f4ecaaba5ff773bce7a6 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005import os
6
7from oeqa.runtime.case import OERuntimeTestCase
8from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009from oeqa.core.decorator.data import skipIfNotFeature
Brad Bishop977dc1a2019-02-06 16:01:43 -050010from oeqa.runtime.decorator.package import OEHasPackage
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011
12class KernelModuleTest(OERuntimeTestCase):
13
14 @classmethod
Brad Bishop977dc1a2019-02-06 16:01:43 -050015 def setUp(cls):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016 src = os.path.join(cls.tc.runtime_files_dir, 'hellomod.c')
17 dst = '/tmp/hellomod.c'
18 cls.tc.target.copyTo(src, dst)
19
20 src = os.path.join(cls.tc.runtime_files_dir, 'hellomod_makefile')
21 dst = '/tmp/Makefile'
22 cls.tc.target.copyTo(src, dst)
23
24 @classmethod
Brad Bishop977dc1a2019-02-06 16:01:43 -050025 def tearDown(cls):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026 files = '/tmp/Makefile /tmp/hellomod.c'
27 cls.tc.target.run('rm %s' % files)
28
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 @skipIfNotFeature('tools-sdk',
30 'Test requires tools-sdk to be in IMAGE_FEATURES')
31 @OETestDepends(['gcc.GccCompileTest.test_gcc_compile'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050032 @OEHasPackage(['kernel-devsrc'])
33 @OEHasPackage(['make'])
34 @OEHasPackage(['gcc'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 def test_kernel_module(self):
36 cmds = [
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 'cd /usr/src/kernel && make scripts prepare',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 'cd /tmp && make',
39 'cd /tmp && insmod hellomod.ko',
40 'lsmod | grep hellomod',
41 'dmesg | grep Hello',
42 'rmmod hellomod', 'dmesg | grep "Cleaning up hellomod"'
43 ]
44 for cmd in cmds:
45 status, output = self.target.run(cmd, 900)
46 self.assertEqual(status, 0, msg='\n'.join([cmd, output]))