21 {
22
24 long long high=0,low=0,average=0;
25 long long expected_cond=500000,expected_total=1000000;
26 double error;
27
34 long long count_total,count_conditional,count_taken,count_nottaken;
35 int cond_avail=1,nottaken_avail=1;
36 int not_expected=0;
37
39
41 printf("\nTesting the PAPI_BR_TKN event.\n");
42 printf("\tIt measures total number of conditional branches not taken\n");
43 }
44
45
49 }
50
51
55 }
56
60 }
61
62
63
67 }
68
71 if (!
quiet) printf(
"Could not add PAPI_BR_CN\n");
72 cond_avail=0;
73
74 }
75
76
80 }
81
84 if (!
quiet) printf(
"Could not add PAPI_BR_TKN\n");
86 }
87
88
92 }
93
96 if (!
quiet) printf(
"Could not add PAPI_BR_NTK\n");
97 nottaken_avail=0;
98
99 }
100
101
106
107
108 if (cond_avail) {
113 }
114
115
120
121
122
123 if (nottaken_avail) {
128 }
129
131 printf("The test code has:\n");
132 printf("\t%lld total branches\n",count_total);
133 if (cond_avail) {
134 printf("\t%lld conditional branches\n",count_conditional);
135 }
136 printf("\t%lld taken branches\n",count_taken);
137 if (nottaken_avail) {
138 printf("\t%lld not-taken branches\n",count_nottaken);
139 }
140
141 }
142
144 printf("Testing a loop with %lld conditional taken branches (%d times):\n",
145 expected_cond,num_runs);
146 }
147
148 for(
i=0;
i<num_runs;
i++) {
151
153
155
157 fprintf(
stderr,
"\tCode unimplemented\n");
158 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
159 }
160
163 "reading PAPI_BR_TKN",
retval );
164 }
165
169 }
170
171 average=(
total/num_runs);
172
174
175 if ((error > 1.0) || (error<-1.0)) {
176 if (!
quiet) printf(
"Instruction count off by more than 1%%\n");
177 not_expected=1;
178
179 }
180
181 if (!
quiet) printf(
"\n");
182
183
184 if (not_expected) {
185
187
188 if ((error > 1.0) || (error<-1.0)) {
189 if (!
quiet) printf(
"Instruction count off by more than 1%%\n");
190 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
191 }
192 else {
193 test_warn(__FILE__,__LINE__,
"Using TOTAL BRANCHES as base rather than CONDITIONAL BRANCHES\n",0);
194 }
195 }
196
198
200
201 return 0;
202}
int branches_testcode(void)
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.
double display_error(long long average, long long high, long long low, long long expected, int quiet)
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 test_warn(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
#define CODE_UNIMPLEMENTED