Skip to content

Commit

Permalink
Add some inherit and inherit_stat tests
Browse files Browse the repository at this point in the history
Fairly simple for now, and still not sure how inherit_stat
really differs.
  • Loading branch information
deater committed Aug 7, 2012
1 parent fec79d7 commit f2959ab
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
7 August 2012
+ Add breakpoint test
+ Add some inherit tests

13 July 2012
+ Fix rdpmc tests to not segfault if support not in kernel
Expand Down
2 changes: 2 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ echo "* Checking basic perf_event functionality"
./validation/format_id_support
./validation/non-existent
./validation/breakpoint_support
./validation/inherit
./validation/inherit_stat

echo
echo "* Checking bugs that PAPI has to work around"
Expand Down
29 changes: 28 additions & 1 deletion validation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ all: \
check_constraints \
format_id_support \
get_cache_info \
inherit \
inherit_stat \
non-existent \
offcore_response \
rdpmc_support \
Expand Down Expand Up @@ -47,7 +49,6 @@ offcore_response.o: offcore_response.c

###


breakpoint_support: breakpoint_support.o ../lib/test_utils.o \
../lib/perf_helpers.o
$(CC) $(LFLAGS) -o breakpoint_support breakpoint_support.o \
Expand Down Expand Up @@ -83,6 +84,30 @@ get_cache_info: get_cache_info.o ../lib/test_utils.o \
get_cache_info.o: get_cache_info.c
$(CC) $(CFLAGS) -c get_cache_info.c

###

inherit: inherit.o ../lib/test_utils.o \
../lib/perf_helpers.o
$(CC) $(LFLAGS) -o inherit inherit.o \
../lib/test_utils.o \
../lib/perf_helpers.o -lpthread

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

###

inherit_stat: inherit_stat.o ../lib/test_utils.o \
../lib/perf_helpers.o
$(CC) $(LFLAGS) -o inherit_stat inherit_stat.o \
../lib/test_utils.o \
../lib/perf_helpers.o -lpthread

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



###

non-existent: non-existent.o ../lib/test_utils.o \
Expand Down Expand Up @@ -170,6 +195,8 @@ clean:
check_constraints \
format_id_support \
get_cache_info \
inherit \
inherit_stat \
non-existent \
offcore_response \
rdpmc_support \
Expand Down
149 changes: 149 additions & 0 deletions validation/inherit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* inherit.c */
/* simple test of the inherit flag */

/* by Vince Weaver vweaver1 _at_ eecs.utk.edu */


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

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

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

int fd;


void *thread_work(void *blah) {

return NULL;
}


char test_string[]="Testing inherit...";

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

int j;
int quiet;
pthread_t our_thread[8];
int read_result;
long long inherit_count,count;

struct perf_event_attr pe;

quiet=test_quiet();

if (!quiet) {
printf("This test checks inherit functionality.\n");
printf("Starting and stopping 8 threads\n");
}

/*************************/
/* With inherit set */
/*************************/

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.inherit=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;

fd=perf_event_open(&pe,0,-1,-1,0);
if (fd<0) {
fprintf(stderr,"Error opening\n");
exit(1);
}

ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE,0);


for(j=0;j<8;j++) {
pthread_create(&our_thread[j],NULL,thread_work,0);
}

for(j=0;j<8;j++) {
pthread_join(our_thread[j],NULL);
}

ioctl(fd, PERF_EVENT_IOC_DISABLE,0);

read_result=read(fd,&inherit_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd);

/****************************/
/* Without inherit set */
/****************************/

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.inherit=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

fd=perf_event_open(&pe,0,-1,-1,0);
if (fd<0) {
fprintf(stderr,"Error opening\n");
exit(1);
}

ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE,0);


for(j=0;j<8;j++) {
pthread_create(&our_thread[j],NULL,thread_work,0);
}

for(j=0;j<8;j++) {
pthread_join(our_thread[j],NULL);
}

ioctl(fd, PERF_EVENT_IOC_DISABLE,0);

read_result=read(fd,&count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd);

if (!quiet) {

printf("\tFound %lld instructions with inherit enabled\n",
inherit_count);
printf("\tFound %lld instructions with inherit disabled\n",
count);

}

if ((inherit_count < 6*count) || (inherit_count > 9*count)) {
fprintf(stderr,"\tInherit count unexpected.\n");
test_fail(test_string);
}

test_pass(test_string);

return 0;
}
149 changes: 149 additions & 0 deletions validation/inherit_stat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* inherit_stat.c */
/* Find out what the inherit_stat flag does */

/* by Vince Weaver vweaver1 _at_ eecs.utk.edu */


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

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

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

int fd;


void *thread_work(void *blah) {

return NULL;
}


char test_string[]="Testing inherit_stat...";

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

int j;
int quiet;
pthread_t our_thread[8];
int read_result;
long long inherit_count,count;

struct perf_event_attr pe;

quiet=test_quiet();

if (!quiet) {
printf("This test checks inherit_stat functionality.\n");
printf("Starting and stopping 8 threads\n");
}

/*************************/
/* With inherit_stat set */
/*************************/

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.inherit_stat=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;

fd=perf_event_open(&pe,0,-1,-1,0);
if (fd<0) {
fprintf(stderr,"Error opening\n");
exit(1);
}

ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE,0);


for(j=0;j<8;j++) {
pthread_create(&our_thread[j],NULL,thread_work,0);
}

for(j=0;j<8;j++) {
pthread_join(our_thread[j],NULL);
}

ioctl(fd, PERF_EVENT_IOC_DISABLE,0);

read_result=read(fd,&inherit_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd);

/****************************/
/* Without inherit_stat set */
/****************************/

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.inherit_stat=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

fd=perf_event_open(&pe,0,-1,-1,0);
if (fd<0) {
fprintf(stderr,"Error opening\n");
exit(1);
}

ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE,0);


for(j=0;j<8;j++) {
pthread_create(&our_thread[j],NULL,thread_work,0);
}

for(j=0;j<8;j++) {
pthread_join(our_thread[j],NULL);
}

ioctl(fd, PERF_EVENT_IOC_DISABLE,0);

read_result=read(fd,&count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd);

if (!quiet) {

printf("\tFound %lld instructions with inherit_stat enabled\n",
inherit_count);
printf("\tFound %lld instructions with inherit_stat disabled\n",
count);

}

if ((inherit_count < 6*count) || (inherit_count > 9*count)) {
fprintf(stderr,"\tInherit count unexpected.\n");
test_fail(test_string);
}

test_pass(test_string);

return 0;
}

0 comments on commit f2959ab

Please sign in to comment.