Skip to content

Commit

Permalink
add ioctl_flag_group test
Browse files Browse the repository at this point in the history
This tests the PERF_IOC_FLAG_GROUP paramater

I was somehow unaware of this until recently
  • Loading branch information
deater committed Jun 28, 2013
1 parent e312934 commit d898816
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
28 June 2013
+ Add ioctl_flag_group test
+ Add nmi_soft_lockup_test

+ All the fuzzer stuff
Expand Down
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ echo "* Checking basic perf_event functionality"
./validation/inherit
./validation/inherit_stat
./validation/enable_on_exec
./validation/ioctl_flag_group

echo
echo "* Checking overflow functionality"
Expand Down
16 changes: 16 additions & 0 deletions validation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ all: \
get_cache_info \
inherit \
inherit_stat \
ioctl_flag_group \
non-existent \
offcore_response \
offcore_response_mask \
Expand Down Expand Up @@ -124,6 +125,20 @@ inherit_stat.o: inherit_stat.c
$(CC) $(CFLAGS) -c inherit_stat.c


###

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

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



###

Expand Down Expand Up @@ -202,6 +217,7 @@ clean:
get_cache_info \
inherit \
inherit_stat \
ioctl_flag_group \
non-existent \
offcore_response \
offcore_response_mask \
Expand Down
321 changes: 321 additions & 0 deletions validation/ioctl_flag_group.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
/* ioctl_flag_group.c */
/* Test the PERF_IOC_FLAG_GROUP ioctl parameter */

/* by Vince Weaver vincent.weaver _at_ maine.edu */


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

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

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

char test_string[]="Testing PERF_IOC_FLAG_GROUP...";

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

int fd[2];
int quiet;
int read_result;
long long insn_count,cycles_count;
int error=0;

struct perf_event_attr pe;

quiet=test_quiet();

if (!quiet) {
printf("This test the PERF_IOC_FLAG_GROUP ioctl parameter.\n\n");
}

/**********************************************/
/* With ENABLE/DISABLE on GROUP LEADER with 0 */
/**********************************************/

if (!quiet) {
printf("Testing on GROUP LEADER with param 0\n");
}

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_CPU_CYCLES;
pe.disabled=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

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

instructions_million();

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

read_result=read(fd[0],&insn_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

read_result=read(fd[1],&cycles_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd[0]);
close(fd[1]);

if (!quiet) {
printf("\t%lld instructions\n",insn_count);
printf("\t%lld cycles\n",cycles_count);
}

if ((insn_count<100) || (cycles_count<100)) {
fprintf(stderr,"Error! Should have values for insn and cycles\n");
error++;
}

/*****************************************************************/
/* With ENABLE/DISABLE on GROUP LEADER with PERF_IOC_FLAG_GROUP */
/*****************************************************************/

if (!quiet) {
printf("Testing on GROUP LEADER with param PERF_IOC_FLAG_GROUP\n");
}

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_CPU_CYCLES;
pe.disabled=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

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

instructions_million();

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

read_result=read(fd[0],&insn_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

read_result=read(fd[1],&cycles_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd[0]);
close(fd[1]);


if (!quiet) {
printf("\t%lld instructions\n",insn_count);
printf("\t%lld cycles\n",cycles_count);
}

if ((insn_count<100) || (cycles_count<100)) {
fprintf(stderr,"Error! Should have values for insn and cycles\n");
error++;
}


/**********************************************/
/* With ENABLE/DISABLE on non-group-leader with 0 */
/**********************************************/

if (!quiet) {
printf("Testing non-leader with param 0\n");
}

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_CPU_CYCLES;
pe.disabled=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

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

instructions_million();

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

read_result=read(fd[0],&insn_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

read_result=read(fd[1],&cycles_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd[0]);
close(fd[1]);

if (!quiet) {
printf("\t%lld instructions\n",insn_count);
printf("\t%lld cycles\n",cycles_count);
}

if ((insn_count>100) || (cycles_count>100)) {
fprintf(stderr,"Error! Should have 0 for insn and cycles\n");
error++;
}


/**************************************************************/
/* With ENABLE/DISABLE on non-leader with PERF_IOC_FLAG_GROUP */
/**************************************************************/

if (!quiet) {
printf("Testing on non-leader with param PERF_IOC_FLAG_GROUP\n");
}

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

pe.type=PERF_TYPE_HARDWARE;
pe.config=PERF_COUNT_HW_CPU_CYCLES;
pe.disabled=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

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

ioctl(fd[1], PERF_EVENT_IOC_RESET, PERF_IOC_FLAG_GROUP);
ioctl(fd[1], PERF_EVENT_IOC_ENABLE,PERF_IOC_FLAG_GROUP);

instructions_million();

ioctl(fd[1], PERF_EVENT_IOC_DISABLE,PERF_IOC_FLAG_GROUP);

read_result=read(fd[0],&insn_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

read_result=read(fd[1],&cycles_count,sizeof(long long));

if (read_result!=sizeof(long long)) {
fprintf(stderr,"\tImproper return from read: %d\n",read_result);
test_fail(test_string);
}

close(fd[0]);
close(fd[1]);


if (!quiet) {
printf("\t%lld instructions\n",insn_count);
printf("\t%lld cycles\n",cycles_count);
}

if ((insn_count<100) || (cycles_count<100)) {
fprintf(stderr,"Error! Should have values for insn and cycles\n");
error++;
}

if (error) {
test_fail(test_string);
}

test_pass(test_string);

return 0;
}

0 comments on commit d898816

Please sign in to comment.