1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #ifdef __lint 30 #pragma error_messages(off, E_VALUE_TYPE) 31 #endif 32 33 #include <stdio.h> 34 #include <stdlib.h> 35 #include <signal.h> 36 #include <unistd.h> 37 #include <string.h> 38 #include <sys/types.h> 39 #include <sys/file.h> 40 #include <sys/fcntl.h> 41 #include <math.h> 42 #include <sys/dditypes.h> 43 #include <sys/ddidmareq.h> 44 #include <sys/ddi_impldefs.h> 45 #include <sys/processor.h> 46 #include <sys/pset.h> 47 #include <time.h> 48 #include <kstat.h> 49 #include <fp.h> 50 #include <fptest.h> 51 #include <fpstestmsg.h> 52 #include <externs.h> 53 #include <fps_ereport.h> 54 #include <fps_defines.h> 55 56 #define GetBoxStringLen SYS_NMLN 57 #define NANO_IN_MILI 1000000 58 #define MILI_IN_SEC 1000 59 #define str_v9 "sparcv9" 60 #define str_v9b "sparcv9+vis2" 61 #define testname "fptest" 62 63 static int fps_exec_time = 0; 64 static int fps_verbose_msg = 0; 65 static int fpu_cpu = -1; 66 static int test_group = 1; 67 static int stress_level = 1; 68 static int limit_group = 1; 69 static int proc_fr; 70 static int lowstresslapagroup_len; 71 static int lowstresslapagroup1000_len; 72 static int lowstresslapagroup1500_len; 73 static int lowstresslapagroup2000_len; 74 static int medstresslapagroup_len; 75 static int highstresslapagroup_len; 76 static struct LapaGroup *lowstresslapagroup; 77 78 static void exe_time(hrtime_t timeStart); 79 static void process_fpu_args(int argc, char *argv[]); 80 static int check_proc(int cpu_id); 81 static int do_lapack(int unit, struct fps_test_ereport *report); 82 static int dpmath(struct fps_test_ereport *report); 83 static int is_cpu_on(int unit); 84 static int spmath(struct fps_test_ereport *report); 85 static int start_testing(int unit, 86 struct fps_test_ereport *report); 87 88 /* 89 * main(int argc, char *argv[]) 90 * is the main entry into the test. 91 */ 92 int 93 main(int argc, char *argv[]) 94 { 95 int test_ret; 96 int procb; 97 int proc_setb; 98 int ret = FPU_OK; 99 hrtime_t test_start; 100 psetid_t opset = PS_NONE; 101 processorid_t proc_used = PBIND_NONE; 102 static struct fps_test_ereport ereport_data; 103 104 /* these are % ( modulo ) values */ 105 lowstresslapagroup1000_len = 106 (sizeof (LowStressLapaGroup_1000) / sizeof (struct LapaGroup)) - 1; 107 lowstresslapagroup1500_len = 108 (sizeof (LowStressLapaGroup_1500) / sizeof (struct LapaGroup)) - 1; 109 lowstresslapagroup2000_len = 110 (sizeof (LowStressLapaGroup_2000) / sizeof (struct LapaGroup)) - 1; 111 medstresslapagroup_len = 112 (sizeof (MedStressLapaGroup) / sizeof (struct LapaGroup)) - 1; 113 highstresslapagroup_len = 114 (sizeof (HighStressLapaGroup) / sizeof (struct LapaGroup)) - 1; 115 116 /* default frequency values */ 117 proc_fr = 1000; 118 lowstresslapagroup_len = lowstresslapagroup1000_len; 119 lowstresslapagroup = LowStressLapaGroup_1000; 120 121 initialize_fps_test_struct(&ereport_data); 122 123 process_fpu_args(argc, argv); 124 125 fps_msg(fps_verbose_msg, gettext(FPSM_04), lowstresslapagroup_len, 126 medstresslapagroup_len, highstresslapagroup_len); 127 128 #ifdef V9B 129 fps_msg(fps_verbose_msg, gettext(FPSM_03), testname, "V9B"); 130 #else 131 fps_msg(fps_verbose_msg, gettext(FPSM_03), testname, "V9"); 132 #endif 133 134 if (fpu_cpu < 0) 135 return (FPU_INVALID_ARG); 136 137 test_start = gethrtime(); 138 139 procb = processor_bind(P_PID, P_MYID, fpu_cpu, NULL); 140 141 if (procb) { 142 if ((pset_assign(PS_QUERY, 143 (processorid_t)fpu_cpu, &opset) == 0) && 144 (opset != PS_NONE)) { 145 proc_setb = pset_bind(opset, P_PID, P_MYID, NULL); 146 } 147 148 if (proc_setb) { 149 return (FPU_BIND_FAIL); 150 } 151 152 procb = processor_bind(P_PID, P_MYID, fpu_cpu, NULL); 153 154 if (procb) { 155 (void) pset_bind(PS_NONE, P_PID, P_MYID, NULL); 156 return (FPU_BIND_FAIL); 157 } 158 } 159 160 /* start testing */ 161 ereport_data.cpu_id = fpu_cpu; 162 test_ret = start_testing(fpu_cpu, &ereport_data); 163 164 /* 165 * Testing is now done and a return code is selected. 166 * FPU_OK: No problems found on FPU tested. 167 * 168 * FPU_BIND_FAIL: CPU currently bound to is not the 169 * one started on. Attempt to file ereport if CPU 170 * is supported, but don't include resource so 171 * CPU isn't offlined. 172 * 173 * FPU_UNSUPPORT: Test wasn't run on a supported CPU. 174 * Error was found, but no ereport will be filed since 175 * CPU is unsupported and test values may not be valid. 176 * 177 * FPU_FOROFFLINE: Error found on FPU and ereport 178 * payload successfully sent. 179 * 180 * FPU_EREPORT_INCOM: Error found on FPU, ereport payload 181 * sent, but some nonessential information failed to add 182 * to that payload. CPU will still be offlined. 183 * 184 * FPU_EREPORT_FAIL: Error found on FPU, but ereport payload 185 * failed to transfer either due to lack of mandatory data 186 * or unable to send on FPScrubber systevent channel. 187 */ 188 189 if (test_ret == FPU_FOROFFLINE) { 190 /* 191 * check bind and 192 * check if on supported plaform 193 */ 194 (void) processor_bind(P_PID, P_MYID, PBIND_QUERY, &proc_used); 195 196 if (proc_used != (processorid_t)fpu_cpu || 197 proc_used == PBIND_NONE) { 198 ret = FPU_BIND_FAIL; 199 ereport_data.is_valid_cpu = 0; 200 } 201 202 if (check_proc(fpu_cpu) != 0) { 203 ret = FPU_UNSUPPORT; 204 ereport_data.is_valid_cpu = 0; 205 } 206 207 if (ret != FPU_UNSUPPORT) { 208 test_ret = fps_generate_ereport_struct(&ereport_data); 209 if (ret != FPU_BIND_FAIL) { 210 ret = test_ret; 211 } 212 } 213 } 214 215 if (fps_exec_time) 216 exe_time(test_start); 217 218 return (ret); 219 } 220 221 /* 222 * exe_time(hrtime_t timeStart, int unit) 223 * returns Execution time: H.M.S.Msec 224 */ 225 static void 226 exe_time(hrtime_t time_start) 227 { 228 hrtime_t mili_now; 229 hrtime_t mili_start; 230 long hour; 231 long minute; 232 long second; 233 long mili; 234 long dif_mili; 235 long mili_to_sec; 236 237 mili_start = time_start / NANO_IN_MILI; 238 mili_now = gethrtime() / NANO_IN_MILI; 239 240 dif_mili = (long)(mili_now - mili_start); 241 mili_to_sec = dif_mili / MILI_IN_SEC; 242 hour = mili_to_sec / 3600; 243 minute = (mili_to_sec - (hour * 3600)) / 60; 244 second = (mili_to_sec - ((hour * 3600) + (minute * 60))); 245 mili = 246 (dif_mili - ((second * 1000) + (((hour * 3600) + 247 (minute * 60)) * 1000))); 248 249 (void) printf("Execution time: %ldH.%ldM.%ldS.%ldMsec\n", hour, minute, 250 second, mili); 251 (void) fflush(NULL); 252 } 253 254 /* 255 * start_testing(int unit, int argc, char *argv[], 256 * struct fps_test_ereport *report) performs each sub-test 257 * sequentially and stores any failed test information in 258 * report. 259 */ 260 static int 261 start_testing(int unit, struct fps_test_ereport *report) 262 { 263 int lim; 264 int sdclimit; 265 266 if (report == NULL) 267 return (-1); 268 269 /* 270 * The non-lapack logic will be executed when -p 0 OR -p ALL 271 */ 272 if ((0 == test_group) || (12345 == test_group)) { 273 fps_msg(fps_verbose_msg, gettext(FPSM_01), unit, limit_group); 274 275 /* turn on signal handlers */ 276 (void) winitfp(); 277 278 if (fpu_sysdiag(report) != 0) { 279 return (FPU_FOROFFLINE); 280 } 281 282 /* turn off signal handlers */ 283 (void) restore_signals(); 284 285 if (spmath(report) != 0) { 286 return (FPU_FOROFFLINE); 287 } 288 289 if (dpmath(report) != 0) { 290 return (FPU_FOROFFLINE); 291 } 292 293 if (cbbcopy(report) != 0) { 294 return (FPU_FOROFFLINE); 295 } 296 297 sdclimit = 100; 298 299 if (limit_group == 2) 300 sdclimit = 1000; 301 if (limit_group == 3) 302 sdclimit = 10000; 303 304 if (cheetah_sdc_test(sdclimit, report) != 0) { 305 return (FPU_FOROFFLINE); 306 } 307 308 lim = 100; 309 310 if (limit_group == 2) 311 lim = 1000; 312 if (limit_group == 3) 313 lim = 100000; 314 315 if (fpu_fdivd(lim, report) != 0) { 316 return (FPU_FOROFFLINE); 317 } 318 319 if (fpu_fmuld(lim, report) != 0) { 320 return (FPU_FOROFFLINE); 321 } 322 323 if (fpu_fmulx(lim, report) != 0) { 324 return (FPU_FOROFFLINE); 325 } 326 327 #ifdef V9B 328 329 lim = 10; 330 331 if (limit_group == 2) 332 lim = 100; 333 if (limit_group == 3) 334 lim = 1000; 335 336 if (align_data(lim, report) != 0) { 337 return (FPU_FOROFFLINE); 338 } 339 340 if (vis_test(report) != 0) { 341 return (FPU_FOROFFLINE); 342 } 343 344 #endif 345 346 if (test_group == 0) 347 return (FPU_OK); 348 349 } /* end the non lapack area */ 350 351 if (do_lapack(unit, report) != 0) 352 return (FPU_FOROFFLINE); 353 354 return (FPU_OK); 355 } 356 357 /* 358 * do_lapack(struct fps_test_ereport *report) calls the lapack 359 * tests and stores any error info into report. 360 */ 361 static int 362 do_lapack(int unit, struct fps_test_ereport *report) 363 { 364 int lapa_group_index; 365 int lapa_loop_stress; 366 int lapa_stress; 367 int lapa_loop; 368 int high_lim; 369 int low_lim; 370 371 fps_msg(fps_verbose_msg, gettext(FPSM_05), limit_group); 372 373 switch (limit_group) { 374 case 1: 375 lapa_group_index = test_group % lowstresslapagroup_len; 376 377 if (lapa_group_index <= 0) 378 lapa_group_index = 1; 379 380 low_lim = lowstresslapagroup[lapa_group_index].limLow; 381 high_lim = lowstresslapagroup[lapa_group_index].limHigh; 382 383 if (test_group == 12345) { 384 low_lim = 1; 385 high_lim = 386 lowstresslapagroup[lowstresslapagroup_len - 1] 387 .limHigh; 388 } 389 390 break; 391 case 2: 392 lapa_group_index = test_group % medstresslapagroup_len; 393 394 if (lapa_group_index <= 0) 395 lapa_group_index = 1; 396 397 low_lim = MedStressLapaGroup[lapa_group_index].limLow; 398 high_lim = MedStressLapaGroup[lapa_group_index].limHigh; 399 400 if (test_group == 12345) { 401 low_lim = 1; 402 high_lim = 403 MedStressLapaGroup[medstresslapagroup_len - 1] 404 .limHigh; 405 } 406 break; 407 case 3: 408 lapa_group_index = test_group % highstresslapagroup_len; 409 410 if (lapa_group_index <= 0) 411 lapa_group_index = 1; 412 413 low_lim = HighStressLapaGroup[lapa_group_index].limLow; 414 high_lim = HighStressLapaGroup[lapa_group_index].limHigh; 415 416 if (test_group == 12345) { 417 low_lim = 1; 418 high_lim = 419 HighStressLapaGroup[highstresslapagroup_len - 1] 420 .limHigh; 421 } 422 423 /* hidden arg -s X */ 424 if (stress_level > 4000) { 425 low_lim = 1; 426 high_lim = stress_level; 427 } 428 break; 429 default: 430 low_lim = 100; 431 high_lim = 200; 432 break; 433 } 434 435 if (low_lim < 1) 436 low_lim = 101; 437 438 if (high_lim > 10000) 439 high_lim = 201; 440 441 for (lapa_stress = low_lim; lapa_stress <= high_lim; 442 lapa_stress = lapa_stress + 1) { 443 if (lapa_stress > 999) { 444 for (lapa_loop = lapa_stress; lapa_loop <= high_lim; 445 lapa_loop = lapa_loop + 1000) { 446 lapa_loop_stress = lapa_loop; 447 448 if (lapa_loop_stress == 4000) 449 lapa_loop_stress = 4016; 450 if (lapa_loop_stress == 7000) 451 lapa_loop_stress = 7016; 452 if (lapa_loop_stress == 8000) 453 lapa_loop_stress = 8034; 454 455 if (slinpack_test(lapa_loop_stress, unit, 456 report, fps_verbose_msg)) 457 return (-4); 458 #ifndef __lint 459 if (dlinpack_test(lapa_loop_stress, unit, 460 report, fps_verbose_msg)) 461 return (-4); 462 #endif 463 } 464 break; 465 } 466 467 if (slinpack_test(lapa_stress, unit, report, fps_verbose_msg)) 468 return (-4); 469 #ifndef __lint 470 if (dlinpack_test(lapa_stress, unit, report, fps_verbose_msg)) 471 return (-4); 472 #endif 473 } 474 475 return (0); 476 } 477 478 479 /* 480 * spmath(int unit, struct fps_test_ereport *report) 481 * peforms basic tests of the arithmetic operations: 482 * +, -, *, and /. If any errors, they are stored in 483 * report. 484 */ 485 static int 486 spmath(struct fps_test_ereport *report) 487 { 488 char err_data[MAX_INFO_SIZE]; 489 float a; 490 float ans; 491 float b; 492 float expect_ans; 493 uint64_t expected; 494 uint64_t observed; 495 496 a = 1.2345; 497 b = 0.9876; 498 499 #ifndef __lint 500 ans = a + b; 501 #endif 502 ans = a + b; 503 expect_ans = 2.2221000; 504 if (ans != expect_ans) { 505 if (ans < (2.2221000 - SPMARGIN) || 506 ans > (2.2221000 + SPMARGIN)) { 507 (void) snprintf(err_data, sizeof (err_data), 508 "\nExpected: %.8f\nObserved: %.8f", 509 expect_ans, ans); 510 expected = (uint64_t)(*(uint32_t *)&expect_ans); 511 observed = (uint64_t)(*(uint32_t *)&ans); 512 setup_fps_test_struct(IS_EREPORT_INFO, 513 report, 6112, &observed, &expected, 1, 514 1, err_data); 515 516 return (-2); 517 } 518 } 519 520 ans = (a - b); 521 expect_ans = 0.2469000; 522 if (ans != expect_ans) { 523 if (ans < (0.2469000 - SPMARGIN) || 524 ans > (0.2469000 + SPMARGIN)) { 525 (void) snprintf(err_data, sizeof (err_data), 526 "\nExpected: %.8f\nObserved: %.8f", 527 expect_ans, ans); 528 expected = (uint64_t)(*(uint32_t *)&expect_ans); 529 observed = (uint64_t)(*(uint32_t *)&ans); 530 setup_fps_test_struct(IS_EREPORT_INFO, 531 report, 6113, &observed, &expected, 1, 532 1, err_data); 533 534 return (-2); 535 } 536 } 537 538 ans = a * b; 539 expect_ans = 1.2191923; 540 if (ans != expect_ans) { 541 if (ans < (1.2191923 - SPMARGIN) || 542 ans > (1.2191923 + SPMARGIN)) { 543 (void) snprintf(err_data, sizeof (err_data), 544 "\nExpected: %.8f\nObserved: %.8f", 545 expect_ans, ans); 546 expected = (uint64_t)(*(uint32_t *)&expect_ans); 547 observed = (uint64_t)(*(uint32_t *)&ans); 548 setup_fps_test_struct(IS_EREPORT_INFO, 549 report, 6114, &observed, &expected, 1, 550 1, err_data); 551 552 return (-2); 553 } 554 } 555 556 ans = a / b; 557 expect_ans = 1.2500000; 558 if (ans != expect_ans) { 559 if (ans < (1.2500000 - SPMARGIN) || 560 ans > (1.2500000 + SPMARGIN)) { 561 (void) snprintf(err_data, sizeof (err_data), 562 "\nExpected: %.8f\nObserved: %.8f", 563 expect_ans, ans); 564 expected = (uint64_t)(*(uint32_t *)&expect_ans); 565 observed = (uint64_t)(*(uint32_t *)&ans); 566 setup_fps_test_struct(IS_EREPORT_INFO, 567 report, 6115, &observed, &expected, 1, 568 1, err_data); 569 570 return (-2); 571 } 572 } 573 574 ans = a + (a - b); 575 expect_ans = 1.4814000; 576 if (ans != expect_ans) { 577 if (ans < (1.4814000 - SPMARGIN) || 578 ans > (1.4814000 + SPMARGIN)) { 579 (void) snprintf(err_data, sizeof (err_data), 580 "\nExpected: %.8f\nObserved: %.8f", 581 expect_ans, ans); 582 expected = (uint64_t)(*(uint32_t *)&expect_ans); 583 observed = (uint64_t)(*(uint32_t *)&ans); 584 setup_fps_test_struct(IS_EREPORT_INFO, 585 report, 6116, &observed, &expected, 1, 586 1, err_data); 587 588 return (-2); 589 } 590 } 591 592 ans = a - (a + b); 593 expect_ans = -(0.9876000); 594 if (ans != expect_ans) { 595 if (ans < (-(0.9876000) - SPMARGIN) || 596 ans > (-(0.9876000) + SPMARGIN)) { 597 (void) snprintf(err_data, sizeof (err_data), 598 "\nExpected: %.8f\nObserved: %.8f", 599 expect_ans, ans); 600 expected = (uint64_t)(*(uint32_t *)&expect_ans); 601 observed = (uint64_t)(*(uint32_t *)&ans); 602 setup_fps_test_struct(IS_EREPORT_INFO, 603 report, 6117, &observed, &expected, 1, 604 1, err_data); 605 606 return (-2); 607 } 608 } 609 610 ans = a + (a * b); 611 expect_ans = 2.4536924; 612 if (ans != expect_ans) { 613 if (ans < (2.4536924 - SPMARGIN) || 614 ans > (2.4536924 + SPMARGIN)) { 615 (void) snprintf(err_data, sizeof (err_data), 616 "\nExpected: %.8f\nObserved: %.8f", 617 expect_ans, ans); 618 expected = (uint64_t)(*(uint32_t *)&expect_ans); 619 observed = (uint64_t)(*(uint32_t *)&ans); 620 setup_fps_test_struct(IS_EREPORT_INFO, 621 report, 6118, &observed, &expected, 1, 622 1, err_data); 623 624 return (-2); 625 } 626 } 627 628 ans = a - (a * b); 629 expect_ans = 0.0153078; 630 if (ans != expect_ans) { 631 if (ans < (0.0153078 - SPMARGIN) || 632 ans > (0.0153078 + SPMARGIN)) { 633 (void) snprintf(err_data, sizeof (err_data), 634 "\nExpected: %.8f\nObserved: %.8f", 635 expect_ans, ans); 636 expected = (uint64_t)(*(uint32_t *)&expect_ans); 637 observed = (uint64_t)(*(uint32_t *)&ans); 638 setup_fps_test_struct(IS_EREPORT_INFO, 639 report, 6119, &observed, &expected, 1, 640 1, err_data); 641 642 return (-2); 643 } 644 } 645 646 ans = a + (a / b); 647 expect_ans = 2.4844999; 648 if (ans != expect_ans) { 649 if (ans < (2.4844999 - SPMARGIN) || 650 ans > (2.4844999 + SPMARGIN)) { 651 (void) snprintf(err_data, sizeof (err_data), 652 "\nExpected: %.8f\nObserved: %.8f", 653 expect_ans, ans); 654 expected = (uint64_t)(*(uint32_t *)&expect_ans); 655 observed = (uint64_t)(*(uint32_t *)&ans); 656 setup_fps_test_struct(IS_EREPORT_INFO, 657 report, 6120, &observed, &expected, 1, 658 1, err_data); 659 660 return (-2); 661 } 662 } 663 664 ans = a - (a / b); 665 expect_ans = expect_ans; 666 if (ans != -(0.0155000)) { 667 if (ans < (-(0.0155000) - SPMARGIN) || 668 ans > (-(0.0155000) + SPMARGIN)) { 669 (void) snprintf(err_data, sizeof (err_data), 670 "\nExpected: %.8f\nObserved: %.8f", 671 expect_ans, ans); 672 expected = (uint64_t)(*(uint32_t *)&expect_ans); 673 observed = (uint64_t)(*(uint32_t *)&ans); 674 setup_fps_test_struct(IS_EREPORT_INFO, 675 report, 6121, &observed, &expected, 1, 676 1, err_data); 677 678 return (-2); 679 } 680 } 681 682 ans = a * (a + b); 683 expect_ans = 2.7431827; 684 if (ans != expect_ans) { 685 if (ans < (2.7431827 - SPMARGIN) || 686 ans > (2.7431827 + SPMARGIN)) { 687 (void) snprintf(err_data, sizeof (err_data), 688 "\nExpected: %.8f\nObserved: %.8f", 689 expect_ans, ans); 690 expected = (uint64_t)(*(uint32_t *)&expect_ans); 691 observed = (uint64_t)(*(uint32_t *)&ans); 692 setup_fps_test_struct(IS_EREPORT_INFO, 693 report, 6122, &observed, &expected, 1, 694 1, err_data); 695 696 return (-2); 697 } 698 } 699 700 ans = a * (a - b); 701 expect_ans = 0.3047981; 702 if (ans != expect_ans) { 703 if (ans < (0.3047981 - SPMARGIN) || 704 ans > (0.3047981 + SPMARGIN)) { 705 (void) snprintf(err_data, sizeof (err_data), 706 "\nExpected: %.8f\nObserved: %.8f", 707 expect_ans, ans); 708 expected = (uint64_t)(*(uint32_t *)&expect_ans); 709 observed = (uint64_t)(*(uint32_t *)&ans); 710 setup_fps_test_struct(IS_EREPORT_INFO, 711 report, 6123, &observed, &expected, 1, 712 1, err_data); 713 714 return (-2); 715 } 716 } 717 718 ans = a / (a + b); 719 expect_ans = 0.5555556; 720 if (ans != expect_ans) { 721 if (ans < (0.5555556 - SPMARGIN) || 722 ans > (0.5555556 + SPMARGIN)) { 723 (void) snprintf(err_data, sizeof (err_data), 724 "\nExpected: %.8f\nObserved: %.8f", 725 expect_ans, ans); 726 expected = (uint64_t)(*(uint32_t *)&expect_ans); 727 observed = (uint64_t)(*(uint32_t *)&ans); 728 setup_fps_test_struct(IS_EREPORT_INFO, 729 report, 6124, &observed, &expected, 1, 730 1, err_data); 731 732 return (-2); 733 } 734 } 735 736 ans = a / (a - b); 737 expect_ans = 4.9999995; 738 if (ans != expect_ans) { 739 if (ans < (4.9999995 - SPMARGIN) || 740 ans > (4.9999995 + SPMARGIN)) { 741 (void) snprintf(err_data, sizeof (err_data), 742 "\nExpected: %.8f\nObserved: %.8f", 743 expect_ans, ans); 744 expected = (uint64_t)(*(uint32_t *)&expect_ans); 745 observed = (uint64_t)(*(uint32_t *)&ans); 746 setup_fps_test_struct(IS_EREPORT_INFO, 747 report, 6125, &observed, &expected, 1, 748 1, err_data); 749 750 return (-2); 751 } 752 } 753 754 ans = a * (a / b); 755 expect_ans = 1.5431250; 756 if (ans != expect_ans) { 757 if (ans < (1.5431250 - SPMARGIN) || 758 ans > (1.5431250 + SPMARGIN)) { 759 (void) snprintf(err_data, sizeof (err_data), 760 "\nExpected: %.8f\nObserved: %.8f", 761 expect_ans, ans); 762 expected = (uint64_t)(*(uint32_t *)&expect_ans); 763 observed = (uint64_t)(*(uint32_t *)&ans); 764 setup_fps_test_struct(IS_EREPORT_INFO, 765 report, 6126, &observed, &expected, 1, 766 1, err_data); 767 768 return (-2); 769 } 770 } 771 772 ans = a / (a * b); 773 expect_ans = 1.0125557; 774 if (ans != expect_ans) { 775 if (ans < (1.0125557 - SPMARGIN) || 776 ans > (1.0125557 + SPMARGIN)) { 777 (void) snprintf(err_data, sizeof (err_data), 778 "\nExpected: %.8f\nObserved: %.8f", 779 expect_ans, ans); 780 expected = (uint64_t)(*(uint32_t *)&expect_ans); 781 observed = (uint64_t)(*(uint32_t *)&ans); 782 setup_fps_test_struct(IS_EREPORT_INFO, 783 report, 6127, &observed, &expected, 1, 784 1, err_data); 785 786 return (-2); 787 } 788 } 789 790 return (0); 791 } 792 793 /* 794 * dpmath(int unit, struct fps_test_ereport *report) 795 * peforms basic tests of the arithmetic operations: 796 * +, -, *, and /. It also performs tests of cos, 797 * sine, tan, log, sqrt, and exp. If any errors, 798 * they are stored in report. 799 */ 800 static int 801 dpmath(struct fps_test_ereport *report) 802 { 803 char err_data[MAX_INFO_SIZE]; 804 double a; 805 double ans; 806 double b; 807 double expect_ans; 808 double expect_ans2; 809 double result; 810 double x; 811 uint64_t expected; 812 uint64_t observed; 813 814 a = 1.2345; 815 b = 0.9876; 816 817 ans = (a + b); 818 expect_ans = 2.222100000000000; 819 if (ans != expect_ans) { 820 if (ans < (expect_ans - DPMARGIN) || 821 ans > (expect_ans + DPMARGIN)) { 822 expected = *(uint64_t *)&expect_ans; 823 observed = *(uint64_t *)&ans; 824 (void) snprintf(err_data, sizeof (err_data), 825 "\nExpected: %.16f\nObserved: %.16f", 826 expect_ans, ans); 827 setup_fps_test_struct(IS_EREPORT_INFO, 828 report, 6128, &observed, &expected, 1, 1, 829 err_data); 830 831 return (-3); 832 } 833 } 834 835 ans = (a - b); 836 expect_ans = 0.246899999999999; 837 if (ans != expect_ans) { 838 if (ans < (expect_ans - DPMARGIN) || 839 ans > (expect_ans + DPMARGIN)) { 840 expected = *(uint64_t *)&expect_ans; 841 observed = *(uint64_t *)&ans; 842 (void) snprintf(err_data, sizeof (err_data), 843 "\nExpected: %.16f\nObserved: %.16f", 844 expect_ans, ans); 845 setup_fps_test_struct(IS_EREPORT_INFO, 846 report, 6129, &observed, &expected, 1, 1, 847 err_data); 848 849 return (-3); 850 } 851 } 852 853 ans = a * b; 854 expect_ans = 1.219192199999999; 855 if (ans != expect_ans) { 856 if (ans < (expect_ans - DPMARGIN) || 857 ans > (expect_ans + DPMARGIN)) { 858 expected = *(uint64_t *)&expect_ans; 859 observed = *(uint64_t *)&ans; 860 (void) snprintf(err_data, sizeof (err_data), 861 "\nExpected: %.16f\nObserved: %.16f", 862 expect_ans, ans); 863 setup_fps_test_struct(IS_EREPORT_INFO, 864 report, 6130, &observed, &expected, 1, 1, 865 err_data); 866 867 return (-3); 868 } 869 } 870 871 ans = a / b; 872 expect_ans = 1.249999999999999; 873 if (ans != expect_ans) { 874 if (ans < (expect_ans - DPMARGIN) || 875 ans > (expect_ans + DPMARGIN)) { 876 expected = *(uint64_t *)&expect_ans; 877 observed = *(uint64_t *)&ans; 878 (void) snprintf(err_data, sizeof (err_data), 879 "\nExpected: %.16f\nObserved: %.16f", 880 expect_ans, ans); 881 setup_fps_test_struct(IS_EREPORT_INFO, 882 report, 6131, &observed, &expected, 1, 1, 883 err_data); 884 885 return (-3); 886 } 887 } 888 889 ans = a + (a - b); 890 expect_ans = 1.481399999999999; 891 if (ans != expect_ans) { 892 if (ans < (expect_ans - DPMARGIN) || 893 ans > (expect_ans + DPMARGIN)) { 894 expected = *(uint64_t *)&expect_ans; 895 observed = *(uint64_t *)&ans; 896 (void) snprintf(err_data, sizeof (err_data), 897 "\nExpected: %.16f\nObserved: %.16f", 898 expect_ans, ans); 899 setup_fps_test_struct(IS_EREPORT_INFO, 900 report, 6132, &observed, &expected, 1, 1, 901 err_data); 902 903 return (-3); 904 } 905 } 906 907 ans = a - (a + b); 908 expect_ans = -(0.987600000000000); 909 if (ans != expect_ans) { 910 if (ans < (expect_ans - DPMARGIN) || 911 ans > (expect_ans + DPMARGIN)) { 912 expected = *(uint64_t *)&expect_ans; 913 observed = *(uint64_t *)&ans; 914 (void) snprintf(err_data, sizeof (err_data), 915 "\nExpected: %.16f\nObserved: %.16f", 916 expect_ans, ans); 917 setup_fps_test_struct(IS_EREPORT_INFO, 918 report, 6133, &observed, &expected, 1, 1, 919 err_data); 920 921 return (-3); 922 } 923 } 924 925 ans = a + (a * b); 926 expect_ans = 2.453692200000000; 927 if (ans != expect_ans) { 928 if (ans < (expect_ans - DPMARGIN) || 929 ans > (expect_ans + DPMARGIN)) { 930 expected = *(uint64_t *)&expect_ans; 931 observed = *(uint64_t *)&ans; 932 (void) snprintf(err_data, sizeof (err_data), 933 "\nExpected: %.16f\nObserved: %.16f", 934 expect_ans, ans); 935 setup_fps_test_struct(IS_EREPORT_INFO, 936 report, 6134, &observed, &expected, 1, 1, 937 err_data); 938 939 return (-3); 940 } 941 } 942 943 ans = a - (a * b); 944 expect_ans = 0.015307800000000; 945 if (ans != expect_ans) { 946 if (ans < (expect_ans - DPMARGIN) || 947 ans > (expect_ans + DPMARGIN)) { 948 expected = *(uint64_t *)&expect_ans; 949 observed = *(uint64_t *)&ans; 950 (void) snprintf(err_data, sizeof (err_data), 951 "\nExpected: %.16f\nObserved: %.16f", 952 expect_ans, ans); 953 setup_fps_test_struct(IS_EREPORT_INFO, 954 report, 6135, &observed, &expected, 1, 1, 955 err_data); 956 957 return (-3); 958 } 959 } 960 961 ans = a + (a / b); 962 expect_ans = 2.484500000000000; 963 if (ans != expect_ans) { 964 if (ans < (expect_ans - DPMARGIN) || 965 ans > (expect_ans + DPMARGIN)) { 966 expected = *(uint64_t *)&expect_ans; 967 observed = *(uint64_t *)&ans; 968 (void) snprintf(err_data, sizeof (err_data), 969 "\nExpected: %.16f\nObserved: %.16f", 970 expect_ans, ans); 971 setup_fps_test_struct(IS_EREPORT_INFO, 972 report, 6136, &observed, &expected, 1, 1, 973 err_data); 974 975 return (-3); 976 } 977 } 978 979 ans = a - (a / b); 980 expect_ans = -(0.015499999999999); 981 if (ans != expect_ans) { 982 if (ans < (expect_ans - DPMARGIN) || 983 ans > (expect_ans + DPMARGIN)) { 984 expected = *(uint64_t *)&expect_ans; 985 observed = *(uint64_t *)&ans; 986 (void) snprintf(err_data, sizeof (err_data), 987 "\nExpected: %.16f\nObserved: %.16f", 988 expect_ans, ans); 989 setup_fps_test_struct(IS_EREPORT_INFO, 990 report, 6137, &observed, &expected, 1, 1, 991 err_data); 992 993 return (-3); 994 } 995 } 996 997 ans = a * (a + b); 998 expect_ans = 2.743182449999999; 999 if (ans != expect_ans) { 1000 if (ans < (expect_ans - DPMARGIN) || 1001 ans > (expect_ans + DPMARGIN)) { 1002 expected = *(uint64_t *)&expect_ans; 1003 observed = *(uint64_t *)&ans; 1004 (void) snprintf(err_data, sizeof (err_data), 1005 "\nExpected: %.16f\nObserved: %.16f", 1006 expect_ans, ans); 1007 setup_fps_test_struct(IS_EREPORT_INFO, 1008 report, 6138, &observed, &expected, 1, 1, 1009 err_data); 1010 1011 return (-3); 1012 } 1013 } 1014 1015 ans = a * (a - b); 1016 expect_ans = 0.304798049999999; 1017 if (ans != expect_ans) { 1018 if (ans < (expect_ans - DPMARGIN) || 1019 ans > (expect_ans + DPMARGIN)) { 1020 expected = *(uint64_t *)&expect_ans; 1021 observed = *(uint64_t *)&ans; 1022 (void) snprintf(err_data, sizeof (err_data), 1023 "\nExpected: %.16f\nObserved: %.16f", 1024 expect_ans, ans); 1025 setup_fps_test_struct(IS_EREPORT_INFO, 1026 report, 6139, &observed, &expected, 1, 1, 1027 err_data); 1028 1029 return (-3); 1030 } 1031 } 1032 1033 1034 ans = a / (a + b); 1035 expect_ans = 0.555555555555555; 1036 if (ans != expect_ans) { 1037 if (ans < (expect_ans - DPMARGIN) || 1038 ans > (expect_ans + DPMARGIN)) { 1039 expected = *(uint64_t *)&expect_ans; 1040 observed = *(uint64_t *)&ans; 1041 (void) snprintf(err_data, sizeof (err_data), 1042 "\nExpected: %.16f\nObserved: %.16f", 1043 expect_ans, ans); 1044 setup_fps_test_struct(IS_EREPORT_INFO, 1045 report, 6140, &observed, &expected, 1, 1, 1046 err_data); 1047 1048 return (-3); 1049 } 1050 } 1051 1052 ans = a / (a - b); 1053 expect_ans = 5.000000000000002; 1054 if (ans != expect_ans) { 1055 if (ans < (expect_ans - DPMARGIN) || 1056 ans > (expect_ans + DPMARGIN)) { 1057 expected = *(uint64_t *)&expect_ans; 1058 observed = *(uint64_t *)&ans; 1059 (void) snprintf(err_data, sizeof (err_data), 1060 "\nExpected: %.16f\nObserved: %.16f", 1061 expect_ans, ans); 1062 setup_fps_test_struct(IS_EREPORT_INFO, 1063 report, 6141, &observed, &expected, 1, 1, 1064 err_data); 1065 1066 return (-3); 1067 } 1068 } 1069 1070 ans = a * (a / b); 1071 expect_ans = 1.543124999999999; 1072 if (ans != expect_ans) { 1073 if (ans < (expect_ans - DPMARGIN) || 1074 ans > (expect_ans + DPMARGIN)) { 1075 expected = *(uint64_t *)&expect_ans; 1076 observed = *(uint64_t *)&ans; 1077 (void) snprintf(err_data, sizeof (err_data), 1078 "\nExpected: %.16f\nObserved: %.16f", 1079 expect_ans, ans); 1080 setup_fps_test_struct(IS_EREPORT_INFO, 1081 report, 6142, &observed, &expected, 1, 1, 1082 err_data); 1083 1084 return (-3); 1085 } 1086 } 1087 1088 ans = a / (a * b); 1089 expect_ans = 1.012555690562980; 1090 if (ans != expect_ans) { 1091 if (ans < (expect_ans - DPMARGIN) || 1092 ans > (expect_ans + DPMARGIN)) { 1093 expected = *(uint64_t *)&expect_ans; 1094 observed = *(uint64_t *)&ans; 1095 (void) snprintf(err_data, sizeof (err_data), 1096 "\nExpected: %.16f\nObserved: %.16f", 1097 expect_ans, ans); 1098 setup_fps_test_struct(IS_EREPORT_INFO, 1099 report, 6143, &observed, &expected, 1, 1, 1100 err_data); 1101 1102 return (-3); 1103 } 1104 } 1105 1106 /* Start Double Precision test of trg functions */ 1107 1108 /* sin of values in the range of -2pi to +2pi */ 1109 result = sin(-(pi * 2)); 1110 expect_ans = -(0.000000000820413); 1111 if (result != expect_ans) { 1112 if (result < (expect_ans - DPMARGIN) || 1113