Skip to content

Add basic unit tests for refactored functions in rcl_yaml_param_parser (coverage part 1/3)#771

Merged
brawner merged 6 commits intomasterfrom
brawner/rcl_yaml-basic-unit-tests
Sep 2, 2020
Merged

Add basic unit tests for refactored functions in rcl_yaml_param_parser (coverage part 1/3)#771
brawner merged 6 commits intomasterfrom
brawner/rcl_yaml-basic-unit-tests

Conversation

@brawner
Copy link
Copy Markdown
Contributor

@brawner brawner commented Aug 27, 2020

This is part 1 of added unit tests for increasing coverage of rcl_yaml_param_parser to 95%. This adds additional unit tests for the refactored source code. Depends on #754 and #765

Signed-off-by: Stephen Brawner brawner@gmail.com

@brawner brawner force-pushed the brawner/rcl_yaml-basic-unit-tests branch from cf14a57 to 56ba274 Compare August 27, 2020 21:58
@brawner brawner changed the title Add basic unit tests for refactored functions Add basic unit tests for refactored functions (coverage part 1/3) Aug 27, 2020
@brawner brawner changed the title Add basic unit tests for refactored functions (coverage part 1/3) Add basic unit tests for refactored functions in rcl_yaml_param_parser (coverage part 1/3) Aug 27, 2020
@brawner
Copy link
Copy Markdown
Contributor Author

brawner commented Aug 27, 2020

See #766 and #772 for parts 2 and 3 respectively.

@brawner brawner requested review from Blast545 and hidmic August 27, 2020 22:33
@brawner brawner self-assigned this Aug 27, 2020
Copy link
Copy Markdown
Contributor

@Blast545 Blast545 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions

@brawner
Copy link
Copy Markdown
Contributor Author

brawner commented Aug 28, 2020

Updated these files after running all the tests through valgrind. There were some memory errors with unitialized memory and a couple of leaks.

@brawner brawner force-pushed the brawner/rcl_yaml-basic-unit-tests branch from 5940d72 to 8b9dd40 Compare August 28, 2020 23:33
@brawner brawner changed the base branch from brawner/rcl_yaml-set-values-null to brawner/rcl_yaml-add_val_to_string-leak August 28, 2020 23:34
@brawner
Copy link
Copy Markdown
Contributor Author

brawner commented Aug 28, 2020

Also depends on #775

@brawner brawner force-pushed the brawner/rcl_yaml-add_val_to_string-leak branch from ac7cf6f to a9bab89 Compare August 29, 2020 00:46
@brawner brawner force-pushed the brawner/rcl_yaml-basic-unit-tests branch from 8b9dd40 to 422dd65 Compare August 29, 2020 00:50
Copy link
Copy Markdown
Contributor

@Blast545 Blast545 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending green CI

RCUTILS_RET_OK,
parse_value(event, is_seq, node_idx, parameter_idx, &seq_data_type, params_st)) <<
rcutils_get_error_string().str;
ASSERT_NE(nullptr, params_st->params[0].parameter_values[0].bool_value);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner nit^N: should it be

Suggested change
ASSERT_NE(nullptr, params_st->params[0].parameter_values[0].bool_value);
ASSERT_NE(nullptr, params_st->params[node_idx].parameter_values[parameter_idx].bool_value);

? Same elsewhere.

ASSERT_EQ(RCUTILS_RET_OK, node_params_init(&params_st->params[0], allocator));
params_st->num_nodes = 1u;

// event.data.scaler.value is NULL, but event.data.scalar.length > 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner nit^N:

Suggested change
// event.data.scaler.value is NULL, but event.data.scalar.length > 0
// event.data.scalar.value is NULL, but event.data.scalar.length > 0

parse_key(event, nullptr, &is_new_map, &node_idx, &parameter_idx, &ns_tracker, params_st)) <<
rcutils_get_error_string().str;
EXPECT_TRUE(rcutils_error_is_set());
rcutils_reset_error();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner duplicate?

ASSERT_NE(nullptr, dest_variant.field); \
EXPECT_EQ(*src_variant.field, *dest_variant.field); \
rcl_yaml_variant_fini(&dest_variant, allocator); \
variant.field = nullptr; \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner should it be

Suggested change
variant.field = nullptr; \
src_variant.field = nullptr; \

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned this macro up a bit. Initialization of src/dest_variants now happen inside this macro. Should help prevent stuff like this.

