GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — netdata/src/unit_test.c at master · gitqueue/netdata Expand file tree/ Copy pathunit_test.cMore file actions 1133 lines (941 loc) · 37.7 KB / Copy pathunit_test.cFile metadata and controls1133 lines (941 loc) · 37.7 KB 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 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 #include "common.h" int check_storage_number(calculated_number n, int debug) { char buffer[100]; uint32_t flags = SN_EXISTS; storage_number s = pack_storage_number(n, flags); calculated_number d = unpack_storage_number(s); if(!does_storage_number_exist(s)) { fprintf(stderr, "Exists flags missing for number " CALCULATED_NUMBER_FORMAT "!\n", n); return 5; } calculated_number ddiff = d - n; calculated_number dcdiff = ddiff * 100.0 / n; if(dcdiff < 0) dcdiff = -dcdiff; size_t len = print_calculated_number(buffer, d); calculated_number p = strtold(buffer, NULL); calculated_number pdiff = n - p; calculated_number pcdiff = pdiff * 100.0 / n; if(pcdiff < 0) pcdiff = -pcdiff; if(debug) { fprintf(stderr, CALCULATED_NUMBER_FORMAT " original\n" CALCULATED_NUMBER_FORMAT " packed and unpacked, (stored as 0x%08X, diff " CALCULATED_NUMBER_FORMAT ", " CALCULATED_NUMBER_FORMAT "%%)\n" "%s printed after unpacked (%zu bytes)\n" CALCULATED_NUMBER_FORMAT " re-parsed from printed (diff " CALCULATED_NUMBER_FORMAT ", " CALCULATED_NUMBER_FORMAT "%%)\n\n", n, d, s, ddiff, dcdiff, buffer, len, p, pdiff, pcdiff ); if(len != strlen(buffer)) fprintf(stderr, "ERROR: printed number %s is reported to have length %zu but it has %zu\n", buffer, len, strlen(buffer)); if(dcdiff > ACCURACY_LOSS) fprintf(stderr, "WARNING: packing number " CALCULATED_NUMBER_FORMAT " has accuracy loss %0.7Lf %%\n", n, dcdiff); if(pcdiff > ACCURACY_LOSS) fprintf(stderr, "WARNING: re-parsing the packed, unpacked and printed number " CALCULATED_NUMBER_FORMAT " has accuracy loss %0.7Lf %%\n", n, pcdiff); } if(len != strlen(buffer)) return 1; if(dcdiff > ACCURACY_LOSS) return 3; if(pcdiff > ACCURACY_LOSS) return 4; return 0; } void benchmark_storage_number(int loop, int multiplier) { int i, j; calculated_number n, d; storage_number s; unsigned long long user, system, total, mine, their; char buffer[100]; struct rusage now, last; fprintf(stderr, "\n\nBenchmarking %d numbers, please wait...\n\n", loop); // ------------------------------------------------------------------------ fprintf(stderr, "SYSTEM LONG DOUBLE SIZE: %zu bytes\n", sizeof(calculated_number)); fprintf(stderr, "NETDATA FLOATING POINT SIZE: %zu bytes\n", sizeof(storage_number)); mine = (calculated_number)sizeof(storage_number) * (calculated_number)loop; their = (calculated_number)sizeof(calculated_number) * (calculated_number)loop; if(mine > their) { fprintf(stderr, "\nNETDATA NEEDS %0.2Lf TIMES MORE MEMORY. Sorry!\n", (long double)(mine / their)); } else { fprintf(stderr, "\nNETDATA INTERNAL FLOATING POINT ARITHMETICS NEEDS %0.2Lf TIMES LESS MEMORY.\n", (long double)(their / mine)); } fprintf(stderr, "\nNETDATA FLOATING POINT\n"); fprintf(stderr, "MIN POSITIVE VALUE " CALCULATED_NUMBER_FORMAT "\n", (calculated_number)STORAGE_NUMBER_POSITIVE_MIN); fprintf(stderr, "MAX POSITIVE VALUE " CALCULATED_NUMBER_FORMAT "\n", (calculated_number)STORAGE_NUMBER_POSITIVE_MAX); fprintf(stderr, "MIN NEGATIVE VALUE " CALCULATED_NUMBER_FORMAT "\n", (calculated_number)STORAGE_NUMBER_NEGATIVE_MIN); fprintf(stderr, "MAX NEGATIVE VALUE " CALCULATED_NUMBER_FORMAT "\n", (calculated_number)STORAGE_NUMBER_NEGATIVE_MAX); fprintf(stderr, "Maximum accuracy loss: " CALCULATED_NUMBER_FORMAT "%%\n\n\n", (calculated_number)ACCURACY_LOSS); // ------------------------------------------------------------------------ fprintf(stderr, "INTERNAL LONG DOUBLE PRINTING: "); getrusage(RUSAGE_SELF, &last); // do the job for(j = 1; j < 11 ;j++) { n = STORAGE_NUMBER_POSITIVE_MIN * j; for(i = 0; i < loop ;i++) { n *= multiplier; if(n > STORAGE_NUMBER_POSITIVE_MAX) n = STORAGE_NUMBER_POSITIVE_MIN; print_calculated_number(buffer, n); } } getrusage(RUSAGE_SELF, &now); user = now.ru_utime.tv_sec * 1000000ULL + now.ru_utime.tv_usec - last.ru_utime.tv_sec * 1000000ULL + last.ru_utime.tv_usec; system = now.ru_stime.tv_sec * 1000000ULL + now.ru_stime.tv_usec - last.ru_stime.tv_sec * 1000000ULL + last.ru_stime.tv_usec; total = user + system; mine = total; fprintf(stderr, "user %0.5Lf, system %0.5Lf, total %0.5Lf\n", (long double)(user / 1000000.0), (long double)(system / 1000000.0), (long double)(total / 1000000.0)); // ------------------------------------------------------------------------ fprintf(stderr, "SYSTEM LONG DOUBLE PRINTING: "); getrusage(RUSAGE_SELF, &last); // do the job for(j = 1; j < 11 ;j++) { n = STORAGE_NUMBER_POSITIVE_MIN * j; for(i = 0; i < loop ;i++) { n *= multiplier; if(n > STORAGE_NUMBER_POSITIVE_MAX) n = STORAGE_NUMBER_POSITIVE_MIN; snprintfz(buffer, 100, CALCULATED_NUMBER_FORMAT, n); } } getrusage(RUSAGE_SELF, &now); user = now.ru_utime.tv_sec * 1000000ULL + now.ru_utime.tv_usec - last.ru_utime.tv_sec * 1000000ULL + last.ru_utime.tv_usec; system = now.ru_stime.tv_sec * 1000000ULL + now.ru_stime.tv_usec - last.ru_stime.tv_sec * 1000000ULL + last.ru_stime.tv_usec; total = user + system; their = total; fprintf(stderr, "user %0.5Lf, system %0.5Lf, total %0.5Lf\n", (long double)(user / 1000000.0), (long double)(system / 1000000.0), (long double)(total / 1000000.0)); if(mine > total) { fprintf(stderr, "NETDATA CODE IS SLOWER %0.2Lf %%\n", (long double)(mine * 100.0 / their - 100.0)); } else { fprintf(stderr, "NETDATA CODE IS F A S T E R %0.2Lf %%\n", (long double)(their * 100.0 / mine - 100.0)); } // ------------------------------------------------------------------------ fprintf(stderr, "\nINTERNAL LONG DOUBLE PRINTING WITH PACK / UNPACK: "); getrusage(RUSAGE_SELF, &last); // do the job for(j = 1; j < 11 ;j++) { n = STORAGE_NUMBER_POSITIVE_MIN * j; for(i = 0; i < loop ;i++) { n *= multiplier; if(n > STORAGE_NUMBER_POSITIVE_MAX) n = STORAGE_NUMBER_POSITIVE_MIN; s = pack_storage_number(n, 1); d = unpack_storage_number(s); print_calculated_number(buffer, d); } } getrusage(RUSAGE_SELF, &now); user = now.ru_utime.tv_sec * 1000000ULL + now.ru_utime.tv_usec - last.ru_utime.tv_sec * 1000000ULL + last.ru_utime.tv_usec; system = now.ru_stime.tv_sec * 1000000ULL + now.ru_stime.tv_usec - last.ru_stime.tv_sec * 1000000ULL + last.ru_stime.tv_usec; total = user + system; mine = total; fprintf(stderr, "user %0.5Lf, system %0.5Lf, total %0.5Lf\n", (long double)(user / 1000000.0), (long double)(system / 1000000.0), (long double)(total / 1000000.0)); if(mine > their) { fprintf(stderr, "WITH PACKING UNPACKING NETDATA CODE IS SLOWER %0.2Lf %%\n", (long double)(mine * 100.0 / their - 100.0)); } else { fprintf(stderr, "EVEN WITH PACKING AND UNPACKING, NETDATA CODE IS F A S T E R %0.2Lf %%\n", (long double)(their * 100.0 / mine - 100.0)); } // ------------------------------------------------------------------------ } static int check_storage_number_exists() { uint32_t flags = SN_EXISTS; for(flags = 0; flags < 7 ; flags++) { if(get_storage_number_flags(flags << 24) != flags << 24) { fprintf(stderr, "Flag 0x%08x is not checked correctly. It became 0x%08x\n", flags << 24, get_storage_number_flags(flags << 24)); return 1; } } flags = SN_EXISTS; calculated_number n = 0.0; storage_number s = pack_storage_number(n, flags); calculated_number d = unpack_storage_number(s); if(get_storage_number_flags(s) != flags) { fprintf(stderr, "Wrong flags. Given %08x, Got %08x!\n", flags, get_storage_number_flags(s)); return 1; } if(n != d) { fprintf(stderr, "Wrong number returned. Expected " CALCULATED_NUMBER_FORMAT ", returned " CALCULATED_NUMBER_FORMAT "!\n", n, d); return 1; } return 0; } int unit_test_storage() { if(check_storage_number_exists()) return 0; calculated_number c, a = 0; int i, j, g, r = 0; for(g = -1; g <= 1 ; g++) { a = 0; if(!g) continue; for(j = 0; j < 9 ;j++) { a += 0.0000001; c = a * g; for(i = 0; i < 21 ;i++, c *= 10) { if(c > 0 && c < STORAGE_NUMBER_POSITIVE_MIN) continue; if(c < 0 && c > STORAGE_NUMBER_NEGATIVE_MAX) continue; if(check_storage_number(c, 1)) return 1; } } } benchmark_storage_number(1000000, 2); return r; } // -------------------------------------------------------------------------------------------------------------------- struct feed_values { unsigned long long microseconds; collected_number value; }; struct test { char name[100]; char description[1024]; int update_every; unsigned long long multiplier; unsigned long long divisor; int algorithm; unsigned long feed_entries; unsigned long result_entries; struct feed_values *feed; calculated_number *results; collected_number *feed2; calculated_number *results2; }; // -------------------------------------------------------------------------------------------------------------------- // test1 // test absolute values stored struct feed_values test1_feed[] = { { 0, 10 }, { 1000000, 20 }, { 1000000, 30 }, { 1000000, 40 }, { 1000000, 50 }, { 1000000, 60 }, { 1000000, 70 }, { 1000000, 80 }, { 1000000, 90 }, { 1000000, 100 }, }; calculated_number test1_results[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100 }; struct test test1 = { "test1", // name "test absolute values stored at exactly second boundaries", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_ABSOLUTE, // algorithm 10, // feed entries 9, // result entries test1_feed, // feed test1_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test2 // test absolute values stored in the middle of second boundaries struct feed_values test2_feed[] = { { 500000, 10 }, { 1000000, 20 }, { 1000000, 30 }, { 1000000, 40 }, { 1000000, 50 }, { 1000000, 60 }, { 1000000, 70 }, { 1000000, 80 }, { 1000000, 90 }, { 1000000, 100 }, }; calculated_number test2_results[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100 }; struct test test2 = { "test2", // name "test absolute values stored in the middle of second boundaries", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_ABSOLUTE, // algorithm 10, // feed entries 9, // result entries test2_feed, // feed test2_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test3 struct feed_values test3_feed[] = { { 0, 10 }, { 1000000, 20 }, { 1000000, 30 }, { 1000000, 40 }, { 1000000, 50 }, { 1000000, 60 }, { 1000000, 70 }, { 1000000, 80 }, { 1000000, 90 }, { 1000000, 100 }, }; calculated_number test3_results[] = { 10, 10, 10, 10, 10, 10, 10, 10, 10 }; struct test test3 = { "test3", // name "test incremental values stored at exactly second boundaries", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 9, // result entries test3_feed, // feed test3_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test4 struct feed_values test4_feed[] = { { 500000, 10 }, { 1000000, 20 }, { 1000000, 30 }, { 1000000, 40 }, { 1000000, 50 }, { 1000000, 60 }, { 1000000, 70 }, { 1000000, 80 }, { 1000000, 90 }, { 1000000, 100 }, }; calculated_number test4_results[] = { 10, 10, 10, 10, 10, 10, 10, 10, 10 }; struct test test4 = { "test4", // name "test incremental values stored in the middle of second boundaries", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 9, // result entries test4_feed, // feed test4_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test5 struct feed_values test5_feed[] = { { 500000, 1000 }, { 1000000, 2000 }, { 1000000, 2000 }, { 1000000, 2000 }, { 1000000, 3000 }, { 1000000, 2000 }, { 1000000, 2000 }, { 1000000, 2000 }, { 1000000, 2000 }, { 1000000, 2000 }, }; calculated_number test5_results[] = { 1000, 500, 0, 500, 500, 0, 0, 0, 0 }; struct test test5 = { "test5", // name "test incremental values ups and downs", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 9, // result entries test5_feed, // feed test5_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test6 struct feed_values test6_feed[] = { { 250000, 1000 }, { 250000, 2000 }, { 250000, 3000 }, { 250000, 4000 }, { 250000, 5000 }, { 250000, 6000 }, { 250000, 7000 }, { 250000, 8000 }, { 250000, 9000 }, { 250000, 10000 }, { 250000, 11000 }, { 250000, 12000 }, { 250000, 13000 }, { 250000, 14000 }, { 250000, 15000 }, { 250000, 16000 }, }; calculated_number test6_results[] = { 4000, 4000, 4000, 4000 }; struct test test6 = { "test6", // name "test incremental values updated within the same second", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 16, // feed entries 4, // result entries test6_feed, // feed test6_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test7 struct feed_values test7_feed[] = { { 500000, 1000 }, { 2000000, 2000 }, { 2000000, 3000 }, { 2000000, 4000 }, { 2000000, 5000 }, { 2000000, 6000 }, { 2000000, 7000 }, { 2000000, 8000 }, { 2000000, 9000 }, { 2000000, 10000 }, }; calculated_number test7_results[] = { 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500 }; struct test test7 = { "test7", // name "test incremental values updated in long durations", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 18, // result entries test7_feed, // feed test7_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test8 struct feed_values test8_feed[] = { { 500000, 1000 }, { 2000000, 2000 }, { 2000000, 3000 }, { 2000000, 4000 }, { 2000000, 5000 }, { 2000000, 6000 }, }; calculated_number test8_results[] = { 1250, 2000, 2250, 3000, 3250, 4000, 4250, 5000, 5250, 6000 }; struct test test8 = { "test8", // name "test absolute values updated in long durations", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_ABSOLUTE, // algorithm 6, // feed entries 10, // result entries test8_feed, // feed test8_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test9 struct feed_values test9_feed[] = { { 250000, 1000 }, { 250000, 2000 }, { 250000, 3000 }, { 250000, 4000 }, { 250000, 5000 }, { 250000, 6000 }, { 250000, 7000 }, { 250000, 8000 }, { 250000, 9000 }, { 250000, 10000 }, { 250000, 11000 }, { 250000, 12000 }, { 250000, 13000 }, { 250000, 14000 }, { 250000, 15000 }, { 250000, 16000 }, }; calculated_number test9_results[] = { 4000, 8000, 12000, 16000 }; struct test test9 = { "test9", // name "test absolute values updated within the same second", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_ABSOLUTE, // algorithm 16, // feed entries 4, // result entries test9_feed, // feed test9_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test10 struct feed_values test10_feed[] = { { 500000, 1000 }, { 600000, 1000 + 600 }, { 200000, 1600 + 200 }, { 1000000, 1800 + 1000 }, { 200000, 2800 + 200 }, { 2000000, 3000 + 2000 }, { 600000, 5000 + 600 }, { 400000, 5600 + 400 }, { 900000, 6000 + 900 }, { 1000000, 6900 + 1000 }, }; calculated_number test10_results[] = { 1000, 1000, 1000, 1000, 1000, 1000, 1000 }; struct test test10 = { "test10", // name "test incremental values updated in short and long durations", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 7, // result entries test10_feed, // feed test10_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test11 struct feed_values test11_feed[] = { { 0, 10 }, { 1000000, 20 }, { 1000000, 30 }, { 1000000, 40 }, { 1000000, 50 }, { 1000000, 60 }, { 1000000, 70 }, { 1000000, 80 }, { 1000000, 90 }, { 1000000, 100 }, }; collected_number test11_feed2[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; calculated_number test11_results[] = { 50, 50, 50, 50, 50, 50, 50, 50, 50 }; calculated_number test11_results2[] = { 50, 50, 50, 50, 50, 50, 50, 50, 50 }; struct test test11 = { "test11", // name "test percentage-of-incremental-row with equal values", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_PCENT_OVER_DIFF_TOTAL, // algorithm 10, // feed entries 9, // result entries test11_feed, // feed test11_results, // results test11_feed2, // feed2 test11_results2 // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test12 struct feed_values test12_feed[] = { { 0, 10 }, { 1000000, 20 }, { 1000000, 30 }, { 1000000, 40 }, { 1000000, 50 }, { 1000000, 60 }, { 1000000, 70 }, { 1000000, 80 }, { 1000000, 90 }, { 1000000, 100 }, }; collected_number test12_feed2[] = { 10*3, 20*3, 30*3, 40*3, 50*3, 60*3, 70*3, 80*3, 90*3, 100*3 }; calculated_number test12_results[] = { 25, 25, 25, 25, 25, 25, 25, 25, 25 }; calculated_number test12_results2[] = { 75, 75, 75, 75, 75, 75, 75, 75, 75 }; struct test test12 = { "test12", // name "test percentage-of-incremental-row with equal values", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_PCENT_OVER_DIFF_TOTAL, // algorithm 10, // feed entries 9, // result entries test12_feed, // feed test12_results, // results test12_feed2, // feed2 test12_results2 // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test13 struct feed_values test13_feed[] = { { 500000, 1000 }, { 600000, 1000 + 600 }, { 200000, 1600 + 200 }, { 1000000, 1800 + 1000 }, { 200000, 2800 + 200 }, { 2000000, 3000 + 2000 }, { 600000, 5000 + 600 }, { 400000, 5600 + 400 }, { 900000, 6000 + 900 }, { 1000000, 6900 + 1000 }, }; calculated_number test13_results[] = { 83.3333300, 100, 100, 100, 100, 100, 100 }; struct test test13 = { "test13", // name "test incremental values updated in short and long durations", 1, // update_every 1, // multiplier 1, // divisor RRDDIM_PCENT_OVER_DIFF_TOTAL, // algorithm 10, // feed entries 7, // result entries test13_feed, // feed test13_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test14 struct feed_values test14_feed[] = { { 0, 0x015397dc42151c41ULL }, { 13573000, 0x015397e612e3ff5dULL }, { 29969000, 0x015397f905ecdaa8ULL }, { 29958000, 0x0153980c2a6cb5e4ULL }, { 30054000, 0x0153981f4032fb83ULL }, { 34952000, 0x015398355efadaccULL }, { 25046000, 0x01539845ba4b09f8ULL }, { 29947000, 0x0153985948bf381dULL }, { 30054000, 0x0153986c5b9c27e2ULL }, { 29942000, 0x0153987f888982d0ULL }, }; calculated_number test14_results[] = { 23.1383300, 21.8515600, 21.8804600, 21.7788000, 22.0112200, 22.4386100, 22.0906100, 21.9150800 }; struct test test14 = { "test14", // name "issue #981 with real data", 30, // update_every 8, // multiplier 1000000000, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 8, // result entries test14_feed, // feed test14_results, // results NULL, // feed2 NULL // results2 }; struct feed_values test14b_feed[] = { { 0, 0 }, { 13573000, 13573000 }, { 29969000, 13573000 + 29969000 }, { 29958000, 13573000 + 29969000 + 29958000 }, { 30054000, 13573000 + 29969000 + 29958000 + 30054000 }, { 34952000, 13573000 + 29969000 + 29958000 + 30054000 + 34952000 }, { 25046000, 13573000 + 29969000 + 29958000 + 30054000 + 34952000 + 25046000 }, { 29947000, 13573000 + 29969000 + 29958000 + 30054000 + 34952000 + 25046000 + 29947000 }, { 30054000, 13573000 + 29969000 + 29958000 + 30054000 + 34952000 + 25046000 + 29947000 + 30054000 }, { 29942000, 13573000 + 29969000 + 29958000 + 30054000 + 34952000 + 25046000 + 29947000 + 30054000 + 29942000 }, }; calculated_number test14b_results[] = { 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000 }; struct test test14b = { "test14b", // name "issue #981 with dummy data", 30, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 8, // result entries test14b_feed, // feed test14b_results, // results NULL, // feed2 NULL // results2 }; struct feed_values test14c_feed[] = { { 29000000, 29000000 }, { 1000000, 29000000 + 1000000 }, { 30000000, 29000000 + 1000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 + 30000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 }, { 30000000, 29000000 + 1000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 + 30000000 }, }; calculated_number test14c_results[] = { 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000 }; struct test test14c = { "test14c", // name "issue #981 with dummy data, checking for late start", 30, // update_every 1, // multiplier 1, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 9, // result entries test14c_feed, // feed test14c_results, // results NULL, // feed2 NULL // results2 }; // -------------------------------------------------------------------------------------------------------------------- // test15 struct feed_values test15_feed[] = { { 0, 1068066388 }, { 1008752, 1068822698 }, { 993809, 1069573072 }, { 995911, 1070324135 }, { 1014562, 1071078166 }, { 994684, 1071831349 }, { 993128, 1072235739 }, { 1010332, 1072958871 }, { 1003394, 1073707019 }, { 995201, 1074460255 }, }; collected_number test15_feed2[] = { 178825286, 178825286, 178825286, 178825286, 178825498, 178825498, 179165652, 179202964, 179203282, 179204130 }; calculated_number test15_results[] = { 5857.4080000, 5898.4540000, 5891.6590000, 5806.3160000, 5914.2640000, 3202.2630000, 5589.6560000, 5822.5260000, 5911.7520000 }; calculated_number test15_results2[] = { 0.0000000, 0.0000000, 0.0024944, 1.6324779, 0.0212777, 2655.1890000, 290.5387000, 5.6733610, 6.5960220 }; struct test test15 = { "test15", // name "test incremental with 2 dimensions", 1, // update_every 8, // multiplier 1024, // divisor RRDDIM_INCREMENTAL, // algorithm 10, // feed entries 9, // result entries test15_feed, // feed test15_results, // results test15_feed2, // feed2 test15_results2 // results2 }; // -------------------------------------------------------------------------------------------------------------------- int run_test(struct test *test) { fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description); rrd_memory_mode = RRD_MEMORY_MODE_RAM; rrd_update_every = test->update_every; char name[101]; snprintfz(name, 100, "unittest-%s", test->name); // create the chart RRDSET *st = rrdset_create("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", 1, test->update_every, RRDSET_TYPE_LINE); RRDDIM *rd = rrddim_add(st, "dim1", NULL, test->multiplier, test->divisor, test->algorithm); RRDDIM *rd2 = NULL; if(test->feed2) rd2 = rrddim_add(st, "dim2", NULL, test->multiplier, test->divisor, test->algorithm); st->debug = 1; // feed it with the test data time_t time_now = 0, time_start = time(NULL); unsigned long c; collected_number last = 0; for(c = 0; c < test->feed_entries; c++) { if(debug_flags) fprintf(stderr, "\n\n"); if(c) { time_now += test->feed[c].microseconds; fprintf(stderr, " > %s: feeding position %lu, after %0.3f seconds (%0.3f seconds from start), delta " CALCULATED_NUMBER_FORMAT ", rate " CALCULATED_NUMBER_FORMAT "\n", test->name, c+1, (float)test->feed[c].microseconds / 1000000.0, (float)time_now / 1000000.0, ((calculated_number)test->feed[c].value - (calculated_number)last) * (calculated_number)test->multiplier / (calculated_number)test->divisor, (((calculated_number)test->feed[c].value - (calculated_number)last) * (calculated_number)test->multiplier / (calculated_number)test->divisor) / (calculated_number)test->feed[c].microseconds * (calculated_number)1000000); rrdset_next_usec(st, test->feed[c].microseconds); } else { fprintf(stderr, " > %s: feeding position %lu\n", test->name, c+1); } fprintf(stderr, " >> %s with value " COLLECTED_NUMBER_FORMAT "\n", rd->name, test->feed[c].value); rrddim_set(st, "dim1", test->feed[c].value); last = test->feed[c].value; if(rd2) { fprintf(stderr, " >> %s with value " COLLECTED_NUMBER_FORMAT "\n", rd2->name, test->feed2[c]); rrddim_set(st, "dim2", test->feed2[c]); } rrdset_done(st); // align the first entry to second boundary if(!c) { fprintf(stderr, " > %s: fixing first collection time to be %llu microseconds to second boundary\n", test->name, test->feed[c].microseconds); rd->last_collected_time.tv_usec = st->last_collected_time.tv_usec = st->last_updated.tv_usec = test->feed[c].microseconds; // time_start = st->last_collected_time.tv_sec; } } // check the result int errors = 0; if(st->counter != test->result_entries) { fprintf(stderr, " %s stored %lu entries, but we were expecting %lu, ### E R R O R ###\n", test->name, st->counter, test->result_entries); errors++; } unsigned long max = (st->counter < test->result_entries)?st->counter:test->result_entries; for(c = 0 ; c < max ; c++) { calculated_number v = unpack_storage_number(rd->values[c]); calculated_number n = test->results[c]; int same = (roundl(v * 10000000.0) == roundl(n * 10000000.0))?1:0; fprintf(stderr, " %s/%s: checking position %lu (at %lu secs), expecting value " CALCULATED_NUMBER_FORMAT ", found " CALCULATED_NUMBER_FORMAT ", %s\n", test->name, rd->name, c+1, (rrdset_first_entry_t(st) + c * st->update_every) - time_start, n, v, (same)?"OK":"### E R R O R ###"); if(!same) errors++; if(rd2) { v = unpack_storage_number(rd2->values[c]); n = test->results2[c]; same = (roundl(v * 10000000.0) == roundl(n * 10000000.0))?1:0; fprintf(stderr, " %s/%s: checking position %lu (at %lu secs), expecting value " CALCULATED_NUMBER_FORMAT ", found " CALCULATED_NUMBER_FORMAT ", %s\n", test->name, rd2->name, c+1, (rrdset_first_entry_t(st) + c * st->update_every) - time_start, n, v, (same)?"OK":"### E R R O R ###"); if(!same) errors++; } } return errors; } int run_all_mockup_tests(void) { if(run_test(&test1)) return 1; if(run_test(&test2)) return 1; if(run_test(&test3)) return 1; if(run_test(&test4)) return 1; if(run_test(&test5)) return 1; if(run_test(&test6)) return 1; if(run_test(&test7)) return 1; |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |