-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test error inputs handling, fix few bugs (#119)
* Test error inputs handling * Add mask tests * Apply code review fix
- Loading branch information
1 parent
301686e
commit f9272e8
Showing
3 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Unit tests | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- name: Install PyYAML | ||
run: | | ||
pip3 install -r requirements.txt | ||
pip3 install coverage | ||
- name: Test error outputs | ||
run: coverage run -m unittest -b | ||
- name: Generate coverage | ||
run: coverage xml | ||
- name: Upload coverage | ||
uses: codecov/codecov-action@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from parse import * | ||
import logging | ||
import unittest | ||
|
||
class ConstantParseTest(unittest.TestCase): | ||
def test_constant(self): | ||
self.assertEqual(parse_constant('10'), 10) | ||
self.assertEqual(parse_constant('0xa'), 10) | ||
self.assertEqual(parse_constant('0xA'), 10) | ||
self.assertEqual(parse_constant('0b1010'), 10) | ||
|
||
class EncodingLineTest(unittest.TestCase): | ||
def setUp(self): | ||
logger = logging.getLogger() | ||
logger.disabled = True | ||
|
||
def assertError(self, string): | ||
self.assertRaises(SystemExit, process_enc_line, string, 'rv_i') | ||
|
||
def test_lui(self): | ||
name, data = process_enc_line('lui rd imm20 6..2=0x0D 1..0=3', 'rv_i') | ||
self.assertEqual(name, 'lui') | ||
self.assertEqual(data['extension'], ['rv_i']) | ||
self.assertEqual(data['match'], '0x37') | ||
self.assertEqual(data['mask'], '0x7f') | ||
|
||
def test_overlapping(self): | ||
self.assertError('jol rd jimm20 6..2=0x00 3..0=7') | ||
|
||
def test_invalid_order(self): | ||
self.assertError('jol 2..6=0x1b') | ||
|
||
def test_illegal_value(self): | ||
self.assertError('jol rd jimm20 2..0=10') | ||
self.assertError('jol rd jimm20 2..0=0xB') | ||
|
||
@unittest.skip('not implemented') | ||
def test_overlapping_field(self): | ||
self.assertError('jol rd rs1 jimm20 6..2=0x1b 1..0=3') | ||
|
||
def test_illegal_field(self): | ||
self.assertError('jol rd jimm128 2..0=10') |