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