Skip to content

Commit

Permalink
Add single-shot overflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Nov 21, 2012
1 parent 435eae9 commit 4cf9f82
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
21 November 2012
+ Add single-shot overflow test

4 November 2012
+ Make new validation_privileged category

Expand Down
7 changes: 5 additions & 2 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ echo "* Checking events that require special permissions"

echo
echo "* Checking basic perf_event functionality"
./validation/simple_overflow_leader
./validation/simple_overflow_sibling
./validation/format_id_support
./validation/non-existent
./validation/breakpoint_support
./validation/breakpoint_overflow
./validation/inherit
./validation/inherit_stat
./validation/enable_on_exec

echo "* Checking overflow functionality"
./validation/simple_overflow_leader
./validation/simple_overflow_sibling
./validation/simultaneous_group_overflow
./validation/simultaneous_overflow
./validation/single_shot_overflow

echo
echo "* Checking mmap record sample functionality"
Expand Down
21 changes: 19 additions & 2 deletions validation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ all: \
simple_overflow_leader \
simple_overflow_sibling \
simultaneous_group_overflow \
simultaneous_overflow
simultaneous_overflow \
single_shot_overflow


###
Expand Down Expand Up @@ -251,6 +252,21 @@ simple_overflow_sibling.o: simple_overflow_sibling.c
$(CC) $(CFLAGS) -c simple_overflow_sibling.c


###

single_shot_overflow: single_shot_overflow.o ../lib/test_utils.o \
../lib/perf_helpers.o \
../lib/instructions_testcode.o
$(CC) $(LFLAGS) -o single_shot_overflow single_shot_overflow.o \
../lib/test_utils.o \
../lib/perf_helpers.o \
../lib/instructions_testcode.o

single_shot_overflow.o: single_shot_overflow.c
$(CC) $(CFLAGS) -c single_shot_overflow.c



clean:
rm -f *~ *.o \
breakpoint_overflow \
Expand All @@ -268,5 +284,6 @@ clean:
simple_overflow_leader \
simple_overflow_sibling \
simultaneous_group_overflow \
simultaneous_overflow
simultaneous_overflow \
single_shot_overflow

156 changes: 156 additions & 0 deletions validation/single_shot_overflow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/* single_shot_overflow.c */
/* by Vince Weaver vincent.weaver _at_ maine.edu */

/* Test single-shot overflow */

#define _GNU_SOURCE 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>
#include <fcntl.h>

#include <errno.h>

#include <signal.h>

#include <sys/mman.h>

#include <sys/ioctl.h>
#include <asm/unistd.h>
#include <sys/prctl.h>

#include "perf_event.h"
#include "test_utils.h"
#include "perf_helpers.h"
#include "instructions_testcode.h"

static struct signal_counts {
int in,out,msg,err,pri,hup,unknown,total;
} count = {0,0,0,0,0,0,0,0};

static int fd1;

static void our_handler(int signum,siginfo_t *oh, void *blah) {
int ret;

ret=ioctl(fd1, PERF_EVENT_IOC_DISABLE, 0);

switch(oh->si_code) {
case POLL_IN: count.in++; break;
case POLL_OUT: count.out++; break;
case POLL_MSG: count.msg++; break;
case POLL_ERR: count.err++; break;
case POLL_PRI: count.pri++; break;
case POLL_HUP: count.hup++; break;
default: count.unknown++; break;
}

count.total++;

ret=ioctl(fd1, PERF_EVENT_IOC_REFRESH,1);

(void) ret;

}

int main(int argc, char** argv) {

int ret,quiet;

struct perf_event_attr pe;

struct sigaction sa;
void *our_mmap;
char test_string[]="Testing single shot overflow...";

quiet=test_quiet();

if (!quiet) printf("This tests single-shot overflow.\n");

memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = our_handler;
sa.sa_flags = SA_SIGINFO;

if (sigaction( SIGIO, &sa, NULL) < 0) {
fprintf(stderr,"Error setting up signal handler\n");
exit(1);
}

memset(&pe,0,sizeof(struct perf_event_attr));

pe.type=PERF_TYPE_HARDWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.sample_period=100000;
pe.sample_type=PERF_SAMPLE_IP;
pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID;
pe.disabled=1;
pe.pinned=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;
pe.wakeup_events=1;

arch_adjust_domain(&pe,quiet);

fd1=perf_event_open(&pe,0,-1,-1,0);
if (fd1<0) {
if (!quiet) fprintf(stderr,"Error opening leader %llx\n",pe.config);
test_fail(test_string);
}

our_mmap=mmap(NULL, (1+1)*4096,
PROT_READ|PROT_WRITE, MAP_SHARED, fd1, 0);

fcntl(fd1, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC);
fcntl(fd1, F_SETSIG, SIGIO);
fcntl(fd1, F_SETOWN,getpid());

ioctl(fd1, PERF_EVENT_IOC_RESET, 0);

ret=ioctl(fd1, PERF_EVENT_IOC_REFRESH,1);

if (ret<0) {
if (!quiet) {
fprintf(stderr,"Error with PERF_EVENT_IOC_ENABLE of group leader: "
"%d %s\n",errno,strerror(errno));
test_fail(test_string);
}
}

instructions_million();

if (!quiet) {
printf("Counts, using mmap buffer %p\n",our_mmap);
printf("\tPOLL_IN : %d\n",count.in);
printf("\tPOLL_OUT: %d\n",count.out);
printf("\tPOLL_MSG: %d\n",count.msg);
printf("\tPOLL_ERR: %d\n",count.err);
printf("\tPOLL_PRI: %d\n",count.pri);
printf("\tPOLL_HUP: %d\n",count.hup);
printf("\tUNKNOWN : %d\n",count.unknown);
}

if (count.total==0) {
if (!quiet) printf("No overflow events generated.\n");
test_fail(test_string);
}

if (count.in!=0) {
if (!quiet) printf("Unexpected POLL_IN interrupt.\n");
test_fail(test_string);
}

if (count.hup!=10) {
if (!quiet) printf("POLL_HUP value %d, expected %d.\n",
count.hup,10);
test_fail(test_string);
}

test_pass(test_string);

return 0;
}

0 comments on commit 4cf9f82

Please sign in to comment.