blob: 479e5206184a3f2850e8a56c6f05dd3944706c31 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001import os
2import re
3import shutil
4import datetime
5
6import oeqa.utils.ftools as ftools
7from oeqa.selftest.case import OESelftestTestCase
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var
9from oeqa.core.decorator.oeid import OETestID
10from oeqa.utils.network import get_free_port
11
12class BitbakePrTests(OESelftestTestCase):
13
14 @classmethod
15 def setUpClass(cls):
16 super(BitbakePrTests, cls).setUpClass()
17 cls.pkgdata_dir = get_bb_var('PKGDATA_DIR')
18
19 def get_pr_version(self, package_name):
20 package_data_file = os.path.join(self.pkgdata_dir, 'runtime', package_name)
21 package_data = ftools.read_file(package_data_file)
22 find_pr = re.search("PKGR: r[0-9]+\.([0-9]+)", package_data)
23 self.assertTrue(find_pr, "No PKG revision found in %s" % package_data_file)
24 return int(find_pr.group(1))
25
26 def get_task_stamp(self, package_name, recipe_task):
27 stampdata = get_bb_var('STAMP', target=package_name).split('/')
28 prefix = stampdata[-1]
29 package_stamps_path = "/".join(stampdata[:-1])
30 stamps = []
31 for stamp in os.listdir(package_stamps_path):
32 find_stamp = re.match("%s\.%s\.([a-z0-9]{32})" % (re.escape(prefix), recipe_task), stamp)
33 if find_stamp:
34 stamps.append(find_stamp.group(1))
35 self.assertFalse(len(stamps) == 0, msg="Cound not find stamp for task %s for recipe %s" % (recipe_task, package_name))
36 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))
37 return str(stamps[0])
38
39 def increment_package_pr(self, package_name):
40 inc_data = "do_package_append() {\n bb.build.exec_func('do_test_prserv', d)\n}\ndo_test_prserv() {\necho \"The current date is: %s\"\n}" % datetime.datetime.now()
41 self.write_recipeinc(package_name, inc_data)
42 res = bitbake(package_name, ignore_status=True)
43 self.delete_recipeinc(package_name)
44 self.assertEqual(res.status, 0, msg=res.output)
45
46 def config_pr_tests(self, package_name, package_type='rpm', pr_socket='localhost:0'):
47 config_package_data = 'PACKAGE_CLASSES = "package_%s"' % package_type
48 self.write_config(config_package_data)
49 config_server_data = 'PRSERV_HOST = "%s"' % pr_socket
50 self.append_config(config_server_data)
51
52 def run_test_pr_service(self, package_name, package_type='rpm', track_task='do_package', pr_socket='localhost:0'):
53 self.config_pr_tests(package_name, package_type, pr_socket)
54
55 self.increment_package_pr(package_name)
56 pr_1 = self.get_pr_version(package_name)
57 stamp_1 = self.get_task_stamp(package_name, track_task)
58
59 self.increment_package_pr(package_name)
60 pr_2 = self.get_pr_version(package_name)
61 stamp_2 = self.get_task_stamp(package_name, track_task)
62
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 self.assertTrue(os.path.exists(exported_db_path))
76
77 if replace_current_db:
78 current_db_path = os.path.join(get_bb_var('PERSISTENT_DIR'), 'prserv.sqlite3')
79 self.assertTrue(os.path.exists(current_db_path), msg="Path to current PR Service database is invalid: %s" % current_db_path)
80 os.remove(current_db_path)
81
82 import_result = runCmd("bitbake-prserv-tool import %s" % exported_db_path, ignore_status=True)
83 os.remove(exported_db_path)
84 self.assertEqual(import_result.status, 0, msg="PR Service database import failed: %s" % import_result.output)
85
86 self.increment_package_pr(package_name)
87 pr_2 = self.get_pr_version(package_name)
88
89 self.assertTrue(pr_2 - pr_1 == 1, "Step between same pkg. revision is greater than 1")
90
91 @OETestID(930)
92 def test_import_export_replace_db(self):
93 self.run_test_pr_export_import('m4')
94
95 @OETestID(931)
96 def test_import_export_override_db(self):
97 self.run_test_pr_export_import('m4', replace_current_db=False)
98
99 @OETestID(932)
100 def test_pr_service_rpm_arch_dep(self):
101 self.run_test_pr_service('m4', 'rpm', 'do_package')
102
103 @OETestID(934)
104 def test_pr_service_deb_arch_dep(self):
105 self.run_test_pr_service('m4', 'deb', 'do_package')
106
107 @OETestID(933)
108 def test_pr_service_ipk_arch_dep(self):
109 self.run_test_pr_service('m4', 'ipk', 'do_package')
110
111 @OETestID(935)
112 def test_pr_service_rpm_arch_indep(self):
113 self.run_test_pr_service('xcursor-transparent-theme', 'rpm', 'do_package')
114
115 @OETestID(937)
116 def test_pr_service_deb_arch_indep(self):
117 self.run_test_pr_service('xcursor-transparent-theme', 'deb', 'do_package')
118
119 @OETestID(936)
120 def test_pr_service_ipk_arch_indep(self):
121 self.run_test_pr_service('xcursor-transparent-theme', 'ipk', 'do_package')
122
123 @OETestID(1419)
124 def test_stopping_prservice_message(self):
125 port = get_free_port()
126
127 runCmd('bitbake-prserv --host localhost --port %s --loglevel=DEBUG --start' % port)
128 ret = runCmd('bitbake-prserv --host localhost --port %s --loglevel=DEBUG --stop' % port)
129
130 self.assertEqual(ret.status, 0)
131