加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

测试NAND Flash稳定性小程序

发布时间:2020-12-15 06:25:32 所属栏目:百科 来源:网络整理
导读:下面的程序可以用来测试NAND Flash 稳定性,主要思想是反复读写NAND Flash上的文件及对比读写是否一致,最后统计结果。 test.c #include stdio.h #include string.h #include stdlib.h #include sys/wait.h ?? #include sys/types.h? #include memory.h int

下面的程序可以用来测试NAND Flash 稳定性,主要思想是反复读写NAND Flash上的文件及对比读写是否一致,最后统计结果。 test.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/wait.h> ?? #include <sys/types.h>? #include <memory.h> int main(int argc,char **argv) { if(argc < 4) { printf("argc is not enough,exit ! n"); printf("Run as: ./test srcFile destFile loop n"); exit(1); } ?? ?? int i = 0; pid_t status; int cmd1_fork_err = 0; int cmd1_err = 0; int cmd2_fork_err = 0; int cmd2_err = 0; int cmd22_fork_err = 0; int cmd22_err = 0; ?? ?int diff_count = 0; int cmd3_fork_err = 0; int cmd3_err = 0; char *src = argv[1]; char *dest = argv[2]; ?? ?int len1 = strlen(src); int len2= strlen(dest); int loop = atoi(argv[3]); char *cp = "cp "; char *rm = "rm "; char *md5sum = "md5sum "; char *to = " > "; char *log1 = "1.txt"; char *log2 = "2.txt"; char tmp1[200] = {''}; char tmp2[200] = {''}; char tmp22[200] = {''}; ?? ?char tmp3[200] = {''}; char *cmd1 = tmp1; char *cmd2 = tmp2; char *cmd22 = tmp22; char *cmd3 = tmp3; ?? ?char tmpBuf[40] = {''}; ?? ?char tmpBuf1[40] = {''}; ?? ?char *md51 = tmpBuf; ?? ?char *md52 = tmpBuf1; ?? ?FILE *fp; ?? ? ? ? strcpy(tmp1,cp); strcpy(&tmp1[3],src); tmp1[3 + len1] = ' '; strcpy(&tmp1[4 + len1],dest); printf("cmd1 %s n",cmd1); strcpy(tmp2,md5sum); strcpy(&tmp2[7],src); strcpy(&tmp2[7 + len1],to); ?? ?strcpy(&tmp2[7 + len1 + 3],log1); printf("cmd2 %s n",cmd2); ?? ? strcpy(tmp22,md5sum); strcpy(&tmp22[7],dest); strcpy(&tmp22[7 + len2],to); strcpy(&tmp22[7 + len2 + 3],log2); printf("cmd22 %s n",cmd22); ?? ?strcpy(tmp3,rm); strcpy(&tmp3[3],dest); printf("cmd3 %s n",cmd3); ?? ? ? for(i = 0; i < loop; i++) { status = system(cmd1); if (-1 == status)? { ?? printf("%s fork fail n",cmd1); cmd1_fork_err++; printf("system error! n"); ? } else { //printf("%s exit status value = [0x%x]n",cmd1,status); if (WIFEXITED(status)) { if (0 == WEXITSTATUS(status)) ? { ? printf("%s run shell script successfully.n",cmd1);? ? ? ? ? ? } ? else ? { ? cmd1_err++; ?? ? ? ? ? ? ? ?printf("%s run shell script fail,script exit code: %dn",WEXITSTATUS(status)); } } else? { cmd1_err++; printf("%s exit status = [%d]n",WEXITSTATUS(status)); } } sleep(3); printf("n"); ?? ? ? ? status = system(cmd2); if (-1 == status) { printf("%s fork fail n",cmd2); cmd2_fork_err++; printf("system error! n"); } else { //printf("%s exit status value = [0x%x]n",cmd2,status); if (WIFEXITED(status)) { if (0 == WEXITSTATUS(status)) { printf("%s run shell script successfully.n",cmd2); } else { cmd2_err++; printf("%s run shell script fail,WEXITSTATUS(status)); } } else? { cmd2_err++; printf("%s exit status = [%d]n",WEXITSTATUS(status)); } } ?? sleep(3); ?? ? ? ?printf("n"); status = system(cmd22); if (-1 == status) { printf("%s fork fail n",cmd22); cmd22_fork_err++; printf("system error! n"); } else { //printf("%s exit status value = [0x%x]n",cmd22,cmd22); } else { cmd22_err++; printf("%s run shell script fail,WEXITSTATUS(status)); } } else { cmd22_err++; printf("%s exit status = [%d]n",WEXITSTATUS(status)); } } sleep(3); printf("n"); ?? ?if((fp = fopen(log1,"rb"))==NULL) ?? ?{ ?? ?printf("Can not open file %s n",log1); ?? ?return 1; ?? ?} ?? ? ? ?fread(tmpBuf,sizeof(char),32,fp); ?? ? ? ?fclose(fp); ?? ? ? ?printf("md51: %s n",md51); ?? ? ? ? ?? ? ? ?if((fp = fopen(log2,log2); ?? ?return 1; ?? ?} ?? ? ? ?fread(tmpBuf1,fp); ?? ? ? ?fclose(fp); ?? ? ? ?printf("md52: %s n",md52); ?? ? ? ? ?? ? ? ?if(0 != memcmp(tmpBuf,tmpBuf1,32)) ?? ? ? ?{ ?? ? ? ? ? ?diff_count++; ?? ? ? ?} status = system(cmd3); if (-1 == status) { printf("%s fork fail n",cmd3); cmd3_fork_err++; printf("system error! n"); } else? { //printf("%s exit status value = [0x%x]n",cmd3,status); if (WIFEXITED(status)) { ? if (0 == WEXITSTATUS(status)) ? ?{ printf("%s run shell script successfully.n",cmd3); } else { cmd3_err++; printf("%s run shell script fail,WEXITSTATUS(status)); } } else { cmd3_err++; printf("%s exit status = [%d]n",WEXITSTATUS(status)); } } sleep(3); printf("%d complete! n",(i+1)); } printf("n"); printf("Result: %s: fork error = %d,shell error = %d n",cmd1_fork_err,cmd1_err); printf("Result: %s: fork error = %d,cmd2_fork_err,cmd2_err); ?? ?printf("Result: %s: fork error = %d,cmd22_fork_err,cmd22_err); ?? ?printf("Result: diff_count = %d ?n",diff_count); printf("Result: %s: fork error = %d,cmd3_fork_err,cmd3_err); return 0; } Makefile: test: test.c mips-linux-gnu-gcc -EL test.c -o test

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读