Skip to content

Commit

Permalink
Add recording round trip test
Browse files Browse the repository at this point in the history
Replacing the hard-coded recording tests that faltered from the protocol
changes. This solution just generates messages and then does some round
trips with them, which caught a number of bugs already.
  • Loading branch information
askmeaboutlo0m committed Aug 7, 2023
1 parent 2ffa977 commit 97bf3f3
Show file tree
Hide file tree
Showing 7 changed files with 1,158 additions and 102 deletions.
19 changes: 19 additions & 0 deletions src/drawdance/generators/protogen/messages.h.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,24 @@ DP_Message *DP_message_parse_body(DP_MessageType type, unsigned int context_id,

#define {{ message.enum_name }}_STATIC_LENGTH {{ message.static_payload_length }}
{% for f in message.fields %}
{% if f.min != f.max %}

#define {{ message.enum_name }}_{{ f.func_name|upper }}_MIN_{{ f.array_size_name|upper }} {{ f.min }}
#define {{ message.enum_name }}_{{ f.func_name|upper }}_MAX_{{ f.array_size_name|upper }} {{ f.max }}
{% endif %}
{% if f.flags %}

{% for flag in f.flags %}
#define {{ flag.define_name }} 0x{{ '%.x'|format(flag.value) }}
{% endfor %}

#define DP_{{ message.func_name|upper }}_NUM_{{ f.func_name|upper }} {{ f.flags|length }}
#define DP_{{ message.func_name|upper }}_ALL_{{ f.func_name|upper }} \
{% for flag in f.flags %}
{{ flag.define_name }}{% if not loop.last %}, \{% endif %}

{% endfor %}

const char *DP_{{ message.func_name }}_{{ f.func_name }}_flag_name(unsigned int value);
{% endif %}
{% if f.variants %}
Expand All @@ -98,6 +110,13 @@ DP_Message *DP_message_parse_body(DP_MessageType type, unsigned int context_id,
#define {{ variant.define_name }} {{ variant.value }}
{% endfor %}

#define DP_{{ message.func_name|upper }}_NUM_{{ f.func_name|upper }} {{ f.variants|length }}
#define DP_{{ message.func_name|upper }}_ALL_{{ f.func_name|upper }} \
{% for variant in f.variants %}
{{ variant.define_name }}{% if not loop.last %}, \{% endif %}

{% endfor %}

const char *DP_{{ message.func_name }}_{{ f.func_name }}_variant_name(unsigned int value);
{% endif %}
{% endfor %}
Expand Down
8 changes: 8 additions & 0 deletions src/drawdance/generators/protogen/protogen_drawdance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,14 @@ def __init__(self, message, field):
else:
self.sub = None

divisor = self.deserialize_field_divisor
if divisor:
self.min = field.min_len // divisor
self.max = field.max_len // divisor
else:
self.min = field.min_len
self.max = field.max_len

def access(self, subject):
return self.type.access(self, subject)

Expand Down
6 changes: 5 additions & 1 deletion src/drawdance/libcommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ endif()

if(TESTS)
add_dptest_targets(common dptest
"test/base64.c;test/file.c;test/queue.c;test/rect.c;test/vector.c"
test/base64.c
test/file.c
test/queue.c
test/rect.c
test/vector.c
)
endif()
12 changes: 6 additions & 6 deletions src/drawdance/libmsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ dp_target_sources(dpmsg
)

target_include_directories(dpmsg PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(dpmsg PRIVATE dpcommon uthash parson)
target_link_libraries(dpmsg PUBLIC dpcommon uthash parson)

# if(BUILD_TESTS)
# add_dptest_targets(msg dptest
# test/read_write_roundtrip.c
# )
# endif()
if(TESTS)
add_dptest_targets(msg dptest
test/read_write_roundtrip.c
)
endif()
Loading

0 comments on commit 97bf3f3

Please sign in to comment.