Skip to content

Commit

Permalink
Seqgen use json instead of xml (#177)
Browse files Browse the repository at this point in the history
* 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
Lex-ari authored Jul 24, 2024
1 parent 2c95a45 commit bd9cd3d
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cls
CMake
cmdhist
cmds
cmp
CODEFILE
Codemirror
colorized
Expand Down Expand Up @@ -230,6 +231,7 @@ FFFF
fieldset
figcaption
figsize
filecmp
filemode
fileno
filepath
Expand Down
2 changes: 1 addition & 1 deletion src/fprime_gds/common/loaders/cmd_json_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class CmdJsonLoader(JsonLoader):
"""Class to load xml based command dictionaries"""
"""Class to load json based command dictionaries"""

COMMANDS_FIELD = "commands"

Expand Down
2 changes: 1 addition & 1 deletion src/fprime_gds/common/loaders/event_json_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class EventJsonLoader(JsonLoader):
"""Class to load xml based event dictionaries"""
"""Class to load json based event dictionaries"""

EVENTS_FIELD = "events"

Expand Down
8 changes: 4 additions & 4 deletions src/fprime_gds/common/tools/seqgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from fprime_gds.common.data_types import exceptions as gseExceptions
from fprime_gds.common.data_types.cmd_data import CmdData, CommandArgumentsException
from fprime_gds.common.encoders.seq_writer import SeqBinaryWriter
from fprime_gds.common.loaders.cmd_xml_loader import CmdXmlLoader
from fprime_gds.common.loaders.cmd_json_loader import CmdJsonLoader
from fprime_gds.common.parsers.seq_file_parser import SeqFileParser

__author__ = "Tim Canham"
Expand Down Expand Up @@ -56,9 +56,9 @@ def generateSequence(inputFile, outputFile, dictionary, timebase, cont=False):
raise SeqGenException(msg)

# Check the user environment:
cmd_xml_dict = CmdXmlLoader()
cmd_json_dict = CmdJsonLoader(dictionary)
try:
(cmd_id_dict, cmd_name_dict, versions) = cmd_xml_dict.construct_dicts(
(cmd_id_dict, cmd_name_dict, versions) = cmd_json_dict.construct_dicts(
dictionary
)
except gseExceptions.GseControllerUndefinedFileException:
Expand Down 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.FRIENDLY_GREETING "Hello!"
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
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()

0 comments on commit bd9cd3d

Please sign in to comment.