initial commit

This commit is contained in:
wgroeneveld 2018-11-27 16:41:46 +01:00
parent 5c215ac2f1
commit 174bb14124
5 changed files with 80 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.idea
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

6
opbtest/__init__.py Normal file
View File

@ -0,0 +1,6 @@
# use "import opbtest" and extend from OpbTestCase:
# from opbtest import OpbTestCase
# class TestMyStuff(OpbTestCase):
from .opbtestcase import OpbTestCase

48
opbtest/opbtestcase.py Normal file
View File

@ -0,0 +1,48 @@
from unittest import TestCase
import subprocess, os, time, json, glob
class OpbTestAssertions():
def __init__(self, json, case):
self.jsondata = json
self.case = case
self.register = None
def reg(self, register):
self.register = register
return self
def contains(self, expected):
if self.register is None:
self.case.fail("First call reg() to assert which register to check!")
self.case.assertReg(self.jsondata, "a", int(self.register[1], 16), expected)
class OpbTestCase(TestCase):
def tearDown(self):
for file in glob.glob('tmp_*'):
pass
os.remove(file)
def execute_psm(self, psm):
with open("tmp_" + str(time.time()) + ".psm4", "w") as file:
file.write(psm)
r = subprocess.call("opbasm -6 -c " + file.name, shell=True)
self.assertTrue(r == 0, "Opbasm compilation failed of source: " + psm)
try:
json_out = subprocess.check_output("opbsim -v -j -m:" + file.name.replace(".psm4", ".mem"), shell=True)
except subprocess.CalledProcessError as e:
self.fail("Opbsim simulation failed with: " + '\n>>> '.join(('\n' + str(e.output)).splitlines()).lstrip())
json_out = json.loads(json_out)
self.assertTrue(json_out['termination'] == 'termNormal', 'Simulation failed with ' + json_out['termination'])
return json_out
def assertPsm(self, jsondata):
return OpbTestAssertions(jsondata, self)
def assertReg(self, jsondata, bank, nr, expected):
self.assertEqual(expected, jsondata["regs_" + bank][nr])

11
setup.py Normal file
View File

@ -0,0 +1,11 @@
from setuptools import setup
setup(name='opbtest',
version='0.1',
description='Open PicoBlaze Assembler Test package',
url='https://github.com/wgroeneveld/opbtest',
author='Wouter Groeneveld',
author_email='wouter.groeneveld@kuleuven.be',
license='MIT',
packages=['opbtest'],
zip_safe=False)

13
test/basicasm.py Normal file
View File

@ -0,0 +1,13 @@
from opbtest import OpbTestCase
class TestBasicAsm(OpbTestCase):
def test_basic_register_loading(self):
psm = """load s0, 1
output sD, FF"""
result = self.execute_psm(psm)
self.assertPsm(result).reg("s0").contains(1)