/*
MFS_QA.c: Quality Assurence program.

Compiler: BC++ 3.1, 
          Turbo C++ 1.01(3.01) (free from http://cc.codegear.com/free/cpp)
          MSC 6.0,
          MSVC 1.52.
      
Compile mode: large

Project: SD_QA.c 
         ..\..\lib\upac5000.lib
         ..\..\lib\sd_v101.lib
         
Hardware: uPAC-5001
    
[2009,Oct,26] by Kevin
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "..\..\Lib\g4500.h"   
#include "..\..\Lib\microSD.h"

#define _Test_Length 1000
#define _Test_Loop   500
char far sFileData[_Test_Length],sStandardData[_Test_Length];

void Test_Performance(void)
{
    int iFileHandle,i;
    int iRet,iFaile=0;
    long lLastTimeTicks,lTimeDiff,lOffset,lSize;
    
    
    iFileHandle=pc_open("A:\Perform.txt",(word)(PO_WRONLY|PO_CREAT|PO_TRUNC),(word)(PS_IWRITE|PS_IREAD));
    if(iFileHandle>=0)
    {
        Print("pc_open() : A:Perform.txt ok, File handle=%d.....\r\n", iFileHandle);
        
        lLastTimeTicks=GetTimeTicks();
        for(i=0;i<10000;i++)
            lOffset=pc_seek(iFileHandle,10L,PSEEK_SET);
        lTimeDiff=GetTimeTicks()-lLastTimeTicks;
        
        pc_close(iFileHandle);    
        Print("pc_lseek takes %7.3f ms\n\r",(float)lTimeDiff/10000.0);
    }
    else
    {
        Print("pc_open(): A:Perform.txt failed! Error:%d\r\n", iFileHandle);
        Print("\n\rTest result=failed!\n\r");
    }
    
    lLastTimeTicks=GetTimeTicks();
    for(i=0;i<100;i++)
    {
        iFileHandle=pc_open("A:\Perform.txt",(word)(PO_WRONLY|PO_CREAT),(word)(PS_IWRITE|PS_IREAD));
        pc_close(iFileHandle);  
    }
    lTimeDiff=GetTimeTicks()-lLastTimeTicks;
    Print("pc_open & pc_close takes %7.3f ms\n\r",(float)lTimeDiff/100.0);
   
    lLastTimeTicks=GetTimeTicks();
    for(i=0;i<1;i++)
    {
        lSize=pc_get_totalSize_KB();
        if(lSize==-1L)
        {
            Print("pc_get_totalSize_KB error\n\r");
            break;
        }
    }
    lTimeDiff=GetTimeTicks()-lLastTimeTicks;
    Print("pc_get_totalSize_KB=%ld takes %7.3f ms\n\r",lSize,(float)lTimeDiff/1.0);       
        
    lLastTimeTicks=GetTimeTicks();
    for(i=0;i<1;i++)
    {
        lSize=pc_get_freeSize_KB();
        if(lSize==-1L)
        {
            Print("pc_get_freeSize_KB error\n\r");
            break;
        }
    }
    lTimeDiff=GetTimeTicks()-lLastTimeTicks;
    Print("pc_get_freeSize_KB=%ld takes %7.3f ms\n\r",lSize,(float)lTimeDiff/1.0);
        
    
    
    lLastTimeTicks=GetTimeTicks();
    for(i=0;i<1;i++)
    {
        lSize=pc_get_usedSize_KB();
        if(lSize==-1L)
        {
            Print("pc_get_usedSize_KB error\n\r");
            break;
        }
    }
    lTimeDiff=GetTimeTicks()-lLastTimeTicks;
    Print("pc_get_usedSize_KB=%ld takes %7.3f ms\n\r",lSize,(float)lTimeDiff/1.0);
}
        
    
void Test_Write_Speed(void)
{
    /*
    Test item: Writing speed (calls WriteFile)
    Description:  
        Create a file "Speed.txt". 
    */
    
    int iFileHandle,i;
    int iRet,iFaile=0;
    long lLastTimeTicks,lTimeDiff;

    iFileHandle=pc_open("A:\Speed.txt",(word)(PO_WRONLY|PO_CREAT),(word)(PS_IWRITE|PS_IREAD));
    if(iFileHandle>=0)
    {
        Print("pc_open() : A:Speed.txt ok, File handle=%d.....\r\n", iFileHandle);

        //Prepare data: 0,1,2,...,8,9,0,1,....
        for(i=0;i<_Test_Length;i++)
            sFileData[i]='0'+i%10;
        
        lLastTimeTicks=GetTimeTicks();
        for(i=0;i<_Test_Loop;i++)
        {
            iRet=pc_write(iFileHandle,sFileData,_Test_Length);
            //if(iRet<=0)
            if(iRet!=_Test_Length)
            {
                Print("Loop%d Write data failed! Error code=%d\r\n",i, iRet);
                iFaile=1;
                break;
            }
            Print(".");
            Delay(50);
        }
        lTimeDiff=GetTimeTicks()-lLastTimeTicks;
        
        iRet=pc_close(iFileHandle);
        if(iRet==NoError)
        {
            Print("\n\pc_close(): A:Speed.txt ok.\n\r");
            if(iFaile==0)
            {
                Print("\n\rTest result=ok. WriteFile %ld Bytes takes %ldms(%5.1fKB/Sec)\n\r",
                      (long)_Test_Loop*(long)_Test_Length,
                      lTimeDiff,
                      (float)_Test_Loop*(float)_Test_Length/lTimeDiff); 
            }
            else Print("\n\rTest result=failed!\n\r");
        }
        else
        {
            Print("\n\pc_close(): A:Speed.txt failed! Error code=%d\r\n", iRet);
            Print("\n\rTest result=failed!\n\r");
        } 
    }
    else
    {
        Print("pc_open(): A:Speed.txt failed! Error:%d\r\n", iFileHandle);
        Print("\n\rTest result=failed!\n\r");
    }    
}    

void Test_Append(void)
{
    /*
    Test item: Append speed (calls pc_write)
    Description:  
        Create a file "Append.txt". 
    */
    
    int iFileHandle,i;
    int iRet,iFaile=0;

    iFileHandle=pc_open("A:\Append.txt",(word)(PO_WRONLY|PO_APPEND|PO_CREAT),(word)(PS_IWRITE|PS_IREAD));
    if(iFileHandle>=0)
    {
        Print("pc_open() : A:Append.txt ok, File handle=%d.....\r\n", iFileHandle);

        //Prepare data: 0,1,2,...,8,9,0,1,....
        for(i=0;i<_Test_Length;i++)
            sFileData[i]='0'+i%10;
        
        for(i=0;i<10;i++)
        {
            iRet=pc_write(iFileHandle,sFileData,_Test_Length);
            if(iRet<=0)
            {
                Print("Loop%d Write data failed! Error code=%d\r\n",i, iRet);
                iFaile=1;
                break;
            }
            else
                Print("Append data to append.txt ok.\n\r");
            //Print("Append data to append.txt ok.(%ld)\n\r",pc_tell(iFileHandle));
        }
        
        iRet=pc_close(iFileHandle);
        if(iRet==NoError)
        {
            Print("\n\pc_close(): A:Append.txt ok.\n\r");
            if(iFaile==0)
            {
                Print("\n\rAppend to append.txt ok.\n\r");
              
            }
            else Print("\n\rTest result=failed!\n\r");
        }
        else
        {
            Print("\n\pc_close(): A:Append.txt failed! Error code=%d\r\n", iRet);
            Print("\n\rTest result=failed!\n\r");
        } 
    }
    else
    {
        Print("pc_open(): A:Append.txt failed! Error:%d\r\n", iFileHandle);
        Print("\n\rTest result=failed!\n\r");
    }    
}    


void Test_Read_Speed(void)
{
    /*
    Test item: Reading speed (calls ReadFile)
    Description:  
        Read data from A:Speed.txt and check its correction.
        "Speed.txt" should be created advanced by TestWritingSpeed().
    */
    int iFileHandle,i,j;
    int iRet,iFaile=0;
    long lLastTimeTicks,lTimeDiff;
    
    //Prepare standard data: 0,1,2,...,8,9,0,1,.... 
    for(i=0;i<_Test_Length;i++)
        sStandardData[i]='0'+i%10;
       
    iFileHandle=pc_open("A:\Speed.txt",(word)(PO_RDONLY),(word)PS_IREAD);   
    if(iFileHandle>=0)
    {
        Print("OpenFile() : A:Speed.txt ok, File handle=%d.....\r\n", iFileHandle);
        
        lLastTimeTicks=GetTimeTicks();
        for(i=0;i<_Test_Loop;i++)
        {
            memset(sFileData,0,_Test_Length);
            
            iRet=pc_read(iFileHandle,sFileData,_Test_Length);
            if(iRet!=_Test_Length)
            {
                Print("Loop%d Read data failed! Error code=%u\r\n",i, iRet);
                iFaile=1;
                iRet=pc_close(iFileHandle);
                break;
            }
            else if(memcmp(sFileData,sStandardData,_Test_Length)!=NoError)
            {
                Print("Loop%d, Compare data failed! Error code=%u\r\n",i, iRet);
                Print("Standard :File\n\r");
                for(j=0;j<_Test_Length;j++)
                {
                    if(sStandardData[j]!=sFileData[j])
                    {
                        Print("{Data[%d] %c:%c [%02d]:[%02d]} ",j,sStandardData[j],sFileData[j],sStandardData[j],sFileData[j]);
                        break;
                    }
                }
                Print("\n\r");
                iRet=pc_close(iFileHandle);
                iFaile=1;
                break;
            }
            else Print(".");
        }
        
        if(i==_Test_Loop)
        {
            lTimeDiff=GetTimeTicks()-lLastTimeTicks;
            iRet=pc_close(iFileHandle);
            if(iRet==NoError)
            {
                Print("\n\rCloseFile(): A:Speed.txt ok.\n\r");
                if(iFaile==0)
                {
                    Print("\n\rTest result=ok. ReadFile %ld Bytes takes %ldms(%5.1fKB/Sec)\n\r",
                          (long)_Test_Loop*(long)_Test_Length,
                          lTimeDiff,
                          (float)_Test_Loop*(float)_Test_Length/lTimeDiff); 
                }
                else Print("\n\rTest result=failed!\n\r");
            }
            else
            {
                Print("\n\pc_close(): A:Speed.txt failed! Error code=%d\r\n", iRet);
                Print("\n\rTest result=failed!\n\r");
            }
        }
        else
        {
            Print("\n\rTest result=failed!\n\r");
        }
    }
    else
    {
        Print("pc_open(): A:Speed.txt failed! Error:%d\r\n", iFileHandle);
        Print("\n\rTest result=failed!\n\r");
    }
}

