2015-09-07 16:38:06 +08:00
|
|
|
#include <linux/err.h>
|
2012-11-10 08:46:49 +08:00
|
|
|
#include "perf.h"
|
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "thread_map.h"
|
|
|
|
#include "tests.h"
|
2014-07-15 05:46:48 +08:00
|
|
|
#include "debug.h"
|
2012-11-10 08:46:49 +08:00
|
|
|
|
perf tests: Pass the subtest index to each test routine
Some tests have sub-tests we want to run, so allow passing this.
Wang tried to avoid having to touch all tests, but then, having the
test.func in an anonymous union makes the build fail on older compilers,
like the one in RHEL6, where:
test a = {
.func = foo,
};
fails.
To fix it leave the func pointer in the main structure and pass the subtest
index to all tests, end result function is the same, but we have just one
function pointer, not two, with and without the subtest index as an argument.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-5genj0ficwdmelpoqlds0u4y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-11-19 23:01:48 +08:00
|
|
|
int test__syscall_openat_tp_fields(int subtest __maybe_unused)
|
2012-11-10 08:46:49 +08:00
|
|
|
{
|
2013-12-20 01:43:45 +08:00
|
|
|
struct record_opts opts = {
|
2012-11-10 08:46:49 +08:00
|
|
|
.target = {
|
|
|
|
.uid = UINT_MAX,
|
|
|
|
.uses_mmap = true,
|
|
|
|
},
|
2014-01-15 04:52:14 +08:00
|
|
|
.no_buffering = true,
|
|
|
|
.freq = 1,
|
|
|
|
.mmap_pages = 256,
|
|
|
|
.raw_samples = true,
|
2012-11-10 08:46:49 +08:00
|
|
|
};
|
|
|
|
const char *filename = "/etc/passwd";
|
|
|
|
int flags = O_RDONLY | O_DIRECTORY;
|
2013-03-11 15:43:12 +08:00
|
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
2012-11-10 08:46:49 +08:00
|
|
|
struct perf_evsel *evsel;
|
|
|
|
int err = -1, i, nr_events = 0, nr_polls = 0;
|
2014-08-14 10:22:45 +08:00
|
|
|
char sbuf[STRERR_BUFSIZE];
|
2012-11-10 08:46:49 +08:00
|
|
|
|
|
|
|
if (evlist == NULL) {
|
|
|
|
pr_debug("%s: perf_evlist__new\n", __func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-04-16 21:52:53 +08:00
|
|
|
evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
|
2015-09-07 16:38:06 +08:00
|
|
|
if (IS_ERR(evsel)) {
|
2012-11-10 08:46:49 +08:00
|
|
|
pr_debug("%s: perf_evsel__newtp\n", __func__);
|
|
|
|
goto out_delete_evlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__add(evlist, evsel);
|
|
|
|
|
|
|
|
err = perf_evlist__create_maps(evlist, &opts.target);
|
|
|
|
if (err < 0) {
|
|
|
|
pr_debug("%s: perf_evlist__create_maps\n", __func__);
|
|
|
|
goto out_delete_evlist;
|
|
|
|
}
|
|
|
|
|
2016-04-12 05:15:29 +08:00
|
|
|
perf_evsel__config(evsel, &opts, NULL);
|
2012-11-10 08:46:49 +08:00
|
|
|
|
2015-06-23 06:36:02 +08:00
|
|
|
thread_map__set_pid(evlist->threads, 0, getpid());
|
2012-11-10 08:46:49 +08:00
|
|
|
|
|
|
|
err = perf_evlist__open(evlist);
|
|
|
|
if (err < 0) {
|
2014-08-14 10:22:45 +08:00
|
|
|
pr_debug("perf_evlist__open: %s\n",
|
tools: Introduce str_error_r()
The tools so far have been using the strerror_r() GNU variant, that
returns a string, be it the buffer passed or something else.
But that, besides being tricky in cases where we expect that the
function using strerror_r() returns the error formatted in a provided
buffer (we have to check if it returned something else and copy that
instead), breaks the build on systems not using glibc, like Alpine
Linux, where musl libc is used.
So, introduce yet another wrapper, str_error_r(), that has the GNU
interface, but uses the portable XSI variant of strerror_r(), so that
users rest asured that the provided buffer is used and it is what is
returned.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-d4t42fnf48ytlk8rjxs822tf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-07-06 22:56:20 +08:00
|
|
|
str_error_r(errno, sbuf, sizeof(sbuf)));
|
2014-01-04 02:56:06 +08:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 08:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = perf_evlist__mmap(evlist, UINT_MAX, false);
|
|
|
|
if (err < 0) {
|
2014-08-14 10:22:45 +08:00
|
|
|
pr_debug("perf_evlist__mmap: %s\n",
|
tools: Introduce str_error_r()
The tools so far have been using the strerror_r() GNU variant, that
returns a string, be it the buffer passed or something else.
But that, besides being tricky in cases where we expect that the
function using strerror_r() returns the error formatted in a provided
buffer (we have to check if it returned something else and copy that
instead), breaks the build on systems not using glibc, like Alpine
Linux, where musl libc is used.
So, introduce yet another wrapper, str_error_r(), that has the GNU
interface, but uses the portable XSI variant of strerror_r(), so that
users rest asured that the provided buffer is used and it is what is
returned.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-d4t42fnf48ytlk8rjxs822tf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-07-06 22:56:20 +08:00
|
|
|
str_error_r(errno, sbuf, sizeof(sbuf)));
|
2014-01-04 03:54:12 +08:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 08:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__enable(evlist);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate the event:
|
|
|
|
*/
|
2015-04-16 21:52:53 +08:00
|
|
|
openat(AT_FDCWD, filename, flags);
|
2012-11-10 08:46:49 +08:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int before = nr_events;
|
|
|
|
|
|
|
|
for (i = 0; i < evlist->nr_mmaps; i++) {
|
|
|
|
union perf_event *event;
|
|
|
|
|
|
|
|
while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
|
|
|
|
const u32 type = event->header.type;
|
|
|
|
int tp_flags;
|
|
|
|
struct perf_sample sample;
|
|
|
|
|
|
|
|
++nr_events;
|
|
|
|
|
2013-10-24 15:43:33 +08:00
|
|
|
if (type != PERF_RECORD_SAMPLE) {
|
|
|
|
perf_evlist__mmap_consume(evlist, i);
|
2012-11-10 08:46:49 +08:00
|
|
|
continue;
|
2013-10-24 15:43:33 +08:00
|
|
|
}
|
2012-11-10 08:46:49 +08:00
|
|
|
|
|
|
|
err = perf_evsel__parse_sample(evsel, event, &sample);
|
|
|
|
if (err) {
|
2015-10-19 23:23:48 +08:00
|
|
|
pr_debug("Can't parse sample, err = %d\n", err);
|
2014-01-04 04:25:49 +08:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 08:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tp_flags = perf_evsel__intval(evsel, &sample, "flags");
|
|
|
|
|
|
|
|
if (flags != tp_flags) {
|
|
|
|
pr_debug("%s: Expected flags=%#x, got %#x\n",
|
|
|
|
__func__, flags, tp_flags);
|
2014-01-04 04:25:49 +08:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 08:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
goto out_ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nr_events == before)
|
2014-08-19 04:25:59 +08:00
|
|
|
perf_evlist__poll(evlist, 10);
|
2012-11-10 08:46:49 +08:00
|
|
|
|
|
|
|
if (++nr_polls > 5) {
|
|
|
|
pr_debug("%s: no events!\n", __func__);
|
2014-01-04 04:25:49 +08:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 08:46:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
out_ok:
|
|
|
|
err = 0;
|
|
|
|
out_delete_evlist:
|
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|