Skip to content

Commit

Permalink
Add new wakeup_events_overflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Nov 24, 2012
1 parent e6f7f0c commit 94cd167
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
23 November 2012
+ Add wakeup_events_overflow test

21 November 2012
+ Add single-shot overflow test
+ Add single_shot_w_enable
Expand Down
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ echo "* Checking overflow functionality"
./validation/simultaneous_overflow
./validation/single_shot_overflow
./validation/single_shot_w_enable
./validation/wakeup_events_overflow

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


###
Expand Down Expand Up @@ -279,6 +280,18 @@ single_shot_w_enable: single_shot_w_enable.o ../lib/test_utils.o \
single_shot_w_enable.o: single_shot_w_enable.c
$(CC) $(CFLAGS) -c single_shot_w_enable.c

###

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

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


clean:
Expand All @@ -300,5 +313,6 @@ clean:
simultaneous_group_overflow \
simultaneous_overflow \
single_shot_overflow \
single_shot_w_enable
single_shot_w_enable \
wakeup_events_overflow

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

/* Test overflows generated by wakeup events */

#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;

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++;

(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 wakeup events overflow...";

quiet=test_quiet();

if (!quiet) printf("This tests wakeup event overflows.\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_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.sample_period=100000;
pe.watermark=0;
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_ENABLE,0);

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.hup!=0) {
if (!quiet) printf("Unexpected POLL_HUP signal.\n");
test_fail(test_string);
}

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

test_pass(test_string);

return 0;
}

0 comments on commit 94cd167

Please sign in to comment.