void Test_Seek_Tell(void)
{
    /*
    Test item: Seek & Tell
    Description:  
        Create a file "SeekTell.txt". Call Tell, Seek, then read data 
        to check whether Tell and Seek work.
    */
    
    int iFileHandle,i,j,iMode;
    int iRet,iFaile=0;
    long lPosition,lOffset;
    
    iFileHandle=pc_open("A:\SeekTell.txt",(word)(PO_WRONLY|PO_CREAT|PO_TRUNC),(word)(PS_IWRITE|PS_IREAD));
    if(iFileHandle>=0)
    {
        Print("OpenFile() : A:SeekTell.txt ok, File handle=%d.....\r\n", iFileHandle);

        //Prepare data: 0,1,2,...,8,9,0,1,....
        for(i=0;i<_Test_Length;i++)
            sFileData[i]='0'+i%10;
        
        iRet=pc_write(iFileHandle,sFileData,_Test_Length);
        if(iRet==_Test_Length)
        {
            Print("Write data ok.\n\r");
        }
        else
        {
            Print("Write data failed! Error code=%d\r\n",iRet);
            iFaile=1;
        }
        
        if(iFaile==0)
        {
            iRet=pc_close(iFileHandle);
            if(iRet==NoError)
            {
                Print("\n\rpc_close(): A:SeekTell.txt ok.\n\r");
            }
            else
            {
                Print("\n\pc_close(): A:SeekTell.txt failed! Error code=%d\r\n", iRet);
                Print("\n\rTest result=failed!\n\r");
                iFaile=1;
            }
        } 
    }
    else
    {
        Print("pc_open(): A:SeekTell.txt failed! Error:%d\r\n", iFileHandle);
        Print("\n\rTest result=failed!\n\r");
        iFaile=1;
    }
    
    if(iFaile==0)
    {
        for(i=0;i<_Test_Length;i++)
            sStandardData[i]='0'+i%10;
       
        iFileHandle=pc_open("A:\SeekTell.txt",(word)(PO_RDONLY),(word)PS_IREAD);   
        if(iFileHandle>=0)
        {
            Print("pc_open() : A:SeekTell.txt ok, File handle=%d.....\r\n", iFileHandle);
            
            for(iMode=0;iMode<3;iMode++)   
            {
                if(iMode==PSEEK_SET) Print("\n\rPSEEK_SET mode:\n\r");
                if(iMode==PSEEK_CUR) Print("\n\rPSEEK_CUR mode:\n\r");
                if(iMode==PSEEK_END) Print("\n\rPSEEK_END mode:\n\r");
                
                for(i=0;i<10;i++)
                {    
                    memset(sFileData,0,10);
                
                    lOffset=i*(_Test_Length/10);
                    if(iMode==PSEEK_SET)
                    {
                        pc_seek(iFileHandle,lOffset,PSEEK_SET);
                    }
                    else if(iMode==PSEEK_CUR)
                    {
                        pc_seek(iFileHandle,lOffset,PSEEK_SET);
                        pc_seek(iFileHandle,10,PSEEK_CUR);
                        lOffset+=10;
                    }
                    else if(iMode==PSEEK_END)
                    {
                        pc_seek(iFileHandle,0L-lOffset-10L,PSEEK_END);
                        lOffset=_Test_Length-lOffset-10L;
                    }
                        
                    lPosition=pc_tell(iFileHandle);
                    if(lPosition!=lOffset)
                    {
                        Print("Tell error, Tell=%ld, lOffset=%ld\n\r",lPosition,lOffset);
                        Print("\n\rTest result=failed!\n\r");
                        iFaile=1;
                        break;
                    }
                    
                    iRet=pc_read(iFileHandle,sFileData,10);
                    if(iRet<=0)
                    {
                        Print("Read data failed! Error code=%u\r\n",iRet);
                        iFaile=1;
                        break;
                    }
                
                    else if(memcmp(sFileData,sStandardData+lOffset,10)!=NoError)
                    {
                        Print("Compare data failed! Error code=%u\r\n",iRet);
                        Print("Standard :File\n\r");
                        for(j=0;j<10;j++)
                        {
                            if(sStandardData[lOffset+j]!=sFileData[j])
                            Print("{Data[%ld] %c:%c [%02d]:[%02d]} ",
                                    lOffset+j,
                                    sStandardData[lOffset+j],
                                    sFileData[j],
                                    sStandardData[lOffset+j],
                                    sFileData[j]);
                            Delay(5);
                        }
                        Print("\n\r");
                        iFaile=1;
                        break;
                    }
                    else 
                    {
                        Print("%05ld ok. ",lOffset); //Compare data ok.
                        if((i+1)%5==0) Print("\n\r");
                    }
                }
            }
        }
        else
        {
            Print("pc_open(): A:SeekTell.txt failed! Error:%d\r\n", iFileHandle);
            Print("\n\rTest result=failed!\n\r");
            iFaile=1;
        }
        
        if(iFaile==0)
        {
            iRet=pc_close(iFileHandle);
            if(iRet==NoError)
            {
                Print("\n\rpc_close(): A:SeekTell.txt ok.\n\r");
                Print("\n\rTest result=ok!\n\r");
            }
            else
            {
                Print("\n\rpc_close(): A:SeekTell.txt failed! Error code=%d\r\n", iRet);
                Print("\n\rTest result=failed!\n\r");
            }
        }
        else
        {
            Print("\n\rTest result=failed!\n\r");
        }
    }
    else
    {
        Print("pc_open(): A:SeekTell.txt failed! Error:%d\r\n", iFileHandle);
        Print("\n\rTest result=failed!\n\r");
    }
}


