forked from deater/perf_event_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |