Skip to content

Commit

Permalink
Added serialization size test for override capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervdPerk-NXP committed Feb 23, 2021
1 parent 8e8b9ee commit d2c5008
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/nunavut/lang/c/templates/definitions.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static_assert({{ t | full_reference_name }}_EXTENT_BYTES_ >= {# -#}
{%- endif %}
#define {{ t | full_reference_name }}_{{ f.name }}_ARRAY_CAPACITY_ {{ f.data_type.capacity }}U
{%- if options.enable_override_variable_array_capacity and f.data_type is VariableLengthArrayType %}
#elif !defined(reg_drone_service_battery_Status_0_2_DISABLE_SERIALIZATION_BUFFER_CHECK)
# define reg_drone_service_battery_Status_0_2_DISABLE_SERIALIZATION_BUFFER_CHECK
#elif !defined({{ t | full_reference_name }}_DISABLE_SERIALIZATION_BUFFER_CHECK_)
# define {{ t | full_reference_name }}_DISABLE_SERIALIZATION_BUFFER_CHECK_
#endif
#if {{ t | full_reference_name }}_{{ f.name }}_ARRAY_CAPACITY_ > {{ f.data_type.capacity }}U
# error {{ t | full_reference_name }}_{{ f.name }}_ARRAY_CAPACITY_ > {{ f.data_type.capacity }}U
Expand Down
2 changes: 1 addition & 1 deletion src/nunavut/lang/c/templates/serialization.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{% macro _serialize_impl(t) %}
const {{ typename_unsigned_length }} capacity_bytes = *inout_buffer_size_bytes;
{%- if options.enable_override_variable_array_capacity %}
#ifndef reg_drone_service_battery_Status_0_2_DISABLE_SERIALIZATION_BUFFER_CHECK
#ifndef {{ t | full_reference_name }}_DISABLE_SERIALIZATION_BUFFER_CHECK_
{% endif %}
if ((8U * ({{ typename_unsigned_bit_length }}) capacity_bytes) < {{ t.inner_type.bit_length_set|max }}UL)
{
Expand Down
11 changes: 11 additions & 0 deletions verification/c/suite/test_override_variable_array_capacity.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
static void testPrimitiveArrayVariableOverride(void)
{
regulated_basics_PrimitiveArrayVariable_0_1 ref;
uint8_t buf[regulated_basics_PrimitiveArrayVariable_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_ - 1];

#if NUNAVUT_SUPPORT_LANGUAGE_OPTION_ENABLE_OVERRIDE_VARIABLE_ARRAY_CAPACITY == 1
TEST_ASSERT_EQUAL(sizeof(ref.a_u64.elements[0]) * OVERRIDE_SIZE, sizeof(ref.a_u64.elements));
Expand All @@ -29,6 +30,16 @@ static void testPrimitiveArrayVariableOverride(void)
regulated_basics_PrimitiveArrayVariable_0_1_n_f32_ARRAY_CAPACITY_,
sizeof(ref.n_f64.elements));
#endif

size_t size = sizeof(buf);

#if NUNAVUT_SUPPORT_LANGUAGE_OPTION_ENABLE_OVERRIDE_VARIABLE_ARRAY_CAPACITY == 1
TEST_ASSERT_EQUAL(NUNAVUT_SUCCESS,
regulated_basics_PrimitiveArrayVariable_0_1_serialize_(&ref, &buf[0], &size));
#else
TEST_ASSERT_EQUAL(-NUNAVUT_ERROR_SERIALIZATION_BUFFER_TOO_SMALL,
regulated_basics_PrimitiveArrayVariable_0_1_serialize_(&ref, &buf[0], &size));
#endif
}

void setUp(void)
Expand Down

0 comments on commit d2c5008

Please sign in to comment.