1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
|
/* A Memcheck test program for conditional loads and stores,
as shown in do_conditional_{load,store}32.
Program is run twice, once for loads and once for stores, only
because each run generates 80 errors, and we want to see them all.
Doing both loads and stores in each run runs into the problem that
errors are more aggressively commoned up after the 100th, and so
some that we want to see aren't shown. Splitting the run into two
pieces avoids this.
On ARM we hardwire genuine conditional loads and stores to be
tested -- which is the real point of this test, since we are sure
they will turn into IRLoadG/IRStoreG. On other platforms we make
do with whatever gcc gives us for the equivalent C fragment. In
both cases Memcheck's results should be identical -- at least in
error counts; line numbers unfortunately will differ. Hence there
are -arm and -non-arm expected output files. */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "../memcheck.h"
typedef unsigned int UInt;
typedef unsigned char Bool;
#define False ((Bool)0)
#define True ((Bool)1)
static void make_undef ( void* addr, size_t len )
{
(void) VALGRIND_MAKE_MEM_UNDEFINED(addr, len);
}
static void make_def ( void* addr, size_t len )
{
(void) VALGRIND_MAKE_MEM_DEFINED(addr, len);
}
// Returns either |*src| or |alt|.
__attribute__((noinline))
UInt do_conditional_load32 ( UInt* src, UInt alt, Bool b )
{
UInt res;
# if defined(__linux__) && defined(__arm__)
__asm__ __volatile__(
"mov r5, %2" "\n\t" // alt
"tst %3, #0xFF" "\n\t" // b
"it ne" "\n\t"
"ldrne r5, [%1]" "\n\t" // src
"mov %0, r5" "\n\t" // res
: /*OUT*/"=r"(res)
: /*IN*/"r"(src), "r"(alt), "r"(b)
: /*TRASH*/ "r5","cc","memory"
);
# else
__asm__ __volatile__("" ::: "cc","memory");
res = b ? *src : alt;
# endif
// res might be undefined. Paint it as defined so the
// caller can look at it without invoking further errors.
make_def(&res, sizeof(res));
return res;
}
// Possibly writes |alt| to |*dst|, and returns the resulting
// value of |*dst|.
__attribute__((noinline))
UInt do_conditional_store32 ( UInt* dst, UInt alt, Bool b )
{
# if defined(__linux__) && defined(__arm__)
__asm__ __volatile__(
"mov r5, %1" "\n\t" // alt
"tst %2, #0xFF" "\n\t" // b
"it ne" "\n\t"
"strne r5, [%0]" "\n\t" // dst
: /*OUT*/
: /*IN*/"r"(dst), "r"(alt), "r"(b)
: /*TRASH*/ "r5","cc","memory"
);
# else
__asm__ __volatile__("" ::: "cc","memory");
if (b) *dst = alt;
# endif
/* Now we need to get hold of the value at *dst. But it might be
unaddressible and/or undefined. Hence turn off error reporting
when getting it. */
UInt res;
VALGRIND_DISABLE_ERROR_REPORTING;
res = *dst;
VALGRIND_ENABLE_ERROR_REPORTING;
make_def(&res, sizeof(res));
return res;
}
/* --- LOAD ----------------------------------------- LOAD --- */
/* --- LOAD ----------------------------------------- LOAD --- */
/* --- LOAD ----------------------------------------- LOAD --- */
/* For conditional loads, there are 64 combinations to test.
cond: { defined-true, defined-false,
undefined-true, undefined-false } D1 D0 U1 U0
x
addr: { defined-valid, defined-invalid,
undefined-valid, undefined-invalid } DV DI UV UI
x
alt: { defined, undefined } Da Ub
x
data: { defined, undefined } Dc Ud
// a, b, c, d refer to actual values
The general form of the test is:
1. Place data at *addr
2. return "cond ? *addr : alt"
*/
typedef enum { Cond_D1=10, Cond_D0, Cond_U1, Cond_U0 } Inp_Cond;
typedef enum { Addr_DV=20, Addr_DI, Addr_UV, Addr_UI } Inp_Addr;
typedef enum { Alt_Da=30, Alt_Ub } Inp_Alt;
typedef enum { Data_Dc=40, Data_Ud } Inp_Data;
typedef
struct { Inp_Cond inp_Cond; Inp_Addr inp_Addr;
Inp_Alt inp_Alt; Inp_Data inp_Data;
char res; char defErr_Cond; char defErr_Addr; char addrErr; }
TestCase;
const TestCase loadCases[64] = {
// ADDR ALT COND DATA Res
// defErr-COND
// defErr-ADDR
// addrErr
// In all of the next 16 cases, the load definitely happens
// and |alt| is therefore irrelevant
{ Cond_D1, Addr_DV, Alt_Da, Data_Dc, 'C', 'N', 'N', 'N' }, // 0
{ Cond_D1, Addr_DV, Alt_Da, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D1, Addr_DV, Alt_Ub, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D1, Addr_DV, Alt_Ub, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D1, Addr_DI, Alt_Da, Data_Dc, 'C', 'N', 'N', 'Y' },
{ Cond_D1, Addr_DI, Alt_Da, Data_Ud, 'D', 'N', 'N', 'Y' },
{ Cond_D1, Addr_DI, Alt_Ub, Data_Dc, 'C', 'N', 'N', 'Y' },
{ Cond_D1, Addr_DI, Alt_Ub, Data_Ud, 'D', 'N', 'N', 'Y' },
{ Cond_D1, Addr_UV, Alt_Da, Data_Dc, 'C', 'N', 'Y', 'N' }, // 8
{ Cond_D1, Addr_UV, Alt_Da, Data_Ud, 'D', 'N', 'Y', 'N' },
{ Cond_D1, Addr_UV, Alt_Ub, Data_Dc, 'C', 'N', 'Y', 'N' },
{ Cond_D1, Addr_UV, Alt_Ub, Data_Ud, 'D', 'N', 'Y', 'N' },
{ Cond_D1, Addr_UI, Alt_Da, Data_Dc, 'C', 'N', 'Y', 'Y' },
{ Cond_D1, Addr_UI, Alt_Da, Data_Ud, 'D', 'N', 'Y', 'Y' },
{ Cond_D1, Addr_UI, Alt_Ub, Data_Dc, 'C', 'N', 'Y', 'Y' },
{ Cond_D1, Addr_UI, Alt_Ub, Data_Ud, 'D', 'N', 'Y', 'Y' },
// In the next 16 cases, the load definitely does not happen,
// so we just return |alt|.
{ Cond_D0, Addr_DV, Alt_Da, Data_Dc, 'A', 'N', 'N', 'N' }, // 16
{ Cond_D0, Addr_DV, Alt_Da, Data_Ud, 'A', 'N', 'N', 'N' },
{ Cond_D0, Addr_DV, Alt_Ub, Data_Dc, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_DV, Alt_Ub, Data_Ud, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Da, Data_Dc, 'A', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Da, Data_Ud, 'A', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Ub, Data_Dc, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Ub, Data_Ud, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_UV, Alt_Da, Data_Dc, 'A', 'N', 'N', 'N' }, // 24
{ Cond_D0, Addr_UV, Alt_Da, Data_Ud, 'A', 'N', 'N', 'N' },
{ Cond_D0, Addr_UV, Alt_Ub, Data_Dc, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_UV, Alt_Ub, Data_Ud, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Da, Data_Dc, 'A', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Da, Data_Ud, 'A', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Ub, Data_Dc, 'B', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Ub, Data_Ud, 'B', 'N', 'N', 'N' },
// ADDR ALT COND DATA Res
// defErr-COND
// defErr-ADDR
// addrErr
// In the next 16 cases, the load happens, but the condition
// is undefined. This means that it should behave like the
// first group of 16 cases, except that we should also get a
// complaint about the definedness of the condition.
{ Cond_U1, Addr_DV, Alt_Da, Data_Dc, 'C', 'Y', 'N', 'N' }, // 32
{ Cond_U1, Addr_DV, Alt_Da, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U1, Addr_DV, Alt_Ub, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U1, Addr_DV, Alt_Ub, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U1, Addr_DI, Alt_Da, Data_Dc, 'C', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_DI, Alt_Da, Data_Ud, 'D', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_DI, Alt_Ub, Data_Dc, 'C', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_DI, Alt_Ub, Data_Ud, 'D', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_UV, Alt_Da, Data_Dc, 'C', 'Y', 'Y', 'N' }, // 40
{ Cond_U1, Addr_UV, Alt_Da, Data_Ud, 'D', 'Y', 'Y', 'N' },
{ Cond_U1, Addr_UV, Alt_Ub, Data_Dc, 'C', 'Y', 'Y', 'N' },
{ Cond_U1, Addr_UV, Alt_Ub, Data_Ud, 'D', 'Y', 'Y', 'N' },
{ Cond_U1, Addr_UI, Alt_Da, Data_Dc, 'C', 'Y', 'Y', 'Y' },
{ Cond_U1, Addr_UI, Alt_Da, Data_Ud, 'D', 'Y', 'Y', 'Y' },
{ Cond_U1, Addr_UI, Alt_Ub, Data_Dc, 'C', 'Y', 'Y', 'Y' },
{ Cond_U1, Addr_UI, Alt_Ub, Data_Ud, 'D', 'Y', 'Y', 'Y' },
// In this last group of 16 cases, the load does not happen,
// but the condition is undefined. So we just return |alt|,
// and also complain about the condition. Hence it's like the
// second group of 16 cases except that we also get a complaint
// about the condition.
{ Cond_U0, Addr_DV, Alt_Da, Data_Dc, 'A', 'Y', 'N', 'N' }, // 48
{ Cond_U0, Addr_DV, Alt_Da, Data_Ud, 'A', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DV, Alt_Ub, Data_Dc, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DV, Alt_Ub, Data_Ud, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Da, Data_Dc, 'A', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Da, Data_Ud, 'A', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Ub, Data_Dc, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Ub, Data_Ud, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UV, Alt_Da, Data_Dc, 'A', 'Y', 'N', 'N' }, // 56
{ Cond_U0, Addr_UV, Alt_Da, Data_Ud, 'A', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UV, Alt_Ub, Data_Dc, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UV, Alt_Ub, Data_Ud, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Da, Data_Dc, 'A', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Da, Data_Ud, 'A', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Ub, Data_Dc, 'B', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Ub, Data_Ud, 'B', 'Y', 'N', 'N' } // 63
};
// Constant, corresponding to the test enums
static Bool c_Cond_D1, c_Cond_D0, c_Cond_U1, c_Cond_U0;
static UInt *c_Addr_DV, *c_Addr_DI, *c_Addr_UV, *c_Addr_UI;
static UInt c_Alt_Da, c_Alt_Ub;
static void setup_test_data ( Inp_Data inp_Data )
{
c_Cond_D1 = c_Cond_U1 = True;
c_Cond_D0 = c_Cond_U0 = False;
make_undef(&c_Cond_U1, sizeof(c_Cond_U1));
make_undef(&c_Cond_U0, sizeof(c_Cond_U0));
c_Addr_DV = c_Addr_UV = malloc(4);
c_Addr_DI = c_Addr_UI = malloc(4);
// install test data at the given address
UInt testd = inp_Data == Data_Dc ? 0xCCCCCCCC : 0xDDDDDDDD;
*c_Addr_DV = *c_Addr_DI = testd;
if (inp_Data == Data_Dc) {
// it's already defined
} else {
make_undef(c_Addr_DV, 4);
make_undef(c_Addr_DI, 4);
}
// make the invalid address invalid. This unfortunately loses
// the definedness state of the data that is stored there.
free(c_Addr_DI);
// and set the definedness of the pointers themselves.
make_undef(&c_Addr_UV, sizeof(c_Addr_UV));
make_undef(&c_Addr_UI, sizeof(c_Addr_UI));
// and set up alt
c_Alt_Da = 0xAAAAAAAA;
c_Alt_Ub = 0xBBBBBBBB;
make_undef(&c_Alt_Ub, sizeof(c_Alt_Ub));
}
static void do_test_case ( int caseNo, Bool isLoad, const TestCase* lc )
{
fprintf(stderr,
"\n-----------------------------------------------------------\n");
fprintf(stderr, "%s CASE %d\n", isLoad ? "LOAD" : "STORE", caseNo);
// validate ..
assert(Cond_D1 <= lc->inp_Cond && lc->inp_Cond <= Cond_U0);
assert(Addr_DV <= lc->inp_Addr && lc->inp_Addr <= Addr_UI);
assert(lc->inp_Alt == Alt_Da || lc->inp_Alt == Alt_Ub);
assert(lc->inp_Data == Data_Dc || lc->inp_Data == Data_Ud);
assert('A' <= lc->res && lc->res <= 'D');
assert(lc->defErr_Cond == 'Y' || lc->defErr_Cond == 'N');
assert(lc->defErr_Addr == 'Y' || lc->defErr_Addr == 'N');
assert(lc->addrErr == 'Y' || lc->addrErr == 'N');
// set up test data constants
setup_test_data(lc->inp_Data);
// and select constants for the test, depending on |lc|
// Except, skip i_Data since setup_test_data takes care of it.
Bool i_Cond;
UInt* i_Addr;
UInt i_Alt;
switch (lc->inp_Cond) {
case Cond_D1: i_Cond = c_Cond_D1; break;
case Cond_D0: i_Cond = c_Cond_D0; break;
case Cond_U1: i_Cond = c_Cond_U1; break;
case Cond_U0: i_Cond = c_Cond_U0; break;
default: assert(0);
}
switch (lc->inp_Addr) {
case Addr_DV: i_Addr = c_Addr_DV; break;
case Addr_DI: i_Addr = c_Addr_DI; break;
case Addr_UV: i_Addr = c_Addr_UV; break;
case Addr_UI: i_Addr = c_Addr_UI; break;
default: assert(0);
}
switch (lc->inp_Alt) {
case Alt_Da: i_Alt = c_Alt_Da; break;
case Alt_Ub: i_Alt = c_Alt_Ub; break;
default: assert(0);
}
// How many errors do we expect from this?
UInt n_errs_exp
= (lc->defErr_Cond == 'Y' ? 1 : 0) + (lc->defErr_Addr == 'Y' ? 1 : 0)
+ (lc->addrErr == 'Y' ? 1 : 0);
UInt n_errs_act = VALGRIND_COUNT_ERRORS;
UInt res_act;
if (isLoad) {
res_act = do_conditional_load32(i_Addr, i_Alt, i_Cond);
} else {
res_act = do_conditional_store32(i_Addr, i_Alt, i_Cond);
}
n_errs_act = VALGRIND_COUNT_ERRORS - n_errs_act;
if (n_errs_act == n_errs_exp) {
fprintf(stderr, "PASS: %u errors\n", n_errs_act);
} else {
fprintf(stderr, "FAIL: %u errors expected, %u actual\n",
n_errs_exp, n_errs_act);
}
// What's the expected result value (actual loaded data?)
UInt res_exp = 0;
switch (lc->res) {
case 'A': res_exp = 0xAAAAAAAA; break;
case 'B': res_exp = 0xBBBBBBBB; break;
case 'C': res_exp = 0xCCCCCCCC; break;
case 'D': res_exp = 0xDDDDDDDD; break;
default: assert(0);
}
if (res_act == res_exp) {
fprintf(stderr, "PASS: correct result\n");
} else {
fprintf(stderr, "FAIL: result: %08x expected, %08x actual\n",
res_exp, res_act);
}
free(c_Addr_DV);
}
void do_test_case_steer ( void (*fn)(int,Bool,const TestCase*),
int i, Bool isLd, const TestCase* tc )
{
__asm__ __volatile__("");
if (i == 0) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 1) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 2) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 3) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 4) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 5) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 6) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 7) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 8) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 9) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 10) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 11) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 12) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 13) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 14) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 15) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 16) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 17) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 18) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 19) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 20) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 21) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 22) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 23) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 24) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 25) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 26) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 27) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 28) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 29) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 30) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 31) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 32) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 33) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 34) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 35) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 36) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 37) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 38) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 39) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 40) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 41) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 42) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 43) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 44) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 45) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 46) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 47) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 48) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 49) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 50) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 51) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 52) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 53) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 54) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 55) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 56) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 57) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 58) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 59) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 60) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 61) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 62) { fn(i,isLd,tc); return; };
__asm__ __volatile__("");
if (i == 63) { fn(i,isLd,tc); return; };
assert(0);
}
/* --- STORE --------------------------------------- STORE --- */
/* --- STORE --------------------------------------- STORE --- */
/* --- STORE --------------------------------------- STORE --- */
/* For conditional stores, there are 64 combinations to test.
cond: { defined-true, defined-false,
undefined-true, undefined-false } D1 D0 U1 U0
x
addr: { defined-valid, defined-invalid,
undefined-valid, undefined-invalid } DV DI UV UI
x
alt: { defined, undefined } Da Ub
x
data: { defined, undefined } Dc Ud
// a, b, c, d refer to actual values
The general form of the test is:
1. Place data at *addr
2. do "if (cond) *addr = alt"
3 return *addr
Hence identical setup to the load cases, although the roles of
data and alt are somewhat confusingly swapped. |data| here is
the "didn't happen" result, and |alt| is the "did happen" result.
*/
const TestCase storeCases[64] = {
// ADDR ALT COND DATA Res
// defErr-COND
// defErr-ADDR
// addrErr
// In all of the next 16 cases, the store definitely happens
// and |data| is therefore irrelevant
{ Cond_D1, Addr_DV, Alt_Da, Data_Dc, 'A', 'N', 'N', 'N' }, // 0
{ Cond_D1, Addr_DV, Alt_Da, Data_Ud, 'A', 'N', 'N', 'N' },
{ Cond_D1, Addr_DV, Alt_Ub, Data_Dc, 'B', 'N', 'N', 'N' },
{ Cond_D1, Addr_DV, Alt_Ub, Data_Ud, 'B', 'N', 'N', 'N' },
{ Cond_D1, Addr_DI, Alt_Da, Data_Dc, 'A', 'N', 'N', 'Y' },
{ Cond_D1, Addr_DI, Alt_Da, Data_Ud, 'A', 'N', 'N', 'Y' },
{ Cond_D1, Addr_DI, Alt_Ub, Data_Dc, 'B', 'N', 'N', 'Y' },
{ Cond_D1, Addr_DI, Alt_Ub, Data_Ud, 'B', 'N', 'N', 'Y' },
{ Cond_D1, Addr_UV, Alt_Da, Data_Dc, 'A', 'N', 'Y', 'N' }, // 8
{ Cond_D1, Addr_UV, Alt_Da, Data_Ud, 'A', 'N', 'Y', 'N' },
{ Cond_D1, Addr_UV, Alt_Ub, Data_Dc, 'B', 'N', 'Y', 'N' },
{ Cond_D1, Addr_UV, Alt_Ub, Data_Ud, 'B', 'N', 'Y', 'N' },
{ Cond_D1, Addr_UI, Alt_Da, Data_Dc, 'A', 'N', 'Y', 'Y' },
{ Cond_D1, Addr_UI, Alt_Da, Data_Ud, 'A', 'N', 'Y', 'Y' },
{ Cond_D1, Addr_UI, Alt_Ub, Data_Dc, 'B', 'N', 'Y', 'Y' },
{ Cond_D1, Addr_UI, Alt_Ub, Data_Ud, 'B', 'N', 'Y', 'Y' },
// In the next 16 cases, the store definitely does not happen,
// so we just return |data|.
{ Cond_D0, Addr_DV, Alt_Da, Data_Dc, 'C', 'N', 'N', 'N' }, // 16
{ Cond_D0, Addr_DV, Alt_Da, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_DV, Alt_Ub, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D0, Addr_DV, Alt_Ub, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Da, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Da, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Ub, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D0, Addr_DI, Alt_Ub, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_UV, Alt_Da, Data_Dc, 'C', 'N', 'N', 'N' }, // 24
{ Cond_D0, Addr_UV, Alt_Da, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_UV, Alt_Ub, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D0, Addr_UV, Alt_Ub, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Da, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Da, Data_Ud, 'D', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Ub, Data_Dc, 'C', 'N', 'N', 'N' },
{ Cond_D0, Addr_UI, Alt_Ub, Data_Ud, 'D', 'N', 'N', 'N' },
// ADDR ALT COND DATA Res
// defErr-COND
// defErr-ADDR
// addrErr
// In the next 16 cases, the store happens, but the condition
// is undefined. This means that it should behave like the
// first group of 16 cases, except that we should also get a
// complaint about the definedness of the condition.
{ Cond_U1, Addr_DV, Alt_Da, Data_Dc, 'A', 'Y', 'N', 'N' }, // 32
{ Cond_U1, Addr_DV, Alt_Da, Data_Ud, 'A', 'Y', 'N', 'N' },
{ Cond_U1, Addr_DV, Alt_Ub, Data_Dc, 'B', 'Y', 'N', 'N' },
{ Cond_U1, Addr_DV, Alt_Ub, Data_Ud, 'B', 'Y', 'N', 'N' },
{ Cond_U1, Addr_DI, Alt_Da, Data_Dc, 'A', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_DI, Alt_Da, Data_Ud, 'A', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_DI, Alt_Ub, Data_Dc, 'B', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_DI, Alt_Ub, Data_Ud, 'B', 'Y', 'N', 'Y' },
{ Cond_U1, Addr_UV, Alt_Da, Data_Dc, 'A', 'Y', 'Y', 'N' }, // 40
{ Cond_U1, Addr_UV, Alt_Da, Data_Ud, 'A', 'Y', 'Y', 'N' },
{ Cond_U1, Addr_UV, Alt_Ub, Data_Dc, 'B', 'Y', 'Y', 'N' },
{ Cond_U1, Addr_UV, Alt_Ub, Data_Ud, 'B', 'Y', 'Y', 'N' },
{ Cond_U1, Addr_UI, Alt_Da, Data_Dc, 'A', 'Y', 'Y', 'Y' },
{ Cond_U1, Addr_UI, Alt_Da, Data_Ud, 'A', 'Y', 'Y', 'Y' },
{ Cond_U1, Addr_UI, Alt_Ub, Data_Dc, 'B', 'Y', 'Y', 'Y' },
{ Cond_U1, Addr_UI, Alt_Ub, Data_Ud, 'B', 'Y', 'Y', 'Y' },
// In this last group of 16 cases, the store does not happen,
// but the condition is undefined. So we just return |data|,
// and also complain about the condition. Hence it's like the
// second group of 16 cases except that we also get a complaint
// about the condition.
{ Cond_U0, Addr_DV, Alt_Da, Data_Dc, 'C', 'Y', 'N', 'N' }, // 48
{ Cond_U0, Addr_DV, Alt_Da, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DV, Alt_Ub, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DV, Alt_Ub, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Da, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Da, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Ub, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U0, Addr_DI, Alt_Ub, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UV, Alt_Da, Data_Dc, 'C', 'Y', 'N', 'N' }, // 56
{ Cond_U0, Addr_UV, Alt_Da, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UV, Alt_Ub, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UV, Alt_Ub, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Da, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Da, Data_Ud, 'D', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Ub, Data_Dc, 'C', 'Y', 'N', 'N' },
{ Cond_U0, Addr_UI, Alt_Ub, Data_Ud, 'D', 'Y', 'N', 'N' } // 63
};
void usage ( char* pname )
{
fprintf(stderr, "usage: %s [loads|stores]\n", pname);
exit(1);
}
int main ( int argc, char** argv )
{
UInt i, nCases;
if (argc != 2) usage(argv[0]);
Bool doLoad = False;
if (0 == strcmp(argv[1], "loads")) {
doLoad = True;
}
else if (0 == strcmp(argv[1], "stores")) {
doLoad = False;
}
else usage(argv[0]);
if (doLoad) {
nCases = sizeof(loadCases) / sizeof(loadCases[0]);
assert(nCases == 64);
for (i = 0; i < nCases; i++)
do_test_case_steer( do_test_case, i, True/*isLoad*/, &loadCases[i] );
} else {
nCases = sizeof(storeCases) / sizeof(storeCases[0]);
assert(nCases == 64);
for (i = 0; i < nCases; i++)
do_test_case_steer( do_test_case, i, False/*!isLoad*/, &storeCases[i] );
}
return 0;
}
|