diff options
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r-- | meta/lib/oeqa/utils/commands.py | 6 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/decorators.py | 19 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/dump.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/httpserver.py | 6 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/logparser.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 54 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/qemutinyrunner.py | 10 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/sshcontrol.py | 1 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/targetbuild.py | 4 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/testexport.py | 2 |
10 files changed, 64 insertions, 42 deletions
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index 48f6441290..18fe39ecfe 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py | |||
@@ -41,7 +41,7 @@ class Command(object): | |||
41 | self.data = data | 41 | self.data = data |
42 | 42 | ||
43 | self.options = dict(self.defaultopts) | 43 | self.options = dict(self.defaultopts) |
44 | if isinstance(self.cmd, basestring): | 44 | if isinstance(self.cmd, str): |
45 | self.options["shell"] = True | 45 | self.options["shell"] = True |
46 | if self.data: | 46 | if self.data: |
47 | self.options['stdin'] = subprocess.PIPE | 47 | self.options['stdin'] = subprocess.PIPE |
@@ -78,7 +78,7 @@ class Command(object): | |||
78 | self.process.kill() | 78 | self.process.kill() |
79 | self.thread.join() | 79 | self.thread.join() |
80 | 80 | ||
81 | self.output = self.output.rstrip() | 81 | self.output = self.output.decode("utf-8").rstrip() |
82 | self.status = self.process.poll() | 82 | self.status = self.process.poll() |
83 | 83 | ||
84 | self.log.debug("Command '%s' returned %d as exit code." % (self.cmd, self.status)) | 84 | self.log.debug("Command '%s' returned %d as exit code." % (self.cmd, self.status)) |
@@ -123,7 +123,7 @@ def bitbake(command, ignore_status=False, timeout=None, postconfig=None, **optio | |||
123 | else: | 123 | else: |
124 | extra_args = "" | 124 | extra_args = "" |
125 | 125 | ||
126 | if isinstance(command, basestring): | 126 | if isinstance(command, str): |
127 | cmd = "bitbake " + extra_args + " " + command | 127 | cmd = "bitbake " + extra_args + " " + command |
128 | else: | 128 | else: |
129 | cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]] | 129 | cmd = [ "bitbake" ] + [a for a in (command + extra_args.split(" ")) if a not in [""]] |
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py index d52f326f1a..0b23565485 100644 --- a/meta/lib/oeqa/utils/decorators.py +++ b/meta/lib/oeqa/utils/decorators.py | |||
@@ -115,6 +115,8 @@ class NoParsingFilter(logging.Filter): | |||
115 | def filter(self, record): | 115 | def filter(self, record): |
116 | return record.levelno == 100 | 116 | return record.levelno == 100 |
117 | 117 | ||
118 | import inspect | ||
119 | |||
118 | def LogResults(original_class): | 120 | def LogResults(original_class): |
119 | orig_method = original_class.run | 121 | orig_method = original_class.run |
120 | 122 | ||
@@ -124,6 +126,19 @@ def LogResults(original_class): | |||
124 | logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log') | 126 | logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log') |
125 | linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log') | 127 | linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log') |
126 | 128 | ||
129 | def get_class_that_defined_method(meth): | ||
130 | if inspect.ismethod(meth): | ||
131 | for cls in inspect.getmro(meth.__self__.__class__): | ||
132 | if cls.__dict__.get(meth.__name__) is meth: | ||
133 | return cls | ||
134 | meth = meth.__func__ # fallback to __qualname__ parsing | ||
135 | if inspect.isfunction(meth): | ||
136 | cls = getattr(inspect.getmodule(meth), | ||
137 | meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0]) | ||
138 | if isinstance(cls, type): | ||
139 | return cls | ||
140 | return None | ||
141 | |||
127 | #rewrite the run method of unittest.TestCase to add testcase logging | 142 | #rewrite the run method of unittest.TestCase to add testcase logging |
128 | def run(self, result, *args, **kws): | 143 | def run(self, result, *args, **kws): |
129 | orig_method(self, result, *args, **kws) | 144 | orig_method(self, result, *args, **kws) |
@@ -135,7 +150,7 @@ def LogResults(original_class): | |||
135 | except AttributeError: | 150 | except AttributeError: |
136 | test_case = self._testMethodName | 151 | test_case = self._testMethodName |
137 | 152 | ||
138 | class_name = str(testMethod.im_class).split("'")[1] | 153 | class_name = str(get_class_that_defined_method(testMethod)).split("'")[1] |
139 | 154 | ||
140 | #create custom logging level for filtering. | 155 | #create custom logging level for filtering. |
141 | custom_log_level = 100 | 156 | custom_log_level = 100 |
@@ -215,7 +230,7 @@ def tag(*args, **kwargs): | |||
215 | def wrap_ob(ob): | 230 | def wrap_ob(ob): |
216 | for name in args: | 231 | for name in args: |
217 | setattr(ob, __tag_prefix + name, True) | 232 | setattr(ob, __tag_prefix + name, True) |
218 | for name, value in kwargs.iteritems(): | 233 | for name, value in kwargs.items(): |
219 | setattr(ob, __tag_prefix + name, value) | 234 | setattr(ob, __tag_prefix + name, value) |
220 | return ob | 235 | return ob |
221 | return wrap_ob | 236 | return wrap_ob |
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py index 63a591d366..71422a9aea 100644 --- a/meta/lib/oeqa/utils/dump.py +++ b/meta/lib/oeqa/utils/dump.py | |||
@@ -3,7 +3,7 @@ import sys | |||
3 | import errno | 3 | import errno |
4 | import datetime | 4 | import datetime |
5 | import itertools | 5 | import itertools |
6 | from commands import runCmd | 6 | from .commands import runCmd |
7 | 7 | ||
8 | def get_host_dumper(d): | 8 | def get_host_dumper(d): |
9 | cmds = d.getVar("testimage_dump_host", True) | 9 | cmds = d.getVar("testimage_dump_host", True) |
diff --git a/meta/lib/oeqa/utils/httpserver.py b/meta/lib/oeqa/utils/httpserver.py index 76518d8ef9..bd76f36468 100644 --- a/meta/lib/oeqa/utils/httpserver.py +++ b/meta/lib/oeqa/utils/httpserver.py | |||
@@ -1,8 +1,8 @@ | |||
1 | import SimpleHTTPServer | 1 | import http.server |
2 | import multiprocessing | 2 | import multiprocessing |
3 | import os | 3 | import os |
4 | 4 | ||
5 | class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer): | 5 | class HTTPServer(http.server.HTTPServer): |
6 | 6 | ||
7 | def server_start(self, root_dir): | 7 | def server_start(self, root_dir): |
8 | import signal | 8 | import signal |
@@ -10,7 +10,7 @@ class HTTPServer(SimpleHTTPServer.BaseHTTPServer.HTTPServer): | |||
10 | os.chdir(root_dir) | 10 | os.chdir(root_dir) |
11 | self.serve_forever() | 11 | self.serve_forever() |
12 | 12 | ||
13 | class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | 13 | class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): |
14 | 14 | ||
15 | def log_message(self, format_str, *args): | 15 | def log_message(self, format_str, *args): |
16 | pass | 16 | pass |
diff --git a/meta/lib/oeqa/utils/logparser.py b/meta/lib/oeqa/utils/logparser.py index 87b50354cd..b377dcd271 100644 --- a/meta/lib/oeqa/utils/logparser.py +++ b/meta/lib/oeqa/utils/logparser.py | |||
@@ -3,7 +3,7 @@ | |||
3 | import sys | 3 | import sys |
4 | import os | 4 | import os |
5 | import re | 5 | import re |
6 | import ftools | 6 | from . import ftools |
7 | 7 | ||
8 | 8 | ||
9 | # A parser that can be used to identify weather a line is a test result or a section statement. | 9 | # A parser that can be used to identify weather a line is a test result or a section statement. |
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 4bede3421c..773cf588b1 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py | |||
@@ -22,9 +22,9 @@ import logging | |||
22 | logger = logging.getLogger("BitBake.QemuRunner") | 22 | logger = logging.getLogger("BitBake.QemuRunner") |
23 | 23 | ||
24 | # Get Unicode non printable control chars | 24 | # Get Unicode non printable control chars |
25 | control_range = range(0,32)+range(127,160) | 25 | control_range = list(range(0,32))+list(range(127,160)) |
26 | control_chars = [unichr(x) for x in control_range | 26 | control_chars = [chr(x) for x in control_range |
27 | if unichr(x) not in string.printable] | 27 | if chr(x) not in string.printable] |
28 | re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) | 28 | re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) |
29 | 29 | ||
30 | class QemuRunner: | 30 | class QemuRunner: |
@@ -71,7 +71,8 @@ class QemuRunner: | |||
71 | if self.logfile: | 71 | if self.logfile: |
72 | # It is needed to sanitize the data received from qemu | 72 | # It is needed to sanitize the data received from qemu |
73 | # because is possible to have control characters | 73 | # because is possible to have control characters |
74 | msg = re_control_char.sub('', unicode(msg, 'utf-8')) | 74 | msg = msg.decode("utf-8") |
75 | msg = re_control_char.sub('', msg) | ||
75 | with codecs.open(self.logfile, "a", encoding="utf-8") as f: | 76 | with codecs.open(self.logfile, "a", encoding="utf-8") as f: |
76 | f.write("%s" % msg) | 77 | f.write("%s" % msg) |
77 | 78 | ||
@@ -79,7 +80,7 @@ class QemuRunner: | |||
79 | import fcntl | 80 | import fcntl |
80 | fl = fcntl.fcntl(o, fcntl.F_GETFL) | 81 | fl = fcntl.fcntl(o, fcntl.F_GETFL) |
81 | fcntl.fcntl(o, fcntl.F_SETFL, fl | os.O_NONBLOCK) | 82 | fcntl.fcntl(o, fcntl.F_SETFL, fl | os.O_NONBLOCK) |
82 | return os.read(o.fileno(), 1000000) | 83 | return os.read(o.fileno(), 1000000).decode("utf-8") |
83 | 84 | ||
84 | 85 | ||
85 | def handleSIGCHLD(self, signum, frame): | 86 | def handleSIGCHLD(self, signum, frame): |
@@ -114,7 +115,7 @@ class QemuRunner: | |||
114 | try: | 115 | try: |
115 | threadsock, threadport = self.create_socket() | 116 | threadsock, threadport = self.create_socket() |
116 | self.server_socket, self.serverport = self.create_socket() | 117 | self.server_socket, self.serverport = self.create_socket() |
117 | except socket.error, msg: | 118 | except socket.error as msg: |
118 | logger.error("Failed to create listening socket: %s" % msg[1]) | 119 | logger.error("Failed to create listening socket: %s" % msg[1]) |
119 | return False | 120 | return False |
120 | 121 | ||
@@ -192,7 +193,7 @@ class QemuRunner: | |||
192 | else: | 193 | else: |
193 | self.ip = ips[0] | 194 | self.ip = ips[0] |
194 | self.server_ip = ips[1] | 195 | self.server_ip = ips[1] |
195 | except IndexError, ValueError: | 196 | except (IndexError, ValueError): |
196 | logger.info("Couldn't get ip from qemu process arguments! Here is the qemu command line used:\n%s\nand output from runqemu:\n%s" % (cmdline, self.getOutput(output))) | 197 | logger.info("Couldn't get ip from qemu process arguments! Here is the qemu command line used:\n%s\nand output from runqemu:\n%s" % (cmdline, self.getOutput(output))) |
197 | self._dump_host() | 198 | self._dump_host() |
198 | self.stop() | 199 | self.stop() |
@@ -219,6 +220,7 @@ class QemuRunner: | |||
219 | stopread = False | 220 | stopread = False |
220 | qemusock = None | 221 | qemusock = None |
221 | bootlog = '' | 222 | bootlog = '' |
223 | data = b'' | ||
222 | while time.time() < endtime and not stopread: | 224 | while time.time() < endtime and not stopread: |
223 | sread, swrite, serror = select.select(socklist, [], [], 5) | 225 | sread, swrite, serror = select.select(socklist, [], [], 5) |
224 | for sock in sread: | 226 | for sock in sread: |
@@ -229,14 +231,19 @@ class QemuRunner: | |||
229 | socklist.remove(self.server_socket) | 231 | socklist.remove(self.server_socket) |
230 | logger.info("Connection from %s:%s" % addr) | 232 | logger.info("Connection from %s:%s" % addr) |
231 | else: | 233 | else: |
232 | data = sock.recv(1024) | 234 | data = data + sock.recv(1024) |
233 | if data: | 235 | if data: |
234 | bootlog += data | 236 | try: |
235 | if re.search(".* login:", bootlog): | 237 | data = data.decode("utf-8") |
236 | self.server_socket = qemusock | 238 | bootlog += data |
237 | stopread = True | 239 | data = b'' |
238 | reachedlogin = True | 240 | if re.search(".* login:", bootlog): |
239 | logger.info("Reached login banner") | 241 | self.server_socket = qemusock |
242 | stopread = True | ||
243 | reachedlogin = True | ||
244 | logger.info("Reached login banner") | ||
245 | except UnicodeDecodeError: | ||
246 | continue | ||
240 | else: | 247 | else: |
241 | socklist.remove(sock) | 248 | socklist.remove(sock) |
242 | sock.close() | 249 | sock.close() |
@@ -277,13 +284,14 @@ class QemuRunner: | |||
277 | if hasattr(self, "origchldhandler"): | 284 | if hasattr(self, "origchldhandler"): |
278 | signal.signal(signal.SIGCHLD, self.origchldhandler) | 285 | signal.signal(signal.SIGCHLD, self.origchldhandler) |
279 | if self.runqemu: | 286 | if self.runqemu: |
280 | os.kill(self.monitorpid, signal.SIGKILL) | 287 | if hasattr(self, "monitorpid"): |
281 | logger.info("Sending SIGTERM to runqemu") | 288 | os.kill(self.monitorpid, signal.SIGKILL) |
282 | try: | 289 | logger.info("Sending SIGTERM to runqemu") |
283 | os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM) | 290 | try: |
284 | except OSError as e: | 291 | os.killpg(os.getpgid(self.runqemu.pid), signal.SIGTERM) |
285 | if e.errno != errno.ESRCH: | 292 | except OSError as e: |
286 | raise | 293 | if e.errno != errno.ESRCH: |
294 | raise | ||
287 | endtime = time.time() + self.runqemutime | 295 | endtime = time.time() + self.runqemutime |
288 | while self.runqemu.poll() is None and time.time() < endtime: | 296 | while self.runqemu.poll() is None and time.time() < endtime: |
289 | time.sleep(1) | 297 | time.sleep(1) |
@@ -325,7 +333,7 @@ class QemuRunner: | |||
325 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] | 333 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] |
326 | # | 334 | # |
327 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] | 335 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] |
328 | processes = ps.split('\n') | 336 | processes = ps.decode("utf-8").split('\n') |
329 | nfields = len(processes[0].split()) - 1 | 337 | nfields = len(processes[0].split()) - 1 |
330 | pids = {} | 338 | pids = {} |
331 | commands = {} | 339 | commands = {} |
@@ -442,7 +450,7 @@ class LoggingThread(threading.Thread): | |||
442 | def stop(self): | 450 | def stop(self): |
443 | self.logger.info("Stopping logging thread") | 451 | self.logger.info("Stopping logging thread") |
444 | if self.running: | 452 | if self.running: |
445 | os.write(self.writepipe, "stop") | 453 | os.write(self.writepipe, bytes("stop", "utf-8")) |
446 | 454 | ||
447 | def teardown(self): | 455 | def teardown(self): |
448 | self.logger.info("Tearing down logging thread") | 456 | self.logger.info("Tearing down logging thread") |
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py index e3d8c669e0..f733258bce 100644 --- a/meta/lib/oeqa/utils/qemutinyrunner.py +++ b/meta/lib/oeqa/utils/qemutinyrunner.py | |||
@@ -13,7 +13,7 @@ import re | |||
13 | import socket | 13 | import socket |
14 | import select | 14 | import select |
15 | import bb | 15 | import bb |
16 | from qemurunner import QemuRunner | 16 | from .qemurunner import QemuRunner |
17 | 17 | ||
18 | class QemuTinyRunner(QemuRunner): | 18 | class QemuTinyRunner(QemuRunner): |
19 | 19 | ||
@@ -50,7 +50,7 @@ class QemuTinyRunner(QemuRunner): | |||
50 | self.server_socket.connect(self.socketfile) | 50 | self.server_socket.connect(self.socketfile) |
51 | bb.note("Created listening socket for qemu serial console.") | 51 | bb.note("Created listening socket for qemu serial console.") |
52 | tries = 0 | 52 | tries = 0 |
53 | except socket.error, msg: | 53 | except socket.error as msg: |
54 | self.server_socket.close() | 54 | self.server_socket.close() |
55 | bb.fatal("Failed to create listening socket.") | 55 | bb.fatal("Failed to create listening socket.") |
56 | tries -= 1 | 56 | tries -= 1 |
@@ -102,7 +102,7 @@ class QemuTinyRunner(QemuRunner): | |||
102 | bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) | 102 | bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) |
103 | output = self.runqemu.stdout | 103 | output = self.runqemu.stdout |
104 | self.stop() | 104 | self.stop() |
105 | bb.note("Output from runqemu:\n%s" % output.read()) | 105 | bb.note("Output from runqemu:\n%s" % output.read().decode("utf-8")) |
106 | return False | 106 | return False |
107 | 107 | ||
108 | return self.is_alive() | 108 | return self.is_alive() |
@@ -131,7 +131,7 @@ class QemuTinyRunner(QemuRunner): | |||
131 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] | 131 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] |
132 | # | 132 | # |
133 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] | 133 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] |
134 | processes = ps.split('\n') | 134 | processes = ps.decode("utf-8").split('\n') |
135 | nfields = len(processes[0].split()) - 1 | 135 | nfields = len(processes[0].split()) - 1 |
136 | pids = {} | 136 | pids = {} |
137 | commands = {} | 137 | commands = {} |
@@ -167,4 +167,4 @@ class QemuTinyRunner(QemuRunner): | |||
167 | basecmd = commands[p].split()[0] | 167 | basecmd = commands[p].split()[0] |
168 | basecmd = os.path.basename(basecmd) | 168 | basecmd = os.path.basename(basecmd) |
169 | if "qemu-system" in basecmd and "-serial unix" in commands[p]: | 169 | if "qemu-system" in basecmd and "-serial unix" in commands[p]: |
170 | return [int(p),commands[p]] \ No newline at end of file | 170 | return [int(p),commands[p]] |
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py index ff88d37bd9..f5d46e03cc 100644 --- a/meta/lib/oeqa/utils/sshcontrol.py +++ b/meta/lib/oeqa/utils/sshcontrol.py | |||
@@ -58,6 +58,7 @@ class SSHProcess(object): | |||
58 | self.process.stdout.close() | 58 | self.process.stdout.close() |
59 | eof = True | 59 | eof = True |
60 | else: | 60 | else: |
61 | data = data.decode("utf-8") | ||
61 | output += data | 62 | output += data |
62 | self.log(data) | 63 | self.log(data) |
63 | endtime = time.time() + timeout | 64 | endtime = time.time() + timeout |
diff --git a/meta/lib/oeqa/utils/targetbuild.py b/meta/lib/oeqa/utils/targetbuild.py index f850d78df1..d538f6b65f 100644 --- a/meta/lib/oeqa/utils/targetbuild.py +++ b/meta/lib/oeqa/utils/targetbuild.py | |||
@@ -10,9 +10,7 @@ import bb.utils | |||
10 | import subprocess | 10 | import subprocess |
11 | from abc import ABCMeta, abstractmethod | 11 | from abc import ABCMeta, abstractmethod |
12 | 12 | ||
13 | class BuildProject(): | 13 | class BuildProject(metaclass=ABCMeta): |
14 | |||
15 | __metaclass__ = ABCMeta | ||
16 | 14 | ||
17 | def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"): | 15 | def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"): |
18 | self.d = d | 16 | self.d = d |
diff --git a/meta/lib/oeqa/utils/testexport.py b/meta/lib/oeqa/utils/testexport.py index 4fbf4bdcb3..57be2ca449 100644 --- a/meta/lib/oeqa/utils/testexport.py +++ b/meta/lib/oeqa/utils/testexport.py | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | import os, re, glob as g, shutil as sh,sys | 7 | import os, re, glob as g, shutil as sh,sys |
8 | from time import sleep | 8 | from time import sleep |
9 | from commands import runCmd | 9 | from .commands import runCmd |
10 | from difflib import SequenceMatcher as SM | 10 | from difflib import SequenceMatcher as SM |
11 | 11 | ||
12 | try: | 12 | try: |