📄 flashtest.c
字号:
/*
* +-------------------------------------------------------------------+
* | Copyright (c) 1995,2000 TriMedia Technologies Inc. |
* | |
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*/
/*------------------------------ Includes ------------------------------------*/
#include <fcntl.h>
#include <tmlib/tmFlash.h>
#include <sys/stat.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
/*---------------------------- Test parameters -------------------------------*/
typedef struct stat StatBuf;
/* #define NROF_ITERATIONS 100000 */
#define MAX_FILE_SIZE 100000
#define E(command) command
#define EE(command) \
{ \
printf(" [%d] ----------- %20s == %d\n", i, #command, command ); \
dump_flash(); \
}
#define FS_ASSERT( assertion, code ) \
{ if (!(assertion)) { \
fprintf(stderr, "Flash file system assert failed; %s (exiting)\n", #code); \
exit(-1); \
} }
/*----------------------- Directory creating / deletion ----------------------*/
#define DIR_CREATE(TOP) \
{ \
E( mkdir ("/flash/"TOP, 0777 )); \
E( touch ("/flash/"TOP"/a" )); \
E( touch ("/flash/"TOP"/b" )); \
E( touch ("/flash/"TOP"/c" )); \
E( mkdir ("/flash/"TOP"/KLOP", 0777 )); \
E( link ("/flash/"TOP"/a", "/flash/"TOP"/KLOP/aa" )); \
E( link ("/flash/"TOP"/KLOP/aa", "/flash/"TOP )); \
}
#define DIR_DELETE( TOP) \
{ \
E( unlink ("/flash/"TOP"/a" )); \
E( unlink ("/flash/"TOP"/KLOP" )); \
E( unlink ("/flash/"TOP"/a" )); \
E( unlink ("/flash/"TOP"/KLOP/aa" )); \
E( unlink ("/flash/"TOP"/KLOP" )); \
E( unlink ("/flash/"TOP"/aa" )); \
E( unlink ("/flash/"TOP"/b" )); \
E( unlink ("/flash/"TOP"/c" )); \
E( unlink ("/flash/"TOP )); \
}
/*------------------------ Recursive directory printing ----------------------*/
Int touch ( String f)
{
Int fd= open(f, O_CREAT | O_WRONLY);
if (fd != -1 && close(fd)) {
return 0;
} else {
return -1;
}
}
void print_file_info(String f)
{
StatBuf buf;
memset((Pointer)&buf,0,sizeof(buf));
if (stat(f,&buf)!=-1) {
printf(" * size= %4d dir=%d chr=%d reg=%d ino=%04d | %s\n",
buf.st_size, S_ISDIR(buf.st_mode),
S_ISCHR(buf.st_mode), S_ISREG(buf.st_mode), buf.st_ino, f
);
}
}
void treewalk(String f)
{
DIR *dirp;
struct dirent *direntp;
dirp = opendir( f );
if (dirp) {
while ( (direntp = readdir( dirp )) != NULL ) {
Char buffer[1000];
sprintf(buffer,"%s/%s",f,direntp->d_name);
print_file_info(buffer);
if (strcmp(direntp->d_name,".") != 0
&& strcmp(direntp->d_name,"..") != 0) {
treewalk(buffer);
}
}
(void)closedir( dirp );
}
}
void dump_flash() { treewalk("/flash"); }
/*------------------------------- Event handler ------------------------------*/
static Int nrof_write_errors;
static void event_handler(FlashEvent);
static EventHandler old_event_handler= event_handler;
static void event_handler(FlashEvent event)
{
if (event == FlashWriteError) {
nrof_write_errors++;
} else
switch (event) {
case FlashFull:
old_event_handler(event);
exit(-1);
case FlashStaleSTTRemoved:
case FlashStaleRootRemoved:
case FlashStaleBootRemoved:
case FlashDangerousWriteError:
case FlashInterruptedMoveRepaired:
old_event_handler(event);
break;
}
}
/*------------------------------ Main program --------------------------------*/
void dump_status()
{
printf("--------------------------------------------------\n");
dump_flash();
FlashUtil_print();
printf("--------------------------------------------------\n");
}
void print_heap()
{
Pointer x= (Pointer)malloc(0x1030);
printf("0x%08x ", x);
free(x);
}
extern void write_read_test
(String prefix,
Int count,
Int task,
Bool multitask,
Int max_file_size
);
Int main()
{
Int i;
printf("--------------- Install Flash_handler --------------\n");
old_event_handler= Flash_install_event_handler( event_handler );
atexit(dump_status);
printf("--------------- START OF FLASH TEST --------------\n");
for (i = 0; i < NROF_ITERATIONS; i++) {
DIR_CREATE("QUICK");
if (i % 100 == 40) DIR_CREATE("SLOW");
if (i % 100 == 50) dump_status();
print_heap();
write_read_test("/flash/",i,0,False,MAX_FILE_SIZE);
if (i % 100 == 60) DIR_DELETE("SLOW");
if (i % 100 == 80) dump_status();
DIR_DELETE("QUICK");
if (i % 100 == 90) dump_status();
}
printf("------------- SUCCESSFULL TERMINATION ------------\n");
exit (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -