test_graph_topo_LDADD = $(COMMON_TEST_LDADD)
+test_cc_prio_map_LDADD = $(COMMON_TEST_LDADD)
+
noinst_PROGRAMS = test_seek test_bitfield test_ctf_writer test_bt_values \
test_ctf_ir_ref test_bt_ctf_field_type_validation test_ir_visit \
- test_trace_listener test_bt_notification_heap test_plugin test_graph_topo
+ test_trace_listener test_bt_notification_heap test_plugin test_graph_topo \
+ test_cc_prio_map
test_seek_SOURCES = test_seek.c
test_bitfield_SOURCES = test_bitfield.c
test_bt_notification_heap_SOURCES = test_bt_notification_heap.c
test_plugin_SOURCES = test_plugin.c
test_graph_topo_SOURCES = test_graph_topo.c
+test_cc_prio_map_SOURCES = test_cc_prio_map.c
check_SCRIPTS = test_seek_big_trace \
test_seek_empty_packet \
--- /dev/null
+/*
+ * test_cc_prio_map.c
+ *
+ * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/ctf-ir/clock-class.h>
+#include <assert.h>
+
+#include "tap/tap.h"
+
+#define NR_TESTS 13
+
+static void test_clock_class_priority_map(void)
+{
+ struct bt_clock_class_priority_map *cc_prio_map;
+ struct bt_ctf_clock_class *cc1;
+ struct bt_ctf_clock_class *cc2;
+ struct bt_ctf_clock_class *cc3;
+ struct bt_ctf_clock_class *cc;
+ uint64_t prio;
+ int ret;
+
+ cc_prio_map = bt_clock_class_priority_map_create();
+ ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds");
+ cc1 = bt_ctf_clock_class_create("cc1");
+ assert(cc1);
+ cc2 = bt_ctf_clock_class_create("cc2");
+ assert(cc2);
+ cc3 = bt_ctf_clock_class_create("cc3");
+ assert(cc3);
+ ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(NULL),
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL");
+ ok(bt_clock_class_priority_map_get_clock_class_priority(NULL, cc1, &prio) < 0,
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (CC priority map)");
+ ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, NULL, &prio) < 0,
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (clock class)");
+ ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, NULL) < 0,
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (priority)");
+ ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map),
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() returns NULL when there's no clock classes");
+ ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc2, 75);
+ assert(ret == 0);
+ cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
+ ok(cc == cc2,
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (1)");
+ BT_PUT(cc);
+ ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc1, 1001);
+ assert(ret == 0);
+ cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
+ ok(cc == cc2,
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)");
+ BT_PUT(cc);
+ ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc3, 11);
+ assert(ret == 0);
+ cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
+ ok(cc == cc3,
+ "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)");
+ BT_PUT(cc);
+ ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, &prio);
+ ok(ret == 0, "bt_clock_class_priority_map_get_clock_class_priority() succeeds");
+ ok(prio == 1001,
+ "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1)");
+ ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc2, &prio);
+ assert(ret == 0);
+ ok(prio == 75,
+ "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2)");
+ ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc3, &prio);
+ assert(ret == 0);
+ ok(prio == 11,
+ "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3)");
+
+ BT_PUT(cc);
+ BT_PUT(cc3);
+ BT_PUT(cc2);
+ BT_PUT(cc1);
+ BT_PUT(cc_prio_map);
+}
+
+int main(int argc, char **argv)
+{
+ plan_tests(NR_TESTS);
+ test_clock_class_priority_map();
+ return exit_status();
+}