summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oeqa/selftest/cases/kernel_pre.py88
-rw-r--r--meta/lib/oeqa/selftest/cases/kernel_test1.py96
2 files changed, 184 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/kernel_pre.py b/meta/lib/oeqa/selftest/cases/kernel_pre.py
new file mode 100644
index 00000000000..84c1708fe8f
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/kernel_pre.py
@@ -0,0 +1,88 @@
+import sys
+import os
+import re
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd
+
+class KernelDev(OESelftestTestCase):
+
+ def setUpLocal(self):
+ sys.stdout = sys.__stdout__
+ print ('\n inside setUpLocal \n')
+ super(KernelDev, self).setUpLocal()
+ self.recipe = 'core-image-minimal'
+ self.machine = 'qemux86-64'
+ self.write_config(
+"""
+MACHINE = "%s"
+"""
+% (self.machine)
+ )
+ print (get_bb_var('MACHINE'))
+ bitbake(self.recipe)
+
+ def test_agetMachine(self):
+ sys.stdout = sys.__stdout__
+ print ('\n inside test_getMachine \n')
+ getmachine = get_bb_var('MACHINE')
+ self.assertEqual(getmachine, 'qemux86-64')
+ print ('Successful set machine as %s' %getmachine)
+
+ def test_bgetLinuxVersion(self):
+ sys.stdout = sys.__stdout__
+ print ('\n inside test_getLinuxVersion \n')
+ result = runCmd('bitbake virtual/kernel -e | grep LINUX_VERSION=')
+ print(' Output = %s' %result.output)
+ getlinuxversion = runCmd('bitbake virtual/kernel -e | grep LINUX_VERSION= > kernel_version')
+ with open ('kernel_version', 'r') as file:
+ for line in file:
+ linux_kernel_version = line.strip()
+ self.assertEqual(result.output, linux_kernel_version)
+ linux_kernel_version = linux_kernel_version.split("\"")[1]
+ linux_kernel_version = linux_kernel_version.split(".")[0] + "." + linux_kernel_version.split(".")[1]
+ print('LINUX_VERSION = %s' %linux_kernel_version )
+
+ #def test_cbitbakelayers_createlayer(self):
+ #sys.stdout = sys.__stdout__
+ print ('\n inside test_bitbakelayers_createlayer \n')
+ build_path = os.environ.get('BUILDDIR')
+
+ print ('build_path = %s' %build_path)
+ poky_path, tail = os.path.split(build_path)
+ print ('poky_path = %s' %poky_path)
+ print ('tail = %s' %tail)
+
+
+ poky_dir = os.chdir(poky_path)
+ print ('poky_dir = %s' %poky_dir)
+ layername = 'meta-kernelautomated'
+ layerpath = os.path.exists(layername)
+ print ('layerpath = %s' %layerpath)
+
+ self.assertTrue(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath)
+
+ result = runCmd('bitbake-layers create-layer %s' %layername)
+ print ('\n after result \n')
+
+ dir_recipe = runCmd('mkdir -p ' + layername +'/recipes-kernel/linux/')
+ dir_linux_yocto =runCmd('mkdir ' + layername +'/recipes-kernel/linux/linux-yocto/')
+ dir_linux_yocto_custom =runCmd('mkdir ' + layername +'/recipes-kernel/linux/linux-yocto-custom/')
+ recipe_append =runCmd('touch ' + layername + '/recipes-kernel/linux/linux-yocto_4%.bbappend')
+
+
+
+ print('LINUX_VERSION = %s' %linux_kernel_version )
+ path_copy_from = poky_path + ("/meta/recipes-kernel/linux/linux-yocto_%s.bb" %linux_kernel_version)
+ print ("\npath_copy_from ::\n%s" %path_copy_from)
+ path_copy_to = poky_path + ("/%s/recipes-kernel/linux/linux-yocto_custom_%s.bb" %(layername, linux_kernel_version))
+ print ("\npath_copy_to ::\n%s" %path_copy_to)
+ result_copy = runCmd('cp %s %s' %(path_copy_from, path_copy_to))
+
+ with open (path_copy_to, 'a') as file:
+ file.write('PV = \"${%s}\"' %linux_kernel_version )
+ file.close()
+
+ build_dir = os.chdir(build_path)
+ result = runCmd('bitbake-layers add-layer ../%s' %layername)
+
+
diff --git a/meta/lib/oeqa/selftest/cases/kernel_test1.py b/meta/lib/oeqa/selftest/cases/kernel_test1.py
new file mode 100644
index 00000000000..029f1c378d0
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/kernel_test1.py
@@ -0,0 +1,96 @@
+import sys
+import os
+import logging
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd
+from oeqa.utils.git import GitRepo, GitError
+
+class KernelDev(OESelftestTestCase):
+
+ def setUpLocal(self):
+ sys.stdout = sys.__stdout__
+ print ('\n inside setUpLocal \n')
+ super(KernelDev, self).setUpLocal()
+ self.recipe = 'core-image-minimal'
+ self.machine = 'qemux86-64'
+ self.write_config(
+"""
+MACHINE = "%s"
+"""
+% (self.machine)
+ )
+ print (get_bb_var('MACHINE'))
+
+
+ def test_runCommand(self):
+ # This test step updates the README file
+ sys.stdout = sys.__stdout__
+ print ("\n\ninside test_runCommand\n\n")
+ #writetoreadme = runCmd("echo This is a test to apply a patch to the kernel. >> tmp/work-shared/qemux86-64/kernel-source/README")
+ # self.assertEqual(writetoreadme.output, "")
+
+
+ def test_gitadd(self):
+ # This test step updates the README file
+ sys.stdout = sys.__stdout__
+ print ("\n\ninside test_gidadd\n\n")
+ writetoreadme = runCmd("echo This is a test to apply a patch to the kernel. >> tmp/work-shared/qemux86-64/kernel-source/README")
+ self.assertEqual(writetoreadme.output, "")
+
+
+ #This test step adds modified file "README" to git and creates a patch file "0001-KERNEL-DEV-TEST-CASE.patch" at the same location as file
+ repo = GitRepo("tmp/work-shared/qemux86-64/kernel-source", is_topdir=True)
+ os_path = os.path
+
+ GIT_WORK_TREE = os.path.abspath('tmp/work-shared/qemux86-64/kernel-source/README')
+
+ repo.run_cmd('add %s' %(GIT_WORK_TREE))
+
+ commit_message = "KERNEL DEV TEST CASE"
+ git_cmd_commit = ['commit', '-m', commit_message]
+ repo.run_cmd(git_cmd_commit)
+
+ git_cmd_patch = ['format-patch', '-1']
+ repo.run_cmd(git_cmd_patch)
+
+ def test_move(self):
+
+ sys.stdout = sys.__stdout__
+ build_path = os.environ.get('BUILDDIR')
+ print ("\n\ninside test_move\n\n")
+ #logging.debug('build_path = %s' %build_path)
+ print ('build_path = %s' %build_path)
+ poky_path, tail = os.path.split(build_path)
+ print ('poky_path = %s' %poky_path)
+ print ('tail = %s' %tail)
+ poky_dir = os.chdir(poky_path)
+ print ('poky_dir = %s' %poky_dir)
+ #file_path = build + tmp/work-shared/qemux86-64/kernel-source/0001-KERNEL-DEV-TEST-CASE.patch
+ patch_file = build_path + '/tmp/work-shared/qemux86-64/kernel-source/0001-KERNEL-DEV-TEST-CASE.patch'
+ new_path = poky_path + '/meta-kernelautomated/recipes-kernel/linux/linux-yocto/'
+ print ('new_path = %s' %new_path)
+
+ result = runCmd('mv %s %s' %(patch_file, new_path))
+ self.assertEqual(result.output, "")
+ file_name = poky_path + '/meta-kernelautomated/recipes-kernel/linux/linux-yocto_4%.bbappend'
+ print ('file_name = %s' %file_name)
+
+ with open (file_name, 'w') as file:
+ file.write("SRC_URI += \"file://0001-KERNEL-DEV-TEST-CASE.patch\"" + "\n")
+ file.write('FILESEXTRAPATHS_prepend := \"${THISDIR}/${PN}:\"')
+ file.close()
+
+ readme_path = build_path + '/tmp/work-shared/qemux86-64/kernel-source/README'
+ print ('readme_path = %s' %readme_path)
+ remove_readme_file = runCmd('rm %s ' %readme_path)
+ print ('readme removed')
+ self.assertEqual(remove_readme_file.output, "")
+ run_cleanstate = runCmd('bitbake virtual/kernel -c cleansstate')
+ print ('cleanstate')
+ run_buildpatch = runCmd('bitbake virtual/kernel -c patch')
+ print ('build patch')
+ file_exists = os.path.exists(readme_path)
+ print ('file_exists = %s' %file_exists)
+ tail_readme_file = runCmd('tail %s ' %readme_path)
+ print (tail_readme_file.output)
+ \ No newline at end of file