2020-05-24 15:30:55 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2022-01-31 16:59:14 -06:00
|
|
|
// Copyright (C) 2020-2022 Martin Whitaker.
|
2020-05-24 15:30:55 -05:00
|
|
|
//
|
|
|
|
// Derived from an extract of memtest86+ test.c:
|
|
|
|
//
|
|
|
|
// MemTest86+ V5 Specific code (GPL V2.0)
|
|
|
|
// By Samuel DEMEULEMEESTER, sdemeule@memtest.org
|
|
|
|
// http://www.canardpc.com - http://www.memtest.org
|
|
|
|
// Thanks to Passmark for calculate_chunk() and various comments !
|
|
|
|
// ----------------------------------------------------
|
|
|
|
// test.c - MemTest-86 Version 3.4
|
|
|
|
//
|
|
|
|
// Released under version 2 of the Gnu Public License.
|
|
|
|
// By Chris Brady
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "display.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include "test_funcs.h"
|
|
|
|
#include "test_helper.h"
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Public Functions
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2022-01-31 16:59:14 -06:00
|
|
|
int test_modulo_n(int my_cpu, int iterations, testword_t pattern1, testword_t pattern2, int n, int offset)
|
2020-05-24 15:30:55 -05:00
|
|
|
{
|
|
|
|
int ticks = 0;
|
|
|
|
|
2022-01-31 16:59:14 -06:00
|
|
|
if (my_cpu == master_cpu) {
|
2020-05-24 15:30:55 -05:00
|
|
|
display_test_pattern_values(pattern1, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write every nth location with pattern1.
|
|
|
|
for (int i = 0; i < vm_map_size; i++) {
|
|
|
|
testword_t *start, *end;
|
2022-01-31 16:59:14 -06:00
|
|
|
calculate_chunk(&start, &end, my_cpu, i, sizeof(testword_t));
|
2024-03-12 19:43:26 -05:00
|
|
|
if ((end - start) < (n - 1)) SKIP_RANGE(1) // we need at least n words for this test
|
2020-05-24 15:30:55 -05:00
|
|
|
end -= n; // avoids pointer overflow when incrementing p
|
|
|
|
|
|
|
|
testword_t *p = start + offset; // we assume each chunk has at least 'n' words, so this won't overflow
|
|
|
|
testword_t *pe = start;
|
|
|
|
|
|
|
|
bool at_end = false;
|
|
|
|
do {
|
|
|
|
// take care to avoid pointer overflow
|
|
|
|
if ((end - pe) >= SPIN_SIZE) {
|
|
|
|
pe += SPIN_SIZE - 1;
|
|
|
|
} else {
|
|
|
|
at_end = true;
|
|
|
|
pe = end;
|
|
|
|
}
|
|
|
|
ticks++;
|
2022-01-31 16:59:14 -06:00
|
|
|
if (my_cpu < 0) {
|
2020-05-24 15:30:55 -05:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-31 16:59:14 -06:00
|
|
|
test_addr[my_cpu] = (uintptr_t)p;
|
2020-05-24 15:30:55 -05:00
|
|
|
do {
|
2021-12-23 03:46:01 -06:00
|
|
|
write_word(p, pattern1);
|
2020-05-24 15:30:55 -05:00
|
|
|
} while (p <= (pe - n) && (p += n)); // test before increment in case pointer overflows
|
2022-01-31 16:59:14 -06:00
|
|
|
do_tick(my_cpu);
|
2020-05-24 15:30:55 -05:00
|
|
|
BAILOUT;
|
|
|
|
} while (!at_end && ++pe); // advance pe to next start point
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the rest of memory "iteration" times with pattern2.
|
|
|
|
for (int i = 0; i < iterations; i++) {
|
|
|
|
for (int j = 0; j < vm_map_size; j++) {
|
|
|
|
testword_t *start, *end;
|
2022-01-31 16:59:14 -06:00
|
|
|
calculate_chunk(&start, &end, my_cpu, j, sizeof(testword_t));
|
2024-03-12 19:43:26 -05:00
|
|
|
if ((end - start) < (n - 1)) SKIP_RANGE(1) // we need at least n words for this test
|
2020-05-24 15:30:55 -05:00
|
|
|
|
|
|
|
int k = 0;
|
|
|
|
testword_t *p = start;
|
|
|
|
testword_t *pe = start;
|
|
|
|
|
|
|
|
bool at_end = false;
|
|
|
|
do {
|
|
|
|
// take care to avoid pointer overflow
|
|
|
|
if ((end - pe) >= SPIN_SIZE) {
|
|
|
|
pe += SPIN_SIZE - 1;
|
|
|
|
} else {
|
|
|
|
at_end = true;
|
|
|
|
pe = end;
|
|
|
|
}
|
|
|
|
ticks++;
|
2022-01-31 16:59:14 -06:00
|
|
|
if (my_cpu < 0) {
|
2020-05-24 15:30:55 -05:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-31 16:59:14 -06:00
|
|
|
test_addr[my_cpu] = (uintptr_t)p;
|
2020-05-24 15:30:55 -05:00
|
|
|
do {
|
|
|
|
if (k != offset) {
|
2021-12-23 03:46:01 -06:00
|
|
|
write_word(p, pattern2);
|
2020-05-24 15:30:55 -05:00
|
|
|
}
|
|
|
|
k++;
|
|
|
|
if (k == n) {
|
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
} while (p++ < pe); // test before increment in case pointer overflows
|
2022-01-31 16:59:14 -06:00
|
|
|
do_tick(my_cpu);
|
2020-05-24 15:30:55 -05:00
|
|
|
BAILOUT;
|
|
|
|
} while (!at_end && ++pe); // advance pe to next start point
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-31 16:59:14 -06:00
|
|
|
flush_caches(my_cpu);
|
2021-12-23 05:00:10 -06:00
|
|
|
|
2020-05-24 15:30:55 -05:00
|
|
|
// Now check every nth location.
|
|
|
|
for (int i = 0; i < vm_map_size; i++) {
|
|
|
|
testword_t *start, *end;
|
2022-01-31 16:59:14 -06:00
|
|
|
calculate_chunk(&start, &end, my_cpu, i, sizeof(testword_t));
|
2024-03-12 19:43:26 -05:00
|
|
|
if ((end - start) < (n - 1)) SKIP_RANGE(1) // we need at least n words for this test
|
2020-05-24 15:30:55 -05:00
|
|
|
end -= n; // avoids pointer overflow when incrementing p
|
|
|
|
|
|
|
|
testword_t *p = start + offset; // we assume each chunk has at least 'offset' words, so this won't overflow
|
|
|
|
testword_t *pe = start;
|
|
|
|
|
|
|
|
bool at_end = false;
|
|
|
|
do {
|
|
|
|
// take care to avoid pointer overflow
|
|
|
|
if ((end - pe) >= SPIN_SIZE) {
|
|
|
|
pe += SPIN_SIZE - 1;
|
|
|
|
} else {
|
|
|
|
at_end = true;
|
|
|
|
pe = end;
|
|
|
|
}
|
|
|
|
ticks++;
|
2022-01-31 16:59:14 -06:00
|
|
|
if (my_cpu < 0) {
|
2020-05-24 15:30:55 -05:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-31 16:59:14 -06:00
|
|
|
test_addr[my_cpu] = (uintptr_t)p;
|
2020-05-24 15:30:55 -05:00
|
|
|
do {
|
2021-12-23 03:46:01 -06:00
|
|
|
testword_t actual = read_word(p);
|
2020-05-24 15:30:55 -05:00
|
|
|
if (unlikely(actual != pattern1)) {
|
|
|
|
data_error(p, pattern1, actual, true);
|
|
|
|
}
|
|
|
|
} while (p <= (pe - n) && (p += n)); // test before increment in case pointer overflows
|
2022-01-31 16:59:14 -06:00
|
|
|
do_tick(my_cpu);
|
2020-05-24 15:30:55 -05:00
|
|
|
BAILOUT;
|
|
|
|
} while (!at_end && ++pe); // advance pe to next start point
|
|
|
|
}
|
|
|
|
|
|
|
|
return ticks;
|
|
|
|
}
|