kernelmodule.py 1.5 KB

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