SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / tests / utils / testapp / gen-syscall-events / gen-syscall-events.c
CommitLineData
030312cf 1/*
9d16b343 2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
030312cf 3 *
9d16b343 4 * SPDX-License-Identifier: LGPL-2.1-only
030312cf 5 *
030312cf
FD
6 */
7
030312cf
FD
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
2463b787
JR
16
17static
18int 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
47error:
48 return ret;
49}
50
030312cf
FD
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 */
57int main(int argc, char **argv)
58{
2463b787
JR
59 int ret;
60 const char *start_file, *path1, *path2;
030312cf 61
2463b787 62 if (argc != 4) {
030312cf 63 fprintf(stderr, "Error: Missing argument\n");
2463b787 64 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE PATH1_TO_OPEN PATH2_TO_OPEN\n", argv[0]);
030312cf
FD
65 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]);
66 ret = -1;
67 goto error;
68 }
69
70 start_file = argv[1];
2463b787
JR
71 path1 = argv[2];
72 path2 = argv[3];
030312cf
FD
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 */
2463b787
JR
87 ret = open_read_close(path1);
88 if (ret == -1) {
030312cf
FD
89 ret = -1;
90 goto error;
91 }
92
2463b787 93 ret = open_read_close(path2);
030312cf 94 if (ret == -1) {
030312cf
FD
95 ret = -1;
96 goto error;
97 }
98
99error:
100 return ret;
101}
This page took 0.057943 seconds and 5 git commands to generate.