diff options
Diffstat (limited to 'meta/lib/oeqa/utils/qemurunner.py')
-rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 4704422211..ed74ea8fad 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py | |||
@@ -21,6 +21,7 @@ import threading | |||
21 | import codecs | 21 | import codecs |
22 | import logging | 22 | import logging |
23 | from oeqa.utils.dump import HostDumper | 23 | from oeqa.utils.dump import HostDumper |
24 | from collections import defaultdict | ||
24 | 25 | ||
25 | # Get Unicode non printable control chars | 26 | # Get Unicode non printable control chars |
26 | control_range = list(range(0,32))+list(range(127,160)) | 27 | control_range = list(range(0,32))+list(range(127,160)) |
@@ -31,7 +32,7 @@ re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) | |||
31 | class QemuRunner: | 32 | class QemuRunner: |
32 | 33 | ||
33 | def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, | 34 | def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, |
34 | use_kvm, logger, use_slirp=False, serial_ports=2): | 35 | use_kvm, logger, use_slirp=False, serial_ports=2, boot_patterns = defaultdict(str)): |
35 | 36 | ||
36 | # Popen object for runqemu | 37 | # Popen object for runqemu |
37 | self.runqemu = None | 38 | self.runqemu = None |
@@ -57,6 +58,7 @@ class QemuRunner: | |||
57 | self.use_slirp = use_slirp | 58 | self.use_slirp = use_slirp |
58 | self.serial_ports = serial_ports | 59 | self.serial_ports = serial_ports |
59 | self.msg = '' | 60 | self.msg = '' |
61 | self.boot_patterns = boot_patterns | ||
60 | 62 | ||
61 | self.runqemutime = 120 | 63 | self.runqemutime = 120 |
62 | self.qemu_pidfile = 'pidfile_'+str(os.getpid()) | 64 | self.qemu_pidfile = 'pidfile_'+str(os.getpid()) |
@@ -65,6 +67,25 @@ class QemuRunner: | |||
65 | 67 | ||
66 | self.logger = logger | 68 | self.logger = logger |
67 | 69 | ||
70 | # Enable testing other OS's | ||
71 | # Set commands for target communication, and default to Linux ALWAYS | ||
72 | # Other OS's or baremetal applications need to provide their | ||
73 | # own implementation passing it through QemuRunner's constructor | ||
74 | # or by passing them through TESTIMAGE_BOOT_PATTERNS[flag] | ||
75 | # provided variables, where <flag> is one of the mentioned below. | ||
76 | accepted_patterns = ['search_reached_prompt', 'send_login_user', 'search_login_succeeded', 'search_cmd_finished'] | ||
77 | default_boot_patterns = defaultdict(str) | ||
78 | # Default to the usual paterns used to communicate with the target | ||
79 | default_boot_patterns['search_reached_prompt'] = b' login:' | ||
80 | default_boot_patterns['send_login_user'] = 'root\n' | ||
81 | default_boot_patterns['search_login_succeeded'] = r"root@[a-zA-Z0-9\-]+:~#" | ||
82 | default_boot_patterns['search_cmd_finished'] = r"[a-zA-Z0-9]+@[a-zA-Z0-9\-]+:~#" | ||
83 | |||
84 | # Only override patterns that were set e.g. login user TESTIMAGE_BOOT_PATTERNS[send_login_user] = "webserver\n" | ||
85 | for pattern in accepted_patterns: | ||
86 | if not self.boot_patterns[pattern]: | ||
87 | self.boot_patterns[pattern] = default_boot_patterns[pattern] | ||
88 | |||
68 | def create_socket(self): | 89 | def create_socket(self): |
69 | try: | 90 | try: |
70 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 91 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
@@ -321,7 +342,7 @@ class QemuRunner: | |||
321 | self.log(data) | 342 | self.log(data) |
322 | 343 | ||
323 | data = b'' | 344 | data = b'' |
324 | if b' login:' in bootlog: | 345 | if self.boot_patterns['search_reached_prompt'] in bootlog: |
325 | self.server_socket = qemusock | 346 | self.server_socket = qemusock |
326 | stopread = True | 347 | stopread = True |
327 | reachedlogin = True | 348 | reachedlogin = True |
@@ -353,8 +374,8 @@ class QemuRunner: | |||
353 | 374 | ||
354 | # If we are not able to login the tests can continue | 375 | # If we are not able to login the tests can continue |
355 | try: | 376 | try: |
356 | (status, output) = self.run_serial("root\n", raw=True) | 377 | (status, output) = self.run_serial(self.boot_patterns['send_login_user'], raw=True) |
357 | if re.search(r"root@[a-zA-Z0-9\-]+:~#", output): | 378 | if re.search(self.boot_patterns['search_login_succeeded'], output): |
358 | self.logged = True | 379 | self.logged = True |
359 | self.logger.debug("Logged as root in serial console") | 380 | self.logger.debug("Logged as root in serial console") |
360 | if netconf: | 381 | if netconf: |
@@ -478,7 +499,7 @@ class QemuRunner: | |||
478 | if answer: | 499 | if answer: |
479 | data += answer.decode('utf-8') | 500 | data += answer.decode('utf-8') |
480 | # Search the prompt to stop | 501 | # Search the prompt to stop |
481 | if re.search(r"[a-zA-Z0-9]+@[a-zA-Z0-9\-]+:~#", data): | 502 | if re.search(self.boot_patterns['search_cmd_finished'], data): |
482 | break | 503 | break |
483 | else: | 504 | else: |
484 | raise Exception("No data on serial console socket") | 505 | raise Exception("No data on serial console socket") |