PI Ziheng embedded: memory read and write correctness stress test program (memtester)


Hello everyone, I’m a ruffian Heng. I’m a serious technical ruffian. Today, ruffian Heng introduces to youMemory read write correctness stress test program memtester

In embedded system, the importance of ram is self-evident. The performance and stability of the system are closely related to ram. There are many different indicators about memory performance, among which the most basic indicator is access reliability (that is, the correctness of reading and writing). Only stable and reliable memory access can ensure the normal operation of the system. Most of the time, a simple memory read-write test can not find hidden problems, so we need a complete memory access stress test program. Today, piziheng will talk about memtester in detail.

1、 Memory performance test assembly

Before talking about memtester, PI Ziheng will give you some popular memory performance testing tools commonly used in Linux system. They are MBW, memtester, lmbench and sysbench. These testing tools (programs) have their own emphases

MBW: memory bandwidth testing tool;

2、 Memtester program

Memtester is a test program written by Simon Kirby in 1999 (V1 version), which has been maintained and updated by Charles cazabon (V2 and later versions). It is mainly for UNIX like system. The official homepage introduces “a user space utility for testing the memory subsystem for faults.”, In fact, it is to test the reliability of memory (mainly DDR) read and write access (only correctness, independent of speed performance), which is an essential test to verify the board level hardware equipment.

The perspective of the whole memtester test is from the user’s point of view. From the user’s point of view, different test scenarios, namely test cases, are set up, and then functional tests are carried out. Attention is paid to testing from the system level, that is, not only memory particles, but also system board level wiring, IO performance, PCB and other related factors, Whether the memory is still working properly.

2.1 acquisition procedure

The latest version of memtester program is 4.5.0, and the earlier V1 / V2 / V3 version can’t be downloaded at present. In 2012, Charles cazabon rewritten the program and released a new v4.0.0, which has been updated irregularly since then. V4. X is also the most popular version at present.

Core program download:http://pyropus.ca/software/memtester/

After downloading the core package, you can find the source code in the file of memtester-4.5.0 \. The detailed source file directory is as follows:


If it is transplanted to the arm Cortex-M platform to run on a bare system, it is generally only necessary to modify the memtester. C file. Other source files are some header files containing changes. Memtester itself does not have much transplantation work. Its source code is originally used to run on UNIX like system, In the embedded system, we only need to delete some code related to the system platform, in addition to the implementation of the print function.

2.2 configuration parameters

The configuration options in the source code of memtester are as follows:

/*The following needs to be customized*/

2.3 program analysis

Let’s try to analyze the main function entry of memtester. The main() function is used to analyze some input parameters at the beginning. In fact, it is mainly used to obtain three important variables: memory test start address, total length of memory test, and the number of stress test cycles. With these three variable values, we will start to run the test algorithm functions in the tests. C file one by one

