diff --git a/doc/todo.md b/doc/todo.md index 858243a..f6129ae 100644 --- a/doc/todo.md +++ b/doc/todo.md @@ -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 diff --git a/src/manta/__init__.py b/src/manta/__init__.py index a6419cf..813bbcc 100644 --- a/src/manta/__init__.py +++ b/src/manta/__init__.py @@ -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": diff --git a/test/api_gen/invalid_configs/0_mangled_yaml.yaml b/test/api_gen/invalid_configs/0_mangled_yaml.yaml new file mode 100644 index 0000000..866e678 --- /dev/null +++ b/test/api_gen/invalid_configs/0_mangled_yaml.yaml @@ -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 \ No newline at end of file diff --git a/test/api_gen/invalid_configs/1_mangled_yaml.yaml b/test/api_gen/invalid_configs/1_mangled_yaml.yaml new file mode 100644 index 0000000..c786cdb --- /dev/null +++ b/test/api_gen/invalid_configs/1_mangled_yaml.yaml @@ -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 \ No newline at end of file diff --git a/test/api_gen/invalid_configs/2_mangled_yaml.yaml b/test/api_gen/invalid_configs/2_mangled_yaml.yaml new file mode 100644 index 0000000..9386d37 --- /dev/null +++ b/test/api_gen/invalid_configs/2_mangled_yaml.yaml @@ -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 \ No newline at end of file diff --git a/test/api_gen/run_test.py b/test/api_gen/run_test.py index a0b7ca4..366797a 100644 --- a/test/api_gen/run_test.py +++ b/test/api_gen/run_test.py @@ -1 +1,46 @@ -# try to build manta instances from valid and invalid configuration files \ No newline at end of file +# 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!")