From 94bec82e9f10111725f5797a72907dd2d491f4f1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 13 Mar 2024 15:59:22 -0400 Subject: [PATCH] plugins/common/muxing: compare stream class clock classes When comparing two streams and all else is equal about the stream and their classes, compare the clock classes attached to the stream classes. My use case for this is that I'm writing a test where two source components send a stream beginning message to a muxer components. The only difference between the two is the clock classes associated to the stream classes. Some stream classes have an associated clock class, some don't. In other cases, the stream classes differ only by some properties of their clock classes. I want to be sure that the messages will come out of the muxer's priority heap in a stable order. Change-Id: I113704dac4ff952573c3dd96acd33b295425a863 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12054 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/common/muxing/muxing.c | 108 +++++++++++++++++------------ 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/src/plugins/common/muxing/muxing.c b/src/plugins/common/muxing/muxing.c index a923b62e..35bfad13 100644 --- a/src/plugins/common/muxing/muxing.c +++ b/src/plugins/common/muxing/muxing.c @@ -232,6 +232,7 @@ int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream) const char *left_stream_name, *right_stream_name, *left_stream_class_name, *right_stream_class_name; const bt_stream_class *left_stream_class, *right_stream_class; + const bt_clock_class *left_cc, *right_cc; /* * No need to compare stream id as it was checked earlier and if we are @@ -339,59 +340,74 @@ int compare_streams(const bt_stream *left_stream, const bt_stream *right_stream) goto end; } - if (!bt_stream_class_supports_packets(left_stream_class)) { - /* Skip all packet related checks. */ - goto end; - } + if (bt_stream_class_supports_packets(left_stream_class)) { + /* + * Compare stream class presence of discarded packets beginning default + * clock snapshot. + */ + if (bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && + !bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && + bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { + ret = -1; + goto end; + } - /* - * Compare stream class presence of discarded packets beginning default - * clock snapshot. - */ - if (bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && - !bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(left_stream_class) && - bt_stream_class_packets_have_beginning_default_clock_snapshot(right_stream_class)) { - ret = -1; - goto end; - } + /* + * Compare stream class presence of discarded packets end default clock + * snapshot. + */ + if (bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && + !bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && + bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { + ret = -1; + goto end; + } - /* - * Compare stream class presence of discarded packets end default clock - * snapshot. - */ - if (bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && - !bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_packets_have_end_default_clock_snapshot(left_stream_class) && - bt_stream_class_packets_have_end_default_clock_snapshot(right_stream_class)) { - ret = -1; - goto end; + /* Compare stream class support of discarded packets. */ + if (bt_stream_class_supports_discarded_packets(left_stream_class) && + !bt_stream_class_supports_discarded_packets(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_supports_discarded_packets(left_stream_class) && + bt_stream_class_supports_discarded_packets(right_stream_class)) { + ret = -1; + goto end; + } + + /* Compare stream class discarded packets default clock snapshot. */ + if (bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && + !bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { + ret = 1; + goto end; + } else if (!bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && + bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { + ret = -1; + goto end; + } } - /* Compare stream class support of discarded packets. */ - if (bt_stream_class_supports_discarded_packets(left_stream_class) && - !bt_stream_class_supports_discarded_packets(right_stream_class)) { - ret = 1; - goto end; - } else if (!bt_stream_class_supports_discarded_packets(left_stream_class) && - bt_stream_class_supports_discarded_packets(right_stream_class)) { + /* Compare the clock classes associated to the stream classes. */ + left_cc = bt_stream_class_borrow_default_clock_class_const(left_stream_class); + right_cc = bt_stream_class_borrow_default_clock_class_const(right_stream_class); + + if (!left_cc && !right_cc) { + ret = compare_clock_classes(left_cc, right_cc); + + if (ret != 0) { + goto end; + } + } else if (left_cc && !right_cc) { ret = -1; goto end; - } - - /* Compare stream class discarded packets default clock snapshot. */ - if (bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && - !bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { + } else if (!left_cc && right_cc) { ret = 1; goto end; - } else if (!bt_stream_class_discarded_packets_have_default_clock_snapshots(left_stream_class) && - bt_stream_class_discarded_packets_have_default_clock_snapshots(right_stream_class)) { - ret = -1; - goto end; } end: @@ -632,7 +648,7 @@ int compare_messages_same_type(struct messages_to_compare *msgs) int ret = 0; /* - * Both messages are of the same type, we must compare characterics of + * Both messages are of the same type, we must compare characteristics of * the messages such as the attributes of the event in a event message. */ BT_ASSERT_DBG(bt_message_get_type(msgs->left.msg) == -- 2.34.1