Skip to content

Commit

Permalink
Add hw_sw_mix test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Mar 13, 2013
1 parent 13a99f3 commit bec1faa
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
29 January 2012
13 March 2013
+ Add hw_sw_mix test

29 January 2013
+ Add sw_start_leader test

27 November 2012
Expand Down
17 changes: 17 additions & 0 deletions corner_cases/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LFLAGS =
all: \
check_reset_mpx \
context_switch_user_kernel \
hw_sw_mix \
ioctl_refresh_0 \
max_multiplex \
multiple_active \
Expand Down Expand Up @@ -139,6 +140,21 @@ signal_after_exec.o: signal_after_exec.c

###

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

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


###

sw_start_leader: sw_start_leader.o \
../lib/perf_helpers.o \
../lib/test_utils.o \
Expand Down Expand Up @@ -189,6 +205,7 @@ clean:
rm -f *~ *.o \
check_reset_mpx \
context_switch_user_kernel \
hw_sw_mix \
ioctl_refresh_0 \
max_multiplex \
multiple_active \
Expand Down
124 changes: 124 additions & 0 deletions corner_cases/hw_sw_mix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* hw_sw_mix.c */
/* by Vince Weaver vincent.weaver _at_ maine.edu */

/* Tests if mixes of hardware and software events work */
/* especially for the problem case where the group leader */
/* is not a hardware event. */

/* Based on a test by Jiri Olsa */

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

#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,e;

struct perf_event_attr pe[EVENTS];

char test_string[]="Testing mixes of HW an SW events...";

quiet=test_quiet();

if (!quiet) {
printf("Testing mixes of HW and SW events if group leader is SW.\n");
printf("This is known to be broken through 3.9\n");
}

if (!quiet) printf("Testing with: ");
for(e=0;e<(1<<EVENTS);e++) {

for(i=0;i<EVENTS;i++) {
memset(&pe[i],0,sizeof(struct perf_event_attr));
pe[i].size=sizeof(struct perf_event_attr);

if (e&(1<<i)) {
pe[i].type=PERF_TYPE_HARDWARE;
pe[i].config=PERF_COUNT_HW_CPU_CYCLES;
if (!quiet) printf("H");
}
else {
pe[i].type=PERF_TYPE_SOFTWARE;
pe[i].config=PERF_COUNT_SW_TASK_CLOCK;
if (!quiet) printf("S");
}

if (i==0) {
pe[i].disabled=1;
}

pe[i].exclude_kernel=1;
pe[i].read_format=PERF_FORMAT_GROUP;

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

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) {
if (!quiet) printf("Unexpected read size\n");
test_fail(test_string);
}

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

for(i=0;i<EVENTS;i++) {
if (count[i]==0) {
if (!quiet) {
fprintf(stderr,"Counter %d did not start as expected\n",i);
}
test_fail(test_string);
}
}

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 @@ -63,6 +63,7 @@ echo "* Checking bugs that PAPI has to work around"
echo
echo "* Checking other bugs"
./corner_cases/sw_start_leader
./corner_cases/hw_sw_mix

echo
echo "* Checking bugs that can silently produce wrong results"
Expand Down

0 comments on commit bec1faa

Please sign in to comment.