diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index c73e032..6245d5d 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.10", "3.11"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -18,6 +18,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint + pip install -r requirements.txt - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint $(git ls-files '*.py') --max-public-methods=30 --ignore=tests diff --git a/README.md b/README.md index 44a8e1b..0e87e10 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# processor-ci-communication \ No newline at end of file +# Processor CI Communication + +[![Pylint](https://github.com/LSC-Unicamp/processor_ci_communication/actions/workflows/pylint.yml/badge.svg)](https://github.com/LSC-Unicamp/processor_ci_communication/actions/workflows/pylint.yml) \ No newline at end of file diff --git a/core/file.py b/core/file.py index 8d23a9f..2ca3128 100644 --- a/core/file.py +++ b/core/file.py @@ -1,47 +1,101 @@ +""" +This module contains utility functions for handling files and directories. + +It includes functions for: +- Reading files and returning their content. +- Listing files in directories. +- Opening files in a directory and reading their content. +""" + import os -import glob -def read_file(path: str) -> tuple[list[str], int]: +def read_file(path: str) -> tuple[list[int], int]: + """Reads a file and returns its content and the number of lines. + + Args: + path (str): Path to the file. + + Returns: + tuple[list[int], int]: Tuple with the file content (as integers) and the number of lines. + + Raises: + FileNotFoundError: If the specified file does not exist. + ValueError: If a line in the file cannot be converted to an integer. + """ if not os.path.isfile(path): - FileNotFoundError(f"Erro: O arquivo '{path}' não foi encontrado.") + raise FileNotFoundError(f"Error: The file '{path}' was not found.") - file = open(path) data = [] - - for line in file.readlines(): - data.append(int(line.replace("\n", ""), 16)) + with open(path, 'r', encoding='utf-8') as file: + for line in file: + try: + data.append(int(line.strip(), 16)) + except ValueError as e: + raise ValueError( + f'Error converting line to integer: {e}' + ) from e return data, len(data) def list_files_in_dir(path: str) -> list[str]: + """List all files in a directory. + + Args: + path (str): Path to the directory. + + Returns: + list[str]: List with the files in the directory. + + Raises: + FileNotFoundError: If the directory does not exist. + OSError: For other errors related to accessing the directory. + """ + if not os.path.isdir(path): + raise FileNotFoundError( + f"Error: The directory '{path}' was not found." + ) + try: return [ file for file in os.listdir(path) if os.path.isfile(os.path.join(path, file)) ] - except FileNotFoundError: - print(f"Erro: O diretório '{path}' não foi encontrado.") - return [] - except Exception as e: - print(f"Erro: {e}") - return [] + except OSError as e: + raise OSError(f'Error accessing the directory: {e}') from e def open_files_in_dir(path: str) -> list[dict[str, list[str]]]: + """Open all files in a directory and return their content. + + Args: + path (str): Path to the directory. + + Returns: + list[dict[str, list[str]]]: List with the files' content. + + Raises: + FileNotFoundError: If the directory does not exist. + OSError: For other errors related to accessing the directory or files. + """ + if not os.path.isdir(path): + raise FileNotFoundError( + f"Error: The directory '{path}' was not found." + ) + files_content = [] try: for file_name in os.listdir(path): file_path = os.path.join(path, file_name) if os.path.isfile(file_path): - with open(file_path, "r", encoding="utf-8") as f: + with open(file_path, 'r', encoding='utf-8') as f: file_data = f.readlines() - files_content.append({file_name: [line.strip() for line in file_data]}) - except FileNotFoundError: - print(f"Erro: O diretório '{path}' não foi encontrado.") - except Exception as e: - print(f"Erro: {e}") + files_content.append( + {file_name: [line.strip() for line in file_data]} + ) + except OSError as e: + raise OSError(f'Error processing files in the directory: {e}') from e return files_content diff --git a/core/serial.py b/core/serial.py index f3011de..57f5b9f 100644 --- a/core/serial.py +++ b/core/serial.py @@ -1,107 +1,267 @@ -import os +""" +Module for interfacing with a processor using serial communication. + +This module contains the `ProcessorCIInterface` class, which implements methods +to control and interact with a processor by sending commands via a serial interface. +""" + import time import serial class ProcessorCIInterface: + """ + Interface for communication with a processor via serial commands. + + This class provides methods for sending commands, manipulating memory, + and executing operations on a processor connected via a serial interface. + """ + def __init__(self, port: str, baudrate: int, timeout: int = 1) -> None: + """ + Initializes the serial interface with the provided parameters. + + Args: + port (str): Serial port to use (e.g., '/dev/ttyUSB0'). + baudrate (int): Communication speed in baud rate. + timeout (int): Timeout for serial operations (in seconds). + """ self.port = port self.baudrate = baudrate - self.serial = serial.Serial(port, baudrate) + self.serial = serial.Serial(port, baudrate, timeout=timeout) self.serial.flushInput() self.serial.flushOutput() - def send_data(self, data: bytes) -> None: + def _send_data(self, data: bytes) -> None: + """ + Sends data through the serial port. + + Args: + data (bytes): Data to be sent. + """ self.serial.write(data) def read_data(self, size: int = 4) -> bytes: + """ + Reads data from the serial port. + + Args: + size (int): Number of bytes to read. + + Returns: + bytes: Data read from the serial port. + """ return self.serial.read(size) def print_data(self, data: bytes) -> None: + """ + Prints the received data in hexadecimal format. + + Args: + data (bytes): Data to be printed. + """ for byte in data: - print(f"{byte:02x}", end="") + print(f'{byte:02x}', end='') print() def data_available(self) -> bool: + """ + Checks if data is available on the serial port. + + Returns: + bool: `True` if data is available, otherwise `False`. + """ return self.serial.in_waiting > 0 def close(self) -> None: + """ + Closes the serial connection. + """ self.serial.close() - def send_command(self, opcode: int, immediate: int) -> None: + def _send_command(self, opcode: int, immediate: int) -> None: + """ + Sends a command to the processor. + + Args: + opcode (int): Operation code. + immediate (int): Immediate value to send with the command. + """ opcode = opcode & 0xFF immediate = immediate << 8 - data = opcode | immediate - data = data.to_bytes(4, "big") - self.send_data(data) + data = data.to_bytes(4, 'big') + self._send_data(data) def send_rawdata(self, data: int) -> None: - data = data.to_bytes(4, "big") - self.send_data(data) + """ + Sends raw data to the processor. + + Args: + data (int): Data to be sent. + """ + data = data.to_bytes(4, 'big') + self._send_data(data) def send_clk_pulses(self, n: int) -> None: - self.send_command(0x43, n) + """ + Sends a specific number of clock pulses to the processor. + + Args: + n (int): Number of clock pulses to send. + """ + self._send_command(0x43, n) def stop_clk(self) -> None: - self.send_command(0x53, 0) + """ + Stops the processor clock. + """ + self._send_command(0x53, 0) def resume_clk(self) -> None: - self.send_command(0x72, 0) + """ + Resumes the processor clock. + """ + self._send_command(0x72, 0) def reset_core(self) -> None: - self.send_command(0x52, 0) + """ + Resets the processor core. + """ + self._send_command(0x52, 0) def write_memory( self, address: int, value: int, second_memory: bool = False ) -> None: + """ + Writes a value to the processor's memory. + + Args: + address (int): Memory address. + value (int): Value to write. + second_memory (bool): Whether to access the second memory block. + """ address = address >> 2 if second_memory: address = address | 0x80000000 - self.send_command(0x57, address) + self._send_command(0x57, address) self.send_rawdata(value) def read_memory(self, address: int, second_memory: bool = False) -> int: + """ + Reads a value from the processor's memory. + + Args: + address (int): Memory address. + second_memory (bool): Whether to access the second memory block. + + Returns: + int: Value read from memory. + """ address = address >> 2 if second_memory: address = address | 0x80000000 - self.send_command(0x4C, address) - return self.read_data() + self._send_command(0x4C, address) + data = self.read_data() + return int.from_bytes(data, 'big') def load_msb_accumulator(self, value: int) -> None: - self.send_command(0x55, value) + """ + Loads the most significant byte (MSB) into the accumulator. + + Args: + value (int): Value to load into the MSB of the accumulator. + """ + self._send_command(0x55, value) def load_lsb_accumulator(self, value: int) -> None: - self.send_command(0x6C, value & 0xFF) + """ + Loads the least significant byte (LSB) into the accumulator. + + Args: + value (int): Value to load into the LSB of the accumulator. + """ + self._send_command(0x6C, value & 0xFF) def add_to_accumulator(self, value: int) -> None: - self.send_command(0x41, value) + """ + Adds a value to the current accumulator value. + + Args: + value (int): Value to add to the accumulator. + """ + self._send_command(0x41, value) def write_accumulator_to_memory(self, address: int) -> None: - self.send_command(0x77, address) + """ + Writes the accumulator value to a specific memory address. + + Args: + address (int): Memory address where the accumulator value will be written. + """ + self._send_command(0x77, address) def write_to_accumulator(self, value: int) -> None: - self.send_command(0x73, value) + """ + Writes a value directly into the accumulator. + + Args: + value (int): Value to write into the accumulator. + """ + self._send_command(0x73, value) def read_accumulator(self) -> int: - self.send_command(0x72, 0) + """ + Reads the current value stored in the accumulator. + + Returns: + int: Value of the accumulator. + """ + self._send_command(0x72, 0) return self.read_data() def set_timeout(self, timeout: int) -> None: - self.send_command(0x54, timeout) + """ + Sets the timeout duration for processor operations. + + Args: + timeout (int): Timeout value in seconds. + """ + self._send_command(0x54, timeout) def set_memory_page_size(self, size: int) -> None: - self.send_command(0x50, size) + """ + Configures the memory page size for the processor. + + Args: + size (int): Size of the memory page in bytes. + """ + self._send_command(0x50, size) def run_memory_tests( - self, number_of_pages: int, breakpoint: int = -1, timeout: int = -1 + self, + number_of_pages: int = 16, + stop_address: int = -1, + timeout: int = -1, ) -> bytes: - if breakpoint != -1: - self.set_execution_end_address(breakpoint) + """ + Runs memory tests on the processor. + + Args: + number_of_pages (int): Number of memory pages to test. + stop_address (int, optional): Address at which execution should stop. Defaults to -1 + (no specific stop address). + timeout (int, optional): Timeout duration for the test. Defaults to -1 (no timeout). + + Returns: + bytes: Data received as a result of the memory test. + """ + if stop_address != -1: + self.set_execution_end_address(stop_address) if timeout != -1: self.set_timeout(timeout) - self.send_command(0x45, number_of_pages) + self._send_command(0x45, number_of_pages) while not self.data_available(): time.sleep(0.1) @@ -109,22 +269,53 @@ def run_memory_tests( return self.read_data() def get_module_id(self) -> int: - self.send_command(0x70, 0) + """ + Retrieves the module ID of the connected processor. + + Returns: + int: Module ID as received from the processor. + """ + self._send_command(0x70, 0) return self.read_data() def set_execution_end_address(self, address: int) -> None: - self.send_command(0x44, address) + """ + Sets the end address for execution operations. - def set_accumulator_as_end_address(self): - self.send_command(0x64, 0) + Args: + address (int): Address at which execution should stop. + """ + self._send_command(0x44, address) + + def set_accumulator_as_end_address(self) -> None: + """ + Sets the current accumulator value as the execution end address. + """ + self._send_command(0x64, 0) def write_from_accumulator(self, n: int, data: list[int]) -> None: - self.send_command(0x65, n) + """ + Writes multiple values from the accumulator to memory. + + Args: + n (int): Number of values to write. + data (list[int]): List of data values to write to memory. + """ + self._send_command(0x65, n) for i in range(n): self.send_rawdata(data[i]) def read_from_accumulator(self, n: int) -> list[int]: - self.send_command(0x62, n) + """ + Reads multiple values from memory into the accumulator. + + Args: + n (int): Number of values to read. + + Returns: + list[int]: List of data values read from memory. + """ + self._send_command(0x62, n) data = [] for _ in range(n): data_line = self.read_data() @@ -133,19 +324,42 @@ def read_from_accumulator(self, n: int) -> list[int]: return data def get_accumulator_value(self) -> int: - self.send_command(0x61, 0) + """ + Retrieves the current value stored in the accumulator. + + Returns: + int: Value of the accumulator. + """ + self._send_command(0x61, 0) return self.read_data() def change_memory_access_priority(self) -> None: - self.send_command(0x4F, 0) + """ + Changes the priority of memory access operations. + """ + self._send_command(0x4F, 0) - def execute_until_stop(self, breakpoint: int = -1, timeout: int = -1) -> bytes: - if breakpoint != -1: - self.set_execution_end_address(breakpoint) - if timeout != -1: - self.set_timeout(timeout) + def execute_until_stop( + self, stop_address: int = -1, exec_timeout: int = -1 + ) -> bytes: + """ + Executes the processor until it stops, with optional stop address and timeout. + + Args: + stop_address (int): Optional stop address for execution. + exec_timeout (int): Optional timeout for execution. - self.send_command(0x75, 0) + Returns: + bytes: Data received after execution. + """ + if stop_address != -1: + self.set_execution_end_address( + stop_address + ) # Garantia de que o método existe + if exec_timeout != -1: + self.set_timeout(exec_timeout) # Garantia de que o método existe + + self._send_command(0x75, 0) while not self.data_available(): time.sleep(0.1) @@ -153,9 +367,15 @@ def execute_until_stop(self, breakpoint: int = -1, timeout: int = -1) -> bytes: return self.read_data(8) def sync(self) -> bytes: - self.send_data(0x70) + """ + Synchronizes the interface with the processor. + + Returns: + bytes: Response data after synchronization. + """ + self._send_data(b'\x70') if not self.data_available(): - self.send_data(0x70) + self._send_data(b'\x70') return self.read_data(4) diff --git a/core/shell.py b/core/shell.py index 409fbcb..e1465e8 100644 --- a/core/shell.py +++ b/core/shell.py @@ -1,161 +1,315 @@ +""" +Shell interface for interacting with the ProcessorCIInterface. + +This module provides an interactive command-line interface (CLI) that allows users to +send various commands to a processor for controlling its clock, memory, accumulator, +and other operations. The shell is built using the `cmd` module and integrates +directly with the ProcessorCIInterface class to communicate with the processor. + +Commands include: + - Clock control (start, stop, resume) + - Memory read and write operations + - Accumulator manipulation + - Execution control (e.g., setting breakpoints, running memory tests) +""" + + import cmd from core.serial import ProcessorCIInterface from core.file import read_file class ProcessorCIInterfaceShell(cmd.Cmd, ProcessorCIInterface): - prompt = "ProcessorCIInterface> " + """ + Shell interface for interacting with the processor via serial commands. + + This class provides an interactive shell that allows sending commands to the processor, + such as clock control, memory read and write, accumulator manipulation, and more. + """ def __init__(self, port: str, baudrate: int, timeout: int = 1) -> None: + """ + Initializes the communication interface with the processor and the interactive shell. + + Args: + port (str): Serial port for communication with the processor. + baudrate (int): Data transmission rate. + timeout (int): Timeout duration for read operations (in seconds). + """ ProcessorCIInterface.__init__(self, port, baudrate, timeout) cmd.Cmd.__init__(self) - def do_exit(self, arg): + def do_exit(self, _): + """ + Exits the interactive shell. + + Args: + _: Unused argument. + """ return True def do_write_clk(self, arg): + """ + Sends clock pulses to the processor. + + Args: + arg (str): Number of clock pulses to send. + """ self.send_clk_pulses(int(arg)) def do_stop_clk(self, _): + """ + Stops the processor's clock. + """ self.stop_clk() def do_resume_clk(self, _): + """ + Resumes the processor's clock. + """ self.resume_clk() def do_reset_core(self, _): + """ + Resets the processor's core. + """ self.reset_core() def do_write_memory(self, arg): + """ + Writes a value to the processor's memory. + + Args: + arg (str): Address and value to write to memory (in hexadecimal). + """ arg = arg.split() address, value = arg[0], arg[1] second_memory = False if len(arg) > 2: second_memory = bool(int(arg[1])) - self.write_memory(int(address, 16), int(value, 16), second_memory) def do_read_memory(self, arg): + """ + Reads a value from the processor's memory. + + Args: + arg (str): Memory address to read from (in hexadecimal). + """ arg = arg.split() second_memory = False address = int(arg[0], 16) if len(arg) > 1: second_memory = bool(int(arg[1])) - self.print_data(self.read_memory(address, second_memory)) def do_load_msb_accumulator(self, arg): + """ + Loads the Most Significant Byte (MSB) into the accumulator. + + Args: + arg (str): Value to load into the MSB (in hexadecimal). + """ self.load_msb_accumulator(int(arg, 16)) def do_load_lsb_accumulator(self, arg): + """ + Loads the Least Significant Byte (LSB) into the accumulator. + + Args: + arg (str): Value to load into the LSB (in hexadecimal). + """ self.load_lsb_accumulator(int(arg, 16)) def do_add_to_accumulator(self, arg): + """ + Adds a value to the accumulator. + + Args: + arg (str): Value to add to the accumulator (in hexadecimal). + """ self.add_to_accumulator(int(arg, 16)) def do_write_accumulator_to_memory(self, arg): + """ + Writes the accumulator's value to memory. + + Args: + arg (str): Memory address where the accumulator will be written (in hexadecimal). + """ self.write_accumulator_to_memory(int(arg, 16)) def do_write_to_accumulator(self, arg): - self.write_to_accumulator(int(arg, 16)) + """ + Directly writes a value to the accumulator. - def do_read_accumulator(self, _): - self.print_data(self.read_accumulator()) + Args: + arg (str): Value to write to the accumulator (in hexadecimal). + """ + self.write_to_accumulator(int(arg, 16)) def do_set_timeout(self, arg): + """ + Sets the timeout duration for operations. + + Args: + arg (str): Timeout duration in seconds. + """ self.set_timeout(int(arg)) def do_set_memory_page_size(self, arg): + """ + Sets the size of memory pages. + + Args: + arg (str): Memory page size. + """ self.set_memory_page_size(int(arg)) - def do_run_memory_tests(self, _): - self.run_memory_tests() + def do_run_memory_tests(self, arg): + """ + Runs memory tests. + + Args: + arg (str): Number of pages to test. + """ + self.run_memory_tests(number_of_pages=int(arg)) def do_get_module_id(self, _): + """ + Retrieves the processor's module ID. + """ self.print_data(self.get_module_id()) def do_set_breakpoint(self, arg): + """ + Sets a breakpoint at the specified address. + + Args: + arg (str): Address of the breakpoint (in hexadecimal). + """ self.set_execution_end_address(int(arg, 16)) - def do_set_accumulator_as_breakpoint(self, arg): + def do_set_accumulator_as_breakpoint(self, _): + """ + Sets the accumulator as the breakpoint. + """ self.set_accumulator_as_end_address() def do_write_from_accumulator(self, arg): - data = [] + """ + Writes data from the accumulator to memory. + Args: + arg (str): Number of bytes to write from the accumulator. + """ + data = [] for _ in range(int(arg)): data.append(int(input(), 16)) - self.write_from_accumulator(int(arg), data) - def do_read_to_accumulator(self, arg): - data = self.read_to_accumulator(int(arg)) - - for byte in data: - self.print_data(byte) - def do_read_accumulator(self): + """ + Reads the current value of the accumulator. + """ self.print_data(self.get_accumulator_value()) def do_swap_memory_to_core(self): + """ + Swaps the memory access priority with the core. + """ self.change_memory_access_priority() def do_until(self, _): + """ + Executes the processor until the stop condition is met. + """ self.execute_until_stop() def do_sync(self, _): + """ + Synchronizes the interface with the processor. + """ self.print_data(self.sync()) def do_write_file_in_memory(self, arg): - arg = arg.split() + """ + Writes the contents of a file directly to the processor's memory. + Args: + arg (str): Filename to load into memory. + """ + arg = arg.split() if len(arg) > 1: self.add_to_accumulator(int(arg[1], 16)) data, size = read_file(arg[0]) - self.write_from_accumulator(size, data) def do_help(self, arg): + """ + Displays help for available commands in the shell. + + Args: + arg (str): Specific command to get help for. If not provided, + lists all available commands. + """ if arg: try: - func = getattr(self, "do_" + arg) + func = getattr(self, 'do_' + arg) print( - func.__doc__ if func.__doc__ else f"Sem ajuda disponível para {arg}" + func.__doc__ + if func.__doc__ + else f'No help available for {arg}' ) except AttributeError: - print(f"Comando {arg} não encontrado.") + print(f'Command {arg} not found.') else: - print("Comandos disponíveis:") - print("exit - Sai do shell.") - print("write_clk - Envia n pulsos de clock.") - print("stop_clk - Para o clock.") - print("resume_clk - Retoma o clock.") - print("reset_core - Reseta o núcleo.") + print('Available commands:') + print('exit - Exits the shell.') + print('write_clk - Sends n clock pulses.') + print('stop_clk - Stops the clock.') + print('resume_clk - Resumes the clock.') + print('reset_core - Resets the core.') + print( + 'write_memory
- Writes to memory at the given address.' + ) + print( + 'read_memory
- Reads from memory at the given address.' + ) + print( + 'load_msb_accumulator - Loads MSB into the accumulator.' + ) + print( + 'load_lsb_accumulator - Loads LSB into the accumulator.' + ) + print( + 'add_to_accumulator - Adds a value to the accumulator.' + ) + print( + 'write_accumulator_to_memory
- Writes the accumulator to memory.' + ) + print( + 'write_to_accumulator - Writes directly to the accumulator.' + ) + print('read_accumulator - Reads the value of the accumulator.') + print('set_timeout - Sets the timeout duration.') + print('set_memory_page_size - Sets the memory page size.') + print('run_memory_tests - Runs memory tests.') + print('get_module_id - Gets the module ID.') print( - "write_memory - Escreve na memória no endereço fornecido." + 'set_breakpoint
- Sets a breakpoint at the address.' ) - print("read_memory - Lê a memória no endereço fornecido.") - print("load_msb_accumulator - Carrega o MSB no acumulador.") - print("load_lsb_accumulator - Carrega o LSB no acumulador.") - print("add_to_accumulator - Adiciona um valor ao acumulador.") print( - "write_accumulator_to_memory - Escreve o acumulador na memória." + 'set_accumulator_as_breakpoint - Sets the accumulator as a breakpoint.' ) - print("write_to_accumulator - Escreve diretamente no acumulador.") - print("read_accumulator - Lê o valor do acumulador.") - print("set_timeout - Define o tempo limite.") print( - "set_memory_page_size - Define o tamanho da página de memória." + 'write_from_accumulator - Writes n bytes from the accumulator.' ) - print("run_memory_tests - Executa testes de memória.") - print("get_module_id - Obtém o ID do módulo.") - print("set_breakpoint - Define um breakpoint no endereço.") print( - "set_accumulator_as_breakpoint - Define o acumulador como breakpoint." + 'read_to_accumulator - Reads n bytes into the accumulator.' ) print( - "write_from_accumulator - Escreve n bytes a partir do acumulador." + 'swap_memory_to_core - Swaps memory access priority with the core.' ) - print("read_to_accumulator - Lê n bytes no acumulador.") - print("swap_memory_to_core - Troca a prioridade de acesso à memória.") - print("until - Executa até a condição de parada.") + print('until - Executes until the stop condition is met.') diff --git a/main.py b/main.py index 87f6a85..1e61b7c 100644 --- a/main.py +++ b/main.py @@ -1,47 +1,71 @@ -import os +""" +This module handles the setup and execution of the communication interface with the controller. + +It parses command-line arguments to configure communication parameters (port, baudrate, timeout) and +optionally starts an interactive shell for communication with the controller. +Additionally, it supports loading test programs and directories containing test +programs onto the controller. + +Functions: + main() -- Parses command-line arguments and starts the controller shell if specified. +""" + import argparse from core.shell import ProcessorCIInterfaceShell -from core.serial import ProcessorCIInterface def main(): + """Main function that parses command-line arguments and starts a shell for + communication with the controller. + + This function processes various command-line arguments to: + - Set communication parameters such as port, baudrate, and timeout. + - Optionally start a shell session for interacting with the controller. + """ parser = argparse.ArgumentParser() parser.add_argument( - "-p", "--port", help="Porta de comunicação com o controlador", required=True + '-p', + '--port', + help='Port for communication with the controller', + required=True, ) parser.add_argument( - "-b", - "--baudrate", - help="Velocidade de comunicação com o controlador", + '-b', + '--baudrate', + help='Baud rate for communication with the controller', default=115200, ) parser.add_argument( - "-t", - "--timeout", - help="Tempo de espera para a comunicação com o controlador", + '-t', + '--timeout', + help='Timeout for communication with the controller', default=1, ) parser.add_argument( - "-T", "--test_program", help="Programa de teste a ser carregado no controlador" + '-T', + '--test_program', + help='Test program to be loaded onto the controller', ) parser.add_argument( - "-d", - "--test_directory", - help="Diretório com os programas de teste a serem carregados no controlador", + '-d', + '--test_directory', + help='Directory containing test programs to be loaded onto the controller', ) parser.add_argument( - "-s", - "--shell", - help="Inicia um shell de comunicação com o controlador", - action="store_true", + '-s', + '--shell', + help='Starts a shell for communication with the controller', + action='store_true', ) args = parser.parse_args() if args.shell: - shell = ProcessorCIInterfaceShell(args.port, args.baudrate, args.timeout) + shell = ProcessorCIInterfaceShell( + args.port, args.baudrate, args.timeout + ) shell.cmdloop() -if __name__ == "__main__": +if __name__ == '__main__': main() diff --git a/requirements.txt b/requirements.txt index 1ba25d9..652113b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ pathspec==0.12.1 platformdirs==4.3.6 pyserial==3.5 unittest-xml-reporting==3.2.0 +xmlrunner \ No newline at end of file diff --git a/run_tests.py b/run_tests.py index bde9e44..211c919 100644 --- a/run_tests.py +++ b/run_tests.py @@ -1,27 +1,33 @@ +""" +This script discovers and runs all unit tests in the specified directory, +then generates XML reports for each test case. The results are saved in the +'./test-reports' directory with a unique filename based on the test case and timestamp. +""" + import os import time import unittest import xmlrunner -if __name__ == "__main__": - # Diretório onde os testes estão localizados - test_dir = "/eda/processor-ci-communication/tests" +if __name__ == '__main__': + # Directory where the tests are located + TEST_DIR = '/eda/processor-ci-communication/tests' - # Descobrir todos os testes dentro do diretório - test_suites = unittest.defaultTestLoader.discover(test_dir, pattern="*.py") + # Discover all test files within the directory + test_suites = unittest.defaultTestLoader.discover(TEST_DIR, pattern='*.py') - # Criar a pasta para os relatórios XML, se não existir - os.makedirs("test-reports", exist_ok=True) + # Create the test reports directory if it does not exist + os.makedirs('test-reports', exist_ok=True) - # Iterar sobre cada arquivo de teste + # Iterate over each test suite for test_suite in test_suites: - # Para cada suite de teste, percorra os casos de teste + # For each suite of tests, iterate over the test cases for test_case in test_suite: - # Gera um nome de arquivo único com base no nome da suite e no timestamp + # Generate a unique file name based on the test case name and timestamp test_case_name = test_case.__class__.__name__ - timestamp = str(int(time.time())) - report_file = f"test-reports/results_{test_case_name}_{timestamp}.xml" + TIMESTAMP = str(int(time.time())) + REPORT_FILE = f'test-reports/results_{test_case_name}_{TIMESTAMP}.xml' - # Executar os testes e salvar os resultados em arquivos separados - with open(report_file, "w") as output: + # Run the tests and save the results in separate files + with open(REPORT_FILE, 'w', encoding='utf-8') as output: xmlrunner.XMLTestRunner(output=output).run(test_case) diff --git a/setup.py b/setup.py index cdbf314..9bdf9c4 100644 --- a/setup.py +++ b/setup.py @@ -1,24 +1,43 @@ +""" +This is the setup configuration for the Processor CI Communication package. + +It defines the package metadata, dependencies, and includes files required for +the package installation. + +The setup uses setuptools to configure the package for distribution and installation. + +Dependencies: + - A requirements.txt file should be present for external dependencies. +""" + from setuptools import setup, find_packages +# Read the contents of README.md and requirements.txt with specified encoding +with open('README.md', 'r', encoding='utf-8') as readme_file: + long_description = readme_file.read() + +with open('requirements.txt', 'r', encoding='utf-8') as req_file: + install_requires = req_file.read().splitlines() + setup( - name="processor_ci_communication", # Nome do pacote - version="0.1.0", # Versão inicial - description="Processor CI Communication Interface", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - author="Julio Avelar", - author_email="julio.avelar@students.ic.unicamp.br", - url="https://github.com/LSC-Unicamp/LSC-Unicamp/processor_ci_communication", # Repositório + name='processor_ci_communication', # Package name + version='0.1.0', # Initial version + description='Processor CI Communication Interface', + long_description=long_description, + long_description_content_type='text/markdown', + author='Julio Avelar', + author_email='julio.avelar@students.ic.unicamp.br', + url='https://github.com/LSC-Unicamp/LSC-Unicamp/processor_ci_communication', # Repository URL packages=find_packages(), classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: POSIX :: Linux", + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: POSIX :: Linux', ], package_data={ - "core": ["*.py"], # Inclua todos os arquivos .py no pacote 'core' + 'core': ['*.py'], # Include all .py files in the 'core' package }, python_requires='>=3.8', include_package_data=True, - install_requires=open("requirements.txt").read().splitlines(), + install_requires=install_requires, ) diff --git a/tests/test_00.py b/tests/test_00.py index 7531da9..9affaa7 100644 --- a/tests/test_00.py +++ b/tests/test_00.py @@ -7,118 +7,148 @@ class TestTypeIBasic(unittest.TestCase): def setUp(self): - self.port = os.getenv("PORT", "/dev/ttyACM0") + self.port = os.getenv('PORT', '/dev/ttyACM0') self.controller = ProcessorCIInterface(self.port, 115200, 1) id = self.controller.get_module_id() self.controller.set_timeout(200) self.controller.set_execution_end_address(60) def test_addi(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/000-addi.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/000-addi.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 5) + self.assertEqual(int.from_bytes(retorno, 'big'), 5) def test_andi(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/014-andi.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/014-andi.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 1) + self.assertEqual(int.from_bytes(retorno, 'big'), 1) def test_ori(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/015-ori.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/015-ori.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 7) + self.assertEqual(int.from_bytes(retorno, 'big'), 7) def test_xori(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/016-xori.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/016-xori.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 6) + self.assertEqual(int.from_bytes(retorno, 'big'), 6) def test_slti(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/012-slti.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/012-slti.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0) + self.assertEqual(int.from_bytes(retorno, 'big'), 0) def test_slti_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/018-slti.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/018-slti.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 1) + self.assertEqual(int.from_bytes(retorno, 'big'), 1) def test_sltiu(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/019-sltiu.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/019-sltiu.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 1) + self.assertEqual(int.from_bytes(retorno, 'big'), 1) def test_slli(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/011-slli.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/011-slli.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 8) + self.assertEqual(int.from_bytes(retorno, 'big'), 8) def test_slli_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/017-slli.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/017-slli.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x10) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x10) def test_srli(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/013-srli.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/013-srli.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 2) + self.assertEqual(int.from_bytes(retorno, 'big'), 2) def test_lw(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/022-lw.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/022-lw.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x809) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x809) def test_lh(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/023-lh.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/023-lh.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0xFFC0) + self.assertEqual(int.from_bytes(retorno, 'big'), 0xFFC0) def test_lb(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/024-lb.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/024-lb.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0xFF) + self.assertEqual(int.from_bytes(retorno, 'big'), 0xFF) def test_jalr(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/042-jalr.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/042-jalr.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 7) + self.assertEqual(int.from_bytes(retorno, 'big'), 7) def test_jalr_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/043-jalr.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/043-jalr.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 7) + self.assertEqual(int.from_bytes(retorno, 'big'), 7) -if __name__ == "__main__": - with open("test-reports/results_type_i_basic.xml", "w") as output: +if __name__ == '__main__': + with open('test-reports/results_type_i_basic.xml', 'w') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) diff --git a/tests/test_01.py b/tests/test_01.py index eac6f85..6b3b3de 100644 --- a/tests/test_01.py +++ b/tests/test_01.py @@ -7,83 +7,103 @@ class TestTypeRBasic(unittest.TestCase): def setUp(self): - self.port = os.getenv("PORT", "/dev/ttyACM0") + self.port = os.getenv('PORT', '/dev/ttyACM0') self.controller = ProcessorCIInterface(self.port, 115200, 1) id = self.controller.get_module_id() self.controller.set_timeout(200) self.controller.set_execution_end_address(60) def test_add(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/001-add.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/001-add.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_sub(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/002-sub.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/002-sub.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_and(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/003-and.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/003-and.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 1) + self.assertEqual(int.from_bytes(retorno, 'big'), 1) def test_or(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/004-or.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/004-or.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 7) + self.assertEqual(int.from_bytes(retorno, 'big'), 7) def test_xor(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/005-xor.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/005-xor.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 6) + self.assertEqual(int.from_bytes(retorno, 'big'), 6) def test_slt(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/007-slt.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/007-slt.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0) + self.assertEqual(int.from_bytes(retorno, 'big'), 0) def test_sltu(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/008-sltu.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/008-sltu.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0) + self.assertEqual(int.from_bytes(retorno, 'big'), 0) def test_sll(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/006-sll.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/006-sll.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 8) + self.assertEqual(int.from_bytes(retorno, 'big'), 8) def test_srl(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/009-srl.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/009-srl.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 2) + self.assertEqual(int.from_bytes(retorno, 'big'), 2) def test_sra(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/010-sra.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/010-sra.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 2) + self.assertEqual(int.from_bytes(retorno, 'big'), 2) -if __name__ == "__main__": - with open("test-reports/results_type_r_basic.xml", "w") as output: +if __name__ == '__main__': + with open('test-reports/results_type_r_basic.xml', 'w') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) diff --git a/tests/test_02.py b/tests/test_02.py index 02f3aff..c962f5d 100644 --- a/tests/test_02.py +++ b/tests/test_02.py @@ -7,34 +7,40 @@ class TestTypeRBasic(unittest.TestCase): def setUp(self): - self.port = os.getenv("PORT", "/dev/ttyACM0") + self.port = os.getenv('PORT', '/dev/ttyACM0') self.controller = ProcessorCIInterface(self.port, 115200, 1) id = self.controller.get_module_id() self.controller.set_timeout(200) self.controller.set_execution_end_address(60) def test_sw(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/025-sw.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/025-sw.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x1E) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x1E) def test_sh(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/026-sh.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/026-sh.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0xFFC0) + self.assertEqual(int.from_bytes(retorno, 'big'), 0xFFC0) def test_sb(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/027-sb.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/027-sb.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0xFE) + self.assertEqual(int.from_bytes(retorno, 'big'), 0xFE) -if __name__ == "__main__": - with open("test-reports/results_type_s_basic.xml", "w") as output: +if __name__ == '__main__': + with open('test-reports/results_type_s_basic.xml', 'w') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) diff --git a/tests/test_03.py b/tests/test_03.py index 9cefcbd..cd8da8f 100644 --- a/tests/test_03.py +++ b/tests/test_03.py @@ -7,97 +7,121 @@ class TestTypeRBasic(unittest.TestCase): def setUp(self): - self.port = os.getenv("PORT", "/dev/ttyACM0") + self.port = os.getenv('PORT', '/dev/ttyACM0') self.controller = ProcessorCIInterface(self.port, 115200, 1) id = self.controller.get_module_id() self.controller.set_timeout(200) self.controller.set_execution_end_address(60) def test_beq(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/028-beq.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/028-beq.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x11) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x11) def test_beq_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/029-beq.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/029-beq.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_bne(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/038-bne.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/038-bne.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x11) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x11) def test_bne_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/039-bne.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/039-bne.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_blt(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/034-blt.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/034-blt.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x11) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x11) def test_blt_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/035-blt.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/035-blt.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_bge(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/030-bge.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/030-bge.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x11) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x11) def test_bge_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/031-bge.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/031-bge.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_bltu(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/036-bltu.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/036-bltu.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x11) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x11) def test_bltu_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/037-bltu.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/037-bltu.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) def test_bgeu(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/032-bgeu.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/032-bgeu.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x11) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x11) def test_bgeu_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/033-bgeu.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/033-bgeu.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 10) + self.assertEqual(int.from_bytes(retorno, 'big'), 10) -if __name__ == "__main__": - with open("test-reports/results_type_b_basic.xml", "w") as output: +if __name__ == '__main__': + with open('test-reports/results_type_b_basic.xml', 'w') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) diff --git a/tests/test_04.py b/tests/test_04.py index 732e1df..811a2ec 100644 --- a/tests/test_04.py +++ b/tests/test_04.py @@ -7,27 +7,31 @@ class TestTypeRBasic(unittest.TestCase): def setUp(self): - self.port = os.getenv("PORT", "/dev/ttyACM0") + self.port = os.getenv('PORT', '/dev/ttyACM0') self.controller = ProcessorCIInterface(self.port, 115200, 1) id = self.controller.get_module_id() self.controller.set_timeout(200) self.controller.set_execution_end_address(60) def test_auipc(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/021-auipc.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/021-auipc.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x000DA004) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x000DA004) def test_lui(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/044-lui.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/044-lui.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0x0006D000) + self.assertEqual(int.from_bytes(retorno, 'big'), 0x0006D000) -if __name__ == "__main__": - with open("test-reports/results_type_u_basic.xml", "w") as output: +if __name__ == '__main__': + with open('test-reports/results_type_u_basic.xml', 'w') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) diff --git a/tests/test_05.py b/tests/test_05.py index 6dae00b..18146d1 100644 --- a/tests/test_05.py +++ b/tests/test_05.py @@ -7,27 +7,31 @@ class TestTypeRBasic(unittest.TestCase): def setUp(self): - self.port = os.getenv("PORT", "/dev/ttyACM0") + self.port = os.getenv('PORT', '/dev/ttyACM0') self.controller = ProcessorCIInterface(self.port, 115200, 1) id = self.controller.get_module_id() self.controller.set_timeout(200) self.controller.set_execution_end_address(60) def test_jal(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/040-jal.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/040-jal.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0xA) + self.assertEqual(int.from_bytes(retorno, 'big'), 0xA) def test_jal_2(self): - dados, size = read_file("/eda/processor-ci-tests/tests/memory/041-jal.hex") + dados, size = read_file( + '/eda/processor-ci-tests/tests/memory/041-jal.hex' + ) self.controller.write_from_accumulator(size, dados) self.controller.execute_until_stop() retorno = self.controller.read_memory(60) - self.assertEqual(int.from_bytes(retorno, "big"), 0xF) + self.assertEqual(int.from_bytes(retorno, 'big'), 0xF) -if __name__ == "__main__": - with open("test-reports/results_type_j_basic.xml", "w") as output: +if __name__ == '__main__': + with open('test-reports/results_type_j_basic.xml', 'w') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output))