Skip to content

Commit

Permalink
File management and parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor-Lake committed Nov 21, 2024
1 parent 44d7d54 commit 46866df
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 26 deletions.
173 changes: 172 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,175 @@
*.out
*.app

build/
build/


env/
out.bit
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
processors/
*.fs
out/
*.bit
teste.py
temp/
arquivos.txt
25 changes: 22 additions & 3 deletions test_runner/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,28 @@ def read_file(name):

def read_files_in_dir(path):
try:
file = [read_file(file) for file in glob.glob(f"{path}/*.hex", recursive=True)]
file.append(path)
return file
if path.endswith("/memory"):
path = path[:-7] # Remove the '/memory' suffix
print("path: ", path)
files = []

file_test = []
for entry in os.scandir(f"{path}/memory"):
if entry.is_file() and entry.name.endswith(".hex"):
file_test.append(read_file(entry.path))

file_answer = []
for entry in os.scandir(f"{path}/reference"):
if entry.is_file() and entry.name.endswith(".hex"):
file_answer.append(read_file(entry.path))

print("Files in reference directory: ", [entry.path for entry in os.scandir(path) if entry.is_dir()])
print("teste: ", file_test)
print("resposta: ", file_answer)
files.append(file_test)
files.append(file_answer)
files.append(path)
return files
except FileNotFoundError:
print(f"Error: The directory '{path}' was not found.")
return []
Expand Down
4 changes: 0 additions & 4 deletions test_runner/testing_testes/hello1/not_memory/005-xor.hex

This file was deleted.

4 changes: 0 additions & 4 deletions test_runner/testing_testes/hello1/not_memory/006-sll.hex

This file was deleted.

9 changes: 9 additions & 0 deletions test_runner/testing_testes/hello1/program/000-addi.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.text

.global _start;

_start:
addi a1, zero, 5; # a1 = zero + 5

sw a1, 60(zero);

10 changes: 10 additions & 0 deletions test_runner/testing_testes/hello1/program/001-add.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.text

.global _start;

_start:
addi a1, zero, 5; # a1 = zero + 5
add a1, a1, a1;

sw a1, 60(zero);

1 change: 1 addition & 0 deletions test_runner/testing_testes/hello1/reference/000.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00000005
1 change: 1 addition & 0 deletions test_runner/testing_testes/hello1/reference/001.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000A
4 changes: 0 additions & 4 deletions test_runner/testing_testes/hello2/not_memory/007-slt.hex

This file was deleted.

4 changes: 0 additions & 4 deletions test_runner/testing_testes/hello2/not_memory/008-sltu.hex

This file was deleted.

13 changes: 13 additions & 0 deletions test_runner/testing_testes/hello2/program/002-sub.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.text

.global _start;

_start:
addi a1, zero, 15; # a1 = zero + 15

addi a2, zero, 5;

sub a3, a1, a2;

sw a3, 60(zero);

12 changes: 12 additions & 0 deletions test_runner/testing_testes/hello2/program/003-and.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.text

.global _start;

_start:
addi a1, zero, 5; # a1 = zero + 5
addi a2, zero, 3; # a2 = zero + 3

and a3, a1, a2;

sw a3, 60(zero);

1 change: 1 addition & 0 deletions test_runner/testing_testes/hello2/reference/002.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000A
1 change: 1 addition & 0 deletions test_runner/testing_testes/hello2/reference/003.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00000001
30 changes: 24 additions & 6 deletions test_runner/verificator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,47 @@

#test_extensão_tipo_timestamp.xml

# Adiciona o diretório raiz do projeto ao sys.path


import os
import sys
import file as f
import argparse


sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))


from processor_ci_communication.core.serial import ProcessorCIInterface


class Verificator:
def __init__(self, path):
def __init__(self, path, port, baudrate, timeout):
self.path = path
#self.interface = ProcessorCIInterface()
#self.interface.open()
self.interface = ProcessorCIInterface(port, baudrate, timeout)


def run_tests(self):
tests = []
paths = f.list_find_paths(self.path)
print(paths)
#print(paths)
for path in paths:
tests.append(f.read_files_in_dir(path))
print(tests)
#print(tests)



#default to test:
#python3 verificator.py -p /dev/ttyACM0 -b 115200 -t 2
def main():
verifier = Verificator("/eda/processor-ci-tests/test_runner/testing_testes")
parser = argparse.ArgumentParser()
parser.add_argument("--port", "-p", type=str, help="Porta de comunicação", required=True)
parser.add_argument("--baudrate", "-b", type=int, help="Baudrate de comunicação", required=True)
parser.add_argument("--timeout", "-t", type=int, help="Timeout de comunicação", required=True)
args = parser.parse_args()

verifier = Verificator("/home/victor/processor_ci/processor-ci-tests/test_runner/testing_testes", args.port, args.baudrate, args.timeout)
verifier.run_tests()
return 0

Expand Down

0 comments on commit 46866df

Please sign in to comment.