From 0e4a41926040dea20996763ec7d2d6a257809d4b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 30 Mar 2017 22:42:42 -0400 Subject: [PATCH] tests: add clock class priority map tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- tests/Makefile.am | 3 +- tests/lib/Makefile.am | 6 ++- tests/lib/test_cc_prio_map.c | 99 ++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 tests/lib/test_cc_prio_map.c diff --git a/tests/Makefile.am b/tests/Makefile.am index f5fd0773..7bb413ab 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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/** \ diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 4b11ac1b..cd53661e 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -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 index 00000000..c883815c --- /dev/null +++ b/tests/lib/test_cc_prio_map.c @@ -0,0 +1,99 @@ +/* + * test_cc_prio_map.c + * + * Copyright 2017 - Philippe Proulx + * + * 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 +#include +#include + +#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(); +} -- 2.34.1