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/graph/clock-class-priority-map.h>
21 #include <babeltrace/ctf-ir/clock-class.h>
28 static void test_clock_class_priority_map(void)
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
;
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");
42 cc2
= bt_ctf_clock_class_create("cc2");
44 cc3
= bt_ctf_clock_class_create("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);
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 (1)");
62 ret
= bt_clock_class_priority_map_add_clock_class(cc_prio_map
, cc1
, 1001);
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 (2)");
68 ret
= bt_clock_class_priority_map_add_clock_class(cc_prio_map
, cc3
, 11);
70 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
72 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)");
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");
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
);
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
);
85 "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3)");
94 int main(int argc
, char **argv
)
97 test_clock_class_priority_map();