Tests: ust: clock override plugin
[lttng-tools.git] / tests / regression / ust / clock-override / lttng-ust-clock-override-test.c
1 /*
2 * lttng-clock-override-test.c
3 *
4 * Copyright (c) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * Copyright (c) 2015 Jonthan Rajotte <jonathan.rajotte-julien@efficios.com>
6 * Based on lttng-clock-override-example.c from LTTng-ust example
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27 #include <stdlib.h>
28 #include <time.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <lttng/ust-clock.h>
32
33 static
34 uint64_t plugin_read64(void)
35 {
36 /* Freeze time */
37 return 0;
38 }
39
40 static
41 uint64_t plugin_freq(void)
42 {
43 return 1000; /* 1KHz clock (very coarse!) */
44 }
45
46 static
47 int plugin_uuid(char *uuid)
48 {
49 const char myuuid[] = "83c63deb-7aa4-48fb-abda-946f400d76e6";
50 memcpy(uuid, myuuid, LTTNG_UST_UUID_STR_LEN);
51 return 0;
52 }
53
54 static
55 const char *plugin_name(void)
56 {
57 return "lttng_test_clock_override";
58 }
59
60 static
61 const char *plugin_description(void)
62 {
63 return "Freeze time with 1KHz for regression test";
64 }
65
66 void lttng_ust_clock_plugin_init(void)
67 {
68 int ret;
69
70 ret = lttng_ust_trace_clock_set_read64_cb(plugin_read64);
71 if (ret) {
72 fprintf(stderr, "Error setting clock override read64 callback: %s\n",
73 strerror(-ret));
74 goto error;
75 }
76 ret = lttng_ust_trace_clock_set_freq_cb(plugin_freq);
77 if (ret) {
78 fprintf(stderr, "Error setting clock override freq callback: %s\n",
79 strerror(-ret));
80 goto error;
81 }
82 ret = lttng_ust_trace_clock_set_uuid_cb(plugin_uuid);
83 if (ret) {
84 fprintf(stderr, "Error setting clock override uuid callback: %s\n",
85 strerror(-ret));
86 goto error;
87 }
88
89 ret = lttng_ust_trace_clock_set_name_cb(plugin_name);
90 if (ret) {
91 fprintf(stderr, "Error setting clock override name callback: %s\n",
92 strerror(-ret));
93 goto error;
94 }
95
96 ret = lttng_ust_trace_clock_set_description_cb(plugin_description);
97 if (ret) {
98 fprintf(stderr, "Error setting clock override description callback: %s\n",
99 strerror(-ret));
100 goto error;
101 }
102
103 ret = lttng_ust_enable_trace_clock_override();
104 if (ret) {
105 fprintf(stderr, "Error enabling clock override: %s\n",
106 strerror(-ret));
107 goto error;
108 }
109
110 return;
111
112 error:
113 exit(EXIT_FAILURE);
114 }
This page took 0.031398 seconds and 4 git commands to generate.