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

📄 tcases.c

📁 MMI层OBJ不能完全编译
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
 * Flash File System (ffs)
 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com
 *
 * ffs test cases
 *
 * $Id: tcases.c 1.13.1.1.1.66 Thu, 08 Jan 2004 15:05:23 +0100 tsj $
 *
 ******************************************************************************/

#ifndef TARGET
#include "ffs.cfg"
#endif

#include "ffs/ffs_api.h"  // Temp 
#include "ffs/ffs.h"

#include "ffs/board/tffs.h"
#include "ffs/board/core.h" // only for block/object recovery test flags
#include "ffs/board/tdata.h"
#include "ffs/board/ffstrace.h"
#include "ffs/board/drv.h"
#include "ffs/pcm.h"

#if((TARGET == 1) || (RIV_ENV==1))
#include "rvf/rvf_api.h"  // this include rv_general.h and rvf_target.h
#include "rvm/rvm_use_id_list.h"
#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stddef.h>

#if (TARGET == 0)
#include <setjmp.h>
#endif

#define LUDIR  "/europe/sweden"
#define MFDIR "/pcm"

// TODO: reimplement test case bfull (not valid any more).

// TODO: Cleanup in beginning of each test case for as many cases as
// possible, so they can be re-run.

// TODO: Make as many cases as possible fully independent of number of
// blocks and size of blocks in ffs.

// TODO: Every testcase should test if it is applicable to the current
// environment, e.g. some tests are impossible if e have a 2 or 3 block
// file system.

// TODO: test case for testing age functionality
// TODO: Implement case_ren
// TODO: Implement case_rm

// NOTEME: DO something with test case flags (PC, IT, RND)?

// Should we make a test case where we use case_lsr to make map of objects (
// ensuring mapsize is prime). In a loop, we select a random object (object
// index[rnd%size]) and perform a random operation on that object?

// Should test data (tdata[]) be of sizes 2^n+n or Xn+n where n = 0..15

// Should all test files have suffix ".<tdata-index>"? This would make very
// easy data checking!

// Add compiler define: WITH_PCM

//unsigned char ffs_image[4*4*1024];
//int ffs_ram_image_address = (int) &ffs_image;


/******************************************************************************
 * Prototypes and Globals
 ******************************************************************************/

// Helper functions
int cleanup(int min_space);
int make_random_file(char *dirname, int max_size, int min_size);
int ignore_file(char *pathname);
int mkfs(void);
void list_rep_inodes();
int case_trace_mask(int p0, int p1);
int case_reinit(int p0, int p1);
int case_debug_help(int p0, int p1);

struct object_s {
    char *name;
    struct xstat_s stat;
};

const struct testcase_s testcase[];

// Benchmark (not in use yet)
struct results_s {
    int w16B;
    int w256B;
    int w4096B;
    int rew4096B;
    int r16B;
    int r256B;
    int r4096B;
    int lfile;
    int ldir;
    int lonef;
};

/******************************************************************************
 * Collective Test Cases
 ******************************************************************************/

// test cases: all, alot, most, much + specific ones 

// NOTEME: removed test case_find() from alot, tall and test because there is no
// buffer overflow check

int case_all(int p0, int p1)
{
#if (TARGET == 1)
    UINT32 time_begin, elapsed;
    time_begin = tffs_timer_begin();
#endif
    // We have to run test case 'init' after test case 'format'. This is
    // because 'init' test case calls test_ffs_params_get() which
    // initializes variables used in many of the testcases.
    
    error = test_run("ninit;format;i;world;eu;pcm;apiexc;"
                     "bigf;open;rw;seek;append;ren;mopen;"
                     "jnl;irec;ibrec;drec;trunc;dbrec;stat;"
                     "lu;fc;root;dirs;frd;bfull;dsync;"
                     "ssym;ri;x;fwflags;query;octrl;pfblkh;pfob;pfframe");
#if (TARGET == 1)
    elapsed = tffs_timer_end(time_begin);
    ttw(ttr(TTrAll, "Time elapsed %ds" NL, elapsed / 1000));
#endif

    test_statistics_print();

    return error;
    // Not implemented test cases...
    return test_run("rm;pcm;");
}

int case_alot(int p0, int p1)
{
    return test_run("ninit;format;ri;i;ri;world;ri;eu;ri;fwflags;ri;"
                    "bigf;ri;open;ri;rw;ri;seek;ri;append;ri;ren;ri;"
                    "jnl;ri;irec;ri;dbrec;ri;stat;ri;trunc;ri;mopen;ri;"
                    "lu;ri;fc;ri;root;ri;dirs;ri;frd;ri;bfull;ri;"
                    "ssym;ri;x;ri;dsync;ri;pcm;ri;query;ri;octrl");
}

// NOTEME: removed jnl and find
int case_tall(int p0, int p1)
{
    return test_run("ninit;format;i;world;eu;fwflags;"
                    "bigf;irec;drec;ren;apiexc;"
                    "stat;open;rw;seek;trunc;append;octrl;"
                    "lu;fc;root;dirs;frd;bfull;pcm;query;"
                    "ssym;x;ex;bf;nb;mopen;dsync");
}

// Ad hoc test case
int case_test(int p0, int p1)
{
    return test_run("format;i;world;eu;ri;mopen1;ri;fwflags;ri;"
                    "bigf;ri;jnl;ri;irec;ri;dbrec;ri;pcm;ri;"
                    "trunc1;ri;stat;open1;ri;rw1;ri;seek1;ri;ren;ri;"
                    "lu;ri;fc;ri;root;ri;dirs;ri;frd;ri;bfull;ri;"
                    "ssym;ri;x;ri;append;ri;dsync;ri;");
}

// Status: 11-08-2004 test run okay 
int case_power_fail(int p0, int p1)
{
    return test_run("pfblkh;pfob;pfframe;pfrjnl;pfrblkh;jnl;ibrec;dbrec;pfre");
}

extern struct dev_s dev;
// Agressive all. Run case 'all' for dev.numblocks in the range dev.numblocks..4
int case_aall(int p0, int p1)
{
    char myname[20];

    int i, failed = 0;
   
    if (dev.numblocks * dev.blocksize > 1024*1024)
        strcpy(myname, "/ffs/b999");
    else
        strcpy(myname, "/ffs/b99");

    /** There's no need to test for i=127,126,125,124..3,2,1. So for i
     * >= 20 we progress a little faster. */
    for (i = dev.numblocks; i >= 3; i -= (i >= 20 ? i/4 : 1))
    {
        tw(tr(TR_FUNC, TrTest, "TEST aall. %d\n", i));
        ttw(ttr(TTrTest, "TEST aall. %d" NL, i));

        error = tffs_preformat(0xDEAD);
        expect(error, EFFS_OK);

        sprintf(myname, "/ffs/b%d", i);
        tffs_format(myname, 0x2BAD);
        expect(error, EFFS_OK);
        
        failed += test_run("i;world;eu;bigf;bfull;"
                           "jnl;irec;drec;dbrec;stat;dsync;"
                           "open;rw;seek;trunc;ren;mopen;"
                           "lu;fc;root;dirs;frd;append;" 
                           "ssym;find;ri;x");

    }
    return failed;
}

// This is a collection of all failing testcases to be investigated.
int case_fail(int p0, int p1)
{
    int result;
    const char imeifile[] = "/europe/norway/IMEI";

    switch (p0) {
    case 1:
        tw(tr(TR_FUNC, TrTestHigh, 
              "remember to run case_fcontrol before this one\n"));
        // Make symlink to imeifile and try to update it
        error = tffs_symlink("/europe/imie", imeifile);
        expect(error, EFFS_ACCESS);

        error = tffs_file_write("/europe/imie", TDATA(1), FFS_O_CREATE | FFS_O_TRUNC);
        expect(error, EFFS_ACCESS);
        break;
    case 2:    
        if (1) {
            const char bigfile[] = "/iceberg";
            int bytes_max, file_size;
            char myname[] = "/ffs/b7";

            error = tffs_preformat(0xDEAD);
            expect(error, EFFS_OK);

            error = tffs_format(myname, 0x2BAD);
            expect(error, EFFS_OK);

            ffs_query(Q_BYTES_FREE, (uint32 *) &bytes_max);
  
// File the system with this huge file
            file_size = bytes_max;

            ttw(ttr(TTrTest, "Bigfile of size %d" NL, file_size));
            tw(tr(TR_FUNC, TrTestHigh, "Bigfile of size %d\n", file_size));

            error = tffs_file_write(bigfile, (char *) tdata[TDATA_HUGE], file_size, FFS_O_CREATE | FFS_O_EXCL);
            expect(error, EFFS_OK);
        }
        break;
            
    default:
        result = 1;
    }
        return result;
}

int case_okay(int p0, int p1)
{

    tw(tr(TR_FUNC, TrTest, "journal size %d\n", fs.journal_size));
    tw(tr(TR_FUNC, TrTest, "journal entry size %d\n", sizeof(struct journal_s)));

    return 0;
}


// Run testcases in a random order. Only the test cases in the test case
// table that are marked as re-runnable, are run.
int case_rand(int p0, int p1)
{
    int i, n, seed, max = 0, error = 0;
    const struct testcase_s *p;
// This is a way to activate trace at a defined test number. If rand
// test number 134 fail it is possible to activate trace at test number
// 133 etc. Note we have to change activate_trace_nr manual before compile.
    int activate_trace_nr = 0;       
    int trace_mask = 0xFFDFF;
// NOTE: use p1 as active_trace_nr? or make it

    p0 = (p0 == 0 ? 117 : p0); // Number of test cases to run
    p1 = (p1 == 0 ? 567 : p1); // Initial seed
    seed = p1;
    if (seed == 1) {
        ; // TODO: Set seed as a variable of current time
    }

    // TODO: Initialize seed from p1.

    // First count total number of test cases
    for (p = testcase; p->name; p++)
        max++;

    tw(tr(TR_FUNC, TrTestHigh,
          "Number of available random test cases = %d\n", max));

    for (i = 0; i < p0; i++)
    {
        do {
            n = rand() % max;
        } while ((testcase[n].flags & RND) == 0);

        if ((i + 1) == activate_trace_nr) {
#if (TARGET == 0)
            tr_init(trace_mask, 2, 0 );
#else
            ttr_init(trace_mask);
#endif
            tw(tr_bstat());
        }

        tw(tr(TR_FUNC, TrTest, "Nr: %d", i + 1));
        ttw(ttr(TTrTest, "Nr: %d" NL, i + 1));
        
        if ((error = test_run(testcase[n].name)))
            break;
    }
    
    if (p1 == 1)
        tw(tr(TR_FUNC, TrTestHigh, "Initial seed = %d\n", seed));
    
    test_statistics_print();
    return error;
}


/******************************************************************************
 * Population Tests
 ******************************************************************************/

int case_world(int p0, int p1)
{
    int i;
    const char *dirs[] = { "/antarctica",    "/africa",
                           "/asia",          "/europe",
                           "/north-america", "/south-america",
                           "/australia" };

    // Cleanup
    for (i = 0; i < sizeof(dirs)/sizeof(char *); i++) {
        tffs_remove(dirs[i]);
    }

    for (i = 0; i < sizeof(dirs)/sizeof(char *); i++) {
        error = tffs_mkdir(dirs[i]);
        expect(error, EFFS_OK);
    }
    return 0;
}


int case_europe(int p0, int p1)
{
    int i;
    const char *dirs[] = { "/europe/denmark", "/europe/sweden",
                           "/europe/norway",  "/europe/finland" };

    // Cleanup
    for (i = 0; i < sizeof(dirs)/sizeof(char *); i++) {
        error = tffs_remove(dirs[i]);
    }

    for (i = 0; i < sizeof(dirs)/sizeof(char *); i++) {
        error = tffs_mkdir(dirs[i]);
        expect(error, EFFS_OK);
    }
    return 0;
}

int case_denmark(int p0, int p1)
{
    // Cleanup
    tffs_remove("/europe/denmark/jutland");
    tffs_remove("/europe/denmark/sealand");

    error = tffs_mkdir("/europe/denmark/jutland");
    expect(error, EFFS_OK);
    error = tffs_mkdir("/europe/denmark/sealand");
    expect(error, EFFS_OK);

    return 0;
}

⌨️ 快捷键说明

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