tests: add clock class priority map tests
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 31 Mar 2017 02:42:42 +0000 (22:42 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:39 +0000 (12:57 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/Makefile.am
tests/lib/Makefile.am
tests/lib/test_cc_prio_map.c [new file with mode: 0644]

index f5fd07738bb54a3dff0716f17e6c67b1fe267dee..7bb413ab9bb0fce4b7bd793ed3751f9fde4e6074 100644 (file)
@@ -21,7 +21,8 @@ TESTS = bin/test_trace_read \
        lib/test_trace_listener \
        lib/test_bt_notification_heap \
        lib/test_plugin_complete \
-       lib/test_graph_topo
+       lib/test_graph_topo \
+       lib/test_cc_prio_map
 
 EXTRA_DIST = $(srcdir)/ctf-traces/** \
             $(srcdir)/debug-info-data/** \
index 4b11ac1bbc98d972b931f611cdb0a0f4a1f42442..cd53661eac9d051e58ea1bad50c5c8899c6cafea 100644 (file)
@@ -38,9 +38,12 @@ test_plugin_LDADD = $(COMMON_TEST_LDADD)
 
 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
@@ -53,6 +56,7 @@ test_trace_listener_SOURCES = test_trace_listener.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 \
diff --git a/tests/lib/test_cc_prio_map.c b/tests/lib/test_cc_prio_map.c
new file mode 100644 (file)
index 0000000..c883815
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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();
+}
This page took 0.026004 seconds and 4 git commands to generate.