Skip to content

Commit

Permalink
tests: add tests/error_returns/e2big test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Oct 11, 2013
1 parent 71ba413 commit 83b9083
Show file tree
Hide file tree
Showing 5 changed files with 186 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 @@
11 October 2013
+ Add tests/errors/e2big

18 September 2013
+ Fix breakpoint_support test that was broken by too-clever gcc 4.8
+ Release version 0.28
Expand Down
6 changes: 6 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ echo " + $TESTS_DIR/ioctl/ioctl_id"
echo -n " "
$TESTS_DIR/ioctl/ioctl_id

echo
echo "* Checking error returns"
echo " + $TESTS_DIR/errors/e2big"
echo -n " "
$TESTS_DIR/errors/e2big

echo
echo "* Checking overflow functionality"
echo " + $TESTS_DIR/overflow/breakpoint_overflow"
Expand Down
41 changes: 41 additions & 0 deletions tests/error_returns/Makefile
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
7 changes: 5 additions & 2 deletions tests/error_returns/README
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ ENOENT
Invalid attr.type setting
ENOSYS
PERF_SOUREC_STACK_TRACE not supported
E2BIG
attr structure bigger than expected and non-zero
EOPNOTSUPP
PMU interrupt not available and requested sampling
Request branch tracing and not available
Expand All @@ -30,3 +28,8 @@ EBUSY
EAGAIN
ENOMEM
Kernel failed while allocating memory
E2BIG
size value too low (below PERF_ATTR_SIZE_VER0 but 0 is OK)
size value too high (above pagesize)
size value high and padding is non-zero

131 changes: 131 additions & 0 deletions tests/error_returns/e2big.c
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;
}

0 comments on commit 83b9083

Please sign in to comment.