Skip to content

Commit

Permalink
+ For corner cases now print results as OLD/NEW BEHAVIOR
Browse files Browse the repository at this point in the history
+ Add the bugs/nmi_watchdog_group_leader test
+ Release version 0.24
  • Loading branch information
deater committed Feb 16, 2012
1 parent 44b7373 commit 9b649aa
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 108 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
8 September 2011
+ Re-arrange directory structure a bit
+ Add the corner_cases/signal_after_exec test
+ For corner cases now print results as OLD/NEW BEHAVIOR
+ Add the bugs/nmi_watchdog_group_leader test
+ Release version 0.24


10 August 2011
+ Add branches ARM assembly thanks to sam wang.
This turned up a bug in Cortex A9 kernel generalized event.
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
all:
cd lib && make
cd bugs && make
cd corner_cases && make
cd crashes && make
cd generalized_events && make
cd validation && make
Expand All @@ -12,6 +13,7 @@ clean:
rm -rf *~
cd lib && make clean
cd bugs && make clean
cd corner_cases && make clean
cd crashes && make clean
cd generalized_events && make clean
cd validation && make clean
Expand Down
115 changes: 18 additions & 97 deletions bugs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ CC = gcc
CFLAGS = -Wall -O2 -I../include
LFLAGS =

all: sampled_notleader_refresh overflow_requires_mmap \
read_group_attached check_schedulability \
check_papi_multiplexing sync_read_required \
ioctl_refresh_0 context_switch_user_kernel \
wrong_size_enospc signal_after_exec \
test_child
all: \
read_group_attached \
check_schedulability \
check_papi_multiplexing \
sync_read_required \
nmi_watchdog_group_leader

#

Expand All @@ -22,30 +22,6 @@ all: sampled_notleader_refresh overflow_requires_mmap \

###

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

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

###

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

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

###

read_group_attached: read_group_attached.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
Expand Down Expand Up @@ -88,50 +64,6 @@ check_papi_multiplexing.o: check_papi_multiplexing.c

###

context_switch_user_kernel: context_switch_user_kernel.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
../lib/matrix_multiply.o
$(CC) $(LFLAGS) -o context_switch_user_kernel context_switch_user_kernel.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
../lib/matrix_multiply.o

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

###

signal_after_exec: signal_after_exec.o
# ../lib/perf_helpers.o \
# ../lib/test_utils.o \
# ../lib/matrix_multiply.o
$(CC) $(LFLAGS) -o signal_after_exec signal_after_exec.o
# ../lib/perf_helpers.o \
# ../lib/test_utils.o \
# ../lib/matrix_multiply.o

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


###

wrong_size_enospc: wrong_size_enospc.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
../lib/matrix_multiply.o
$(CC) $(LFLAGS) -o wrong_size_enospc wrong_size_enospc.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
../lib/matrix_multiply.o

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


###

sync_read_required: sync_read_required.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
Expand All @@ -146,35 +78,24 @@ sync_read_required.o: sync_read_required.c

###

ioctl_refresh_0: ioctl_refresh_0.o \
nmi_watchdog_group_leader: nmi_watchdog_group_leader.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
../lib/matrix_multiply.o
$(CC) $(LFLAGS) -o ioctl_refresh_0 ioctl_refresh_0.o \
../lib/test_utils.o
$(CC) $(LFLAGS) -o nmi_watchdog_group_leader nmi_watchdog_group_leader.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
../lib/matrix_multiply.o

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


###

test_child: test_child.o
$(CC) $(LFLAGS) -o test_child test_child.o
../lib/test_utils.o

test_child.0: test_child.c
$(CC) $(CFLAGS) -c test_child.c
nmi_watchdog_group_leader.o: nmi_watchdog_group_leader.c
$(CC) $(CFLAGS) -c nmi_watchdog_group_leader.c

###

clean:
rm -f *~ *.o sampled_notleader_refresh overflow_requires_mmap \
read_group_attached check_schedulability \
check_papi_multiplexing sync_read_required \
ioctl_refresh_0 context_switch_user_kernel \
wrong_size_enospc signal_after_exec \
test_child
rm -f *~ *.o \
read_group_attached \
check_schedulability \
check_papi_multiplexing \
sync_read_required \
nmi_watchdog_group_leader


151 changes: 151 additions & 0 deletions bugs/nmi_watchdog_group_leader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* nmi_watchdog_group_leader --- by Vince Weaver vweaver1 _at_ eecs.utk.edu */

/* If the NMI watchdog is enabled it will steal a performance counter. */
/* There is a bug that if you try to use the maximum number of counters */
/* (not counting the stolen one) with a group leader, sys_perf_open() */
/* will indicate success, as will starting the count, but you will fail */
/* at read time. */

/* This bug still exists in 3.x */
/* The perf NMI watchdog was not introduced until 2.6.34 */

/* This also triggers in the case of the schedulability bug */
/* but since that was fixed in 2.6.34 then in theory there is */
/* no overlap in the tests. */

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

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

#include <sys/ioctl.h>
#include <errno.h>

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


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

