add api generation tests

This commit is contained in:
Fischer Moseley 2023-03-24 10:34:15 -04:00
parent d5dfd3bbf3
commit edf94c9cf7
6 changed files with 136 additions and 7 deletions

View File

@ -22,7 +22,7 @@
- Write out what bus transactions look like and how messages get passed. probably going to need wavedrom for this.
## Testing
- need to add tests for the python itself - does it recognize bad yaml files and produce the right errors when trying to build from them? are good manta files synthesizeable?
- need to build out more tests for the python itself in test/api_gen
- try doing literally anything on Windows lol
## Meta

View File

@ -54,15 +54,14 @@ class UARTInterface:
if (port.vid == 0x403) and (port.pid == 0x6010):
recognized_devices.append(port)
assert len(recognized_devices) == 2, f"Expected to see two serial ports for FT2232 device, but instead see {len(recognized_devices)}."
# board manufacturers seem to always make the 0th serial
# interface on the FT2232 be for programming over JTAG,
# and then the 1st to be for UART. as a result, we always
# grab the device with the larger location
rd = recognized_devices
assert len(recognized_devices) == 2, f"Expected to see two serial ports for FT2232 device, but instead see {len(recognized_devices)}."
assert rd[0].serial_number == rd[1].serial_number, "Serial numbers should be the same on both FT2232 ports - probably somehow grabbed ports on two different devices."
return rd[0].device if rd[0].location > rd[1].location else rd[1].device
def read_register(self, addr):
@ -936,8 +935,15 @@ Supported commands:
elif argv[1] == "ports":
import serial.tools.list_ports
for info in serial.tools.list_ports.comports():
print(info)
for port in serial.tools.list_ports.comports():
print(port)
print(' -> vid: 0x{:04X}'.format(port.vid))
print(' -> pid: 0x{:04X}'.format(port.pid))
print(f" -> ser: {port.serial_number}")
print(f" -> loc: {port.location}")
print(f" -> mftr: {port.manufacturer}")
print(f" -> prod: {port.product}")
print(f" -> desc: {port.description}\n")
# generate the specified configuration
elif argv[1] == "gen":

View File

@ -0,0 +1,26 @@
---
cores:
my_io_core:
type: io
inputs:
btnu: 1
btnd: 1
btnl: Q
btnr: 1
btnc: 1
sw: 16
outputs:
led: 16
led16_b: 1
led16_g: 1
led16_r: 1
led17_b: 1
led17_g: 1
led17_r: 1
uart:
port: "auto"
baudrate: 115200
clock_freq: 100000000

View File

@ -0,0 +1,26 @@
---
cores:
my_io_core:
type: io
inputs:
btnu: 1
btnd: 1
btnl: 1
btnr: 1
btnc:
sw: 16
outputs:
led: 16
led16_b: 1
led16_g: 1
led16_r: 1
led17_b: 1
led17_g: 1
led17_r: 1
uart:
port: "auto"
baudrate: 115200
clock_freq: 100000000

View File

@ -0,0 +1,26 @@
---
cores:
my_io_core:
type: io
inputs:
btnu: 1
btnd: 1
btnl: 1
btnr: 1
btnc: randomstringthatsnotaninteger
sw: 16
outputs:
led: 16
led16_b: 1
led16_g: 1
led16_r: 1
led17_b: 1
led17_g: 1
led17_r: 1
uart:
port: "auto"
baudrate: 115200
clock_freq: 100000000

View File

@ -1 +1,46 @@
# try to build manta instances from valid and invalid configuration files
# try to build manta instances from valid and invalid configuration files
from os import listdir
from os.path import isfile
from manta import Manta
# Valid Configurations
print(" ==== Testing valid configurations ====")
valid_configs_path = 'test/api_gen/valid_configs/'
for config_file in sorted(listdir(valid_configs_path)):
caught_exception = None
try:
m = Manta(valid_configs_path + config_file)
except Exception as e:
caught_exception = e
if caught_exception is None:
print(f" -> config file {config_file} raised no exceptions.")
else:
raise RuntimeError(f"Configuration {config_file} shouldn't have raised an exception, but raised {caught_exception}")
print('\n')
# Invalid Configurations
print(" ==== Testing invalid configurations ====")
invalid_configs_path = 'test/api_gen/invalid_configs/'
for config_file in sorted(listdir(invalid_configs_path)):
caught_exception = None
try:
m = Manta(invalid_configs_path + config_file)
except Exception as e:
caught_exception = e
if caught_exception is not None:
print(f" -> config file {config_file} raised the following exception: {caught_exception}")
else:
raise RuntimeError(f"Configuration {config_file} should have raised an exception, but did not!")