Commit | Line | Data |
---|---|---|
0e4a4192 PP |
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 13 | |
27 | ||
28 | static void test_clock_class_priority_map(void) | |
29 | { | |
30 | struct bt_clock_class_priority_map *cc_prio_map; | |
31 | struct bt_ctf_clock_class *cc1; | |
32 | struct bt_ctf_clock_class *cc2; | |
33 | struct bt_ctf_clock_class *cc3; | |
34 | struct bt_ctf_clock_class *cc; | |
35 | uint64_t prio; | |
36 | int ret; | |
37 | ||
38 | cc_prio_map = bt_clock_class_priority_map_create(); | |
39 | ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds"); | |
40 | cc1 = bt_ctf_clock_class_create("cc1"); | |
41 | assert(cc1); | |
42 | cc2 = bt_ctf_clock_class_create("cc2"); | |
43 | assert(cc2); | |
44 | cc3 = bt_ctf_clock_class_create("cc3"); | |
45 | assert(cc3); | |
46 | ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(NULL), | |
47 | "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL"); | |
48 | ok(bt_clock_class_priority_map_get_clock_class_priority(NULL, cc1, &prio) < 0, | |
49 | "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (CC priority map)"); | |
50 | ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, NULL, &prio) < 0, | |
51 | "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (clock class)"); | |
52 | ok(bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, NULL) < 0, | |
53 | "bt_clock_class_priority_map_get_highest_priority_clock_class() handles NULL (priority)"); | |
54 | ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map), | |
55 | "bt_clock_class_priority_map_get_highest_priority_clock_class() returns NULL when there's no clock classes"); | |
56 | ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc2, 75); | |
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 (1)"); | |
61 | BT_PUT(cc); | |
62 | ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc1, 1001); | |
63 | assert(ret == 0); | |
64 | cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map); | |
65 | ok(cc == cc2, | |
66 | "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)"); | |
67 | BT_PUT(cc); | |
68 | ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc3, 11); | |
69 | assert(ret == 0); | |
70 | cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map); | |
71 | ok(cc == cc3, | |
72 | "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)"); | |
73 | BT_PUT(cc); | |
74 | ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, &prio); | |
75 | ok(ret == 0, "bt_clock_class_priority_map_get_clock_class_priority() succeeds"); | |
76 | ok(prio == 1001, | |
77 | "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1)"); | |
78 | ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc2, &prio); | |
79 | assert(ret == 0); | |
80 | ok(prio == 75, | |
81 | "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2)"); | |
82 | ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc3, &prio); | |
83 | assert(ret == 0); | |
84 | ok(prio == 11, | |
85 | "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3)"); | |
86 | ||
87 | BT_PUT(cc); | |
88 | BT_PUT(cc3); | |
89 | BT_PUT(cc2); | |
90 | BT_PUT(cc1); | |
91 | BT_PUT(cc_prio_map); | |
92 | } | |
93 | ||
94 | int main(int argc, char **argv) | |
95 | { | |
96 | plan_tests(NR_TESTS); | |
97 | test_clock_class_priority_map(); | |
98 | return exit_status(); | |
99 | } |