Mesa (master): ci/bare-metal: Convert the main cros-servo boot code to python
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Aug 21 20:28:03 UTC 2020
Module: Mesa
Branch: master
Commit: c63648121e189945e04c4a9963aaeb46db9403ec
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c63648121e189945e04c4a9963aaeb46db9403ec
Author: Eric Anholt <eric at anholt.net>
Date: Wed Aug 19 15:23:24 2020 -0700
ci/bare-metal: Convert the main cros-servo boot code to python
Switching this part to python makes the code clearer and cleans up our
logs as well.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6398>
---
.gitlab-ci/bare-metal/cros-servo.sh | 46 +++--------------
.gitlab-ci/bare-metal/cros_servo_run.py | 87 +++++++++++++++++++++++++++++++++
.gitlab-ci/bare-metal/write-serial.py | 11 -----
3 files changed, 94 insertions(+), 50 deletions(-)
diff --git a/.gitlab-ci/bare-metal/cros-servo.sh b/.gitlab-ci/bare-metal/cros-servo.sh
index 160d82f412a..6de59d97a68 100755
--- a/.gitlab-ci/bare-metal/cros-servo.sh
+++ b/.gitlab-ci/bare-metal/cros-servo.sh
@@ -64,39 +64,12 @@ rm -rf /tftp/*
cp $BM_KERNEL /tftp/vmlinuz
echo "$BM_CMDLINE" > /tftp/cmdline
-# Start watching serials, and power up the device.
-python3 $BM/serial_buffer.py \
- --dev $BM_SERIAL_EC \
- --file serial-ec-output.txt \
- --prefix "SERIAL-EC> " &
-python3 $BM/serial_buffer.py \
- --dev $BM_SERIAL \
- --file serial-output.txt \
- --prefix "SERIAL-CPU> " &
-
-while [ ! -e serial-output.txt ]; do
- sleep 1
-done
-# Flush any partial commands in the EC's prompt, then ask for a reboot.
-$BM/write-serial.py $BM_SERIAL_EC ""
-$BM/write-serial.py $BM_SERIAL_EC reboot
-
-# This is emitted right when the bootloader pauses to check for input. Emit a
-# ^N character to request network boot, because we don't have a
-# direct-to-netboot firmware on cheza.
-$BM/expect-output.sh serial-output.txt -f "load_archive: loading locale_en.bin"
-$BM/write-serial.py $BM_SERIAL `printf '\016'`
-
-# Wait for the device to complete the deqp run
-$BM/expect-output.sh serial-output.txt \
- -f "bare-metal result" \
- -e "---. end Kernel panic" \
- -e "POWER_GOOD not seen in time"
-
-# power down the CPU on the device
-$BM/write-serial.py $BM_SERIAL_EC 'power off'
-
-set -ex
+set +e
+python3 $BM/cros_servo_run.py \
+ --cpu $BM_SERIAL \
+ --ec $BM_SERIAL_EC
+ret=$?
+set -e
# Bring artifacts back from the NFS dir to the build dir where gitlab-runner
# will look for them. Note that results/ may already exist, so be careful
@@ -104,9 +77,4 @@ set -ex
mkdir -p results
cp -Rp /nfs/results/. results/
-set +e
-if grep -q "bare-metal result: pass" serial-output.txt; then
- exit 0
-else
- exit 1
-fi
+exit $ret
diff --git a/.gitlab-ci/bare-metal/cros_servo_run.py b/.gitlab-ci/bare-metal/cros_servo_run.py
new file mode 100755
index 00000000000..0c43419854f
--- /dev/null
+++ b/.gitlab-ci/bare-metal/cros_servo_run.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python3
+#
+# Copyright © 2020 Google LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+import argparse
+import re
+from serial_buffer import SerialBuffer
+import sys
+
+class CrosServoRun:
+ def __init__(self, cpu, ec):
+ self.ec_ser = SerialBuffer(ec, "artifacts/serial-ec.txt", "R SERIAL-EC> ")
+ self.cpu_ser = SerialBuffer(cpu, "artifacts/serial.txt", "R SERIAL-CPU> ")
+
+ def ec_write(self, s):
+ print("W SERIAL-EC> %s" % s)
+ self.ec_ser.serial.write(s.encode())
+
+ def cpu_write(self, s):
+ print("W SERIAL-CPU> %s" % s)
+ self.cpu_ser.serial.write(s.encode())
+
+ def run(self):
+ # Flush any partial commands in the EC's prompt, then ask for a reboot.
+ self.ec_write("\n")
+ self.ec_write("reboot\n")
+
+ # This is emitted right when the bootloader pauses to check for input.
+ # Emit a ^N character to request network boot, because we don't have a
+ # direct-to-netboot firmware on cheza.
+ for line in self.cpu_ser.lines():
+ if re.match("load_archive: loading locale_en.bin", line):
+ self.cpu_write("\016")
+ break
+
+ for line in self.cpu_ser.lines():
+ if re.match("---. end Kernel panic", line):
+ return 1
+ if re.match("POWER_GOOD not seen in time", line):
+ return 1
+
+ result = re.match("bare-metal result: (\S*)", line)
+ if result:
+ if result.group(1) == "pass":
+ return 0
+ else:
+ return 1
+
+ print("Reached the end of the CPU serial log without finding a result")
+ return 1
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--cpu', type=str, help='CPU Serial device', required=True)
+ parser.add_argument('--ec', type=str, help='EC Serial device', required=True)
+ args = parser.parse_args()
+
+ servo = CrosServoRun(args.cpu, args.ec)
+
+ retval = servo.run()
+
+ # power down the CPU on the device
+ servo.ec_write("power off\n")
+
+ sys.exit(retval)
+
+if __name__ == '__main__':
+ main()
diff --git a/.gitlab-ci/bare-metal/write-serial.py b/.gitlab-ci/bare-metal/write-serial.py
deleted file mode 100755
index 6a57ea754af..00000000000
--- a/.gitlab-ci/bare-metal/write-serial.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/python3
-
-import sys
-import serial
-
-dev = sys.argv[1]
-command = sys.argv[2] + '\n'
-
-ser = serial.Serial(dev, 115200, timeout=5)
-ser.write(command.encode())
-ser.close()
More information about the mesa-commit
mailing list