0c43419854f05f2042eca2adb32df980c981cc4d
[mesa.git] / .gitlab-ci / bare-metal / cros_servo_run.py
1 #!/usr/bin/env python3
2 #
3 # Copyright © 2020 Google LLC
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
23
24 import argparse
25 import re
26 from serial_buffer import SerialBuffer
27 import sys
28
29 class CrosServoRun:
30 def __init__(self, cpu, ec):
31 self.ec_ser = SerialBuffer(ec, "artifacts/serial-ec.txt", "R SERIAL-EC> ")
32 self.cpu_ser = SerialBuffer(cpu, "artifacts/serial.txt", "R SERIAL-CPU> ")
33
34 def ec_write(self, s):
35 print("W SERIAL-EC> %s" % s)
36 self.ec_ser.serial.write(s.encode())
37
38 def cpu_write(self, s):
39 print("W SERIAL-CPU> %s" % s)
40 self.cpu_ser.serial.write(s.encode())
41
42 def run(self):
43 # Flush any partial commands in the EC's prompt, then ask for a reboot.
44 self.ec_write("\n")
45 self.ec_write("reboot\n")
46
47 # This is emitted right when the bootloader pauses to check for input.
48 # Emit a ^N character to request network boot, because we don't have a
49 # direct-to-netboot firmware on cheza.
50 for line in self.cpu_ser.lines():
51 if re.match("load_archive: loading locale_en.bin", line):
52 self.cpu_write("\016")
53 break
54
55 for line in self.cpu_ser.lines():
56 if re.match("---. end Kernel panic", line):
57 return 1
58 if re.match("POWER_GOOD not seen in time", line):
59 return 1
60
61 result = re.match("bare-metal result: (\S*)", line)
62 if result:
63 if result.group(1) == "pass":
64 return 0
65 else:
66 return 1
67
68 print("Reached the end of the CPU serial log without finding a result")
69 return 1
70
71 def main():
72 parser = argparse.ArgumentParser()
73 parser.add_argument('--cpu', type=str, help='CPU Serial device', required=True)
74 parser.add_argument('--ec', type=str, help='EC Serial device', required=True)
75 args = parser.parse_args()
76
77 servo = CrosServoRun(args.cpu, args.ec)
78
79 retval = servo.run()
80
81 # power down the CPU on the device
82 servo.ec_write("power off\n")
83
84 sys.exit(retval)
85
86 if __name__ == '__main__':
87 main()