ci/bare-metal: Apply autopep8 to the bare-metal scripts.

Let's follow proper python formatting (easy now that vscode does it for
me)

Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7434>
This commit is contained in:
Eric Anholt
2020-10-30 16:30:10 -07:00
committed by Marge Bot
parent 9f1cd99ba1
commit ff6741728d
2 changed files with 32 additions and 14 deletions

View File

@@ -28,6 +28,7 @@ from serial_buffer import SerialBuffer
import sys import sys
import threading import threading
class CrosServoRun: class CrosServoRun:
def __init__(self, cpu, ec): def __init__(self, cpu, ec):
# Merged FIFO for the two serial buffers, fed by threads. # Merged FIFO for the two serial buffers, fed by threads.
@@ -35,13 +36,17 @@ class CrosServoRun:
self.sentinel = object() self.sentinel = object()
self.threads_done = 0 self.threads_done = 0
self.ec_ser = SerialBuffer(ec, "results/serial-ec.txt", "R SERIAL-EC> ") self.ec_ser = SerialBuffer(
self.cpu_ser = SerialBuffer(cpu, "results/serial.txt", "R SERIAL-CPU> ") ec, "results/serial-ec.txt", "R SERIAL-EC> ")
self.cpu_ser = SerialBuffer(
cpu, "results/serial.txt", "R SERIAL-CPU> ")
self.iter_feed_ec = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.ec_ser.lines(),)) self.iter_feed_ec = threading.Thread(
target=self.iter_feed_queue, daemon=True, args=(self.ec_ser.lines(),))
self.iter_feed_ec.start() self.iter_feed_ec.start()
self.iter_feed_cpu = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(),)) self.iter_feed_cpu = threading.Thread(
target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(),))
self.iter_feed_cpu.start() self.iter_feed_cpu.start()
# Feed lines from our serial queues into the merged queue, marking when our # Feed lines from our serial queues into the merged queue, marking when our
@@ -119,10 +124,13 @@ class CrosServoRun:
print("Reached the end of the CPU serial log without finding a result") print("Reached the end of the CPU serial log without finding a result")
return 1 return 1
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--cpu', type=str, help='CPU Serial device', required=True) parser.add_argument('--cpu', type=str,
parser.add_argument('--ec', type=str, help='EC Serial device', required=True) help='CPU Serial device', required=True)
parser.add_argument(
'--ec', type=str, help='EC Serial device', required=True)
args = parser.parse_args() args = parser.parse_args()
servo = CrosServoRun(args.cpu, args.ec) servo = CrosServoRun(args.cpu, args.ec)
@@ -137,5 +145,6 @@ def main():
sys.exit(retval) sys.exit(retval)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -22,12 +22,13 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
import argparse import argparse
from datetime import datetime,timezone from datetime import datetime, timezone
import queue import queue
import serial import serial
import threading import threading
import time import time
class SerialBuffer: class SerialBuffer:
def __init__(self, dev, filename, prefix): def __init__(self, dev, filename, prefix):
self.filename = filename self.filename = filename
@@ -45,12 +46,15 @@ class SerialBuffer:
self.sentinel = object() self.sentinel = object()
if self.dev: if self.dev:
self.read_thread = threading.Thread(target=self.serial_read_thread_loop, daemon=True) self.read_thread = threading.Thread(
target=self.serial_read_thread_loop, daemon=True)
else: else:
self.read_thread = threading.Thread(target=self.serial_file_read_thread_loop, daemon=True) self.read_thread = threading.Thread(
target=self.serial_file_read_thread_loop, daemon=True)
self.read_thread.start() self.read_thread.start()
self.lines_thread = threading.Thread(target=self.serial_lines_thread_loop, daemon=True) self.lines_thread = threading.Thread(
target=self.serial_lines_thread_loop, daemon=True)
self.lines_thread.start() self.lines_thread.start()
# Thread that just reads the bytes from the serial device to try to keep from # Thread that just reads the bytes from the serial device to try to keep from
@@ -91,7 +95,7 @@ class SerialBuffer:
if bytes == self.sentinel: if bytes == self.sentinel:
self.read_thread.join() self.read_thread.join()
self.line_queue.put(self.sentinel) self.line_queue.put(self.sentinel)
break; break
# Write our data to the output file if we're the ones reading from # Write our data to the output file if we're the ones reading from
# the serial device # the serial device
@@ -105,7 +109,8 @@ class SerialBuffer:
line = line.decode(errors="replace") line = line.decode(errors="replace")
time = datetime.now().strftime('%y-%m-%d %H:%M:%S') time = datetime.now().strftime('%y-%m-%d %H:%M:%S')
print("{time} {prefix}{line}".format(time=time, prefix=self.prefix, line=line), flush=True, end='') print("{time} {prefix}{line}".format(
time=time, prefix=self.prefix, line=line), flush=True, end='')
self.line_queue.put(line) self.line_queue.put(line)
line = bytearray() line = bytearray()
@@ -119,12 +124,15 @@ class SerialBuffer:
def lines(self): def lines(self):
return iter(self.get_line, self.sentinel) return iter(self.get_line, self.sentinel)
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--dev', type=str, help='Serial device') 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('--file', type=str,
parser.add_argument('--prefix', type=str, help='Prefix for logging serial to stdout', nargs='?') 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() args = parser.parse_args()
@@ -134,5 +142,6 @@ def main():
# them # them
pass pass
if __name__ == '__main__': if __name__ == '__main__':
main() main()