1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/* COVERAGE: perf_event_open */
#define _GNU_SOURCE
#include <unistd.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/ioctl.h>
#ifdef __NR_perf_event_open
#include <linux/perf_event.h>
// Note that the man page says you need to include the following
// file. However, if you aren't using hardware breakpoint events
// (which this testcase doesn't), you don't really need it. Some
// kernels, like 2.6.32-504.el6.s390x, don't have the header.
//
// #include <linux/hw_breakpoint.h>
static inline int
perf_event_open(struct perf_event_attr *attr, pid_t pid,
int cpu, int group_fd, unsigned long flags)
{
return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
}
#endif
int main()
{
#ifdef __NR_perf_event_open
struct perf_event_attr pe;
int fd;
long long count;
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.type = PERF_TYPE_SOFTWARE;
pe.size = sizeof(struct perf_event_attr);
pe.config = PERF_COUNT_SW_CPU_CLOCK;
pe.disabled = 0;
pe.exclude_kernel = 1;
pe.exclude_hv = 1;
fd = perf_event_open(&pe, 0, -1, -1, 0);
//staptest// perf_event_open (XXXX, 0, -1, -1, 0x0) = NNNN
sleep(1);
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
read(fd, &count, sizeof(count));
// Limit testing.
fd = perf_event_open((struct perf_event_attr*)-1, 0, -1, -1, 0);
#ifdef __s390__
//staptest// perf_event_open (0x[7]?[f]+, 0, -1, -1, 0x0) = -NNNN
#else
//staptest// perf_event_open (0x[f]+, 0, -1, -1, 0x0) = -NNNN
#endif
fd = perf_event_open(&pe, -1, -1, -1, 0);
//staptest// perf_event_open (XXXX, -1, -1, -1, 0x0) = -NNNN
fd = perf_event_open(&pe, 0, -1, -1, -1);
//staptest// perf_event_open (XXXX, 0, -1, -1, PERF_FLAG_[^ ]+|XXXX) = -NNNN
close(fd);
#endif
return 0;
}
|