struct test {
    char *name;
    int (*fp)();

struct test tests[] = {
    { "Random Value", test_random_value },
    { "Compare XOR", test_xor_comparison },
    { "Compare SUB", test_sub_comparison },
    { "Compare MUL", test_mul_comparison },
    { "Compare DIV",test_div_comparison },
    { "Compare OR", test_or_comparison },
    { "Compare AND", test_and_comparison },
    { "Sequential Increment", test_seqinc_comparison },
    { "Solid Bits", test_solidbits_comparison },
    { "Block Sequential", test_blockseq_comparison },
    { "Checkerboard", test_checkerboard_comparison },
    { "Bit Spread", test_bitspread_comparison },
    { "Bit Flip", test_bitflip_comparison },
    { "Walking Ones", test_walkbits1_comparison },
    { "Walking Zeroes", test_walkbits0_comparison },
    { "8-bit Writes", test_8bit_wide_random },
    { "16-bit Writes", test_16bit_wide_random },
    { NULL, NULL }

/* Function definitions */
void usage(char *me) {
    fprintf(stderr, "\n"
            "Usage: %s [-p physaddrbase [-d device]] [B|K|M|G] [loops]\n",

Tests. C file is the core of the stress testing algorithm subroutine, a total of 17 functions, involving a variety of memory access experience operation, specific can see a detailed analysis of the online articlehttps://www.jianshu.com/p/ef203c360c4f。

Test function name Test function
test_stuck_address First, all the address values are inverted alternately and put into the corresponding storage location, and then read and compare, repeat n times
test_random_value Equivalent test_ random_ Comparison (Bufa, bufb, count): data sensitive test cases
test_xor_comparison And test_ random_ Value has more XORs than
test_sub_comparison And test_ random_ Value has more than one subtraction operation
test_mul_comparisone And test_ random_ Value has more than one multiply operation
test_div_comparison And test_ random_ Value has more than one division operation
test_or_comparison In test_ random_ Comparison () is merged
test_and_comparison In test_ random_ Comparison () is merged
test_seqinc_comparison It’s test_ blockseq_ A subset of comparison; Simulate customer stress test scenarios
test_solidbits_comparison After fixing all 1, write two buffers, then read and compare, and then write all 0 to read and compare; This is the zero one algorithm
test_blockseq_comparison Write one count block at a time, fill 32bit with byte level number, then take out the comparison, and repeat 256 times; It’s also a pressure use case, but the number of times has increased;
test_checkerboard_comparison Write the set groups of data background in turn, and then read and compare
test_bitspread_comparison It’s still moving in 32bit, but this time it’s not just a 0 or a 1, but two 1s separated by two vacancies / td > between the two 1s
test_bitflip_comparison It is also a bit = 1 in 32bit, which continuously moves to generate data patterns, and then each pattern is executed
test_walkbits1_comparison And test_ walkbits0_ The same is true for comparison
test_walkbits0_comparison It means that the position with bit = 1 moves in 32bit, and every time it moves, it fills the buffer completely. First, it moves from low position to high position, and then it moves from high position to low position
test_8bit_wide_random The char pointer is used to store the value, that is, 8bit is saved each time, so the granularity is finer;
test_16bit_wide_random Use the unsigned short pointer to store the value, that is, store 16 bits each time, and detect different granularity;

2.4 result format

In UNIX like system, using make & make install command to compile can get an executable memtester, which can be executed at willmemtester 10M 1That is to say, apply for 10m memory test once, and the results are as follows:

[[email protected] ~] memtester 10M 1

memtester version 4.5.0 (64-bit)
Copyright (C) 2001-2020 Charles Cazabon.
Licensed under the GNU General Public License version 2 (only).

pagesize is 4096
pagesizemask is 0xfffffffffffff000
want 10MB (10485760 bytes)
got  10MB (10485760 bytes), trying mlock ...locked.
Loop 1/1:
  Stuck Address: ok
  Random Value: ok
  Compare XOR: ok
  Compare SUB: ok
  Compare MUL: ok
  Compare DIV: ok
  Compare OR: ok
  Compare AND: ok
  Sequential Increment: ok
  Solid Bits: ok
  Block Sequential: ok
  Checkerboard: ok
  Bit Spread: ok
  Bit Flip: ok
  Walking Ones: ok
  Walking Zeroes: ok
  8-bit Writes: ok
  16-bit Writes: ok


So far, the pressure test program memtester for memory read-write correctness has been introduced. Where is the applause~~~

Welcome to subscribe

The article will be published to me at the same timeBlog Garden Home PageCSDN home pageZhihu HomepageWeChat official accountOn the platform.

Wechat search“Ruffian scale embedded“Or scan the following QR code, you can see it on your mobile phone for the first time.

Recommended Today

Swift advanced 08: closure & capture principle

closure closurecanCapture and storageOf any constants and variables defined in their contextquote, this is the so-calledClose and wrap those constants and variablesTherefore, it is called“closure”Swift can handle everything for youCaptured memory managementOperation of. Three forms of closure [global function is a special closure]: a global function is a closure that has a name but does […]