4 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
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.
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.
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.
20 #include <babeltrace/ref.h>
21 #include <babeltrace/graph/clock-class-priority-map.h>
22 #include <babeltrace/ctf-ir/clock-class.h>
29 static void test_clock_class_priority_map(void)
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
;
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);
44 cc2
= bt_clock_class_create("cc2", 2);
46 cc3
= bt_clock_class_create("cc3", 3);
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);
52 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
54 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (1)");
56 ret
= bt_clock_class_priority_map_add_clock_class(cc_prio_map
, cc1
, 1001);
58 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
60 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)");
62 ret
= bt_clock_class_priority_map_add_clock_class(cc_prio_map
, cc3
, 11);
64 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
66 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)");
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");
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
);
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
);
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
);
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
);
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
);
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
);
96 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (copy)");
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
);
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
);
106 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (updated, copy)");
113 BT_PUT(cc_prio_map_copy
);
116 int main(int argc
, char **argv
)
118 plan_tests(NR_TESTS
);
119 test_clock_class_priority_map();
120 return exit_status();