Skip to content

Commit

Permalink
Add seqgen test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Lex-ari committed Jul 17, 2024
1 parent f1c80ae commit fa21a12
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/fprime_gds/common/tools/seqgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def main():
action="store",
type=str,
required=True,
help="Dictionary file name",
help="JSON Dictionary file name",
)
parser.add_argument(
"-t",
Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions test/fprime_gds/common/tools/input/simple_bad_sequence.seq
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.FRNDLY_GRTNG "Hello!"

Check failure on line 9 in test/fprime_gds/common/tools/input/simple_bad_sequence.seq

View workflow job for this annotation

GitHub Actions / Spell checking

`GRTNG` is not a recognized word. (unrecognized-spelling)

Check failure on line 9 in test/fprime_gds/common/tools/input/simple_bad_sequence.seq

View workflow job for this annotation

GitHub Actions / Spell checking

`FRNDLY` is not a recognized word. (unrecognized-spelling)
8 changes: 8 additions & 0 deletions test/fprime_gds/common/tools/input/simple_sequence.seq
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 test/fprime_gds/common/tools/resources/simple_dictionary.json
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 test/fprime_gds/common/tools/resources/simple_dictionary.xml
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="&#10; The String command argument&#10; " len="40" type="string"/>
</args>
</command>
</commands>
</dictionary>
39 changes: 37 additions & 2 deletions test/fprime_gds/common/tools/seqgen_unit_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
import filecmp

Check failure on line 1 in test/fprime_gds/common/tools/seqgen_unit_test.py

View workflow job for this annotation

GitHub Actions / Spell checking

`filecmp` is not a recognized word. (unrecognized-spelling)
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.diff_input_sequence(
"./input/simple_sequence.seq",
"./expected/simple_sequence_expected.bin",
"./resources/simple_dictionary.json"
), True)

# This test is expected to fail due to unmatched command in
# simple_bad_sequence.seq and seqgen should produce a SeqGenException.
# Passing these executions is a test failure.
@unittest.expectedFailure
def test_fail_unmatched_command_sequence(self):
self.diff_input_sequence(
"./input/simple_bad_sequence.seq",
"./expected/simple_sequence_expected.bin",
"./resources/simple_dictionary.json"
)

def diff_input_sequence(self, input_sequence, expected_output, 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_output)

Check failure on line 36 in test/fprime_gds/common/tools/seqgen_unit_test.py

View workflow job for this annotation

GitHub Actions / Spell checking

`cmp` is not a recognized word. (unrecognized-spelling)

Check failure on line 36 in test/fprime_gds/common/tools/seqgen_unit_test.py

View workflow job for this annotation

GitHub Actions / Spell checking

`filecmp` is not a recognized word. (unrecognized-spelling)
temp_dir.cleanup()
return is_equal


if __name__ == "__main__":
unittest.main()

0 comments on commit fa21a12

Please sign in to comment.