blob: 9c42fcc5866d5627219c6c7fe129728889e59cc2 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007import os
8
9from oeqa.runtime.case import OERuntimeTestCase
10from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011from oeqa.core.decorator.data import skipIfNotFeature
Brad Bishop977dc1a2019-02-06 16:01:43 -050012from oeqa.runtime.decorator.package import OEHasPackage
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013
14class KernelModuleTest(OERuntimeTestCase):
15
16 @classmethod
Brad Bishop977dc1a2019-02-06 16:01:43 -050017 def setUp(cls):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018 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
Brad Bishop977dc1a2019-02-06 16:01:43 -050027 def tearDown(cls):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 files = '/tmp/Makefile /tmp/hellomod.c'
29 cls.tc.target.run('rm %s' % files)
30
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031 @skipIfNotFeature('tools-sdk',
32 'Test requires tools-sdk to be in IMAGE_FEATURES')
33 @OETestDepends(['gcc.GccCompileTest.test_gcc_compile'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050034 @OEHasPackage(['kernel-devsrc'])
35 @OEHasPackage(['make'])
36 @OEHasPackage(['gcc'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037 def test_kernel_module(self):
38 cmds = [
Brad Bishop316dfdd2018-06-25 12:45:53 -040039 'cd /usr/src/kernel && make scripts prepare',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 '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]))