Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | import os |
| 8 | |
| 9 | from oeqa.runtime.case import OERuntimeTestCase |
| 10 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 11 | from oeqa.core.decorator.data import skipIfNotFeature |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 12 | from oeqa.runtime.decorator.package import OEHasPackage |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | |
| 14 | class KernelModuleTest(OERuntimeTestCase): |
| 15 | |
| 16 | @classmethod |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 17 | def setUp(cls): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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 |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 27 | def tearDown(cls): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 28 | files = '/tmp/Makefile /tmp/hellomod.c' |
| 29 | cls.tc.target.run('rm %s' % files) |
| 30 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | @skipIfNotFeature('tools-sdk', |
| 32 | 'Test requires tools-sdk to be in IMAGE_FEATURES') |
| 33 | @OETestDepends(['gcc.GccCompileTest.test_gcc_compile']) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 34 | @OEHasPackage(['kernel-devsrc']) |
| 35 | @OEHasPackage(['make']) |
| 36 | @OEHasPackage(['gcc']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 37 | def test_kernel_module(self): |
| 38 | cmds = [ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 39 | 'cd /usr/src/kernel && make scripts prepare', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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])) |