Rev 9919 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9919 | Rev 9920 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | return True if sys.platform == "linux" or sys.platform == "linux2" else False |
19 | return True if sys.platform == "linux" or sys.platform == "linux2" else False |
Line 20... | Line 20... | ||
20 | 20 | ||
21 | def is_osx(): |
21 | def is_osx(): |
Line 22... | Line 22... | ||
22 | return True if sys.platform == "darwin" else False |
22 | return True if sys.platform == "darwin" else False |
- | 23 | ||
- | 24 | class TestException(Exception): |
|
- | 25 | def __init__(self, error_kind, message, qemu_cmd): |
|
- | 26 | self.error_kind = error_kind |
|
- | 27 | super().__init__(message) |
|
- | 28 | self.qemu_cmd = qemu_cmd |
|
- | 29 | ||
- | 30 | def kind(self): |
|
23 | 31 | return self.error_kind |
|
- | 32 | ||
24 | class TestTimeoutException(Exception): |
33 | def cmd(self): |
25 | pass |
34 | return self.qemu_cmd |
26 | 35 | ||
- | 36 | class TestException_Timeout(TestException): |
|
- | 37 | def __init__(self, message, qemu_cmd): |
|
- | 38 | super().__init__("TIMEOUT", message, qemu_cmd) |
|
27 | class TestFailureException(Exception): |
39 | |
- | 40 | class TestException_Failure(TestException): |
|
Line 28... | Line 41... | ||
28 | def __init__(self, message): |
41 | def __init__(self, message, qemu_cmd): |
29 | self.message = message |
42 | super().__init__("FAILURE", message, qemu_cmd) |
30 | 43 | ||
31 | class Qemu: |
44 | class Qemu: |
32 | def __init__(self, popen, debug_log): |
45 | def __init__(self, popen, debug_log): |
33 | self.popen = popen |
46 | self.popen = popen |
34 | # Qemu needs time to create debug.log file |
47 | # Qemu needs time to create debug.log file |
35 | while not os.path.exists(debug_log) and self.qemu_is_alive(): |
48 | while not os.path.exists(debug_log) and self.qemu_is_alive(): |
Line 36... | Line 49... | ||
36 | self.wait(0.250) |
49 | self.wait(0.250) |
37 | self.assert_qemu_not_died("waiting for the debug log file") |
50 | self.assert_qemu_not_died("waiting for the debug log file creation") |
Line 38... | Line 51... | ||
38 | self.debug = open(debug_log, "rb") |
51 | self.debug = open(debug_log, "rb") |
39 | 52 | ||
40 | def qemu_is_alive(self): |
53 | def qemu_is_alive(self): |
Line 41... | Line 54... | ||
41 | return self.popen.poll() == None |
54 | return self.popen.poll() == None |
42 | 55 | ||
43 | def assert_qemu_not_died(self, while_): |
56 | def assert_qemu_not_died(self, while_): |
44 | if not self.qemu_is_alive(): |
57 | if not self.qemu_is_alive(): |
Line 67... | Line 80... | ||
67 | if len(log) > len(needle) * 2: |
80 | if len(log) > len(needle) * 2: |
68 | log = log[len(needle):] |
81 | log = log[len(needle):] |
Line 69... | Line 82... | ||
69 | 82 | ||
Line 70... | Line 83... | ||
70 | self.assert_qemu_not_died("waiting for the debug log") |
83 | self.assert_qemu_not_died("waiting for the debug log") |
Line 71... | Line 84... | ||
71 | 84 | ||
72 | self.timeout() |
85 | self.timeout("waiting for the debug log") |
73 | 86 | ||
74 | def kill(self): |
87 | def kill(self): |
75 | if is_win32(): |
88 | if is_win32(): |
76 | # FIXME: This is shit, isn't there anything better? |
89 | # FIXME: This is shit, isn't there anything better? |
Line 77... | Line 90... | ||
77 | subprocess.Popen(f"TASKKILL /F /PID {self.popen.pid} /T", stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL) |
90 | subprocess.Popen(f"TASKKILL /F /PID {self.popen.pid} /T", stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL) |
78 | else: |
91 | else: |
79 | os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM) |
92 | os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM) |
Line 80... | Line 93... | ||
80 | 93 | ||
81 | def timeout(self): |
94 | def timeout(self, while_): |
Line 82... | Line 95... | ||
82 | self.kill() |
95 | self.kill() |