int events[MAX_TEST_EVENTS];
int fd[MAX_TEST_EVENTS];
int count=MAX_TEST_EVENTS;

int i,j,n;
int ret1,ret2,ret3;

struct perf_event_attr pe;

int quiet,nmi_enabled;
char test_string[]="Testing if NMI watchdog breaks event groups "
"of max size...";

quiet=test_quiet();

if (!quiet) {
printf("If the NMI watchdog is enabled it will steal a performance\n");
printf(" counter. There is a bug that if you try to use the\n");
printf(" maximum number of counters anyway, sys_perf_open()\n");
printf(" will succede but will fail when you try to read()\n");
printf(" the values.\n\n");
}

nmi_enabled=detect_nmi_watchdog();
if (!nmi_enabled) {
if (!quiet) {
printf("No NMI watchdog detected, so skipping test.\n\n");
}
test_skip(test_string);
}

if (copy_events(events)) {
test_unimplemented(test_string);
}

for(i=1;i<count;i++) {

if (!quiet) printf("Trying %d events:\n",i);

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

pe.type=PERF_TYPE_RAW;
pe.size=sizeof(struct perf_event_attr);
pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID;

fd[0]=-1;

for(j=0;j<i;j++) {
pe.config=events[j];

if (j==0) {
pe.disabled=1;
pe.pinned=1;
}
else {
pe.disabled=0;
pe.pinned=0;
}

fd[j]=perf_event_open(&pe,0,-1,fd[0],0);
if (fd[j]<0) {

if (!quiet) printf("Finished after event %d\n\n",j);
test_pass(test_string);
exit(1);
}
}

/* start */
ret1=ioctl(fd[0], PERF_EVENT_IOC_ENABLE,0);

/* stop */
ret2=ioctl(fd[0], PERF_EVENT_IOC_DISABLE,0);


#define BUFFER_SIZE 256
long long buffer[BUFFER_SIZE];

ret3=read(fd[0],buffer,BUFFER_SIZE*sizeof(long long));

if (ret3<=0) {
if (!quiet) {
printf("Unexpected read result %d %s\n",ret3,strerror(errno));
}
test_fail(test_string);
}

if (buffer[0]!=j){
if (!quiet) printf("Error! buffer count is %lld not %d!\n",
buffer[0],j);
test_fail(test_string);
}

if (ret1<0) {
if (!quiet) printf("Error starting!\n");
test_fail(test_string);
}

if (ret2<0) {
if (!quiet) printf("Error stopping!\n");
test_fail(test_string);
}

if (!quiet) {
for(n=0;n<buffer[0];n++) {
printf("\t%x %lld\n",events[n],buffer[1+(n*2)]);
}
}

for(n=0;n<j;n++) {
close(fd[n]);
}
}

test_pass(test_string);

return 0;
}
4 changes: 2 additions & 2 deletions corner_cases/context_switch_user_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ int main(int argc, char **argv) {

/* expected before 2.6.34 */
if ((kernel_count==0) && (user_count!=0)) {
test_yellow_no(test_string);
test_yellow_old_behavior(test_string);
}

/* expected as of 2.6.34 */
if ((kernel_count!=0) && (user_count==0)) {
test_green_yes(test_string);
test_green_new_behavior(test_string);
}

if (!quiet) {
Expand Down
4 changes: 2 additions & 2 deletions corner_cases/overflow_requires_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ int main(int argc, char** argv) {

/* if overflows, then we pass */
if (count>0) {
test_pass(test_string);
test_green_new_behavior(test_string);
}
else {
test_kernel_fail(test_string);
test_yellow_old_behavior(test_string);
}

return 0;
Expand Down
10 changes: 7 additions & 3 deletions corner_cases/signal_after_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
/* On 2.6.39 and earlier the execd process gets no signals */
/* On 3.0 and normal it does, which quickly kills the program with SIGIO */

/* Commit that caused the problem f506b3dc0ec454a16d40cab9ee5d75435b39dc50 */
/* Both before and after behavior are apparently unintentional */

#define _GNU_SOURCE 1

#include <stdio.h>
Expand Down Expand Up @@ -65,7 +68,7 @@ int main(int argc, char** argv) {
struct sigaction sa;
pid_t child;

char test_string[]="Testing to see if overflow signals happen after exec.";
char test_string[]="Testing if overflow signals survive exec...";

quiet=test_quiet();

Expand All @@ -87,10 +90,10 @@ int main(int argc, char** argv) {
}

if (status==0) {
test_pass(test_string);
test_yellow_old_behavior(test_string);
}
else {
test_fail(test_string);
test_green_new_behavior(test_string);
}
exit(0);
}
Expand Down Expand Up @@ -127,6 +130,7 @@ int main(int argc, char** argv) {
fd=perf_event_open(&pe,0,-1,-1,0);
if (fd<0) {
fprintf(stderr,"Error opening\n");
test_fail(test_string);
exit(1);
}

Expand Down
Loading

0 comments on commit 9b649aa

Please sign in to comment.