⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtfsdem.c

📁 ertfs文件系统里面既有完整ucos程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
* EBS - RTFS (Real Time File Manager)
*
* Copyright Peter Van Oudenaren , 1993
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*/
/*
*****************************************************************************
    REGRESS.C   - RTFS Excerciser
    
     This program performs two functions. It calls virtually all of the API 
     routines plus it stress tests the system for driver bugs and memory leaks.
     It works by repeatedly opening a disk and then entering an inner loop
	 which creates a directory and then creates N subdirectories below that.
     Finally the inner loop creates NUSERFILES files, writes to them, reads from
     them, seeks, truncates, closes, renames and deletes them. Along the way
     it check set current working directory and get working directory. Finally
     the inner loop deletes all of the subdirectories it created and compares 
     the current disk free space to the free space before it started. These
     should be the same. After the inner loop completes the outer loop closes
     the drive and then reopens it to continue the test.

     There are a few functions that do not get tested, they are:
        pc_gfirst
        pc_gnext
        pc_gdone
        pc_abort
       
     Not all modes of po_open and po_lseek are tested either. Nor does it 
     test your port in multitasking mode. You may modify this program and
     run it in multiple threads if you wish.

     The following parameters may be changed:

        USEPRINTF -  Set this to zero to run completely quietly. If this
                     is done you should set a break point in regress_error()
                     to catch errors.
        test_drive[] - The drive where the test will occur.
        test_dir[]   - The directory where the test will occur
        INNERLOOP   - The Number of times we run the inner loop
        OUTERLOOP   - The Number of times we run the inner loop
        SUBDIRDEPTH  - The depth of the tested subdirectories.
        NSUBDIRS     - The number of subdirectories below test_dir. Must
                       be less then 26. Each of these directories will 
                       have SUBDIRDEPTH subdirectories below it.


To run the program type REGRESS.

*****************************************************************************/

#if (defined(ERTFS_SA))
#include <pcdisk.h>
#else
/* load RTIP configuration settings */
#include "xnconf.h"
#include "drvconf.h"
#include <rtfsapi.h>
#include "demo.h"
#define tm_printf_2(X,Y) tm_printf(X,Y)
#define tm_printf_3(X,Y,Z) tm_printf(X,Y,Z)
#endif

#define INCLUDE_REGRESS 1

#define RGE_FLTDRIVE       3
#define RGE_FREEERROR      4
#define RGE_LEAKERROR      5
#define RGE_MKDIR          6
#define RGE_SCWD           7
#define RGE_MKDIRERR       9
#define RGE_PWD           10
#define RGE_RMDIR         11
#define RGE_DSKCLOSE      12
#define RGE_OPEN          13
#define RGE_SEEK          14
#define RGE_WRITE         15
#define RGE_READ          16
#define RGE_TRUNC         17
#define RGE_FLUSH         18
#define RGE_CLOSE         19
#define RGE_UNLINK        20
#define RGE_MV            21

/* Porting issues */
/* Set this to zero if you don't have tm_printf */
#define USEPRINTF 1

/* Set this to 1 if you have tm_printf and want to see more */
#define VERBOSE   1
char test_drive[] = "A:";         /* The drive where the test will occur */
#define NLONGS 512                /* Longs to write in file write test */
#define SUBDIRDEPTH  4            /* Depth of subdirectories */
#define NSUBDIRS     8            /* <= 26 Number of subdirs at below RTFSTEST */
#define NTESTFILES NUSERFILES

dword test_rtfs_buf[NLONGS];      /* Used in the file write test */

#if (VFAT)
char test_dir[] = "RTFS_Test_Directory";       /* Test will occur in this Directory */
#else
char test_dir[] = "RTFSTEST";      /* Test will occur in this Directory */
#endif
#define INNERLOOP   4              /* Number of times we run the tes suite 
                                      between open and close. */
#define OUTERLOOP   6              /* Number of times we open the drive
                                      run the inner loop and close the drive */

int which_demo_running;

#if (VERBOSE)
#define DIAG_OUT(X,Y) tm_printf_3("%s %s\n", X, Y);
#else
#define DIAG_OUT(X,Y)
#endif


void do_test(void);
char get_test(void);
void do_file_test(void);
void do_rm(char *buffer, int level);
void regress_error(int error);
void regress_test(void);
void tst_shell(void);

// ********************************************************************
// THIS TASK IS THE MAIN PROGRAM
// ********************************************************************

#if (defined(ERTFS_SA))
#if (defined(PLUS))
void  app_entry(void);

#define MAIN_STACK_SIZE 4096

char main_stack[MAIN_STACK_SIZE];
NU_TASK main_task;
void tc_main(dword arg)
{
    app_entry();
}

void Application_Initialize(void *first_available_memory)
{
    // start the timer task
    if (NU_Create_Task(&main_task,
                       "MAIN",
                       tc_main, 
                       0, 0,                    /* argc, argv */
                       main_stack,              /* stack */
                       MAIN_STACK_SIZE,         /* stack size */ 
                       (OPTION)10,              /* priority */
                       (OPTION)0,  /* time slice */
                       (OPTION)NU_PREEMPT, (OPTION)NU_START) != NU_SUCCESS)
        return(FALSE);   // failure
}
#elif (defined(RTPX))
void  app_entry(void);

#define MAIN_STACK_SIZE 4096

char main_stack[MAIN_STACK_SIZE];
TASK main_task;
void tc_main(void)
{
    app_entry();
}

