Replace assert() -> BT_ASSERT() and some preconditions with BT_ASSERT_PRE()
[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/ref.h>
21 #include <babeltrace/graph/clock-class-priority-map.h>
22 #include <babeltrace/ctf-ir/clock-class.h>
23 #include <assert.h>
24
25 #include "tap/tap.h"
26
27 #define NR_TESTS 17
28
29 static void test_clock_class_priority_map(void)
30 {
31 struct bt_clock_class_priority_map *cc_prio_map;
32 struct bt_clock_class_priority_map *cc_prio_map_copy;
33 struct bt_clock_class *cc1;
34 struct bt_clock_class *cc2;
35 struct bt_clock_class *cc3;
36 struct bt_clock_class *cc;
37 uint64_t prio;
38 int ret;
39
40 cc_prio_map = bt_clock_class_priority_map_create();
41 ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds");
42 cc1 = bt_clock_class_create("cc1", 1);
43 assert(cc1);
44 cc2 = bt_clock_class_create("cc2", 2);
45 assert(cc2);
46 cc3 = bt_clock_class_create("cc3", 3);
47 assert(cc3);
48 ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map),
49 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns NULL when there's no clock classes");
50 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc2, 75);
51 assert(ret == 0);
52 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
53 ok(cc == cc2,
54 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (1)");
55 BT_PUT(cc);
56 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc1, 1001);
57 assert(ret == 0);
58 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
59 ok(cc == cc2,
60 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)");
61 BT_PUT(cc);
62 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc3, 11);
63 assert(ret == 0);
64 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map);
65 ok(cc == cc3,
66 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)");
67 BT_PUT(cc);
68 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, &prio);
69 ok(ret == 0, "bt_clock_class_priority_map_get_clock_class_priority() succeeds");
70 ok(prio == 1001,
71 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1)");
72 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc2, &prio);
73 assert(ret == 0);
74 ok(prio == 75,
75 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2)");
76 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc3, &prio);
77 assert(ret == 0);
78 ok(prio == 11,
79 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3)");
80 cc_prio_map_copy = bt_clock_class_priority_map_copy(cc_prio_map);
81 ok(cc_prio_map_copy, "bt_clock_class_priority_map_copy() succeeds");
82 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc1, &prio);
83 assert(ret == 0);
84 ok(prio == 1001,
85 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1, copy)");
86 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc2, &prio);
87 assert(ret == 0);
88 ok(prio == 75,
89 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2, copy)");
90 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc3, &prio);
91 assert(ret == 0);
92 ok(prio == 11,
93 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3, copy)");
94 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map_copy);
95 ok(cc == cc3,
96 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (copy)");
97 BT_PUT(cc);
98 ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map_copy, cc3, 253);
99 ok(ret == 0, "bt_clock_class_priority_map_add_clock_class() succeeds for an existing clock class");
100 ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc3, &prio);
101 assert(ret == 0);
102 ok(prio == 253,
103 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (updated, copy)");
104 cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map_copy);
105 ok(cc == cc2,
106 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (updated, copy)");
107 BT_PUT(cc);
108
109 BT_PUT(cc3);
110 BT_PUT(cc2);
111 BT_PUT(cc1);
112 BT_PUT(cc_prio_map);
113 BT_PUT(cc_prio_map_copy);
114 }
115
116 int main(int argc, char **argv)
117 {
118 plan_tests(NR_TESTS);
119 test_clock_class_priority_map();
120 return exit_status();
121 }
This page took 0.035723 seconds and 4 git commands to generate.