Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import unittest |
| 2 | import os |
| 3 | import logging |
| 4 | import re |
| 5 | import shutil |
| 6 | import datetime |
| 7 | |
| 8 | import oeqa.utils.ftools as ftools |
| 9 | from oeqa.selftest.base import oeSelfTest |
| 10 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var |
| 11 | from oeqa.utils.decorators import testcase |
| 12 | |
| 13 | class BitbakePrTests(oeSelfTest): |
| 14 | |
| 15 | def get_pr_version(self, package_name): |
| 16 | pkgdata_dir = get_bb_var('PKGDATA_DIR') |
| 17 | package_data_file = os.path.join(pkgdata_dir, 'runtime', package_name) |
| 18 | package_data = ftools.read_file(package_data_file) |
| 19 | find_pr = re.search("PKGR: r[0-9]+\.([0-9]+)", package_data) |
| 20 | self.assertTrue(find_pr, "No PKG revision found in %s" % package_data_file) |
| 21 | return int(find_pr.group(1)) |
| 22 | |
| 23 | def get_task_stamp(self, package_name, recipe_task): |
| 24 | stampdata = get_bb_var('STAMP', target=package_name).split('/') |
| 25 | prefix = stampdata[-1] |
| 26 | package_stamps_path = "/".join(stampdata[:-1]) |
| 27 | stamps = [] |
| 28 | for stamp in os.listdir(package_stamps_path): |
| 29 | find_stamp = re.match("%s\.%s\.([a-z0-9]{32})" % (prefix, recipe_task), stamp) |
| 30 | if find_stamp: |
| 31 | stamps.append(find_stamp.group(1)) |
| 32 | self.assertFalse(len(stamps) == 0, msg="Cound not find stamp for task %s for recipe %s" % (recipe_task, package_name)) |
| 33 | self.assertFalse(len(stamps) > 1, msg="Found multiple %s stamps for the %s recipe in the %s directory." % (recipe_task, package_name, package_stamps_path)) |
| 34 | return str(stamps[0]) |
| 35 | |
| 36 | def increment_package_pr(self, package_name): |
| 37 | inc_data = "do_package_append() {\nbb.build.exec_func('do_test_prserv', d)\n}\ndo_test_prserv() {\necho \"The current date is: %s\"\n}" % datetime.datetime.now() |
| 38 | self.write_recipeinc(package_name, inc_data) |
| 39 | bitbake("-ccleansstate %s" % package_name) |
| 40 | res = bitbake(package_name, ignore_status=True) |
| 41 | self.delete_recipeinc(package_name) |
| 42 | self.assertEqual(res.status, 0, msg=res.output) |
| 43 | self.assertTrue("NOTE: Started PRServer with DBfile" in res.output, msg=res.output) |
| 44 | |
| 45 | def config_pr_tests(self, package_name, package_type='rpm', pr_socket='localhost:0'): |
| 46 | config_package_data = 'PACKAGE_CLASSES = "package_%s"' % package_type |
| 47 | self.write_config(config_package_data) |
| 48 | config_server_data = 'PRSERV_HOST = "%s"' % pr_socket |
| 49 | self.append_config(config_server_data) |
| 50 | |
| 51 | def run_test_pr_service(self, package_name, package_type='rpm', track_task='do_package', pr_socket='localhost:0'): |
| 52 | self.config_pr_tests(package_name, package_type, pr_socket) |
| 53 | |
| 54 | self.increment_package_pr(package_name) |
| 55 | pr_1 = self.get_pr_version(package_name) |
| 56 | stamp_1 = self.get_task_stamp(package_name, track_task) |
| 57 | |
| 58 | self.increment_package_pr(package_name) |
| 59 | pr_2 = self.get_pr_version(package_name) |
| 60 | stamp_2 = self.get_task_stamp(package_name, track_task) |
| 61 | |
| 62 | bitbake("-ccleansstate %s" % package_name) |
| 63 | self.assertTrue(pr_2 - pr_1 == 1, "Step between same pkg. revision is greater than 1") |
| 64 | self.assertTrue(stamp_1 != stamp_2, "Different pkg rev. but same stamp: %s" % stamp_1) |
| 65 | |
| 66 | def run_test_pr_export_import(self, package_name, replace_current_db=True): |
| 67 | self.config_pr_tests(package_name) |
| 68 | |
| 69 | self.increment_package_pr(package_name) |
| 70 | pr_1 = self.get_pr_version(package_name) |
| 71 | |
| 72 | exported_db_path = os.path.join(self.builddir, 'export.inc') |
| 73 | export_result = runCmd("bitbake-prserv-tool export %s" % exported_db_path, ignore_status=True) |
| 74 | self.assertEqual(export_result.status, 0, msg="PR Service database export failed: %s" % export_result.output) |
| 75 | |
| 76 | if replace_current_db: |
| 77 | current_db_path = os.path.join(get_bb_var('PERSISTENT_DIR'), 'prserv.sqlite3') |
| 78 | self.assertTrue(os.path.exists(current_db_path), msg="Path to current PR Service database is invalid: %s" % current_db_path) |
| 79 | os.remove(current_db_path) |
| 80 | |
| 81 | import_result = runCmd("bitbake-prserv-tool import %s" % exported_db_path, ignore_status=True) |
| 82 | os.remove(exported_db_path) |
| 83 | self.assertEqual(import_result.status, 0, msg="PR Service database import failed: %s" % import_result.output) |
| 84 | |
| 85 | self.increment_package_pr(package_name) |
| 86 | pr_2 = self.get_pr_version(package_name) |
| 87 | |
| 88 | bitbake("-ccleansstate %s" % package_name) |
| 89 | self.assertTrue(pr_2 - pr_1 == 1, "Step between same pkg. revision is greater than 1") |
| 90 | |
| 91 | @testcase(930) |
| 92 | def test_import_export_replace_db(self): |
| 93 | self.run_test_pr_export_import('m4') |
| 94 | |
| 95 | @testcase(931) |
| 96 | def test_import_export_override_db(self): |
| 97 | self.run_test_pr_export_import('m4', replace_current_db=False) |
| 98 | |
| 99 | @testcase(932) |
| 100 | def test_pr_service_rpm_arch_dep(self): |
| 101 | self.run_test_pr_service('m4', 'rpm', 'do_package') |
| 102 | |
| 103 | @testcase(934) |
| 104 | def test_pr_service_deb_arch_dep(self): |
| 105 | self.run_test_pr_service('m4', 'deb', 'do_package') |
| 106 | |
| 107 | @testcase(933) |
| 108 | def test_pr_service_ipk_arch_dep(self): |
| 109 | self.run_test_pr_service('m4', 'ipk', 'do_package') |
| 110 | |
| 111 | @testcase(935) |
| 112 | def test_pr_service_rpm_arch_indep(self): |
| 113 | self.run_test_pr_service('xcursor-transparent-theme', 'rpm', 'do_package') |
| 114 | |
| 115 | @testcase(937) |
| 116 | def test_pr_service_deb_arch_indep(self): |
| 117 | self.run_test_pr_service('xcursor-transparent-theme', 'deb', 'do_package') |
| 118 | |
| 119 | @testcase(936) |
| 120 | def test_pr_service_ipk_arch_indep(self): |
| 121 | self.run_test_pr_service('xcursor-transparent-theme', 'ipk', 'do_package') |