int main()

in scripts/raffs/raffs-test.cpp [281:400]


int main() {
    for (uint32_t i = 0; i < sizeof(randomData); ++i)
        randomData[i] = rand();

    remount();
    assert(!fs->tryMount());

    fs->exists("foobar");

    assert(fs->tryMount());

    for (int i = 0; i < 5; ++i) {
        simpleTest("data.txt", 2);
        remount();
        testAll();
        if (i == 2) {
            fs->forceGC();
            testAll();
        }
    }

    fs->debugDump();
    for (int sz = 0; sz < 64; ++sz)
        simpleTest(NULL, sz);
    simpleTest(NULL, 200);
    simpleTest(NULL, 2000);

    LOG("one");

    testFF(17, 1000);

    LOG("before gc");
    testAll();

    fs->forceGC();
    LOG("after gc");
    testAll();

    auto bufFree = fs->freeSize();
    multiTest(50, 500, SZMULT);
    fs->forceGC();
    LOG("%d/%d", bufFree, fs->freeSize());
    assert(bufFree == fs->freeSize());

    testAll();

    LOG("two");

    multiTest(2, 1000, SZMULT);
    multiTest(10, 1000, SZMULT);
    for (int i = 0; i < 20; ++i)
        multiTest(10, 300, 2 * SZMULT);
    simpleTest(NULL, 1003, 3 * SZMULT);
    testAll();

    LOG("three");

    fs->forceGC();
    auto prevFree = fs->freeSize();
    auto iters = 1000; // more for stress testing
    multiTest(3, 300 * SZMULT, iters);
    multiTest(30, 30 * SZMULT, iters);
    auto diff = prevFree - fs->freeSize();
    fs->forceGC();
    printf("free: %d kb %d\n", fs->freeSize() / 1024, diff);
    testAll();

    fs->dump();

    // re-mount
    flash.snapshotBeforeErase = true;
    remount();
    fs->dump();
    testAll();

#ifndef CODAL_RAFFS_H
    printf("recovery!\n");
    flash.useSnapshot();
#endif

    remount();
    fs->dump();
    multiTest(30, 30 * SZMULT, iters);
    testAll();

    fs->dirRewind();
    NS::DirEntry *ent;
    for (auto f : files) {
        f->visited = false;
    }
    while ((ent = fs->dirRead()) != NULL) {
        auto fc = lookupFile(ent->name, false);
        if (!fc)
            oops();
        if (fc->del) {
            LOG("should be deleted: %s", fc->name);
            oops();
        }
        if (fc->visited) {
            LOG("already visited: %s", fc->name);
            oops();
        }
        if (fc->data.size() != ent->size) {
            LOG("size fail: %s exp %d got %d", fc->name, (int)fc->data.size(), ent->size);
            oops();
        }
        fc->visited = true;
        LOG("%8d %s", ent->size, ent->name);
    }
    for (auto f : files) {
        if (!f->visited && !f->del)
            oops();
    }

    printf("%dk written in %d writes. %d erases; %d s.\n", flash.bytesWritten / 1024,
           flash.numWrites, flash.numErases, (int)(flash.ticks * 7 / 10000000));
    printf("OK\n");

    return 0;
}