hc
2024-03-26 e0728245c89800c2038c23308f2d88969d5b41c8
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
/*
 *  ddr_test.c  --  ddr test application
 *
 *  Copyright (c) 2017 Rockchip Electronics Co. Ltd.
 *  Author: Panzhenzhuan Wang <randy.wang@rock-chips.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "ddr_test.h"
 
#define LOG_TAG "ddr_test"
#include "common.h"
 
#define EMMCPATH "/sys/bus/mmc/devices/mmc0:0001/block/mmcblk0/size"
#define READ_DDR_COMMAND "cat /proc/zoneinfo | busybox grep present | \
               busybox awk 'BEGIN{a=0}{a+=$2}END{print a}'"
 
/* for ddr  */
int ddr_exec(const char *cmd, char *ddrsize_char, unsigned int length)
{
    FILE *pp = popen(cmd, "r");
 
    //Èç¹ûÎļþ´ò¿ªÊ§°Ü£¬ÔòÊä³ö´íÎóÐÅÏ¢
    if (!pp)
    {
        printf("errno=%d\n",errno);
        char * mesg = strerror(errno);  //ʹÓÃstrerror£¨£©·­Òë´íÎó´úÂë
        printf("Mesg:%s\n",mesg);
        return -1;
    }
   if (fgets(ddrsize_char, length, pp) == NULL) {
       printf("popen read from %s is NULL!\n",cmd);
       pclose(pp);
       return -1;
   }
   pclose(pp);
   return 0;
}
 
/* ÄÚ´æÊÇÿҳ4KB£¬echoÑù»úDDRÄÚ´æÎª128M*16 DDR3 SDRAM¼´2GbÒ²¾ÍÊÇ256MB*/
void *ddr_test(void *argv)
{
   int ddr_ret = 0;
   char ddrsize_char[20];
   int ddr_size = 0;
   char cmd[128];
 
    printf("=======  ddr test starting   ========\n");
    //sprintf(cmd,"aplay %s/ddr_test_start.wav",AUDIO_PATH);
    //system(cmd);
    //system("aplay /data/test/ddr_test_start.wav");
    /* For ddr */
    memset(ddrsize_char, 0, sizeof(ddrsize_char));
    ddr_ret = ddr_exec(READ_DDR_COMMAND,ddrsize_char, sizeof(ddrsize_char));
    if (ddr_ret >= 0)
    {
        printf("======%s value is %s=====.\n",READ_DDR_COMMAND,ddrsize_char);
        ddr_size = (int)(atoi(ddrsize_char)*4/1024);
        printf("=========== ddr_size is : %dMB ==========\n",ddr_size);
        if(DDR_CAPACITY != ddr_size)
            goto fail;
    }
    else
    {
        goto fail;
    }
    printf("=========== ddr test success ==========\n");
 
   return (void*)ddr_ret;
fail:
    printf("=========== ddr test failed ==========\n");
 
    return (void*)ddr_ret;
}
 
//Ö÷º¯ÊýÆô¶¯emmc_test
int main(int argc, char *argv[])
{
    int test_flag = 0,err_code = 0;
    char buf[COMMAND_VALUESIZE] = "ddr_test";
    char result[COMMAND_VALUESIZE] = RESULT_PASS;
    test_flag = (int)ddr_test(argv[0]);
    if(test_flag < 0)
    {
        strcpy(result,RESULT_FAIL);
        err_code = DDR_PROC_ERR;
    } else {
        char ddrSize[32] = {0};
        snprintf(ddrSize, sizeof(ddrSize), "size:%dMB",  DDR_CAPACITY);
        strcat(buf, ": ");
        strcat(buf, ddrSize);
    }
 
    send_msg_to_server(buf, result, err_code);
}