博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DRAM test code
阅读量:4285 次
发布时间:2019-05-27

本文共 1318 字,大约阅读时间需要 4 分钟。

#include <stdio.h>

#include <stdlib.h>


#define LEVEL 5

#define RAM_TEST_PATTERNS 2



int

main (int argc, char *argv[])

{

    ulong *ptrMalloc = NULL;

    int i = 0, j = 0;

    ulong test_value;

    ulong *ptrl = NULL;

    int level = 0;



/*

    for ( i = 0; i < 10000; i++) {

        fprintf(stderr," i = %d\n", i);

        ptrMalloc = (char*) malloc(1024 * 1024 * i);

        if (!ptrMalloc) {

            fprintf(stderr,"malloc %d failed\n", i);

            break;

        }

        free(ptrMalloc);

    }

*/


    static const ulong TestPattern[LEVEL][RAM_TEST_PATTERNS] = { 

        {0xFFFFFFFF, 0x00000000},

        {0x55555555, 0xAAAAAAAA},

        {0xA5A5A5A5, 0x5A5A5A5A},

        {0x96969696, 0x69696969},

        {0xCCCCCCCC, 0x33333333}

    };  




    ptrMalloc = (ulong*) malloc(1024 * 1024 * 20 * sizeof(ulong));

    if (!ptrMalloc) {

        fprintf(stderr,"malloc failed\n");

        return -1;

    }


    level = 0;

    for(i = 0; i < RAM_TEST_PATTERNS; i++) {

        test_value = TestPattern[level][i];


        /* Fill Test Pattern */

        for (ptrl = ptrMalloc, j = 0; j < 1024 * 1024 * 20; j++, ptrl++) {

            *ptrl = test_value;

            /*debug*/

            //fprintf(stdout,"Fill test Pattern 0x%x\n",*ptrl);

            //fprintf(stdout,"DRAM Test at address 0x%p\n",ptrl);

        }


        /* Check Test Pattern */

        for (ptrl = ptrMalloc, j = 0; j < 1024 * 1024 * 20 ; j++, ptrl++) {

            if (*ptrl != test_value) {

                printf(" ...FAIL\n");

                printf("DRAM Test Fail at address 0x%p, read:0x%x, should:0x%x\n", ptrl, *ptrl, test_value );

                return 1;

            }

        }



    }





    return 0;

}

转载地址:http://qxsgi.baihongyu.com/

你可能感兴趣的文章