#if (RTPXMSP0)
extern unsigned short STKHQQ;
#endif

void main()
{
#if (RTPXMSP0)
    STKHQQ = 0;
#endif

    px_init();
    main_task = px_task_create("MAIN", tc_main, 
                                      10,
                                      TRUE, MAIN_STACK_SIZE,
                                      main_stack);
    if (!main_task)
        return(FALSE);   // failure
    px_run();
}

#elif (defined(CMX))
void  app_entry(void);

#define MAIN_STACK_SIZE 4096

char main_stack[MAIN_STACK_SIZE];
byte main_task;
void tc_main(void)
{
    app_entry();
}

void main()
{
    K_OS_Init();
#if (defined(CMXRM))
    ks_mask_isr_on(0);
    ks_clear_isr(0);
#endif

    /* initialize POWERPC. GNU does this from its crt0.o   */
    init_ppc();


    if (K_Task_Create_Stack((byte)10, &main_task, tc_main,
                (word32 *)(&main_stack[MAIN_STACK_SIZE-4])) != K_OK)
                    return;   // failure
    if (K_Task_Start(main_task) != K_OK)
            return;


    K_OS_Start();
}



#elif (defined(UCOS))
void  app_entry(void);

#define MAIN_STACK_SIZE 4096
UWORD            OldSP;
UWORD            OldBP;
void interrupt (*OldTickISR)(void);

char main_stack[MAIN_STACK_SIZE];
void tc_main(void *p)
{
    app_entry();
}


void main()
{
    OldBP      = _BP;                                      /* Save current SP and BP                   */
    OldSP      = _SP;
    OldTickISR = getvect(0x08);                            /* Get MS-DOS's tick vector                 */
    setvect(0x81, OldTickISR);                             /* Store MS-DOS's tick to chain             */
    setvect(uCOS, (void interrupt (*)(void))OSCtxSw);      /* uC/OS's context switch vector            */
    OSInit();
    setvect(0x08, (void interrupt (*)(void))OSTickISR);    /* Install uC/OS's clock tick ISR           */

    if (OSTaskCreate(tc_main, (void *) 0,
            &main_stack[MAIN_STACK_SIZE-2],
            62) != OS_NO_ERR)
    {
        tm_printf("Spawn of main task failed. change priority ?\n");
        aos_exit();
    }
    OSStart();
}


#elif (defined(POLLOS))
void  app_entry(void);
void main()
{
#if (defined(POLD860))
    /* initialize POWERPC. GNU does this from its crt0.o   */
    init_ppc();
#endif
    app_entry();
}
#else
#error implement main task entry point for your kernel
#endif
#endif


void  app_entry(void)                             /* __fn__ */
{
char option;

#if (EBSENV)
    aos_start_console_tasks();
#endif

#if (INCLUDE_RTIP)
    /* Initialize the subsystem   */
    tm_puts("Starting Network Services");

    if (xn_rtip_init() != 0)
        tm_puts("xn_rtip_init failed");
#endif

    /* Initialize ertfs  */
    if (!pc_ertfs_init())
        tm_printf("pc_ertfs_init failed");
#if (INCLUDE_VFS)
	// Init VFS *after* any other filesystem as it may MOUNT 
	// other filesystems!
	if (vf_init())
        tm_printf("vf_init failed");
#endif


#if (INCLUDE_REGRESS)
    do
    {
        option = get_test();

        switch (option)
        {
        case 'R':
            regress_test();
            break;
        case 'S':
            tst_shell();
            break;
        case 'Q':
        case 'q':
            aos_exit();
            break;
       default:
            DIAG_OUT("\n","Invalid Choice");
        }       // end of switch
    } while ( (option != 'Q') && (option != 'q') );
#else
    tst_shell();
#endif
}
#if (INCLUDE_REGRESS)

void regress_test(void)
{
int inner_loop;
int outer_loop;
long nfree, nfree_too;
dword blocks_total, blocks_free;

    for (outer_loop = 0; outer_loop < OUTERLOOP; outer_loop++)
    {
#if USEPRINTF
#if (!VERBOSE)
    tm_printf_2("\n %d:", outer_loop);
#endif
#endif
        if (!pc_set_default_drive(test_drive))
            regress_error(RGE_FLTDRIVE);

        /* If test_dir is not there, deltree will just fail */
        pc_deltree(test_dir);
        for (inner_loop = 0; inner_loop < INNERLOOP; inner_loop++)
        {
#if USEPRINTF
#if (!VERBOSE)
            tm_printf("+");
#endif
#endif
            /* Check freespace */
            nfree = pc_free(test_drive, &blocks_total, &blocks_free);        
            if (!nfree)
                regress_error(RGE_FREEERROR);
            do_test();                    /* Call the main test routine */
            /* Check freespace again. They should match */

            nfree_too = pc_free(test_drive, &blocks_total, &blocks_free);        
            if (!nfree_too)
                regress_error(RGE_FREEERROR);
            if (nfree_too != nfree)
                regress_error(RGE_LEAKERROR);
        }
    }
}

/*
    Make the test directory
    loop
        Step into the test directory
        Make another subdiretory
            loop
                Make N deep subdirectories
                    Change into each
                    compare what we know is the directory with
                    what pc_pwd returns.
            End loop
            In the lowest level directory
                loop 
                    create a file
                    open it with multiple file descriptors
                    loop
                        write to it on multiple FDs
                    loop
                        seek and read  on multiple FDs. Testing values
                    flush
                    truncate
                    close                   
                end loop
                loop
                    rename

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -