Commit 51209b1f42cb6d1a7ce7c70be08aef2c988656cc

Authored by Simon Glass
1 parent c9638f50fb

Use common mtest iteration counting

The iteration code is the same for each version of the memory test, so
pull it out into the common function.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 1 changed file with 59 additions and 64 deletions Side-by-side Diff

... ... @@ -626,11 +626,9 @@
626 626 }
627 627 #endif /* CONFIG_LOOPW */
628 628  
629   -static int mem_test_alt(vu_long *start, vu_long *end,
630   - int iteration_limit)
  629 +static ulong mem_test_alt(vu_long *start, vu_long *end)
631 630 {
632 631 vu_long *addr;
633   - int iterations = 1;
634 632 ulong errs = 0;
635 633 ulong val, readback;
636 634 int j;
... ... @@ -657,27 +655,6 @@
657 655 0xaaaaaaaa, /* alternating 1/0 */
658 656 };
659 657  
660   - printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start,
661   - (uint)(uintptr_t)end);
662   - debug("%s:%d: start 0x%p end 0x%p\n",
663   - __func__, __LINE__, start, end);
664   -
665   - for (;;) {
666   - if (ctrlc()) {
667   - putc('\n');
668   - return 1;
669   - }
670   -
671   - if (iteration_limit && iterations > iteration_limit) {
672   - printf("Tested %d iteration(s) with %lu errors.\n",
673   - iterations-1, errs);
674   - return errs != 0;
675   - }
676   -
677   - printf("Iteration: %6d\r", iterations);
678   - debug("\n");
679   - iterations++;
680   -
681 658 /*
682 659 * Data line test: write a pattern to the first
683 660 * location, write the 1's complement to a 'parking'
... ... @@ -710,7 +687,7 @@
710 687 errs++;
711 688 if (ctrlc()) {
712 689 putc('\n');
713   - return 1;
  690 + return -1;
714 691 }
715 692 }
716 693 *addr = ~val;
... ... @@ -723,7 +700,7 @@
723 700 errs++;
724 701 if (ctrlc()) {
725 702 putc('\n');
726   - return 1;
  703 + return -1;
727 704 }
728 705 }
729 706 }
... ... @@ -791,7 +768,7 @@
791 768 errs++;
792 769 if (ctrlc()) {
793 770 putc('\n');
794   - return 1;
  771 + return -1;
795 772 }
796 773 }
797 774 }
... ... @@ -813,7 +790,7 @@
813 790 errs++;
814 791 if (ctrlc()) {
815 792 putc('\n');
816   - return 1;
  793 + return -1;
817 794 }
818 795 }
819 796 }
... ... @@ -855,7 +832,7 @@
855 832 errs++;
856 833 if (ctrlc()) {
857 834 putc('\n');
858   - return 1;
  835 + return -1;
859 836 }
860 837 }
861 838  
862 839  
863 840  
864 841  
865 842  
866 843  
... ... @@ -877,37 +854,38 @@
877 854 errs++;
878 855 if (ctrlc()) {
879 856 putc('\n');
880   - return 1;
  857 + return -1;
881 858 }
882 859 }
883 860 start[offset] = 0;
884 861 }
885   - }
  862 +
  863 + return 0;
886 864 }
887 865  
888   -static int mem_test_quick(vu_long *start, vu_long *end,
889   - int iteration_limit, vu_long pattern)
  866 +static ulong mem_test_quick(vu_long *start, vu_long *end, vu_long pattern,
  867 + int iteration)
890 868 {
891 869 vu_long *addr;
892   - int iterations = 1;
893 870 ulong errs = 0;
894 871 ulong incr;
895 872 ulong val, readback;
896 873  
  874 + /* Alternate the pattern */
897 875 incr = 1;
898   - for (;;) {
899   - if (ctrlc()) {
900   - putc('\n');
901   - return 1;
902   - }
903   -
904   - if (iteration_limit && iterations > iteration_limit) {
905   - printf("Tested %d iteration(s) with %lu errors.\n",
906   - iterations-1, errs);
907   - return errs != 0;
908   - }
909   - ++iterations;
910   -
  876 + if (iteration & 1) {
  877 + incr = -incr;
  878 + /*
  879 + * Flip the pattern each time to make lots of zeros and
  880 + * then, the next time, lots of ones. We decrement
  881 + * the "negative" patterns and increment the "positive"
  882 + * patterns to preserve this feature.
  883 + */
  884 + if (pattern & 0x80000000)
  885 + pattern = -pattern; /* complement & increment */
  886 + else
  887 + pattern = ~pattern;
  888 + }
911 889 printf("\rPattern %08lX Writing..."
912 890 "%12s"
913 891 "\b\b\b\b\b\b\b\b\b\b",
914 892  
... ... @@ -931,24 +909,13 @@
931 909 errs++;
932 910 if (ctrlc()) {
933 911 putc('\n');
934   - return 1;
  912 + return -1;
935 913 }
936 914 }
937 915 val += incr;
938 916 }
939 917  
940   - /*
941   - * Flip the pattern each time to make lots of zeros and
942   - * then, the next time, lots of ones. We decrement
943   - * the "negative" patterns and increment the "positive"
944   - * patterns to preserve this feature.
945   - */
946   - if (pattern & 0x80000000)
947   - pattern = -pattern; /* complement & increment */
948   - else
949   - pattern = ~pattern;
950   - incr = -incr;
951   - }
  918 + return 0;
952 919 }
953 920  
954 921 /*
955 922  
... ... @@ -962,7 +929,9 @@
962 929 vu_long *start, *end;
963 930 int iteration_limit;
964 931 int ret;
  932 + ulong errs = 0; /* number of errors, or -1 if interrupted */
965 933 ulong pattern;
  934 + int iteration;
966 935 #if defined(CONFIG_SYS_ALT_MEMTEST)
967 936 const int alt_test = 1;
968 937 #else
... ... @@ -989,10 +958,36 @@
989 958 else
990 959 iteration_limit = 0;
991 960  
992   - if (alt_test)
993   - ret = mem_test_alt(start, end, iteration_limit);
994   - else
995   - ret = mem_test_quick(start, end, iteration_limit, pattern);
  961 + printf("Testing %08x ... %08x:\n", (uint)(uintptr_t)start,
  962 + (uint)(uintptr_t)end);
  963 + debug("%s:%d: start 0x%p end 0x%p\n",
  964 + __func__, __LINE__, start, end);
  965 +
  966 + for (iteration = 0;
  967 + !iteration_limit || iteration < iteration_limit;
  968 + iteration++) {
  969 + if (ctrlc()) {
  970 + putc('\n');
  971 + errs = -1UL;
  972 + break;
  973 + }
  974 +
  975 + printf("Iteration: %6d\r", iteration + 1);
  976 + debug("\n");
  977 + if (alt_test)
  978 + errs = mem_test_alt(start, end);
  979 + else
  980 + errs = mem_test_quick(start, end, pattern, iteration);
  981 + }
  982 +
  983 + if (errs == -1UL) {
  984 + /* Memory test was aborted */
  985 + ret = 1;
  986 + } else {
  987 + printf("Tested %d iteration(s) with %lu errors.\n",
  988 + iteration, errs);
  989 + ret = errs != 0;
  990 + }
996 991  
997 992 return ret; /* not reached */
998 993 }