コード例 #1
0
ファイル: tomfs_test.c プロジェクト: tomyedwab/tom-os
int test_allocate_blocks() {
    int i;
    TestMemPtr mem_ptr;
    TFS tfs;

    mem_ptr.base_addr = malloc(2560 * TFS_BLOCK_SIZE);
    mem_ptr.num_blocks = 2560;
    mem_ptr.overrun = 0;
    
    tfs.read_fn = &mem_read_fn;
    tfs.write_fn = &mem_write_fn;
    tfs.user_data = &mem_ptr;
    tfsInit(&tfs, NULL, 0);
    
    // There is no valid filesystem yet
    ASSERT_EQUALS(tfsOpenFilesystem(&tfs), -1);

    // Create a filesystem
    ASSERT_EQUALS(tfsInitFilesystem(&tfs, 2560), 0);
    ASSERT_EQUALS(mem_ptr.overrun, 0);

    // Keep allocating random blocks until the whole FS is full
    // (The first block is already allocated by the root directory)
    for (i = 0; i < tfs.header.data_blocks - 1; i++) {
        ASSERT_NOTEQUALS(tfsAllocateBlock(&tfs, 0, 1, 0, 0), 0);
        ASSERT_EQUALS(mem_ptr.overrun, 0);
    }
    // Now all the blocks are full, we cannot allocate any more blocks
    ASSERT_EQUALS(tfsAllocateBlock(&tfs, 0, 1, 0, 0), 0);
    ASSERT_EQUALS(mem_ptr.overrun, 0);

    return 0;
}
コード例 #2
0
ファイル: tomfs_test.c プロジェクト: tomyedwab/tom-os
int test_write_files() {
    int i;
    TestMemPtr mem_ptr;
    TFS tfs;
    FileHandle *handle;
    char buf[TFS_BLOCK_DATA_SIZE*5];

    mem_ptr.base_addr = malloc(2560 * TFS_BLOCK_SIZE);
    mem_ptr.num_blocks = 2560;
    mem_ptr.overrun = 0;
    
    tfs.read_fn = &mem_read_fn;
    tfs.write_fn = &mem_write_fn;
    tfs.user_data = &mem_ptr;
    tfsInit(&tfs, NULL, 0);
    
    // There is no valid filesystem yet
    ASSERT_EQUALS(tfsOpenFilesystem(&tfs), -1);

    // Create a filesystem
    ASSERT_EQUALS(tfsInitFilesystem(&tfs, 2560), 0);
    ASSERT_EQUALS(mem_ptr.overrun, 0);

    // Write less than one block worth of data into a file
    ASSERT_NOTEQUALS(handle = tfsCreateFile(&tfs, "", 0644, "test_single_block"), 0);
    ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, 64, 0));

    // Write more than one block worth of data into a file, less than a
    // block at a time
    ASSERT_NOTEQUALS(handle = tfsCreateFile(&tfs, "", 0644, "test_small_writes"), 0);
    for (i = 0; i < 5; i++) {
        ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, TFS_BLOCK_DATA_SIZE - 100, i * (TFS_BLOCK_DATA_SIZE - 100)));
    }

    // Write more than one block worth of data into a file, exactly a
    // block at a time
    ASSERT_NOTEQUALS(handle = tfsCreateFile(&tfs, "", 0644, "test_med_writes"), 0);
    for (i = 0; i < 5; i++) {
        ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, TFS_BLOCK_DATA_SIZE, i * TFS_BLOCK_DATA_SIZE));
    }

    // Write more than one block worth of data into a file, more than a
    // block at a time
    ASSERT_NOTEQUALS(handle = tfsCreateFile(&tfs, "", 0644, "test_large_writes"), 0);
    for (i = 0; i < 5; i++) {
        ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, TFS_BLOCK_DATA_SIZE + 100, i * (TFS_BLOCK_DATA_SIZE + 100)));
    }

    // Write 5 blocks worth' of data at one time
    ASSERT_NOTEQUALS(handle = tfsCreateFile(&tfs, "", 0644, "test_huge_writes"), 0);
    ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, TFS_BLOCK_DATA_SIZE * 5, 0));

    // Append to an existing file
    ASSERT_NOTEQUALS(handle = tfsOpenFile(&tfs, "", "test_single_block"), 0);
    ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, 64, 64));

    return 0;
}
コード例 #3
0
ファイル: tomfs_test.c プロジェクト: tomyedwab/tom-os
int test_read_files() {
    int i, num;
    TestMemPtr mem_ptr;
    TFS tfs;
    FileHandle *handle;
    char buf[TFS_BLOCK_DATA_SIZE*5];

    mem_ptr.base_addr = malloc(2560 * TFS_BLOCK_SIZE);
    mem_ptr.num_blocks = 2560;
    mem_ptr.overrun = 0;
    
    tfs.read_fn = &mem_read_fn;
    tfs.write_fn = &mem_write_fn;
    tfs.user_data = &mem_ptr;
    tfsInit(&tfs, NULL, 0);
    
    // There is no valid filesystem yet
    ASSERT_EQUALS(tfsOpenFilesystem(&tfs), -1);

    // Create a filesystem
    ASSERT_EQUALS(tfsInitFilesystem(&tfs, 2560), 0);
    ASSERT_EQUALS(mem_ptr.overrun, 0);
    
    for (i = 0; i < TFS_BLOCK_DATA_SIZE * 5 / 4; i++) {
        ((unsigned int *)buf)[i] = 0xffff - i;
    }

    // Write 5 blocks worth' of data at one time
    ASSERT_NOTEQUALS(handle = tfsCreateFile(&tfs, "", 0644, "test_huge_writes"), 0);
    ASSERT_NOERROR(tfsWriteFile(&tfs, handle, buf, TFS_BLOCK_DATA_SIZE * 5, 0));

    // Read the ints back individually and verify they are correct
    for (i = 0; i < TFS_BLOCK_DATA_SIZE * 5 / 4; i++) {
        ASSERT_EQUALS(tfsReadFile(&tfs, handle, &num, 4, i*4), 4);
        ASSERT_EQUALS(num, 0xffff - i);
    }

    // Read the entire buffer back
    ASSERT_EQUALS(tfsReadFile(&tfs, handle, buf, TFS_BLOCK_DATA_SIZE * 5, 0), TFS_BLOCK_DATA_SIZE * 5);
    for (i = 0; i < TFS_BLOCK_DATA_SIZE * 5 / 4; i++) {
        ASSERT_EQUALS(((unsigned int *)buf)[i], 0xffff - i);
    }

    return 0;
}
コード例 #4
0
ファイル: pages.c プロジェクト: dmatlack/moridin
/**
 * @brief Allocate n continuous pages.
 *
 * @return
 *    NULL if n contiguous pages could not be found
 *    0 otherwise
 */
