diff options
author | Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | 2017-05-12 14:40:21 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-06 19:02:43 +0100 |
commit | 157c3be2ca93f076033f725ec1ee912df91f7488 (patch) | |
tree | 8ef896ff7adf78d63b34059cd5b017a4f0a3419a /meta/lib/oeqa/selftest/cases/runtime_test.py | |
parent | 10c512b60d1167122b5fe778b93838dca3def717 (diff) | |
download | poky-157c3be2ca93f076033f725ec1ee912df91f7488.tar.gz |
oeqa/selftest/cases: Migrate test cases into the new oe-qa framework
New framework has different classes/decorators so adapt current test cases to
support these. Changes include changes on base classes and decorators.
Also include paths in selftest/__init__.py isn't needed because the
loader is the standard unittest one.
(From OE-Core rev: ddbbefdd124604d10bd47dd0266b55a764fcc0ab)
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/runtime_test.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/runtime_test.py | 239 |
1 files changed, 239 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/runtime_test.py b/meta/lib/oeqa/selftest/cases/runtime_test.py new file mode 100644 index 0000000000..9fec4d869b --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/runtime_test.py | |||
@@ -0,0 +1,239 @@ | |||
1 | from oeqa.selftest.case import OESelftestTestCase | ||
2 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu | ||
3 | from oeqa.core.decorator.oeid import OETestID | ||
4 | import os | ||
5 | import re | ||
6 | |||
7 | class TestExport(OESelftestTestCase): | ||
8 | |||
9 | @classmethod | ||
10 | def tearDownClass(cls): | ||
11 | runCmd("rm -rf /tmp/sdk") | ||
12 | super(TestExport, cls).tearDownClass() | ||
13 | |||
14 | def test_testexport_basic(self): | ||
15 | """ | ||
16 | Summary: Check basic testexport functionality with only ping test enabled. | ||
17 | Expected: 1. testexport directory must be created. | ||
18 | 2. runexported.py must run without any error/exception. | ||
19 | 3. ping test must succeed. | ||
20 | Product: oe-core | ||
21 | Author: Mariano Lopez <mariano.lopez@intel.com> | ||
22 | """ | ||
23 | |||
24 | features = 'INHERIT += "testexport"\n' | ||
25 | # These aren't the actual IP addresses but testexport class needs something defined | ||
26 | features += 'TEST_SERVER_IP = "192.168.7.1"\n' | ||
27 | features += 'TEST_TARGET_IP = "192.168.7.1"\n' | ||
28 | features += 'TEST_SUITES = "ping"\n' | ||
29 | self.write_config(features) | ||
30 | |||
31 | # Build tesexport for core-image-minimal | ||
32 | bitbake('core-image-minimal') | ||
33 | bitbake('-c testexport core-image-minimal') | ||
34 | |||
35 | testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal') | ||
36 | |||
37 | # Verify if TEST_EXPORT_DIR was created | ||
38 | isdir = os.path.isdir(testexport_dir) | ||
39 | self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir) | ||
40 | |||
41 | with runqemu('core-image-minimal') as qemu: | ||
42 | # Attempt to run runexported.py to perform ping test | ||
43 | test_path = os.path.join(testexport_dir, "oe-test") | ||
44 | data_file = os.path.join(testexport_dir, 'data', 'testdata.json') | ||
45 | manifest = os.path.join(testexport_dir, 'data', 'manifest') | ||
46 | cmd = ("%s runtime --test-data-file %s --packages-manifest %s " | ||
47 | "--target-ip %s --server-ip %s --quiet" | ||
48 | % (test_path, data_file, manifest, qemu.ip, qemu.server_ip)) | ||
49 | result = runCmd(cmd) | ||
50 | # Verify ping test was succesful | ||
51 | self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status') | ||
52 | |||
53 | def test_testexport_sdk(self): | ||
54 | """ | ||
55 | Summary: Check sdk functionality for testexport. | ||
56 | Expected: 1. testexport directory must be created. | ||
57 | 2. SDK tarball must exists. | ||
58 | 3. Uncompressing of tarball must succeed. | ||
59 | 4. Check if the SDK directory is added to PATH. | ||
60 | 5. Run tar from the SDK directory. | ||
61 | Product: oe-core | ||
62 | Author: Mariano Lopez <mariano.lopez@intel.com> | ||
63 | """ | ||
64 | |||
65 | features = 'INHERIT += "testexport"\n' | ||
66 | # These aren't the actual IP addresses but testexport class needs something defined | ||
67 | features += 'TEST_SERVER_IP = "192.168.7.1"\n' | ||
68 | features += 'TEST_TARGET_IP = "192.168.7.1"\n' | ||
69 | features += 'TEST_SUITES = "ping"\n' | ||
70 | features += 'TEST_EXPORT_SDK_ENABLED = "1"\n' | ||
71 | features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n' | ||
72 | self.write_config(features) | ||
73 | |||
74 | # Build tesexport for core-image-minimal | ||
75 | bitbake('core-image-minimal') | ||
76 | bitbake('-c testexport core-image-minimal') | ||
77 | |||
78 | needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME'] | ||
79 | bb_vars = get_bb_vars(needed_vars, 'core-image-minimal') | ||
80 | testexport_dir = bb_vars['TEST_EXPORT_DIR'] | ||
81 | sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR'] | ||
82 | sdk_name = bb_vars['TEST_EXPORT_SDK_NAME'] | ||
83 | |||
84 | # Check for SDK | ||
85 | tarball_name = "%s.sh" % sdk_name | ||
86 | tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name) | ||
87 | msg = "Couldn't find SDK tarball: %s" % tarball_path | ||
88 | self.assertEqual(os.path.isfile(tarball_path), True, msg) | ||
89 | |||
90 | # Extract SDK and run tar from SDK | ||
91 | result = runCmd("%s -y -d /tmp/sdk" % tarball_path) | ||
92 | self.assertEqual(0, result.status, "Couldn't extract SDK") | ||
93 | |||
94 | env_script = result.output.split()[-1] | ||
95 | result = runCmd(". %s; which tar" % env_script, shell=True) | ||
96 | self.assertEqual(0, result.status, "Couldn't setup SDK environment") | ||
97 | is_sdk_tar = True if "/tmp/sdk" in result.output else False | ||
98 | self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment") | ||
99 | |||
100 | tar_sdk = result.output | ||
101 | result = runCmd("%s --version" % tar_sdk) | ||
102 | self.assertEqual(0, result.status, "Couldn't run tar from SDK") | ||
103 | |||
104 | |||
105 | class TestImage(OESelftestTestCase): | ||
106 | |||
107 | def test_testimage_install(self): | ||
108 | """ | ||
109 | Summary: Check install packages functionality for testimage/testexport. | ||
110 | Expected: 1. Import tests from a directory other than meta. | ||
111 | 2. Check install/uninstall of socat. | ||
112 | 3. Check that remote package feeds can be accessed | ||
113 | Product: oe-core | ||
114 | Author: Mariano Lopez <mariano.lopez@intel.com> | ||
115 | Author: Alexander Kanavin <alexander.kanavin@intel.com> | ||
116 | """ | ||
117 | if get_bb_var('DISTRO') == 'poky-tiny': | ||
118 | self.skipTest('core-image-full-cmdline not buildable for poky-tiny') | ||
119 | |||
120 | features = 'INHERIT += "testimage"\n' | ||
121 | features += 'TEST_SUITES = "ping ssh selftest"\n' | ||
122 | # We don't yet know what the server ip and port will be - they will be patched | ||
123 | # in at the start of the on-image test | ||
124 | features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n' | ||
125 | features += 'EXTRA_IMAGE_FEATURES += "package-management"\n' | ||
126 | features += 'PACKAGE_CLASSES = "package_rpm"' | ||
127 | self.write_config(features) | ||
128 | |||
129 | # Build core-image-sato and testimage | ||
130 | bitbake('core-image-full-cmdline socat') | ||
131 | bitbake('-c testimage core-image-full-cmdline') | ||
132 | |||
133 | class Postinst(OESelftestTestCase): | ||
134 | @OETestID(1540) | ||
135 | def test_verify_postinst(self): | ||
136 | """ | ||
137 | Summary: The purpose of this test is to verify the execution order of postinst Bugzilla ID: [5319] | ||
138 | Expected : | ||
139 | 1. Compile a minimal image. | ||
140 | 2. The compiled image will add the created layer with the recipes postinst[ abdpt] | ||
141 | 3. Run qemux86 | ||
142 | 4. Validate the task execution order | ||
143 | Author: Francisco Pedraza <francisco.j.pedraza.gonzalez@intel.com> | ||
144 | """ | ||
145 | features = 'INHERIT += "testimage"\n' | ||
146 | features += 'CORE_IMAGE_EXTRA_INSTALL += "postinst-at-rootfs \ | ||
147 | postinst-delayed-a \ | ||
148 | postinst-delayed-b \ | ||
149 | postinst-delayed-d \ | ||
150 | postinst-delayed-p \ | ||
151 | postinst-delayed-t \ | ||
152 | "\n' | ||
153 | self.write_config(features) | ||
154 | |||
155 | bitbake('core-image-minimal -f ') | ||
156 | |||
157 | postinst_list = ['100-postinst-at-rootfs', | ||
158 | '101-postinst-delayed-a', | ||
159 | '102-postinst-delayed-b', | ||
160 | '103-postinst-delayed-d', | ||
161 | '104-postinst-delayed-p', | ||
162 | '105-postinst-delayed-t'] | ||
163 | path_workdir = get_bb_var('WORKDIR','core-image-minimal') | ||
164 | workspacedir = 'testimage/qemu_boot_log' | ||
165 | workspacedir = os.path.join(path_workdir, workspacedir) | ||
166 | rexp = re.compile("^Running postinst .*/(?P<postinst>.*)\.\.\.$") | ||
167 | with runqemu('core-image-minimal') as qemu: | ||
168 | with open(workspacedir) as f: | ||
169 | found = False | ||
170 | idx = 0 | ||
171 | for line in f.readlines(): | ||
172 | line = line.strip().replace("^M","") | ||
173 | if not line: # To avoid empty lines | ||
174 | continue | ||
175 | m = rexp.search(line) | ||
176 | if m: | ||
177 | self.assertEqual(postinst_list[idx], m.group('postinst'), "Fail") | ||
178 | idx = idx+1 | ||
179 | found = True | ||
180 | elif found: | ||
181 | self.assertEqual(idx, len(postinst_list), "Not found all postinsts") | ||
182 | break | ||
183 | |||
184 | @OETestID(1545) | ||
185 | def test_postinst_rootfs_and_boot(self): | ||
186 | """ | ||
187 | Summary: The purpose of this test case is to verify Post-installation | ||
188 | scripts are called when rootfs is created and also test | ||
189 | that script can be delayed to run at first boot. | ||
190 | Dependencies: NA | ||
191 | Steps: 1. Add proper configuration to local.conf file | ||
192 | 2. Build a "core-image-minimal" image | ||
193 | 3. Verify that file created by postinst_rootfs recipe is | ||
194 | present on rootfs dir. | ||
195 | 4. Boot the image created on qemu and verify that the file | ||
196 | created by postinst_boot recipe is present on image. | ||
197 | Expected: The files are successfully created during rootfs and boot | ||
198 | time for 3 different package managers: rpm,ipk,deb and | ||
199 | for initialization managers: sysvinit and systemd. | ||
200 | |||
201 | """ | ||
202 | file_rootfs_name = "this-was-created-at-rootfstime" | ||
203 | fileboot_name = "this-was-created-at-first-boot" | ||
204 | rootfs_pkg = 'postinst-at-rootfs' | ||
205 | boot_pkg = 'postinst-delayed-a' | ||
206 | #Step 1 | ||
207 | common_features = 'MACHINE = "qemux86"\n' | ||
208 | common_features += 'CORE_IMAGE_EXTRA_INSTALL += "%s %s "\n'% (rootfs_pkg, boot_pkg) | ||
209 | common_features += 'IMAGE_FEATURES += "ssh-server-openssh"\n' | ||
210 | for init_manager in ("sysvinit", "systemd"): | ||
211 | #for sysvinit no extra configuration is needed, | ||
212 | features = '' | ||
213 | if (init_manager is "systemd"): | ||
214 | features += 'DISTRO_FEATURES_append = " systemd"\n' | ||
215 | features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n' | ||
216 | features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n' | ||
217 | features += 'VIRTUAL-RUNTIME_initscripts = ""\n' | ||
218 | for classes in ("package_rpm package_deb package_ipk", | ||
219 | "package_deb package_rpm package_ipk", | ||
220 | "package_ipk package_deb package_rpm"): | ||
221 | features += 'PACKAGE_CLASSES = "%s"\n' % classes | ||
222 | self.write_config(common_features + features) | ||
223 | |||
224 | #Step 2 | ||
225 | bitbake('core-image-minimal') | ||
226 | |||
227 | #Step 3 | ||
228 | file_rootfs_created = os.path.join(get_bb_var('IMAGE_ROOTFS',"core-image-minimal"), | ||
229 | file_rootfs_name) | ||
230 | found = os.path.isfile(file_rootfs_created) | ||
231 | self.assertTrue(found, "File %s was not created at rootfs time by %s" % \ | ||
232 | (file_rootfs_name, rootfs_pkg)) | ||
233 | |||
234 | #Step 4 | ||
235 | testcommand = 'ls /etc/'+fileboot_name | ||
236 | with runqemu('core-image-minimal') as qemu: | ||
237 | sshargs = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' | ||
238 | result = runCmd('ssh %s root@%s %s' % (sshargs, qemu.ip, testcommand)) | ||
239 | self.assertEqual(result.status, 0, 'File %s was not created at firts boot'% fileboot_name) | ||