PAPI  5.7.0.0
papi_br_ucn.c
Go to the documentation of this file.
1 /* This file attempts to test the unconditional branch instruction */
2 /* performance counter PAPI_BR_UCN */
3 
4 /* by Vince Weaver, <vincent.weaver@maine.edu> */
5 
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <string.h>
10 
11 #include "papi.h"
12 #include "papi_test.h"
13 
14 #include "display_error.h"
15 #include "testcode.h"
16 
17 
18 int main(int argc, char **argv) {
19 
20  int num_runs=100,i;
21  long long high=0,low=0,average=0,expected=500000;
22  double error;
23 
24  long long count,total=0;
25  int quiet=0,retval,ins_result;
26  int eventset=PAPI_NULL;
27 
28  quiet=tests_quiet(argc,argv);
29 
30  if (!quiet) {
31  printf("\nTesting the PAPI_BR_UCN event.\n");
32  }
33 
34  /* Init the PAPI library */
36  if ( retval != PAPI_VER_CURRENT ) {
37  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
38  }
39 
40  retval=PAPI_create_eventset(&eventset);
41  if (retval!=PAPI_OK) {
42  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
43  }
44 
45  retval=PAPI_add_named_event(eventset,"PAPI_BR_UCN");
46  if (retval!=PAPI_OK) {
47  test_skip( __FILE__, __LINE__, "adding PAPI_BR_UCN", retval );
48  }
49 
50  if (!quiet) {
51  printf("Testing a loop with %lld unconditional branches (%d times):\n",
52  expected,num_runs);
53  }
54 
55  for(i=0;i<num_runs;i++) {
56  PAPI_reset(eventset);
57  PAPI_start(eventset);
58 
59  ins_result=branches_testcode();
60 
61  retval=PAPI_stop(eventset,&count);
62 
63  if (ins_result==CODE_UNIMPLEMENTED) {
64  fprintf(stderr,"\tCode unimplemented\n");
65  test_skip( __FILE__, __LINE__, "unimplemented", 0);
66  }
67 
68  if (retval!=PAPI_OK) {
69  test_fail( __FILE__, __LINE__,
70  "reading PAPI_TOT_INS", retval );
71  }
72 
73  if (count>high) high=count;
74  if ((low==0) || (count<low)) low=count;
75  total+=count;
76  }
77 
78  average=(total/num_runs);
79 
80  error=display_error(average,high,low,expected,quiet);
81 
82  if ((error > 1.0) || (error<-1.0)) {
83  if (!quiet) printf("Instruction count off by more than 1%%\n");
84  test_fail( __FILE__, __LINE__, "Error too high", 1 );
85  }
86 
87  if (!quiet) printf("\n");
88 
89  test_pass( __FILE__ );
90 
91  PAPI_shutdown();
92 
93  return 0;
94 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
static int expected[NUM_THREADS]
int PAPI_reset(int EventSet)
Definition: papi.c:2459
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int PAPI_library_init(int version)
Definition: papi.c:500
void PAPI_shutdown(void)
Definition: papi.c:4461
int quiet
Definition: rapl_overflow.c:18
int main(int argc, char **argv)
Definition: papi_br_ucn.c:18
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int branches_testcode(void)
static int total
Definition: rapl_overflow.c:9
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long count
int i
Definition: fileop.c:140