struct page *alloc_pages(unsigned long n)
{
	TRACE("n=%d", n);
	ASSERT_NOTEQUALS(n, 0);
	return __alloc_pages(n, zones);
}
コード例 #5
0
ファイル: tomfs_test.c プロジェクト: tomyedwab/tom-os
int test_directories() {
    TestMemPtr mem_ptr;
    TFS tfs;
    FileHandle *dir, *file;
    int idx = 0;
    int count;
    int mode;
    int block_idx;
    int size;
    char filename[256];

    mem_ptr.base_addr = malloc(2560 * TFS_BLOCK_SIZE);
    mem_ptr.num_blocks = 2560;
    mem_ptr.overrun = 0;
    
    tfs.read_fn = &mem_read_fn;
    tfs.write_fn = &mem_write_fn;
    tfs.user_data = &mem_ptr;
    tfsInit(&tfs, NULL, 0);
    
    // Create a filesystem
    ASSERT_EQUALS(tfsInitFilesystem(&tfs, 2560), 0);
    ASSERT_EQUALS(mem_ptr.overrun, 0);

    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);

    // List files in the root directory
    ASSERT_NOTEQUALS(dir = tfsOpenPath(&tfs, "/"), NULL);
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 2);

    // Can also look up files by name
    ASSERT_EQUALS(tfsFindEntry(&tfs, dir, ".", &mode, &block_idx, &size), 0);
    ASSERT_EQUALS(tfsFindEntry(&tfs, dir, "..", &mode, &block_idx, &size), 0);

    tfsCloseHandle(dir);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);
    
    // Create a file in the root directory
    ASSERT_NOTEQUALS((file = tfsCreateFile(&tfs, "/", 0644, "root_1")), 0);

    ASSERT_NOTEQUALS(dir = tfsOpenPath(&tfs, "/"), NULL);
    idx = 0;
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0 || strcmp(filename, "root_1") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 3);

    tfsCloseHandle(dir);
    tfsCloseHandle(file);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);

    // Create a new subdirectory
    ASSERT_NOTEQUALS(dir = tfsCreateDirectory(&tfs, "/", "testdir"), NULL);
    idx = 0;
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 2);

    tfsCloseHandle(dir);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);

    ASSERT_NOTEQUALS(dir = tfsOpenPath(&tfs, "/"), NULL);
    idx = 0;
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0 || strcmp(filename, "root_1") == 0 || strcmp(filename, "testdir") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 4);

    // Can also look up subdirectories by name
    ASSERT_EQUALS(tfsFindEntry(&tfs, dir, "testdir", &mode, &block_idx, &size), 0);

    tfsCloseHandle(dir);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);

    // Create some files in the subdirectory
    ASSERT_NOTEQUALS(file = tfsCreateFile(&tfs, "/testdir", 0644, "child_1"), 0);
    tfsCloseHandle(file);
    ASSERT_NOTEQUALS(file = tfsCreateFile(&tfs, "/testdir", 0644, "child_2"), 0);
    tfsCloseHandle(file);

    ASSERT_NOTEQUALS(dir = tfsOpenPath(&tfs, "/testdir"), NULL);
    idx = 0;
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0 || strcmp(filename, "child_1") == 0 || strcmp(filename, "child_2") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 4);

    tfsCloseHandle(dir);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);

    // One more layer of nesting, because reasons
    ASSERT_NOTEQUALS(dir = tfsCreateDirectory(&tfs, "/testdir", "onemore"), NULL);

    idx = 0;
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 2);

    tfsCloseHandle(dir);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);

    // Create some files in the subdirectory
    ASSERT_NOTEQUALS(file = tfsCreateFile(&tfs, "/testdir/onemore", 0644, "grand_child_1"), 0);
    tfsCloseHandle(file);
    ASSERT_NOTEQUALS(file = tfsCreateFile(&tfs, "/testdir/onemore", 0644, "child_with_a_name_longer_than_ten_characters_because_why_not"), 0);
    tfsCloseHandle(file);

    ASSERT_NOTEQUALS(dir = tfsOpenPath(&tfs, "/testdir/onemore"), NULL);
    idx = 0;
    count = 0;
    while (tfsReadNextEntry(&tfs, dir, &idx, &mode, &block_idx, &size, filename, 256) == 0) {
        ASSERT(strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0 || strcmp(filename, "grand_child_1") == 0 || strcmp(filename, "child_with_a_name_longer_than_ten_characters_because_why_not") == 0);
        count++;
    }
    ASSERT_EQUALS(count, 4);

    tfsCloseHandle(dir);
    ASSERT_EQUALS(tfsGetOpenHandleCount(), 0);
    
    return 0;
}
コード例 #6
0
ファイル: TestTwine009Compare.cpp プロジェクト: ronburr/SLib
void TestTwine009Compare_ToCharStar()
{
	BEGIN_TEST_METHOD( "TestTwine009Compare_ToCharStar" )

	twine empty1;
	const char* empty2 = NULL;
	twine short1 = "Something Short";
	const char* short2 = "Something Short";
	twine long1 = "Something A Bit Longer that Will cause us to allocate memory";
	const char* long2 = "Something A Bit Longer that Will cause us to allocate memory";

	// Ensure that everything has different data pointers:
	ASSERT_NOTEQUALS( empty1(), empty2, "empty1 and empty2 point to the same memory");
	ASSERT_NOTEQUALS( short1(), short2, "short1 and short2 point to the same memory");
	ASSERT_NOTEQUALS( long1(), long2, "long1 and long2 point to the same memory");

	ASSERT_EQUALS( 0, empty1.compare( empty2 ), "empty1.compare( empty2 ) != 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( short1 ), "empty1.compare( short1 ) == 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( short2 ), "empty1.compare( short2 ) == 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( long1 ), "empty1.compare( long1) == 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( long2 ), "empty1.compare( long2) == 0");

	ASSERT_EQUALS( 0, short1.compare( short2 ), "short1.compare( short2 ) != 0");
	ASSERT_NOTEQUALS( 0, short1.compare( empty1 ), "short1.compare( empty1 ) == 0");
	ASSERT_NOTEQUALS( 0, short1.compare( empty2), "short1.compare( empty2) == 0");
	ASSERT_NOTEQUALS( 0, short1.compare( long1 ), "short1.compare( long1) == 0");
	ASSERT_NOTEQUALS( 0, short1.compare( long2 ), "short1.compare( long2) == 0");
	
	ASSERT_EQUALS( 0, long1.compare( long2 ), "long1.compare( long2 ) != 0");
	ASSERT_NOTEQUALS( 0, long1.compare( empty1 ), "long1.compare( empty1 ) == 0");
	ASSERT_NOTEQUALS( 0, long1.compare( empty2), "long1.compare( empty2) == 0");
	ASSERT_NOTEQUALS( 0, long1.compare( short1 ), "long1.compare( short1) == 0");
	ASSERT_NOTEQUALS( 0, long1.compare( short2 ), "long1.compare( short2) == 0");

	END_TEST_METHOD
}
コード例 #7
0
ファイル: TestTwine009Compare.cpp プロジェクト: ronburr/SLib
void TestTwine009Compare_ToTwineCount()
{
	BEGIN_TEST_METHOD( "TestTwine009Compare_ToTwineCount" )
	
	twine empty1;
	twine empty2;
	twine short1 = "Something Short";
	twine short2 = "Something Short";
	twine long1 = "Something A Bit Longer that Will cause us to allocate memory";
	twine long2 = "Something A Bit Longer that Will cause us to allocate memory";

	// Ensure that everything has different data pointers:
	ASSERT_NOTEQUALS( empty1(), empty2(), "empty1 and empty2 point to the same memory");
	ASSERT_NOTEQUALS( short1(), short2(), "short1 and short2 point to the same memory");
	ASSERT_NOTEQUALS( long1(), long2(), "long1 and long2 point to the same memory");

	ASSERT_EQUALS( 0, empty1.compare( empty2, 10 ), "empty1.compare( empty2, 10 ) != 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( short1, 10 ), "empty1.compare( short1, 10 ) == 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( short2, 10 ), "empty1.compare( short2, 10 ) == 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( long1, 10 ), "empty1.compare( long1, 10) == 0");
	ASSERT_NOTEQUALS( 0, empty1.compare( long2, 10 ), "empty1.compare( long2, 10) == 0");

	ASSERT_EQUALS( 0, short1.compare( short2, 10 ), "short1.compare( short2, 10 ) != 0");
	ASSERT_NOTEQUALS( 0, short1.compare( empty1, 10 ), "short1.compare( empty1, 10 ) == 0");
	ASSERT_NOTEQUALS( 0, short1.compare( empty2, 10), "short1.compare( empty2, 10) == 0");
	ASSERT_EQUALS( 0, short1.compare( long1, 10 ), "short1.compare( long1, 10) != 0");
	ASSERT_EQUALS( 0, short1.compare( long2, 10 ), "short1.compare( long2, 10) != 0");
	
	ASSERT_EQUALS( 0, long1.compare( long2, 10 ), "long1.compare( long2, 10 ) != 0");
	ASSERT_NOTEQUALS( 0, long1.compare( empty1, 10 ), "long1.compare( empty1, 10 ) == 0");
	ASSERT_NOTEQUALS( 0, long1.compare( empty2, 10), "long1.compare( empty2, 10) == 0");
	ASSERT_EQUALS( 0, long1.compare( short1, 10 ), "long1.compare( short1, 10) != 0");
	ASSERT_EQUALS( 0, long1.compare( short2, 10 ), "long1.compare( short2, 10) != 0");

	END_TEST_METHOD
}