Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | import os |
| 2 | |
| 3 | from oeqa.runtime.case import OERuntimeTestCase |
| 4 | from oeqa.core.decorator.depends import OETestDepends |
| 5 | from oeqa.core.decorator.oeid import OETestID |
| 6 | from oeqa.core.decorator.data import skipIfNotFeature |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 7 | from oeqa.runtime.decorator.package import OEHasPackage |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | |
| 9 | class KernelModuleTest(OERuntimeTestCase): |
| 10 | |
| 11 | @classmethod |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 12 | def setUp(cls): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | src = os.path.join(cls.tc.runtime_files_dir, 'hellomod.c') |
| 14 | dst = '/tmp/hellomod.c' |
| 15 | cls.tc.target.copyTo(src, dst) |
| 16 | |
| 17 | src = os.path.join(cls.tc.runtime_files_dir, 'hellomod_makefile') |
| 18 | dst = '/tmp/Makefile' |
| 19 | cls.tc.target.copyTo(src, dst) |
| 20 | |
| 21 | @classmethod |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 22 | def tearDown(cls): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 23 | files = '/tmp/Makefile /tmp/hellomod.c' |
| 24 | cls.tc.target.run('rm %s' % files) |
| 25 | |
| 26 | @OETestID(1541) |
| 27 | @skipIfNotFeature('tools-sdk', |
| 28 | 'Test requires tools-sdk to be in IMAGE_FEATURES') |
| 29 | @OETestDepends(['gcc.GccCompileTest.test_gcc_compile']) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 30 | @OEHasPackage(['kernel-devsrc']) |
| 31 | @OEHasPackage(['make']) |
| 32 | @OEHasPackage(['gcc']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | def test_kernel_module(self): |
| 34 | cmds = [ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 35 | 'cd /usr/src/kernel && make scripts prepare', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | 'cd /tmp && make', |
| 37 | 'cd /tmp && insmod hellomod.ko', |
| 38 | 'lsmod | grep hellomod', |
| 39 | 'dmesg | grep Hello', |
| 40 | 'rmmod hellomod', 'dmesg | grep "Cleaning up hellomod"' |
| 41 | ] |
| 42 | for cmd in cmds: |
| 43 | status, output = self.target.run(cmd, 900) |
| 44 | self.assertEqual(status, 0, msg='\n'.join([cmd, output])) |