summaryrefslogtreecommitdiffstats
path: root/meta/classes/testimage.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/testimage.bbclass')
-rw-r--r--meta/classes/testimage.bbclass39
1 files changed, 39 insertions, 0 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index 0d55c3247e..75f0f2c3e3 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -34,6 +34,17 @@ TESTIMAGE_AUTO ??= "0"
34# TEST_QEMUPARAMS can be used to pass extra parameters to qemu, e.g. "-m 1024" for setting the amount of ram to 1 GB. 34# TEST_QEMUPARAMS can be used to pass extra parameters to qemu, e.g. "-m 1024" for setting the amount of ram to 1 GB.
35# TEST_RUNQEMUPARAMS can be used to pass extra parameters to runqemu, e.g. "gl" to enable OpenGL acceleration. 35# TEST_RUNQEMUPARAMS can be used to pass extra parameters to runqemu, e.g. "gl" to enable OpenGL acceleration.
36 36
37# TESTIMAGE_BOOT_PATTERNS can be used to override certain patterns used to communicate with the target when booting,
38# if a pattern is not specifically present on this variable a default will be used when booting the target.
39# TESTIMAGE_BOOT_PATTERNS[<flag>] overrides the pattern used for that specific flag, where flag comes from a list of accepted flags
40# e.g. normally the system boots and waits for a login prompt (login:), after that it sends the command: "root\n" to log as the root user
41# if we wanted to log in as the hypothetical "webserver" user for example we could set the following:
42# TESTIMAGE_BOOT_PATTERNS = "send_login_user search_login_succeeded"
43# TESTIMAGE_BOOT_PATTERNS[send_login_user] = "webserver\n"
44# TESTIMAGE_BOOT_PATTERNS[search_login_succeeded] = "webserver@[a-zA-Z0-9\-]+:~#"
45# The accepted flags are the following: search_reached_prompt, send_login_user, search_login_succeeded, search_cmd_finished.
46# They are prefixed with either search/send, to differentiate if the pattern is meant to be sent or searched to/from the target terminal
47
37TEST_LOG_DIR ?= "${WORKDIR}/testimage" 48TEST_LOG_DIR ?= "${WORKDIR}/testimage"
38 49
39TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}" 50TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}"
@@ -68,6 +79,8 @@ TEST_TARGET ?= "qemu"
68TEST_QEMUPARAMS ?= "" 79TEST_QEMUPARAMS ?= ""
69TEST_RUNQEMUPARAMS ?= "" 80TEST_RUNQEMUPARAMS ?= ""
70 81
82TESTIMAGE_BOOT_PATTERNS ?= ""
83
71TESTIMAGEDEPENDS = "" 84TESTIMAGEDEPENDS = ""
72TESTIMAGEDEPENDS_append_qemuall = " qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot qemu-helper-native:do_addto_recipe_sysroot" 85TESTIMAGEDEPENDS_append_qemuall = " qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot qemu-helper-native:do_addto_recipe_sysroot"
73TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}" 86TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
@@ -150,6 +163,29 @@ def get_testimage_json_result_dir(d):
150def get_testimage_result_id(configuration): 163def get_testimage_result_id(configuration):
151 return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['MACHINE'], configuration['STARTTIME']) 164 return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['MACHINE'], configuration['STARTTIME'])
152 165
166def get_testimage_boot_patterns(d):
167 from collections import defaultdict
168 boot_patterns = defaultdict(str)
169 # Only accept certain values
170 accepted_patterns = ['search_reached_prompt', 'send_login_user', 'search_login_succeeded', 'search_cmd_finished']
171 # Not all patterns need to be overriden, e.g. perhaps we only want to change the user
172 boot_patterns_flags = d.getVarFlags('TESTIMAGE_BOOT_PATTERNS') or {}
173 if boot_patterns_flags:
174 patterns_set = [p for p in boot_patterns_flags.items() if p[0] in d.getVar('TESTIMAGE_BOOT_PATTERNS').split()]
175 for flag, flagval in patterns_set:
176 if flag not in accepted_patterns:
177 bb.fatal('Testimage: The only accepted boot patterns are: search_reached_prompt,send_login_user, \
178 search_login_succeeded,search_cmd_finished\n Make sure your TESTIMAGE_BOOT_PATTERNS=%s \
179 contains an accepted flag.' % d.getVar('TESTIMAGE_BOOT_PATTERNS'))
180 return
181 # We know boot prompt is searched through in binary format, others might be expressions
182 if flag == 'search_reached_prompt':
183 boot_patterns[flag] = flagval.encode()
184 else:
185 boot_patterns[flag] = flagval.encode().decode('unicode-escape')
186 return boot_patterns
187
188
153def testimage_main(d): 189def testimage_main(d):
154 import os 190 import os
155 import json 191 import json
@@ -259,6 +295,9 @@ def testimage_main(d):
259 'serial_ports': len(d.getVar("SERIAL_CONSOLES").split()), 295 'serial_ports': len(d.getVar("SERIAL_CONSOLES").split()),
260 } 296 }
261 297
298 if d.getVar("TESTIMAGE_BOOT_PATTERNS"):
299 target_kwargs['boot_patterns'] = get_testimage_boot_patterns(d)
300
262 # TODO: Currently BBPATH is needed for custom loading of targets. 301 # TODO: Currently BBPATH is needed for custom loading of targets.
263 # It would be better to find these modules using instrospection. 302 # It would be better to find these modules using instrospection.
264 target_kwargs['target_modules_path'] = d.getVar('BBPATH') 303 target_kwargs['target_modules_path'] = d.getVar('BBPATH')