Skip to content

Commit

Permalink
tests: add exclusive bit test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Dec 18, 2013
1 parent 1bed0bb commit 51ac0f2
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
18 December 2013
+ re-arrange a lot of files
+ Fix some tests on ARM
+ add "exclusive" test

28 October 2013
+ Add ioctl_period test

Expand Down
3 changes: 3 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ $TESTS_DIR/breakpoints/breakpoint_support

echo
echo "* Checking basic perf_event functionality"
echo " + $TESTS_DIR/attr_fields/exclusive"
echo -n " "
$TESTS_DIR/attr_fields/exclusive
echo " + $TESTS_DIR/attr_fields/format_id_support"
echo -n " "
$TESTS_DIR/attr_fields/format_id_support
Expand Down
15 changes: 15 additions & 0 deletions tests/attr_fields/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LIB = ../../lib

all: \
enable_on_exec \
exclusive \
format_id_support \
inherit \
inherit_stat
Expand Down Expand Up @@ -65,6 +66,19 @@ enable_on_exec: enable_on_exec.o $(LIB)/test_utils.o \
enable_on_exec.o: enable_on_exec.c
$(CC) $(CFLAGS) -c enable_on_exec.c

###

exclusive: exclusive.o $(LIB)/test_utils.o \
$(LIB)/perf_helpers.o \
$(LIB)/instructions_testcode.o
$(CC) $(LFLAGS) -o exclusive exclusive.o \
$(LIB)/test_utils.o \
$(LIB)/perf_helpers.o \
$(LIB)/instructions_testcode.o

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


###

Expand All @@ -86,6 +100,7 @@ format_id_support.o: format_id_support.c
clean:
rm -f *~ *.o \
enable_on_exec \
exclusive \
format_id_support \
inherit \
inherit_stat
Expand Down
135 changes: 135 additions & 0 deletions tests/attr_fields/exclusive.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* exclusive.c */
/* Test if the exclusive bit works */
/* It doesn't do useful things for most machines */
/* As the NMI watchdog is running and keeps exclusive */
/* eventsets from running. */

/* by Vince Weaver [email protected] */

#define _GNU_SOURCE 1

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

#include <unistd.h>
#include <fcntl.h>

#include <errno.h>

#include <signal.h>

#include <sys/mman.h>

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

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

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

int ret,fd1,quiet,i;
int result;
int nmi_enabled;

struct perf_event_attr pe;

char test_string[]="Testing exclusive eventsets...";

quiet=test_quiet();

if (!quiet) {
printf("Testing exclusive eventsets.\n");
}

nmi_enabled=detect_nmi_watchdog();

/* set up group leader */
memset(&pe,0,sizeof(struct perf_event_attr));
pe.type=PERF_TYPE_HARDWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.disabled=1;
pe.pinned=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

pe.exclusive=1;

arch_adjust_domain(&pe,quiet);

fd1=perf_event_open(&pe,0,-1,-1,0);
if (fd1<0) {
if (!quiet) {
fprintf(stderr,"Error opening leader %llx\n",pe.config);
}
test_fail(test_string);
}

ioctl(fd1, PERF_EVENT_IOC_RESET, 0);

/* enable counting */
ret=ioctl(fd1, PERF_EVENT_IOC_ENABLE,0);

instructions_million();

/* disable counting */
ret=ioctl(fd1, PERF_EVENT_IOC_DISABLE,0);
if (ret<0) {
if (!quiet) printf("Error disabling\n");
}

#define BUFFER_SIZE 1
long long buffer[BUFFER_SIZE];
for(i=0;i<BUFFER_SIZE;i++) {
buffer[i]=-1;
}

result=read(fd1,buffer,BUFFER_SIZE*sizeof(long long));
if (result<0) {
fprintf(stderr,"Unexpected read result %d\n",result);
test_fail(test_string);
}

if (result!=sizeof(long long)) {
fprintf(stderr,"Unexpected read result %d\n",result);
test_fail(test_string);
}

if (!quiet) {
printf("NMI watchdog enabled: %d\n",nmi_enabled);
printf("Value [%d] : %lld\n",0,buffer[0]);
}


/* If nmi watchdog enabled, should fail */
if (nmi_enabled) {
if (buffer[0]!=0) {
if (!quiet) {
fprintf(stderr,"Unexpectedly able to run events\n");
}
test_fail(test_string);
}
}
else {
if (buffer[0]==0) {

if (!quiet) {
fprintf(stderr,"Eventset creation failed for unknown reason\n");
fprintf(stderr,"Is the kernel using an event? Is another user?\n");
}
test_fail(test_string);
}

}


test_pass(test_string);

return 0;
}

0 comments on commit 51ac0f2

Please sign in to comment.