blob: a61876ee61a2d49422c4c4a8c4ed266b5925d756 [file] [log] [blame]
Brad Bishop79641f22019-09-10 07:20:22 -04001import os
2from oeqa.selftest.case import OESelftestTestCase
3from oeqa.utils.commands import runCmd, get_bb_var
4from oeqa.utils.git import GitRepo
5
6class KernelDev(OESelftestTestCase):
7
8 @classmethod
9 def setUpClass(cls):
10 super(KernelDev, cls).setUpClass()
11 # Create the recipe directory structure inside the created layer
12 cls.layername = 'meta-kerneltest'
13 runCmd('bitbake-layers create-layer %s' % cls.layername)
14 runCmd('mkdir -p %s/recipes-kernel/linux/linux-yocto' % cls.layername)
15 cls.recipes_linuxyocto_dir = os.path.join \
16 (cls.builddir, cls.layername, 'recipes-kernel', 'linux', 'linux-yocto')
17 cls.recipeskernel_dir = os.path.dirname(cls.recipes_linuxyocto_dir)
18 runCmd('bitbake-layers add-layer %s' % cls.layername)
19
20 @classmethod
21 def tearDownClass(cls):
22 runCmd('bitbake-layers remove-layer %s' % cls.layername, ignore_status=True)
23 runCmd('rm -rf %s' % cls.layername)
24 super(KernelDev, cls).tearDownClass()
25
26 def setUp(self):
27 super(KernelDev, self).setUp()
28 self.set_machine_config('MACHINE = "qemux86-64"\n')
29
30 def test_apply_patches(self):
31 """
32 Summary: Able to apply a single patch to the Linux kernel source
33 Expected: The README file should exist and the patch changes should be
34 displayed at the end of the file.
35 Product: Kernel Development
36 Author: Yeoh Ee Peng <ee.peng.yeoh@intel.com>
37 AutomatedBy: Mazliana Mohamad <mazliana.mohamad@intel.com>
38 """
39 runCmd('bitbake virtual/kernel -c patch')
40 kernel_source = get_bb_var('STAGING_KERNEL_DIR')
41 readme = os.path.join(kernel_source, 'README')
42
43 # This test step adds modified file 'README' to git and creates a
44 # patch file '0001-KERNEL_DEV_TEST_CASE.patch' at the same location as file
45 patch_content = 'This is a test to apply a patch to the kernel'
46 with open(readme, 'a+') as f:
47 f.write(patch_content)
48 repo = GitRepo('%s' % kernel_source, is_topdir=True)
49 repo.run_cmd('add %s' % readme)
50 repo.run_cmd(['commit', '-m', 'KERNEL_DEV_TEST_CASE'])
51 repo.run_cmd(['format-patch', '-1'])
52 patch_name = '0001-KERNEL_DEV_TEST_CASE.patch'
53 patchpath = os.path.join(kernel_source, patch_name)
54 runCmd('mv %s %s' % (patchpath, self.recipes_linuxyocto_dir))
55 runCmd('rm %s ' % readme)
56 self.assertFalse(os.path.exists(readme))
57
58 recipe_append = os.path.join(self.recipeskernel_dir, 'linux-yocto_%.bbappend')
59 with open(recipe_append, 'w+') as fh:
60 fh.write('SRC_URI += "file://%s"\n' % patch_name)
61 fh.write('FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"')
62
63 runCmd('bitbake virtual/kernel -c clean')
64 runCmd('bitbake virtual/kernel -c patch')
65 self.assertTrue(os.path.exists(readme))
66 result = runCmd('tail -n 1 %s' % readme)
67 self.assertEqual(result.output, patch_content)