ir: trace: pass remove listeners when adding listeners
[babeltrace.git] / tests / lib / test_cc_prio_map.c
1 /*
2 * test_cc_prio_map.c
3 *
4 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <babeltrace/graph/clock-class-priority-map.h>
21 #include <babeltrace/ctf-ir/clock-class.h>
22 #include <assert.h>
23
24 #include "tap/tap.h"
25
26 #define NR_TESTS 21
27
28 static void test_clock_class_priority_map(void)
29 {
30 struct bt_clock_class_priority_map *cc_prio_map;
31 struct bt_clock_class_priority_map *cc_prio_map_copy;
32 struct bt_ctf_clock_class *cc1;
33 struct bt_ctf_clock_class *cc2;
34 struct bt_ctf_clock_class *cc3;
35 struct bt_ctf_clock_class *cc;
36 uint64_t prio;
37 int ret;
38
39 cc_prio_map = bt_clock_class_priority_map_create();
40 ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds");
41 cc1 = bt_ctf_clock_class_create("cc1", 1);
42 assert(cc1);
43 cc2 = bt_ctf_clock_class_create("cc2", 2);
44 assert(cc2);
45 cc3 = bt_ctf_clock_class_create("cc3", 3);
46 assert(cc3);
47 ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(NULL),
48 "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL");
49 ok(bt_clock_class_priority_map_get_clock_class_priority(NULL, cc1, &prio) < 0,
50 "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (CC priority map)");
51 ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, NULL, &prio) < 0,
52 "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (clock class)");
53 ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, NULL) < 0,
54 "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (priority)");
55 ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map),
56 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns NULL when there's no clock classes");
57 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc2, 75);
58 assert(ret == 0);
59 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
60 ok(cc == cc2,
61 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (1)");
62 BT_PUT(cc);
63 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc1, 1001);
64 assert(ret == 0);
65 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
66 ok(cc == cc2,
67 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)");
68 BT_PUT(cc);
69 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc3, 11);
70 assert(ret == 0);
71 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
72 ok(cc == cc3,
73 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)");
74 BT_PUT(cc);
75 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, &prio);
76 ok(ret == 0, "bt_clock_class_priority_map_get_clock_class_priority() succeeds");
77 ok(prio == 1001,
78 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1)");
79 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc2, &prio);
80 assert(ret == 0);
81 ok(prio == 75,
82 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2)");
83 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc3, &prio);
84 assert(ret == 0);
85 ok(prio == 11,
86 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3)");
87 cc_prio_map_copy = bt_clock_class_priority_map_copy(cc_prio_map);
88 ok(cc_prio_map_copy, "bt_clock_class_priority_map_copy() succeeds");
89 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc1, &prio);
90 assert(ret == 0);
91 ok(prio == 1001,
92 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1, copy)");
93 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc2, &prio);
94 assert(ret == 0);
95 ok(prio == 75,
96 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2, copy)");
97 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc3, &prio);
98 assert(ret == 0);
99 ok(prio == 11,
100 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3, copy)");
101 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map_copy);
102 ok(cc == cc3,
103 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (copy)");
104 BT_PUT(cc);
105 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map_copy, cc3, 253);
106 ok(ret == 0, "bt_clock_class_priority_map_add_clock_class() succeeds for an existing clock class");
107 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc3, &prio);
108 assert(ret == 0);
109 ok(prio == 253,
110 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (updated, copy)");
111 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map_copy);
112 ok(cc == cc2,
113 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (updated, copy)");
114 BT_PUT(cc);
115
116 BT_PUT(cc3);
117 BT_PUT(cc2);
118 BT_PUT(cc1);
119 BT_PUT(cc_prio_map);
120 BT_PUT(cc_prio_map_copy);
121 }
122
123 int main(int argc, char **argv)
124 {
125 plan_tests(NR_TESTS);
126 test_clock_class_priority_map();
127 return exit_status();
128 }
This page took 0.038896 seconds and 4 git commands to generate.