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

📄 tffs.c

📁 MMI层OBJ不能完全编译
💻 C
📖 第 1 页 / 共 3 页
字号:
    // fs.blocks_free_min plus one block for inodes
    param.bytes_avail =
        param.bytes_max - (param.block_size * (1 + param.blocks_free_min));

    // Compute number of blocks available for data storage
    param.data_blocks = param.numblocks - (1 + param.blocks_free_min);

    return error;
}

void test_statistics_print(void)
{
    tw(tr(TR_FUNC, TrTest, "Data allocated(%dMB)\n", stats.data_allocated>>20)); 
    tw(tr(TR_FUNC, TrTest, "Reclaim candidates: most-lost(%d), youngest(%d)\n", 
          stats.drec.most_lost, stats.drec.youngest)); 

    tw(tr(TR_FUNC, TrTest, "Data reclaimed:     lost(%dMB), valid(%dMB)\n", 
          stats.drec.lost[0]>>20 , stats.drec.valid[0]>>20)); 

    tw(tr(TR_FUNC, TrTest, "Inodes reclaimed:   num(%d), valid(%d), lost(%d)\n",
          stats.irec.num, stats.irec.valid, stats.irec.lost));

    ttw(ttr(TTrTest, "Data allocated(%dMB)\n" NL, stats.data_allocated>>20)); 
    ttw(ttr(TTrTest, "Reclaim candidates: most-lost(%d), youngest(%d)\n" NL, 
            stats.drec.most_lost, stats.drec.youngest)); 

    ttw(ttr(TTrTest, "Data reclaimed:     lost(%dMB), valid(%dMB)\n" NL, 
          stats.drec.lost[0]>>20 , stats.drec.valid[0]>>20)); 

    ttw(ttr(TTrTest, "Inodes reclaimed:   num(%d), valid(%d), lost(%d)\n" NL,
          stats.irec.num, stats.irec.valid, stats.irec.lost));
}

/******************************************************************************
 * Test and Expect Functions
 ******************************************************************************/

int test_expect(int n, int xn)
{
    if (n == xn)
        return 0;

    tw(tr(TR_FUNC, TrTest,
          "ERROR: expect(%d,%d): got %d, '%s', expected %d, '%s'\n",
          n, xn, n, ffs_strerror(n), xn, ffs_strerror(xn)));
    ttw(ttr(TTrTest, "ERROR: expect(%d,%d)" NL, n, xn));

    return -1;
}

// Expect a return code >= 0 meaning EFFS_OK.
int test_expect_ok(int n)
{
    if (n >= 0)
        return 0;

    tw(tr(TR_FUNC, TrTest,
          "ERROR: expect_ok(%d) got %d, '%s', expected >= EFFS_OK\n",
          n, ffs_strerror(n)));
    ttw(ttr(TTrTest, "ERROR: expect_ok(%d)" NL, n));

    return -1;
}

int test_expect_equal(int n, int xn)
{
    if (n == xn)
        return 0;

    tw(tr(TR_FUNC, TrTest, "ERROR: got %d, expected %d\n", n, xn));
    ttw(ttr(TTrTest, "ERROR: expect_eq(%d,%d" NL, n, xn));

    return -1;
}

int test_expect_not_equal(int n, int xn)
{
    if (n != xn)
        return 0;

    tw(tr(TR_FUNC, TrTest, "ERROR: expect_ne(%d)\n", n));
    ttw(ttr(TTrTest, "ERROR: expect_ne(%d)" NL, n));

    return -1;
}

int test_expect_greater_than(int n, int xn)
{
    if (n > xn)
        return 0;

    tw(tr(TR_FUNC, TrTest, "ERROR: expect_gt(%d,%d) got %d but expected > %d\n",
          n, xn, n, xn));
    ttw(ttr(TTrTest, "ERROR: expect_gt(%d,%d)" NL, n, xn));

    return -1;
}

int test_expect_data(const void *data1, const void *data2, int size)
{
    if (memcmp(data1, data2, size) == 0)
        return 0;
    
    tw(tr(TR_FUNC, TrTest,
          "ERROR: expect_data(%d) got unexpected data\n", size));
    ttw(ttr(TTrTest, "ERROR: expect_data(%d)" NL, size));

    return -1;
}

// Check that contents of file with name <name> is the same as <data> of
// size <size>.
int test_expect_file(const char *name, const void *data, int size)
{
    test.numcalls++;
    if (size > bigbuf_size) {
        tw(tr(TR_FUNC, TrTest, "WARNING: expect_file(%d) buffer too small\n",
              size));
        ttw(ttr(TTrTest, "WARNING: expect_file(%d) buffer too small" NL, size));
#if (TARGET == 1)
        return 0;
#endif
        return -1;
    }
        
    error = ffs_file_read(name, bigbuf, size);
    if (test_expect_greater_than(error, EFFS_OK - 1))
        return -1;
    return test_expect_data(bigbuf, data, size);
}

int test_expect_state(struct ffs_state_s *old, struct ffs_state_s *new)
{
    int old_total, new_total;

    old_total = old->inodes_used - old->inodes_lost;
    new_total = new->inodes_used - new->inodes_lost;

    if (old->objects_total == new->objects_total &&
        old->objects_total == new_total &&
        new->objects_total == old_total &&
        old->bytes_used == new->bytes_used &&
        old->bytes_lost == new->bytes_lost &&
        old->bytes_free == new->bytes_free) {
        return 0;
    }

    ttw(str(TTrTest, "ERROR: ffs state mismatch:" NL NL));
    tw(tr(TR_FUNC, TrTest, "ERROR: ffs state mismatch:\n\n"));
    test_state_objects_print(old, new);
    test_state_bytes_print(old, new);

    return -1;
}

