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