-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seqgen use json instead of xml (#177)
* Swap xml with json for seqgen * Add seqgen test cases * Rename `diff_input_sequence` + Change Test Fail Format * Add Spellcheck expect * Make Test Independant of File Structure
- Loading branch information
Showing
10 changed files
with
114 additions
and
8 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
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
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
Binary file not shown.
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,9 @@ | ||
;-------------------------------------------------------------------- | ||
; Simple sequence file | ||
; Note: that anything after a ';' is a comment | ||
;-------------------------------------------------------------------- | ||
|
||
|
||
R00:00:00 cmdDisp.CMD_NO_OP | ||
R00:00:00 cmdDisp.CMD_NO_OP_STRING "Awesome string!" ; And a nice comment too | ||
R00:00:00 cmdDisp.FRIENDLY_GREETING "Hello!" |
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,8 @@ | ||
;-------------------------------------------------------------------- | ||
; Simple sequence file | ||
; Note: that anything after a ';' is a comment | ||
;-------------------------------------------------------------------- | ||
|
||
|
||
R00:00:00 cmdDisp.CMD_NO_OP | ||
R00:00:00 cmdDisp.CMD_NO_OP_STRING "Awesome string!" ; And a nice comment too |
40 changes: 40 additions & 0 deletions
40
test/fprime_gds/common/tools/resources/simple_dictionary.json
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,40 @@ | ||
{ | ||
"metadata" : { | ||
"deploymentName" : "test", | ||
"projectVersion" : "0", | ||
"frameworkVersion" : "0", | ||
"libraryVersions" : [ | ||
], | ||
"dictionarySpecVersion" : "1.0.0" | ||
}, | ||
"commands" : [ | ||
{ | ||
"name" : "cmdDisp.CMD_NO_OP_STRING", | ||
"commandKind" : "async", | ||
"opcode" : 4097, | ||
"formalParams" : [ | ||
{ | ||
"name" : "arg1", | ||
"type" : { | ||
"name" : "string", | ||
"kind" : "string", | ||
"size" : 40 | ||
}, | ||
"ref" : false, | ||
"annotation" : "The String command argument" | ||
} | ||
], | ||
"queueFullBehavior" : "assert", | ||
"annotation" : "No-op string command" | ||
}, | ||
{ | ||
"name" : "cmdDisp.CMD_NO_OP", | ||
"commandKind" : "async", | ||
"opcode" : 4096, | ||
"formalParams" : [ | ||
], | ||
"queueFullBehavior" : "assert", | ||
"annotation" : "No-op command" | ||
} | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
test/fprime_gds/common/tools/resources/simple_dictionary.xml
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,12 @@ | ||
<dictionary topology="test" framework_version="0" project_version="0"> | ||
<commands> | ||
<command component="cmdDisp" mnemonic="CMD_NO_OP" opcode="0x1000" description="No-op command"> | ||
<args/> | ||
</command> | ||
<command component="cmdDisp" mnemonic="CMD_NO_OP_STRING" opcode="0x1001" description="No-op string command"> | ||
<args> | ||
<arg name="arg1" description=" The String command argument " len="40" type="string"/> | ||
</args> | ||
</command> | ||
</commands> | ||
</dictionary> |
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 |
---|---|---|
@@ -1,7 +1,42 @@ | ||
import filecmp | ||
from pathlib import Path | ||
import tempfile | ||
import unittest | ||
|
||
import fprime_gds.common.tools.seqgen as seqgen | ||
|
||
class APITestCases(unittest.TestCase): | ||
def test_nominal_sequence(self): | ||
|
||
pass | ||
self.assertEqual(self.check_sequence_generates_expected_binary( | ||
Path(__file__).parent / "input" / "simple_sequence.seq", | ||
Path(__file__).parent / "expected" / "simple_expected.bin", | ||
Path(__file__).parent / "resources" / "simple_dictionary.json" | ||
), True) | ||
|
||
def test_fail_unmatched_command_sequence(self): | ||
with self.assertRaisesRegex(seqgen.SeqGenException, "does not match any command in the command dictionary."): | ||
self.check_sequence_generates_expected_binary( | ||
Path(__file__).parent / "input" / "simple_bad_sequence.seq", | ||
Path(__file__).parent / "expected" / "simple_expected.bin", | ||
Path(__file__).parent / "resources" / "simple_dictionary.json" | ||
) | ||
|
||
def check_sequence_generates_expected_binary(self, | ||
input_sequence, | ||
expected_binary, | ||
dictionary): | ||
temp_dir = tempfile.TemporaryDirectory() | ||
output_bin = Path(f"{temp_dir.name}/out_binary") | ||
seqgen.generateSequence( | ||
input_sequence, | ||
output_bin, | ||
dictionary, | ||
0xffff | ||
) | ||
is_equal = filecmp.cmp(output_bin, expected_binary) | ||
temp_dir.cleanup() | ||
return is_equal | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |