mesa/.gitlab-ci/bare-metal/serial_buffer.py

186 lines
6.4 KiB
Python
Raw Normal View History

#!/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
from datetime import datetime, timezone
import queue
import serial
import threading
import time
class SerialBuffer:
def __init__(self, dev, filename, prefix, timeout=None, line_queue=None):
self.filename = filename
self.dev = dev
if dev:
self.f = open(filename, "wb+")
self.serial = serial.Serial(dev, 115200, timeout=timeout)
else:
self.f = open(filename, "rb")
self.serial = None
self.byte_queue = queue.Queue()
# allow multiple SerialBuffers to share a line queue so you can merge
# servo's CPU and EC streams into one thing to watch the boot/test
# progress on.
if line_queue:
self.line_queue = line_queue
else:
self.line_queue = queue.Queue()
self.prefix = prefix
ci: add testing for VC4 drivers (Raspberry Pi 3) This tests OpenGL ES 2.0 CTS suite with VC4 drivers, through baremetal Raspberry Pi 3 devices. The devices are connected to a switch that supports Power over Ethernet (PoE), so the devices can be started/stopped through the switch, and also to a host that runs the GitLab runner through serial-to-USB cables, to monitor the devices to know when the testing finishes. The Raspberries uses a network boot, using NFS and TFTP. For the root filesystem, they use the one created in the armhf container. For the kernel/modules case, this is handled externally. Currently it is using the same kernel/modules that come with the Raspberry Pi OS. In future we could build them in the same armhf container. At this moment we only test armhf architecture, as this is the default one suggested by the Raspberry Pi Foundation. In future we could also add testing for arm64 architecture. Finally, for the very rare ocassions where the Raspberry Pi 3 device is booted but no data is received, it retries the testing for a second time, powering off and on the device in the process. v2: - Remove commit that exists capture devcoredump (Eric) - Squash remaining commits in one (Andres) v3: - Add missing boot timeout check (Juan) v4: - Use locks when running the PoE on/off script (Eric) - Use a timeout for serial read (Eric) v5: - Rename stage to "raspberrypi" (Eric) - Bump up arm64_test tag (Eric) v6: - Make serial buffer timeout optional (Juan) Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7628>
2020-11-15 19:57:55 +00:00
self.timeout = timeout
self.sentinel = object()
self.closing = False
if self.dev:
self.read_thread = threading.Thread(
target=self.serial_read_thread_loop, daemon=True)
else:
self.read_thread = threading.Thread(
target=self.serial_file_read_thread_loop, daemon=True)
self.read_thread.start()
self.lines_thread = threading.Thread(
target=self.serial_lines_thread_loop, daemon=True)
self.lines_thread.start()
def close(self):
self.closing = True
if self.serial:
self.serial.cancel_read()
self.read_thread.join()
self.lines_thread.join()
if self.serial:
self.serial.close()
# Thread that just reads the bytes from the serial device to try to keep from
ci: add testing for VC4 drivers (Raspberry Pi 3) This tests OpenGL ES 2.0 CTS suite with VC4 drivers, through baremetal Raspberry Pi 3 devices. The devices are connected to a switch that supports Power over Ethernet (PoE), so the devices can be started/stopped through the switch, and also to a host that runs the GitLab runner through serial-to-USB cables, to monitor the devices to know when the testing finishes. The Raspberries uses a network boot, using NFS and TFTP. For the root filesystem, they use the one created in the armhf container. For the kernel/modules case, this is handled externally. Currently it is using the same kernel/modules that come with the Raspberry Pi OS. In future we could build them in the same armhf container. At this moment we only test armhf architecture, as this is the default one suggested by the Raspberry Pi Foundation. In future we could also add testing for arm64 architecture. Finally, for the very rare ocassions where the Raspberry Pi 3 device is booted but no data is received, it retries the testing for a second time, powering off and on the device in the process. v2: - Remove commit that exists capture devcoredump (Eric) - Squash remaining commits in one (Andres) v3: - Add missing boot timeout check (Juan) v4: - Use locks when running the PoE on/off script (Eric) - Use a timeout for serial read (Eric) v5: - Rename stage to "raspberrypi" (Eric) - Bump up arm64_test tag (Eric) v6: - Make serial buffer timeout optional (Juan) Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7628>
2020-11-15 19:57:55 +00:00
# buffer overflowing it. If nothing is received in 1 minute, it finalizes.
def serial_read_thread_loop(self):
greet = "Serial thread reading from %s\n" % self.dev
self.byte_queue.put(greet.encode())
while not self.closing:
try:
ci: add testing for VC4 drivers (Raspberry Pi 3) This tests OpenGL ES 2.0 CTS suite with VC4 drivers, through baremetal Raspberry Pi 3 devices. The devices are connected to a switch that supports Power over Ethernet (PoE), so the devices can be started/stopped through the switch, and also to a host that runs the GitLab runner through serial-to-USB cables, to monitor the devices to know when the testing finishes. The Raspberries uses a network boot, using NFS and TFTP. For the root filesystem, they use the one created in the armhf container. For the kernel/modules case, this is handled externally. Currently it is using the same kernel/modules that come with the Raspberry Pi OS. In future we could build them in the same armhf container. At this moment we only test armhf architecture, as this is the default one suggested by the Raspberry Pi Foundation. In future we could also add testing for arm64 architecture. Finally, for the very rare ocassions where the Raspberry Pi 3 device is booted but no data is received, it retries the testing for a second time, powering off and on the device in the process. v2: - Remove commit that exists capture devcoredump (Eric) - Squash remaining commits in one (Andres) v3: - Add missing boot timeout check (Juan) v4: - Use locks when running the PoE on/off script (Eric) - Use a timeout for serial read (Eric) v5: - Rename stage to "raspberrypi" (Eric) - Bump up arm64_test tag (Eric) v6: - Make serial buffer timeout optional (Juan) Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7628>
2020-11-15 19:57:55 +00:00
b = self.serial.read()
if len(b) == 0:
ci: add testing for VC4 drivers (Raspberry Pi 3) This tests OpenGL ES 2.0 CTS suite with VC4 drivers, through baremetal Raspberry Pi 3 devices. The devices are connected to a switch that supports Power over Ethernet (PoE), so the devices can be started/stopped through the switch, and also to a host that runs the GitLab runner through serial-to-USB cables, to monitor the devices to know when the testing finishes. The Raspberries uses a network boot, using NFS and TFTP. For the root filesystem, they use the one created in the armhf container. For the kernel/modules case, this is handled externally. Currently it is using the same kernel/modules that come with the Raspberry Pi OS. In future we could build them in the same armhf container. At this moment we only test armhf architecture, as this is the default one suggested by the Raspberry Pi Foundation. In future we could also add testing for arm64 architecture. Finally, for the very rare ocassions where the Raspberry Pi 3 device is booted but no data is received, it retries the testing for a second time, powering off and on the device in the process. v2: - Remove commit that exists capture devcoredump (Eric) - Squash remaining commits in one (Andres) v3: - Add missing boot timeout check (Juan) v4: - Use locks when running the PoE on/off script (Eric) - Use a timeout for serial read (Eric) v5: - Rename stage to "raspberrypi" (Eric) - Bump up arm64_test tag (Eric) v6: - Make serial buffer timeout optional (Juan) Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7628>
2020-11-15 19:57:55 +00:00
break
self.byte_queue.put(b)
except Exception as err:
print(self.prefix + str(err))
break
self.byte_queue.put(self.sentinel)
# Thread that just reads the bytes from the file of serial output that some
# other process is appending to.
def serial_file_read_thread_loop(self):
greet = "Serial thread reading from %s\n" % self.filename
self.byte_queue.put(greet.encode())
while not self.closing:
line = self.f.readline()
if line:
self.byte_queue.put(line)
else:
time.sleep(0.1)
self.byte_queue.put(self.sentinel)
# Thread that processes the stream of bytes to 1) log to stdout, 2) log to
# file, 3) add to the queue of lines to be read by program logic
def serial_lines_thread_loop(self):
line = bytearray()
while True:
bytes = self.byte_queue.get(block=True)
if bytes == self.sentinel:
self.read_thread.join()
self.line_queue.put(self.sentinel)
break
# Write our data to the output file if we're the ones reading from
# the serial device
if self.dev:
self.f.write(bytes)
self.f.flush()
for b in bytes:
line.append(b)
if b == b'\n'[0]:
line = line.decode(errors="replace")
time = datetime.now().strftime('%y-%m-%d %H:%M:%S')
ci/deqp: Switch to a new dEQP runner written in Rust. I found the C++ runner hard to develop on, and we had stability issues and outstanding feature needs that made me want something I felt good about hacking on. Thus, Rewrite It In Rust of the deqp runner. The new runner includes: - Skip lists don't reshuffle the test list. - Known-flake handling without resorting to skip lists (fixing our main CI reliability issue on a3xx right now). - Per-thread Vulkan shader caches should speed up VK CI runtime. - Tracking of crashes separate from fails (so we can see progress on that front). - Logging of deqp stderr spam (particularly assertion failures!) in the CI log. - Integrated QPA filtering so we don't have bash perf issues for it. - Logging of what caselist to go look at for a given error report (in red, so it's easier to find in your CI log). - The code is 1/3 unit tests, and easy to extend for more coverage. - Non-LAVA CI runs create a failures.csv in artifacts that you can check in as your deqp-*-fails.txt file. - Test runtime is included in results.csv so you can debug how to speed up your CI job. - Pretty summary at the end of the run of slow/flaky/failed tests. Since this is a new runner with a different RNG, the test groups are shuffled one more time. This seems to result in some panfrost T720 stability issues (See its new deqp-panfrost-t720-flakes.txt), and one new flake in freedreno a630. Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7434>
2020-10-29 17:29:28 +00:00
print("{endc}{time} {prefix}{line}".format(
time=time, prefix=self.prefix, line=line, endc='\033[0m'), flush=True, end='')
self.line_queue.put(line)
line = bytearray()
def lines(self, timeout=None, phase=None):
start_time = time.monotonic()
while True:
read_timeout = None
if timeout:
read_timeout = timeout - (time.monotonic() - start_time)
if read_timeout <= 0:
print("read timeout waiting for serial during {}".format(phase))
self.close()
break
try:
line = self.line_queue.get(timeout=read_timeout)
except queue.Empty:
print("read timeout waiting for serial during {}".format(phase))
self.close()
break
if line == self.sentinel:
print("End of serial output")
self.lines_thread.join()
break
yield line
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--dev', type=str, help='Serial device')
parser.add_argument('--file', type=str,
help='Filename for serial output', required=True)
parser.add_argument('--prefix', type=str,
help='Prefix for logging serial to stdout', nargs='?')
args = parser.parse_args()
ser = SerialBuffer(args.dev, args.file, args.prefix or "")
for line in ser.lines():
# We're just using this as a logger, so eat the produced lines and drop
# them
pass
if __name__ == '__main__':
main()