Add api0 compile tests
[lttng-ust.git] / tests / compile / api0 / hello / hello.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2009 Pierre-Marc Fournier
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <sys/mman.h>
11 #include <stdarg.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <fcntl.h>
15 #include <signal.h>
16 #include <string.h>
17 /*
18 * Work-around inet.h missing struct mmsghdr forward declaration, with
19 * triggers a warning when system files warnings are enabled.
20 */
21 struct mmsghdr;
22 #include <arpa/inet.h>
23 #include <stdlib.h>
24 #include <stdbool.h>
25
26 #define TRACEPOINT_DEFINE
27 #include "ust_tests_hello.h"
28
29 static
30 void inthandler(int sig __attribute__((unused)))
31 {
32 printf("in SIGUSR1 handler\n");
33 tracepoint(ust_tests_hello, tptest_sighandler);
34 }
35
36 static
37 int init_int_handler(void)
38 {
39 int result;
40 struct sigaction act;
41
42 memset(&act, 0, sizeof(act));
43 result = sigemptyset(&act.sa_mask);
44 if (result == -1) {
45 perror("sigemptyset");
46 return -1;
47 }
48
49 act.sa_handler = inthandler;
50 act.sa_flags = SA_RESTART;
51
52 /* Only defer ourselves. Also, try to restart interrupted
53 * syscalls to disturb the traced program as little as possible.
54 */
55 result = sigaction(SIGUSR1, &act, NULL);
56 if (result == -1) {
57 perror("sigaction");
58 return -1;
59 }
60
61 return 0;
62 }
63
64 int main(int argc, char **argv)
65 {
66 int i, netint;
67 long values[] = { 1, 2, 3 };
68 char text[10] = "test";
69 double dbl = 2.0;
70 float flt = 2222.0;
71 int delay = 0;
72 bool mybool = 123; /* should print "1" */
73
74 init_int_handler();
75
76 if (argc == 2)
77 delay = atoi(argv[1]);
78
79 fprintf(stderr, "Hello, World!\n");
80
81 sleep(delay);
82
83 fprintf(stderr, "Tracing... ");
84 for (i = 0; i < 1000000; i++) {
85 netint = htonl(i);
86 tracepoint(ust_tests_hello, tptest, i, netint, values,
87 text, strlen(text), dbl, flt, mybool);
88 //usleep(100000);
89 }
90 fprintf(stderr, " done.\n");
91 return 0;
92 }
This page took 0.037032 seconds and 4 git commands to generate.