ASSERT_NE(nullptr, src_variant.field->values); \
src_variant.field->size = array_size; \
for (size_t i = 0; i < array_size; ++i) { \
variant.field->values[i] = tmp_array[i]; \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner should it be

Suggested change
variant.field->values[i] = tmp_array[i]; \
src_variant.field->values[i] = tmp_array[i]; \

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

rcl_yaml_variant_fini(&src_variant, allocator); \
rcl_yaml_variant_fini(&dest_variant, allocator); \
src_variant.field = nullptr; \
dest_variant.field = nullptr; \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner should this be in scoped exits in case asserts above fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted how everything was cleaned up and added a bunch more scope_exits (not just for these).

} while (0)

#define TEST_VARIANT_ARRAY_COPY( \
dest_variant, src_variant, field, array_type, value_type, tmp_array, array_size, allocator) \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner nit: I think you can derive array_size from tmp_array considering tmp_array type is always a primitive array and its type has not decayed yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} while (0)

TEST(TestYamlVariant, copy_fini) {
rcl_variant_t variant =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner nit^N: since this is C++,

Suggested change
rcl_variant_t variant =
rcl_variant_t variant{};

would also work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helps clean things up a bit, done.

EXPECT_STREQ(variant.string_array_value->data[i], copy.string_array_value->data[i]);
}
rcl_yaml_variant_fini(&variant, allocator);
rcl_yaml_variant_fini(&copy, allocator);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner should these be in scoped exits to avoid leaks if any of the asserts above fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@brawner brawner force-pushed the brawner/rcl_yaml-add_val_to_string-leak branch from a9bab89 to 7cd635f Compare August 31, 2020 17:50
@brawner brawner force-pushed the brawner/rcl_yaml-basic-unit-tests branch from 422dd65 to 337f9ee Compare August 31, 2020 22:00
@brawner brawner changed the base branch from brawner/rcl_yaml-add_val_to_string-leak to brawner/rcl_yaml-refactor-srcs August 31, 2020 22:01
@brawner brawner force-pushed the brawner/rcl_yaml-refactor-srcs branch 3 times, most recently from b062da9 to 8d72dc4 Compare September 1, 2020 22:11
Signed-off-by: Stephen Brawner <brawner@gmail.com>
Signed-off-by: Stephen Brawner <brawner@gmail.com>
Signed-off-by: Stephen Brawner <brawner@gmail.com>
Signed-off-by: Stephen Brawner <brawner@gmail.com>
Signed-off-by: Stephen Brawner <brawner@gmail.com>
@brawner brawner force-pushed the brawner/rcl_yaml-basic-unit-tests branch from 68fb9cc to 37cac47 Compare September 1, 2020 23:16
@brawner brawner changed the base branch from brawner/rcl_yaml-refactor-srcs to master September 1, 2020 23:16
@brawner
Copy link
Copy Markdown
Contributor Author

brawner commented Sep 1, 2020

Rebased on to master after merging #754. Testing --packages-select rcl_yaml_param_parser

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Copy Markdown
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ready to go!

src_variant.field = nullptr; \
} while (0)

#define TEST_VARIANT_ARRAY_COPY(field, array_type, value_type, tmp_array) \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brawner nit^N, safe to ignore: you could use decltype expressions to not have to pass types explicitly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

@brawner
Copy link
Copy Markdown
Contributor Author

brawner commented Sep 2, 2020

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Stephen Brawner <brawner@gmail.com>
@brawner brawner force-pushed the brawner/rcl_yaml-basic-unit-tests branch from 67df619 to 8cdc65a Compare September 2, 2020 21:02
@brawner
Copy link
Copy Markdown
Contributor Author

brawner commented Sep 2, 2020

Looks like some more type wrangling was necessary to avoid memory errors.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@brawner brawner merged commit 191d8e5 into master Sep 2, 2020
@delete-merged-branch delete-merged-branch bot deleted the brawner/rcl_yaml-basic-unit-tests branch September 2, 2020 21:25
ahcorde pushed a commit that referenced this pull request Oct 8, 2020
…r (coverage part 1/3) (#771)

* Add basic unit tests for refactored functions

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* PR Fixup

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Fix memory errors

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* headers moved

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Addressing feedback

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Switch to decltype

Signed-off-by: Stephen Brawner <brawner@gmail.com>
ahcorde pushed a commit that referenced this pull request Oct 9, 2020
…r (coverage part 1/3) (#771)

* Add basic unit tests for refactored functions

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* PR Fixup

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Fix memory errors

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* headers moved

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Addressing feedback

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Switch to decltype

Signed-off-by: Stephen Brawner <brawner@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants