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.
tests: add tests/error_returns/e2big test
- Loading branch information
Showing
5 changed files
with
186 additions
and
2 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
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,41 @@ | ||
CC = gcc | ||
CFLAGS = -Wall -O2 -g -I../../include | ||
LFLAGS = | ||
LIB = ../../lib | ||
|
||
all: \ | ||
e2big | ||
|
||
### | ||
|
||
$(LIB)/test_utils.o: $(LIB)/test_utils.c | ||
cd $(LIB) && make | ||
|
||
$(LIB)/branches_testcode.o: $(LIB)/branches_testcode.c | ||
cd $(LIB) && make | ||
|
||
$(LIB)/matrix_multiply.o: $(LIB)/matrix_multiply.c | ||
cd $(LIB) && make | ||
|
||
$(LIB)/perf_helpers.o: $(LIB)/perf_helpers.c | ||
cd $(LIB) && make | ||
|
||
$(LIB)/detect_cache.o: $(LIB)/detect_cache.c | ||
cd $(LIB) && make | ||
|
||
### | ||
|
||
e2big: e2big.o $(LIB)/test_utils.o \ | ||
$(LIB)/perf_helpers.o | ||
$(CC) $(LFLAGS) -o e2big e2big.o \ | ||
$(LIB)/test_utils.o \ | ||
$(LIB)/perf_helpers.o | ||
|
||
e2big.o: e2big.c | ||
$(CC) $(CFLAGS) -c e2big.c | ||
|
||
### | ||
|
||
clean: | ||
rm -f *~ *.o \ | ||
e2big |
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,131 @@ | ||
/* e2big.c */ | ||
/* Tests to see if E2BIG properly returned by perf_event_open() */ | ||
|
||
/* By Vince Weaver vincent.weaver _at_ maine.edu */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <signal.h> | ||
|
||
#include <errno.h> | ||
|
||
#include "perf_event.h" | ||
#include "perf_helpers.h" | ||
#include "test_utils.h" | ||
|
||
int main(int argc, char **argv) { | ||
|
||
int fd,i; | ||
struct perf_event_attr *pe; | ||
char *pointer; | ||
int errors=0; | ||
int quiet; | ||
int expected_size=0; | ||
|
||
char test_string[]="Testing E2BIG errors..."; | ||
|
||
quiet=test_quiet(); | ||
|
||
if (!quiet) { | ||
printf("This tests various size values and checks that\n"); | ||
printf("E2BIG is properly returned.\n\n"); | ||
} | ||
|
||
pointer=calloc(getpagesize()*3,sizeof(char)); | ||
|
||
pe=(struct perf_event_attr *)pointer; | ||
|
||
for(i=0;i<getpagesize()*2;i++) { | ||
|
||
memset(pointer,0,getpagesize()*3); | ||
|
||
pe->type=PERF_TYPE_HARDWARE; | ||
pe->size=i; | ||
pe->config=PERF_COUNT_HW_INSTRUCTIONS; | ||
|
||
fd=perf_event_open(pe, | ||
0, /* current thread */ | ||
-1, /* any cpu */ | ||
-1, /* New Group Leader */ | ||
0 /*0*/ ); | ||
|
||
if (fd<0) { | ||
if (errno==E2BIG) { | ||
if ((i==0) || | ||
((i>=PERF_ATTR_SIZE_VER0) && | ||
(i<=getpagesize()))) { | ||
if (!quiet) { | ||
printf("Unexpected failure with size %d\n",i); | ||
} | ||
errors++; | ||
} | ||
expected_size=pe->size; | ||
|
||
} | ||
else { | ||
if (!quiet) { | ||
printf("Unknown failure with size %d: %s\n", | ||
i,strerror(errno)); | ||
} | ||
errors++; | ||
} | ||
|
||
} | ||
else { | ||
if ((i==0) || | ||
((i>=PERF_ATTR_SIZE_VER0) && | ||
(i<=getpagesize()))) { | ||
/* good */ | ||
} else { | ||
if (!quiet) { | ||
printf("Unexpected success with size %d\n",i); | ||
} | ||
errors++; | ||
} | ||
close(fd); | ||
} | ||
|
||
} | ||
|
||
|
||
// printf("Expected: %d\n",expected_size); | ||
|
||
/* Check if it works with too big size but garbage after */ | ||
|
||
pe->size=expected_size+8; | ||
pointer[expected_size+4]=0xff; | ||
|
||
fd=perf_event_open(pe, | ||
0, /* current thread */ | ||
-1, /* any cpu */ | ||
-1, /* New Group Leader */ | ||
0 /*0*/ ); | ||
|
||
if (fd<0) { | ||
if (errno==E2BIG) { | ||
/* good */ | ||
} | ||
else { | ||
printf("Unexpected error: %s\n",strerror(errno)); | ||
errors++; | ||
} | ||
} | ||
else { | ||
if (!quiet) { | ||
printf("Unexpected success when non-zero present\n"); | ||
printf("Past end of file!\n"); | ||
} | ||
errors++; | ||
close(fd); | ||
} | ||
|
||
if (errors) { | ||
test_fail(test_string); | ||
} | ||
else { | ||
test_pass(test_string); | ||
} | ||
return 0; | ||
} |