Skip to content

Commit

Permalink
Add reset_leader test
Browse files Browse the repository at this point in the history
This tests to see if reseting the group leader resets
children.
  • Loading branch information
deater committed Aug 16, 2012
1 parent ac236d7 commit 41c880e
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
16 August 2012
+ Add reset_leader test

9 August 2012
+ Add enable_on_exec test

Expand Down
41 changes: 29 additions & 12 deletions corner_cases/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ CFLAGS = -Wall -O2 -I../include
LFLAGS =

all: \
sampled_notleader_refresh \
overflow_requires_mmap \
ioctl_refresh_0 \
context_switch_user_kernel \
wrong_size_enospc \
signal_after_exec \
ioctl_refresh_0 \
max_multiplex \
multiple_active \
max_multiplex
overflow_requires_mmap \
reset_leader \
sampled_notleader_refresh \
signal_after_exec \
wrong_size_enospc \


#

Expand Down Expand Up @@ -49,6 +51,20 @@ sampled_notleader_refresh.o: sampled_notleader_refresh.c

###

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

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

###

context_switch_user_kernel: context_switch_user_kernel.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
Expand Down Expand Up @@ -139,11 +155,12 @@ ioctl_refresh_0.o: ioctl_refresh_0.c

clean:
rm -f *~ *.o \
sampled_notleader_refresh \
overflow_requires_mmap \
ioctl_refresh_0 \
context_switch_user_kernel \
wrong_size_enospc \
signal_after_exec \
ioctl_refresh_0 \
max_multiplex \
multiple_active \
max_multiplex
overflow_requires_mmap \
reset_leader \
sampled_notleader_refresh \
signal_after_exec \
wrong_size_enospc
172 changes: 172 additions & 0 deletions corner_cases/reset_leader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/* reset_leader.c */
/* by Vince Weaver vweaver1 _at_ eecs.utk.edu */

/* Test if calling reset on a leader resets all child events */

#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"


#define EVENTS 2

#define READ_SIZE (EVENTS + 1)

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

int fd[EVENTS],ret,quiet;
int result;
int read_result;
long long count[READ_SIZE];
int i;

struct perf_event_attr pe[EVENTS];

char test_string[]="Testing reset on group leader...";

quiet=test_quiet();

if (!quiet) {
printf("Testing if reset on group leader resets children.\n");
}

/* setup instruction event, group leader */

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

pe[0].type=PERF_TYPE_HARDWARE;
pe[0].size=sizeof(struct perf_event_attr);
pe[0].config=PERF_COUNT_HW_INSTRUCTIONS;
pe[0].disabled=1;
pe[0].exclude_kernel=1;
pe[0].read_format=PERF_FORMAT_GROUP;

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

/* setup cycles event, group child */

memset(&pe[1],0,sizeof(struct perf_event_attr));

pe[1].type=PERF_TYPE_HARDWARE;
pe[1].size=sizeof(struct perf_event_attr);
pe[1].config=PERF_COUNT_HW_CPU_CYCLES;
pe[1].disabled=0;
pe[1].exclude_kernel=1;

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

ioctl(fd[0], PERF_EVENT_IOC_RESET, 0);
ioctl(fd[0], PERF_EVENT_IOC_ENABLE,0);

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

ioctl(fd[0], PERF_EVENT_IOC_DISABLE,0);

read_result=read(fd[0],&count,sizeof(long long)*READ_SIZE);
if (read_result!=sizeof(long long)*READ_SIZE) {
printf("Unexpected read size\n");
}

if (!quiet) {
printf("Initial read\n");
for(i=0;i<count[0];i++) {
printf("\t%i Counted %lld\n",i,count[1+i]);
}
}

read_result=read(fd[0],&count,sizeof(long long)*READ_SIZE);
if (read_result!=sizeof(long long)*READ_SIZE) {
printf("Unexpected read size\n");
}

if (!quiet) {
printf("Second read, to be sure\n");
for(i=0;i<count[0];i++) {
printf("\t%i Counted %lld\n",i,count[1+i]);
}
}

ioctl(fd[0], PERF_EVENT_IOC_RESET, 0);

read_result=read(fd[0],&count,sizeof(long long)*READ_SIZE);
if (read_result!=sizeof(long long)*READ_SIZE) {
printf("Unexpected read size\n");
}

if (count[1]!=0) {
fprintf(stderr,"Reset of event 0 did not work\n");
test_fail(test_string);
}

if (count[2]==0) {
fprintf(stderr,"Reset of leader cleared child\n");
test_fail(test_string);
}

if (!quiet) {
printf("After reset of group leader\n");
for(i=0;i<count[0];i++) {
printf("\t%i Counted %lld\n",i,count[1+i]);
}
}


ioctl(fd[1], PERF_EVENT_IOC_RESET, 0);

read_result=read(fd[0],&count,sizeof(long long)*READ_SIZE);
if (read_result!=sizeof(long long)*READ_SIZE) {
printf("Unexpected read size\n");
}

if (count[1]!=0) {
fprintf(stderr,"Reset of event 0 did not work\n");
test_fail(test_string);
}

if (count[2]!=0) {
fprintf(stderr,"Reset of child did not work\n");
test_fail(test_string);
}

if (!quiet) {
printf("After reset of group child\n");
for(i=0;i<count[0];i++) {
printf("\t%i Counted %lld\n",i,count[1+i]);
}
}


for(i=0;i<EVENTS;i++) {
close(fd[i]);
}

(void) ret;

test_pass(test_string);

return 0;
}
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ echo "* Checking for corner-cases in the ABI (not necessarily bugs)"
./corner_cases/signal_after_exec
./corner_cases/multiple_active
./corner_cases/max_multiplex
./corner_cases/reset_leader

echo
echo "* Checking for experimental new functionality"
Expand Down

0 comments on commit 41c880e

Please sign in to comment.