Skip to content

Commit

Permalink
Clean-up: tests: bt2 plug-ins: modernize the plug-ins
Browse files Browse the repository at this point in the history
By virtue of their use of the C Babeltrace 2 APIs, the test plug-ins
perform a fair amount of manual resource management.

To make it possible to adopt a more modern C++ style in those plug-ins,
a number of helpers are introduced.

Introduce reference wrappers for the Babeltrace 2 interface:
  - value_ref: wraps a bt_value reference using std::unique_ptr
  - message_const_ref: wraps a constant message reference using a
    unique_ptr
  - message_iterator_ref: wraps a message iterator reference using a
    unique_ptr
  - event_class_const_ref: wraps a constant event class reference using
    a unique_ptr

A specialized random_access_container_wrapper is specialized to wrap
bt_value arrays of strings.

In doing so, it is possible to eliminate the use of gotos and manual
reference management on error paths. Some struct/classes are renamed to
eliminate ambiguities that arose over the refactoring.

The changes allow some simplifications of the code flow in places which
are applied directly.

Change-Id: I25c148d7970cb89add55a86f2c162973d3d27e4a
Signed-off-by: Jérémie Galarneau <[email protected]>
  • Loading branch information
jgalar committed Mar 12, 2024
1 parent 74021af commit d73aedd
Show file tree
Hide file tree
Showing 7 changed files with 561 additions and 437 deletions.
7 changes: 6 additions & 1 deletion src/common/container-wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class random_access_container_wrapper {
return ContainerOperations::size(_container);
}

bool empty() const
{
return size() == 0;
}

typename std::conditional<std::is_pointer<ElementType>::value, ElementType, ElementType&>::type
operator[](std::size_t index)
{
Expand Down Expand Up @@ -144,7 +149,7 @@ class random_access_container_wrapper {
operator[](std::size_t index) const
{
if (index >= ContainerOperations::size(_container)) {
LTTNG_THROW_INVALID_ARGUMENT_ERROR(lttng::format(
throw std::invalid_argument(lttng::format(
"Out of bound access through random_access_container_wrapper: index={}, size={}",
index,
size()));
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/bt2_plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ lttngtest_la_CXXFLAGS = \
-fvisibility=default

lttngtest_la_SOURCES = \
lttngtest-plugin.cpp
lttngtest-plugin.cpp \
fmt.hpp \
utils.hpp

lttngtest_la_LDFLAGS = \
$(AM_LDFLAGS) \
Expand Down

0 comments on commit d73aedd

Please sign in to comment.