Skip to content

Commit

Permalink
Add enable_on_exec test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Aug 9, 2012
1 parent a1a1e95 commit c16af5a
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
9 August 2012
+ Add enable_on_exec test

7 August 2012
+ Add breakpoint test
+ Add some inherit tests
Expand Down
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ echo "* Checking basic perf_event functionality"
./validation/breakpoint_support
./validation/inherit
./validation/inherit_stat
./validation/enable_on_exec

echo
echo "* Checking bugs that PAPI has to work around"
Expand Down
15 changes: 15 additions & 0 deletions validation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LFLAGS =
all: \
breakpoint_support \
check_constraints \
enable_on_exec \
format_id_support \
get_cache_info \
inherit \
Expand Down Expand Up @@ -121,6 +122,19 @@ non-existent: non-existent.o ../lib/test_utils.o \
non-existent.o: non-existent.c
$(CC) $(CFLAGS) -c non-existent.c

###

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

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


###

Expand Down Expand Up @@ -193,6 +207,7 @@ clean:
rm -f *~ *.o \
breakpoint_support \
check_constraints \
enable_on_exec \
format_id_support \
get_cache_info \
inherit \
Expand Down
143 changes: 143 additions & 0 deletions validation/enable_on_exec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* enable_on_exec.c */
/* by Vince Weaver vweaver1 _at_ eecs.utk.edu */

/* Test if the enable_on_exec flag works */

#define _GNU_SOURCE 1

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

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

#include <sys/ioctl.h>


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


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

int fd,ret,quiet;
int result;
int read_result;
long long count;

struct perf_event_attr pe;

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

char fd_string[BUFSIZ];

quiet=test_quiet();

/* Firxt exec, without enable_on_exec */
if (argc==2) {

fd=atoi(argv[1]);

if (!quiet) {
printf("\tWe've been exec'd without enable_on_exec, fd=%d!\n",fd);
}

result=instructions_million();
if (result==CODE_UNIMPLEMENTED) printf("Warning, no million\n");

read_result=read(fd,&count,sizeof(long long));
if (read_result!=sizeof(long long)) printf("Unexpected read size\n");

if (!quiet) printf("\tCounted %lld instructions\n",count);

close(fd);

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.disabled=1;
pe.exclude_kernel=1;
pe.enable_on_exec=1;

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

if (count!=0) test_fail(test_string);

sprintf(fd_string,"%d",fd);

/* exec ourselves, but with two arguments to change behavior */
execl(argv[0],argv[0],fd_string,fd_string,NULL);

}


/* Second exec, with enable_on_exec */
if (argc==3) {

fd=atoi(argv[1]);

if (!quiet) {
printf("\tWe've been exec'd with enable_on_exec, fd=%d!\n",fd);
}

result=instructions_million();
if (result==CODE_UNIMPLEMENTED) printf("Warning, no million\n");

read_result=read(fd,&count,sizeof(long long));
if (read_result!=sizeof(long long)) printf("Unexpected read size\n");

if (!quiet) printf("\tCounted %lld instructions\n",count);

close(fd);

if (count==0) test_fail(test_string);

test_pass(test_string);

return 0;

}


if (!quiet) {
printf("Testing if enable_on_exec works as expected.\n");
}

/* setup perf-event */

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.disabled=1;
pe.exclude_kernel=1;
pe.enable_on_exec=0;

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

sprintf(fd_string,"%d",fd);


/* exec ourselves, but with an argument to change behavior */
execl(argv[0],argv[0],fd_string,NULL);

(void) ret;

return 0;
}

0 comments on commit c16af5a

Please sign in to comment.