void Test_Openfile(void)
{
    /*
    Test item:DiskA,DiskB can open 10 files at the same time.
    Description:  
        1. Create 25 files on DiskA and DiskB
           Steps:Create 1 file ==> give data ==> close it, repeat to create 25 files.
        2. Open and read the 25 files to check whether its data is correct.
           Steps:Open 25 files ==> read and compare data for opend files 
             ==> Close opend files.
             
            Each disk can open 25 files at the same time,
            On step2, only the first 10 files of each disk can be opend.
            The rest 15 files should return error code when opening.
    */
    int iFileHandle[30],i,disk,iLength;
    int iRet;
    char sFileName[13],sData[80],sStandardData[80];
    int iFaile=0;
    
    Print("============================================================\n\r");
    Print("Testing for opening 25 files in diskA                       \n\r"); 
    Print("============================================================\n\r");
    
    Print("Creating files...\n\r");
    for(i=0;i<25;i++)
    {
        iFaile=0;
        sprintf(sFileName,"Test%02d.txt",i);
        //sprintf(sFileName,"abc.txt");
        iFileHandle[i]=pc_open(sFileName,(word)(PO_WRONLY|PO_CREAT|PO_TRUNC),(word)(PS_IWRITE|PS_IREAD));
        if(iFileHandle[i]>=0)
        {
            sprintf(sData,"test data for A:%s",sFileName);
            iRet=pc_write(iFileHandle[i],sData,strlen(sData));
            if(iRet<=0)
            { 
                iFaile=1;
                iRet=pc_get_errno();
                Print("pc_write %s error, FileHandle=%d,error=%d\n\r",sFileName,iFileHandle[i],iRet);
            }
            iRet=pc_close(iFileHandle[i]);
            if(iRet!=NoError) 
            {
                iFaile=1;
                Print("pc_close %s error\n\r",sFileName);
            }
            if(iFaile==0) Print("%s(%d) ok. ",sFileName,iFileHandle[i]);
        }
        else
        {
            Print("pc_open A:%s error\n\r",sFileName);
            iFaile=1;
        }
            
        if((i+1)%5==0) Print("\n\r");
        Delay(10);
    }
    Print("\n\r");
    
    
    Print("\n\rReading files...\n\r");    
    for(i=0;i<25;i++)
    {
        sprintf(sFileName,"Test%02d.txt",i);
        //sprintf(sFileName,"abc.txt");
        iFileHandle[i]=pc_open(sFileName,(word)(PO_RDONLY),(word)PS_IREAD);
        if(iFileHandle[i]>=0)
        {
            sprintf(sStandardData,"test data for A:%s",sFileName);
            iLength=strlen(sStandardData);
            
            memset(sData,0,80);
            iRet=pc_read(iFileHandle[i],sData,iLength);
            if(iRet==iLength)
            {
                if(memcmp(sData,sStandardData,iLength)!=NoError)
                {
                    Print("%s error!\n\r",sFileName);
                    iFaile=1;
                }
                else Print("%s ok. ",sFileName);
            }    
            else 
            {
                Print("%s Length error\n\r",sFileName);
                iFaile=1;
            }
        }
        else
        {
            //The first 6 files should be opend ok.
            if(i<6) 
            {
				Print("Open %s error(%d)\n\r",sFileName,iFileHandle[i]);
                iFaile=1;
            }
            else 
                Print(".");
        }
        if((i+1)%5==0) Print("\n\r");  
        Delay(10);  
    }
    Print("\n\r");
    
    Print("Closing files ...\n\r");
    for(i=0;i<25;i++)
    {
        if(iFileHandle[i]>=0)
        {
            iRet=pc_close(iFileHandle[i]);
            sprintf(sFileName,"Test%02d.txt",i);
            //sprintf(sFileName,"abc.txt");
            if(iRet==NoError)
            {
                Print("A:%s ok. ",sFileName);
            }
            else
            {
                Print("\n\rClose A:%s error(%d)\n\r",sFileName,iRet);
                iFaile=1;
            }
        }
        else Print(".");
        
        if((i+1)%5==0) Print("\n\r"); 
        Delay(10);
    }
    Print("\n\r");
    
    if(iFaile) Print("\n\rTest result=failed!\n\r");
    else       Print("\n\rTest result=ok.\n\r");
}


void Test_OpenMode(void)
{
    /*
    Test item: Open mode, write/read/append/create/trunc/read only/write only/read and write
    Description:  
  
    */
    int iFileHandle[30],i,iLength;
    int iRet;
    char sFileName[13],sData[80],sStandardData[80];
    int iFaile=0;
    
    Print("============================================================\n\r");
    Print("Testing for open mode                                       \n\r"); 
    Print("============================================================\n\r");
    
    iFaile=0;
    
    //Test 1.  if file not exists, pc_open should get FSERR_NOENT error.
    iRet=pc_del("A:OpenMode.txt");
    if(iRet)
    {
        Print("A:OpenMode.txt deleted.\n\r");
    }
    
    iFileHandle[0]=pc_open("A:OpenMode.txt",(word)(PO_WRONLY),(word)(PS_IWRITE|PS_IREAD));
    if(iFileHandle[0]>=0)
    {
        Print("pc_open should return error code\n\r");
        pc_close(iFileHandle[0]);
        return 0;
    }
    else
    {
        iRet=pc_get_errno();
        if(iRet!=FSERR_NOENT)
        {
            Print("pc_open error code =%d\n\r",iRet);
            return 0;
        }
    }
    Print("test 1. ok\n\r");
    

    //Test 2.  a file should be able to been opend more than once.
    iFileHandle[0]=pc_open("A:OpenMode.txt",(word)(PO_RDWR|PO_CREAT),(word)(PS_IWRITE|PS_IREAD));
    if(iFileHandle[0]>=0)
    {
        iFileHandle[1]=pc_open("A:OpenMode.txt",(word)(PO_RDWR|PO_CREAT),(word)(PS_IWRITE|PS_IREAD));
        if(iFileHandle[1]>=0)
        {
            pc_write(iFileHandle[0],"1234567890",10);
            pc_write(iFileHandle[1],"abcde",5);
            
            pc_close(iFileHandle[0]);
            pc_close(iFileHandle[1]);
            //return 0;
        }
        else
        {
            iRet=pc_get_errno();
            switch(iRet)
            {
                case FSERR_ACCESS:
                    Print("FSERR_ACCESS\n\r");
                    break;
                case FSERR_NOENT:
                    Print("FSERR_NOENT\n\r");
                    break;
            }
            
            Print("pc_open one file twice failed.\n\r");
            Print("FileHandle[0]=%d, FileHandle[1]=%d\n\r",iFileHandle[0],iFileHandle[1]);
        }    
    }
    else
    {
        iRet=pc_get_errno();
        if(iRet!=FSERR_NOENT)
        {
            Print("pc_open error code =%d\n\r",iRet);
            return 0;
        }
    }    
    Print("test 2. ok\n\r");   

    Print("\n\r");
}    