// Check if number of objects is unchanged
int test_expect_objects(struct ffs_state_s *old, struct ffs_state_s *new)
{
    int old_total, new_total;

    test_ffs_state_get(new);

    old_total = old->inodes_used - old->inodes_lost;
    new_total = new->inodes_used - new->inodes_lost;

    if (old->objects_total == new->objects_total &&
        old->objects_total == new_total &&
        new->objects_total == old_total) {
        return 0;
    }

    ttw(ttr(TTrTest, "ERROR: expect_objects(%d, %d, %d, %d, %d, %d)" NL));
    tw(tr(TR_FUNC, TrTest, "ERROR: ffs state mismatch:\n\n"));
    test_state_objects_print(old, new);

    return -1;
}


/******************************************************************************
 * FFS Functions
 ******************************************************************************/

effs_t tffs_file_write(const char *name, void *addr, int size, uint16 option)
{
    test.numcalls++;
    return ffs_file_write(name, addr, size, option);
}

effs_t tffs_mkdir(const char *name)
{
    test.numcalls++;
    return ffs_mkdir(name);
}

effs_t tffs_symlink(const char *name, const char *actualpath)
{
    test.numcalls++;
    return ffs_symlink(name, actualpath);
}

effs_t tffs_remove(const char *name)
{
    test.numcalls++;
    return ffs_remove(name);
}

effs_t tffs_fcontrol(const char *name, int8 action, uint16 param)
{
    test.numcalls++;
    return ffs_fcontrol(name, action, param);
}

effs_t tffs_preformat(uint16 magic)
{
    test.numcalls++;
    return ffs_preformat(magic);
}

effs_t tffs_format(const char *name, uint16 magic)
{
    test.numcalls++;
    return ffs_format(name, magic);
}


int tffs_fread(const char *name, void *addr, int size)
{
    test.numcalls++;
    return ffs_file_read(name, addr, size);
}

int tffs_file_read(const char *name, void *addr, int size)
{
    test.numcalls++;
    return ffs_file_read(name, addr, size);
}

int tffs_opendir(const char *name, struct dir_s *dir)
{
    test.numcalls++;
    return ffs_opendir(name, dir);
}

int tffs_readdir (struct dir_s *dir, char *name, int8 size)
{
    test.numcalls++;
    return ffs_readdir(dir, name, size);
}

int tffs_readlink(const char *name, char *addr, int size)
{
    test.numcalls++;
    return ffs_readlink(name, addr, size);
}

int tffs_rename(const char *oldname, const char *newname)
{
    test.numcalls++;
    return ffs_rename(oldname, newname);
}

effs_t tffs_stat(const char *name, struct stat_s *stat)
{
    test.numcalls++;
    return ffs_stat(name, stat);
}

effs_t tffs_fstat(fd_t fdi, struct stat_s *stat)
{
    test.numcalls++;
    return ffs_fstat(fdi, stat);
}

effs_t tffs_linkstat(const char *name, struct stat_s *stat)
{
    test.numcalls++;
    return ffs_lstat(name, stat);
}

effs_t tffs_lstat(const char *name, struct stat_s *stat)
{
    test.numcalls++;
    return ffs_lstat(name, stat);
}

effs_t tffs_xlstat(const char *name, struct xstat_s *stat)
{
    test.numcalls++;
    return ffs_xlstat(name, stat);
}

effs_t tffs_query(int8 query, void *p)
{
    return ffs_query(query, p);
}


effs_t tffs_initialize(void)
{
    effs_t myerror;
    struct ffs_stats_s old_stats;

    test.numcalls++;

    memcpy(&old_stats, &stats, sizeof(struct ffs_stats_s));
    myerror = ffs_initialize();
    if (myerror < 0 && myerror != EFFS_NOFORMAT) {
        tw(tr(TR_FUNC, TrTest, "ffs_initialize() error = %d\n", myerror));
        exit(1);
    }
    memcpy(&stats, &old_stats, sizeof(struct ffs_stats_s));

    test_ffs_params_get();
    return myerror;
}

effs_t tffs_exit(void)
{
    test.numcalls++;
    return ffs_exit();
}

fd_t tffs_open(const char *pathname, ffs_options_t options)
{
    test.numcalls++;
    return ffs_open(pathname, options);
}

effs_t tffs_close(fd_t fdi)
{
    test.numcalls++;
    return ffs_close(fdi);
}

int tffs_write(fd_t fdi, void *addr, int size)
{
   test.numcalls++;
   return ffs_write(fdi, addr, size);
}

int tffs_read(fd_t fdi, void *addr, int size)
{
   test.numcalls++;
   return ffs_read(fdi, addr, size);
}

int tffs_seek(fd_t fdi, int offset, int whence)
{
  test.numcalls++;
  return ffs_seek(fdi, offset, whence);
}

effs_t tffs_truncate(const char *path, offset_t length) 
{
    test.numcalls++;
    return ffs_truncate(path, length); 
}

effs_t tffs_ftruncate(fd_t fdi, offset_t length) 
{
    test.numcalls++;
    return ffs_ftruncate(fdi, length); 
}

effs_t tffs_fdatasync(fd_t fdi) 
{
    test.numcalls++;
    return ffs_fdatasync(fdi); 
}

/******************************************************************************
 * Powerfail framework
 ******************************************************************************/

#if (TARGET == 0)
void tmp_fix_trace_indent(void);

struct powerfail_s powerfail;

// Set the mode, offset, mask in the global powerfail structure and reset
// the rest of the powerfail struct. Note the mode PFM_RANDOM will interpret
// the offset parameter as the average number of words to write between each
// power fail.
void powerfail_test_begin(int mode, uint16 offset, int mask)
{

⌨️ 快捷键说明

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