Compare commits
5 Commits
386e2d20e4
...
836072cdfd
Author | SHA1 | Date |
---|---|---|
wgroeneveld | 836072cdfd | |
wgroeneveld | 459801389b | |
wgroeneveld | 54b95c438c | |
wgroeneveld | 1144a2a750 | |
wgroeneveld | 3031d576f5 |
51
README.md
51
README.md
|
@ -10,11 +10,35 @@ Example test case:
|
|||
from opbtest import OpbTestCase
|
||||
|
||||
class MyTestCase(OpbTestCase):
|
||||
def test_my_cool_procedure_should_set_some_register(self):
|
||||
assert_that = self.load_file("functions.psm4").testproc("my_cool_procedure").execute()
|
||||
def test_add_registers_counts_reg1_and_reg2_into_reg3(self):
|
||||
assert_that = self.load_file("functions.psm4")\
|
||||
.testproc("add_registers")\
|
||||
.setregs({"s0": 1, "s1": 2})\
|
||||
.execute()
|
||||
assert_that.reg("s5").contains(3)
|
||||
````
|
||||
|
||||
Given the following Assembly:
|
||||
|
||||
```
|
||||
jump main
|
||||
proc add_registers(s0 is one, s1 is two, s5 is result) {
|
||||
load result, 0
|
||||
loop1:
|
||||
add result, 1
|
||||
sub one, 1
|
||||
jump NZ, loop1
|
||||
loop2:
|
||||
add result, 1
|
||||
sub two, 1
|
||||
jump NZ, loop2
|
||||
}
|
||||
main:
|
||||
; this should not be executed
|
||||
load s5, 42
|
||||
load sD, FF
|
||||
```
|
||||
|
||||
That's it! Load your Assembly file, apply setup (mocks, inputs), and verify expectations.
|
||||
|
||||
opbtest relies on [opbasm and opbsim](https://kevinpt.github.io/opbasm) to compile and evaluate your code.
|
||||
|
@ -153,3 +177,26 @@ Before calling `execute()`, you can preload input port values using `mockinput()
|
|||
For instance, `.mockinput(0, 4)` will preload input port 0 with value 4. Psm statements like `input s0, 0` will load 4 into register s4.
|
||||
opbtest acutally replaces the statement with `load s0, 4`, so no actual input statements will be processed.
|
||||
|
||||
### Debugging Tests
|
||||
|
||||
Sometimes, a failing test does not clearly indicate the underlying problem. The Assembly source file is not the same source code as the code that is simulated to get to this result.
|
||||
For example, when mocking, parts are replaced, and when registers are setup, extra loads are done. If you want to take a look at the Assembly file to be compiled and interpreted, add the following to your `setUp` testcase:
|
||||
|
||||
```python
|
||||
def setUp(self):
|
||||
self.do_not_cleanup_files()
|
||||
```
|
||||
|
||||
This will leave the generated Assembly files in the test directory after test execution:
|
||||
|
||||
1. tmp_[timestamp].psm4
|
||||
2. tmp_[timestamp].gen.psm - PicoBlaze macro expanded instructionset
|
||||
3. tmp_[timestamp].fmt, .log metafiles
|
||||
4. tmp_[timestamp].mem - binary.
|
||||
|
||||
Run the assembler yourself:
|
||||
|
||||
1. compiling: `opbasm --6 -c file.psm4` (or `--3` for PicoBlaze 3)
|
||||
2. simulating: `opbsim -v -m:file.mem --pb6` (or `--pb3` for PicoBlaze 3)
|
||||
|
||||
For more information about the commandline flags, see the [Open PicoBlaze Assembler documentation](http://kevinpt.github.io/opbasm/).
|
1
setup.py
1
setup.py
|
@ -3,6 +3,7 @@ from setuptools import setup
|
|||
setup(name='opbtest',
|
||||
version='0.1',
|
||||
description='Open PicoBlaze Assembler Test package',
|
||||
long_description='See https://github.com/wgroeneveld/opbtest/blob/master/README.md',
|
||||
url='https://github.com/wgroeneveld/opbtest',
|
||||
author='Wouter Groeneveld',
|
||||
author_email='wouter.groeneveld@kuleuven.be',
|
||||
|
|
|
@ -19,6 +19,15 @@ func func1(s1 is val) : 1 {
|
|||
load val, 52
|
||||
}
|
||||
|
||||
proc func_with_brackets_in() {
|
||||
if(s0 == 0) {
|
||||
if(s1 == 0) {
|
||||
load s2, 2
|
||||
}
|
||||
}
|
||||
add s2, 1
|
||||
}
|
||||
|
||||
main:
|
||||
load s2, 11
|
||||
add s2, 1
|
||||
|
|
|
@ -21,6 +21,10 @@ class TestFunctions(OpbTestCase):
|
|||
except AssertionError:
|
||||
pass
|
||||
|
||||
def test_proc_with_brackets_in(self):
|
||||
assert_that = self.load_file("functions.psm4").testproc("func_with_brackets_in").execute()
|
||||
assert_that.regs(["s2"]).contains([3])
|
||||
|
||||
def test_proc_with_tab_statements_replaced_well(self):
|
||||
assert_that = self.load_file("functions.psm4").testproc("proc3").replace("add bla, 1", "add bla, 2").execute()
|
||||
assert_that.reg("s5").contains(2)
|
||||
|
|
Loading…
Reference in New Issue