new/external/rk_pcba_test/echo_ddr_test.c

115 lines
3.1 KiB
C
Raw Normal View History

2025-05-10 21:58:58 +08:00
/*
* 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");
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
if (!pp)
{
printf("errno=%d\n",errno);
char * mesg = strerror(errno); //ʹ<><CAB9>strerror<6F><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}
/* <20>ڴ<EFBFBD><DAB4><EFBFBD>ÿҳ4KB<4B><42>echo<68><6F><EFBFBD><EFBFBD>DDR<44>ڴ<EFBFBD>Ϊ128M*16 DDR3 SDRAM<41><4D>2GbҲ<62><D2B2><EFBFBD><EFBFBD>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;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>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);
}