X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Futils%2Ftestapp%2Fgen-kernel-test-events%2Fgen-kernel-test-events.c;fp=tests%2Futils%2Ftestapp%2Fgen-kernel-test-events%2Fgen-kernel-test-events.c;h=820937902b70a934cfd791130f87801517214833;hp=0000000000000000000000000000000000000000;hb=ba5e8d0abf1a68803de9d773fe977792e7b0b5e8;hpb=83d6d6c4496e692df39843142cb8cf96279eaa20 diff --git a/tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events.c b/tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events.c new file mode 100644 index 000000000..820937902 --- /dev/null +++ b/tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) - 2017 Francis Deslauriers + * Copyright (C) - 2018 Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include + +#include "utils.h" + +#define LTTNG_MODULES_FILE "/proc/lttng-test-filter-event" + +/* + * The process waits for the creation of a file passed as argument from an + * external processes to execute a syscall and exiting. This is useful for tests + * in combinaison with LTTng's PID tracker feature where we can trace the kernel + * events generated by our test process only. + */ +int main(int argc, char **argv) +{ + int fd = -1, ret; + char *start_file, *nr_events_str; + ssize_t len; + + if (argc != 3) { + fprintf(stderr, "Error: Missing argument\n"); + fprintf(stderr, "USAGE: %s PATH_WAIT_FILE NR_EVENTS\n", + argv[0]); + ret = -1; + goto end; + } + + start_file = argv[1]; + nr_events_str = argv[2]; + + /* + * Wait for the start_file to be created by an external process + * (typically the test script) before executing the syscalls. + */ + ret = wait_on_file(start_file); + if (ret != 0) { + goto end; + } + + /* + * Start generating events. + */ + fd = open(LTTNG_MODULES_FILE, O_RDWR); + if (fd < 0) { + perror("open"); + ret = -1; + goto end; + } + + len = write(fd, nr_events_str, strlen(nr_events_str) + 1); + if (len != strlen(nr_events_str) + 1) { + perror("write"); + ret = -1; + } else { + ret = 0; + } + +end: + if (fd >= 0) { + int closeret = close(fd); + if (closeret) { + perror("close"); + } + } + return ret; +}