Test_CheckSize(void)
{
    long lSize;
    
    lSize=pc_get_freeSize_KB();
    if(lSize==-1L)
        Print("pc_get_freeSize_KB error\n\r");
    else 
        Print("Free Size= %ld KB\n\r",lSize);
        
    lSize=pc_get_usedSize_KB();
    if(lSize==-1L)
        Print("pc_get_usedSize_KB error\n\r");
    else 
        Print("Used Size= %ld KB\n\r",lSize);
        
    lSize=pc_get_totalSize_KB();
    if(lSize==-1L)
        Print("pc_get_totalSize_KB error\n\r");
    else 
        Print("Total Size= %ld KB\n\r",lSize);
}

void main(void)
{
    int iAction, iRet, iVer,i;
    char cData;
    char LibDate[16];
    unsigned char *SD_QA_Date=__DATE__;

    InitLib();
    
    Print("=============================\n\r");
    if(pc_init())
	{
	    Print("Initialize ok.\n\r");
        Print("[Disk Size=%ld KB]\n\r",pc_get_totalSize_KB());
    }
    else
    {
	    Print("Initialize failed\n\r");
	    iRet=pc_get_errno();   
	    switch(iRet)
	    { 
	        case PCERR_BAD_FORMAT: //1
		        Print("Error 01: format is not FAT\n\r");
		        break;
		    case PCERR_NO_CARD: //2
		        Print("Error 02: no microSD card\n\r");
		        break;
		    default:
		        Print("Error %02d: unknow error\n\r",iRet);
		}
    }
	Print("=============================\n\r\n\r");
    
    iVer=pc_getLibVer();
    pc_getLibDate((unsigned char *) &LibDate);
    
    Print("==============================================\n\r");
    Print("  Quality Assurence Program for microSD. \n\r\n\r");
    Print("  SD_V%03d.Lib built@[%s]           \n\r",iVer,LibDate);
    Print("  SD_QA.exe    built@[%s] by Kevin  \n\r",SD_QA_Date);
    Print("==============================================\n\r");
    
    for(;;)
    {
        Print("\r\n");
        Print("0)Quit\n\r");
        Print("1)WriteFile Speed\n\r");
        Print("2)ReadFile Speed\n\r");
        Print("3)Performance Test\n\r");
        Print("4)Append\n\r");
        Print("5)Open mode\n\r");
        Print("6)Opening 10 file handles \n\r");
        Print("7)Tell & Seek\n\r");
        Print("8)Check Size\n\r");
        
        Print("Please Select(0~8): ");
        Scanf("%d", &iAction);
        
        if(iAction==0)
        {
            break;
        }
            
        Print("\r\n");
        if(iAction==1) Test_Write_Speed();
        if(iAction==2) Test_Read_Speed();
        if(iAction==3) Test_Performance(); 
        if(iAction==4) Test_Append();
        if(iAction==5) Test_OpenMode();
        if(iAction==6) Test_Openfile();
        if(iAction==7) Test_Seek_Tell();
        if(iAction==8) Test_CheckSize();
        
        Print("\r\n\n\rPress any key to continue...\r\n");
        Getch();
    }
}