4
# Copyright © 2020 Google LLC
6
# Permission is hereby granted, free of charge, to any person obtaining a
7
# copy of this software and associated documentation files (the "Software"),
8
# to deal in the Software without restriction, including without limitation
9
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
# and/or sell copies of the Software, and to permit persons to whom the
11
# Software is furnished to do so, subject to the following conditions:
13
# The above copyright notice and this permission notice (including the next
14
# paragraph) shall be included in all copies or substantial portions of the
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28
from serial_buffer import SerialBuffer
34
def __init__(self, cpu, ec):
35
# Merged FIFO for the two serial buffers, fed by threads.
36
self.serial_queue = queue.Queue()
37
self.sentinel = object()
40
self.ec_ser = SerialBuffer(
41
ec, "results/serial-ec.txt", "R SERIAL-EC> ")
42
self.cpu_ser = SerialBuffer(
43
cpu, "results/serial.txt", "R SERIAL-CPU> ")
45
self.iter_feed_ec = threading.Thread(
46
target=self.iter_feed_queue, daemon=True, args=(self.ec_ser.lines(),))
47
self.iter_feed_ec.start()
49
self.iter_feed_cpu = threading.Thread(
50
target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(),))
51
self.iter_feed_cpu.start()
53
# Feed lines from our serial queues into the merged queue, marking when our
55
def iter_feed_queue(self, it):
57
self.serial_queue.put(i)
58
self.serial_queue.put(sentinel)
60
# Return the next line from the queue, counting how many threads have
61
# terminated and joining when done
62
def get_serial_queue_line(self):
63
line = self.serial_queue.get()
64
if line == self.sentinel:
65
self.threads_done = self.threads_done + 1
66
if self.threads_done == 2:
67
self.iter_feed_cpu.join()
68
self.iter_feed_ec.join()
71
# Returns an iterator for getting the next line.
72
def serial_queue_lines(self):
73
return iter(self.get_serial_queue_line, self.sentinel)
75
def ec_write(self, s):
76
print("W SERIAL-EC> %s" % s)
77
self.ec_ser.serial.write(s.encode())
79
def cpu_write(self, s):
80
print("W SERIAL-CPU> %s" % s)
81
self.cpu_ser.serial.write(s.encode())
83
def print_error(self, message):
86
print(RED + message + NO_COLOR)
89
# Flush any partial commands in the EC's prompt, then ask for a reboot.
91
self.ec_write("reboot\n")
93
# This is emitted right when the bootloader pauses to check for input.
94
# Emit a ^N character to request network boot, because we don't have a
95
# direct-to-netboot firmware on cheza.
96
for line in self.serial_queue_lines():
97
if re.search("load_archive: loading locale_en.bin", line):
98
self.cpu_write("\016")
101
# The Cheza boards have issues with failing to bring up power to
102
# the system sometimes, possibly dependent on ambient temperature
104
if re.search("POWER_GOOD not seen in time", line):
105
self.print_error("Detected intermittent poweron failure, restarting run...")
109
for line in self.serial_queue_lines():
110
if re.search("---. end Kernel panic", line):
113
# The Cheza firmware seems to occasionally get stuck looping in
114
# this error state during TFTP booting, possibly based on amount of
115
# network traffic around it, but it'll usually recover after a
117
if re.search("R8152: Bulk read error 0xffffffbf", line):
119
if tftp_failures >= 100:
120
self.print_error("Detected intermittent tftp failure, restarting run...")
123
# There are very infrequent bus errors during power management transitions
124
# on cheza, which we don't expect to be the case on future boards.
125
if re.search("Kernel panic - not syncing: Asynchronous SError Interrupt", line):
126
self.print_error("Detected cheza power management bus error, restarting run...")
129
# These HFI response errors started appearing with the introduction
130
# of piglit runs. CosmicPenguin says:
132
# "message ID 106 isn't a thing, so likely what happened is that we
133
# got confused when parsing the HFI queue. If it happened on only
134
# one run, then memory corruption could be a possible clue"
136
# Given that it seems to trigger randomly near a GPU fault and then
137
# break many tests after that, just restart the whole run.
138
if re.search("a6xx_hfi_send_msg.*Unexpected message id .* on the response queue", line):
139
self.print_error("Detected cheza power management bus error, restarting run...")
142
result = re.search("bare-metal result: (\S*)", line)
144
if result.group(1) == "pass":
149
self.print_error("Reached the end of the CPU serial log without finding a result")
154
parser = argparse.ArgumentParser()
155
parser.add_argument('--cpu', type=str,
156
help='CPU Serial device', required=True)
158
'--ec', type=str, help='EC Serial device', required=True)
159
args = parser.parse_args()
161
servo = CrosServoRun(args.cpu, args.ec)
168
# power down the CPU on the device
169
servo.ec_write("power off\n")
174
if __name__ == '__main__':