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_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
;
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);
43 cc2
= bt_ctf_clock_class_create("cc2", 2);
45 cc3
= bt_ctf_clock_class_create("cc3", 3);
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);
59 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
61 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (1)");
63 ret
= bt_clock_class_priority_map_add_clock_class(cc_prio_map
, cc1
, 1001);
65 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
67 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)");
69 ret
= bt_clock_class_priority_map_add_clock_class(cc_prio_map
, cc3
, 11);
71 cc
= bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map
);
73 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)");
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");
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
);
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
);
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
);
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
);
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
);
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
);
103 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (copy)");
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
);
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
);
113 "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (updated, copy)");
120 BT_PUT(cc_prio_map_copy
);
123 int main(int argc
, char **argv
)
125 plan_tests(NR_TESTS
);
126 test_clock_class_priority_map();
127 return exit_status();