SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / tests / utils / testapp / gen-syscall-events / gen-syscall-events.c
1 /*
2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <sys/syscall.h>
11 #include <unistd.h>
12
13 #include "utils.h"
14
15 #define MAX_LEN 16
16
17 static
18 int open_read_close(const char *path)
19 {
20 int fd, ret;
21 char buf[MAX_LEN];
22 /*
23 * Start generating syscalls. We use syscall(2) to prevent libc to change
24 * the underlying syscall. e.g. calling openat(2) instead of open(2).
25 */
26 fd = syscall(SYS_openat, AT_FDCWD, path, O_RDONLY);
27 if (fd < 0) {
28 perror("open");
29 ret = -1;
30 goto error;
31 }
32
33 ret = syscall(SYS_read, fd, buf, MAX_LEN);
34 if (ret < 0) {
35 perror("read");
36 ret = -1;
37 goto error;
38 }
39
40 ret = syscall(SYS_close, fd);
41 if (ret == -1) {
42 perror("close");
43 ret = -1;
44 goto error;
45 }
46
47 error:
48 return ret;
49 }
50
51 /*
52 * The process waits for the creation of a file passed as argument from an
53 * external processes to execute a syscall and exiting. This is useful for tests
54 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
55 * events generated by our test process only.
56 */
57 int main(int argc, char **argv)
58 {
59 int ret;
60 const char *start_file, *path1, *path2;
61
62 if (argc != 4) {
63 fprintf(stderr, "Error: Missing argument\n");
64 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE PATH1_TO_OPEN PATH2_TO_OPEN\n", argv[0]);
65 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]);
66 ret = -1;
67 goto error;
68 }
69
70 start_file = argv[1];
71 path1 = argv[2];
72 path2 = argv[3];
73
74 /*
75 * Wait for the start_file to be created by an external process
76 * (typically the test script) before executing the syscalls.
77 */
78 ret = wait_on_file(start_file);
79 if (ret != 0) {
80 goto error;
81 }
82
83 /*
84 * Start generating syscalls. We use syscall(2) to prevent libc to change
85 * the underlying syscall. e.g. calling openat(2) instead of open(2).
86 */
87 ret = open_read_close(path1);
88 if (ret == -1) {
89 ret = -1;
90 goto error;
91 }
92
93 ret = open_read_close(path2);
94 if (ret == -1) {
95 ret = -1;
96 goto error;
97 }
98
99 error:
100 return ret;
101 }
This page took 0.045508 seconds and 5 git commands to generate.