20 {
21
23 int num_random_branches=500000;
24 long long high=0,low=0,average=0,
expected=1500000;
25
29
31
33 printf("\nTesting the PAPI_BR_MSP event.\n");
34 }
35
36
40 }
41
42
46 }
47
50 if (!
quiet) printf(
"Could not add PAPI_BR_INS\n");
52 }
53
54
58 }
59
63 }
64
66 printf("\nPart 1: Testing that easy to predict loop has few misses\n");
67 printf("Testing a loop with %lld branches (%d times):\n",
69 printf("\tOn a simple loop like this, "
70 "miss rate should be very small.\n");
71 }
72
73 for(
i=0;
i<num_runs;
i++) {
74
77
79
81
83 fprintf(
stderr,
"\tCode unimplemented\n");
84 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
85 }
86
89 "reading PAPI_TOT_INS",
retval );
90 }
91
95 }
96
97 average=(
total/num_runs);
98
99 if (!
quiet) printf(
"\tAverage number of branch misses: %lld\n",average);
100
101 if (average>1000) {
102 if (!
quiet) printf(
"Branch miss rate too high\n");
103 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
104 }
105
106
107
109 printf("\nPart 2\n");
110 }
111
112 high=0; low=0;
total=0;
113
114 for(
i=0;
i<num_runs;
i++) {
117
119
121
123 fprintf(
stderr,
"\tCode unimplemented\n");
124 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
125 }
126
129 "reading PAPI_TOT_INS",
retval );
130 }
131
135 }
136
137 average=
total/num_runs;
138
141 printf("\nTesting a function that branches "
142 "based on a random number\n");
143 printf(
" The loop has %lld branches\n",
expected);
144 printf(" %d are random branches.\n",num_random_branches);
145 }
146
147 high=0; low=0;
total=0;
148
149 for(
i=0;
i<num_runs;
i++) {
152
154
156
158 fprintf(
stderr,
"\tCode unimplemented\n");
159 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
160 }
161
164 "reading eventset",
retval );
165 }
166
170 }
171
172 average=
total/num_runs;
173
175 double rate = 100.0*(double)average/(double)num_random_branches;
176 printf("\nOut of %d random branches %lld were mispredicted,\n",num_random_branches,average);
177 printf("resulting in a misprediction rate = %.1lf%%.\n",rate);
178 printf("Assuming a good random number generator and no freaky luck\n");
179 printf("the misprediction rate should be around 50%%, and the\n");
180 printf("mispredicts should at least be between %d and %d.\n",
181 num_random_branches/4,(num_random_branches/4)*3);
182 }
183
184 if ( average < (num_random_branches/4)) {
185 if (!
quiet) printf(
"Mispredicts too low\n");
186 test_fail( __FILE__, __LINE__,
"Error too low", 1 );
187 }
188
189 if (average > (num_random_branches/4)*3) {
190 if (!
quiet) printf(
"Mispredicts too high\n");
191 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
192 }
193
194 if (!
quiet) printf(
"\n");
195
197
199
200 return 0;
201
202}
int branches_testcode(void)
int random_branches_testcode(int number, int quiet)
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
int tests_quiet(int argc, char **argv)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_pass(const char *filename)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
#define CODE_UNIMPLEMENTED