2012-11-10 07:46:49 +07:00
|
|
|
#include "perf.h"
|
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "thread_map.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
int test__syscall_open_tp_fields(void)
|
|
|
|
{
|
2013-12-20 00:43:45 +07:00
|
|
|
struct record_opts opts = {
|
2012-11-10 07:46:49 +07:00
|
|
|
.target = {
|
|
|
|
.uid = UINT_MAX,
|
|
|
|
.uses_mmap = true,
|
|
|
|
},
|
2014-01-15 03:52:14 +07:00
|
|
|
.no_buffering = true,
|
|
|
|
.freq = 1,
|
|
|
|
.mmap_pages = 256,
|
|
|
|
.raw_samples = true,
|
2012-11-10 07:46:49 +07:00
|
|
|
};
|
|
|
|
const char *filename = "/etc/passwd";
|
|
|
|
int flags = O_RDONLY | O_DIRECTORY;
|
2013-03-11 14:43:12 +07:00
|
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
2012-11-10 07:46:49 +07:00
|
|
|
struct perf_evsel *evsel;
|
|
|
|
int err = -1, i, nr_events = 0, nr_polls = 0;
|
|
|
|
|
|
|
|
if (evlist == NULL) {
|
|
|
|
pr_debug("%s: perf_evlist__new\n", __func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-11-08 02:41:19 +07:00
|
|
|
evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
|
2012-11-10 07:46:49 +07:00
|
|
|
if (evsel == NULL) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-13 00:34:00 +07:00
|
|
|
perf_evsel__config(evsel, &opts);
|
2012-11-10 07:46:49 +07:00
|
|
|
|
|
|
|
evlist->threads->map[0] = getpid();
|
|
|
|
|
|
|
|
err = perf_evlist__open(evlist);
|
|
|
|
if (err < 0) {
|
|
|
|
pr_debug("perf_evlist__open: %s\n", strerror(errno));
|
2014-01-04 01:56:06 +07:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 07:46:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
err = perf_evlist__mmap(evlist, UINT_MAX, false);
|
|
|
|
if (err < 0) {
|
|
|
|
pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
|
2014-01-04 02:54:12 +07:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 07:46:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__enable(evlist);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate the event:
|
|
|
|
*/
|
|
|
|
open(filename, flags);
|
|
|
|
|
|
|
|
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 14:43:33 +07:00
|
|
|
if (type != PERF_RECORD_SAMPLE) {
|
|
|
|
perf_evlist__mmap_consume(evlist, i);
|
2012-11-10 07:46:49 +07:00
|
|
|
continue;
|
2013-10-24 14:43:33 +07:00
|
|
|
}
|
2012-11-10 07:46:49 +07:00
|
|
|
|
|
|
|
err = perf_evsel__parse_sample(evsel, event, &sample);
|
|
|
|
if (err) {
|
|
|
|
pr_err("Can't parse sample, err = %d\n", err);
|
2014-01-04 03:25:49 +07:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 07:46:49 +07: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 03:25:49 +07:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 07:46:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
goto out_ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nr_events == before)
|
|
|
|
poll(evlist->pollfd, evlist->nr_fds, 10);
|
|
|
|
|
|
|
|
if (++nr_polls > 5) {
|
|
|
|
pr_debug("%s: no events!\n", __func__);
|
2014-01-04 03:25:49 +07:00
|
|
|
goto out_delete_evlist;
|
2012-11-10 07:46:49 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
out_ok:
|
|
|
|
err = 0;
|
|
|
|
out_delete_evlist:
|
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|