static long TestFileSystem(Handle<es::Context> root)
{
    Handle<es::File>       file;

    const char* filename = "test.txt";

    file = root->bind(filename, 0);
    Handle<es::Stream> fileStream = file->getStream();

    long long sizeWritten = 6 * 1024LL;
    long ret = TestReadWrite(fileStream, sizeWritten);
    TEST(ret == sizeWritten);

    Handle<es::File>    dir;
    dir = root->createSubcontext("testDir");

    try
    {
        Handle<es::Stream> dirStream = dir->getStream();
        TEST(!dirStream);
    }
    catch (SystemException<EPERM>& e)
    {

    }
    return 0;
}
예제 #2
0
STATUS DdmTestChaosFile::StartTest(void *context) 
{
	ChaosFile cf0(tcf_names[0]);

	if (cf0.IsValid())
	{
		printf("Persistence check OK!\n");
		return OK;
	}	
	TestCreation();
	TestClose();
	TestOpen();
		
	for (int i=0; i < 30; ++i)
	{
		if (i != 4)
		{
			printf("Closing #%d...", i);
			if (OK == cf[i]->Close())
				printf("Sucess!\n");
			else
				printf("Failed!\n");
		}
	}

	TestReadWrite();
		
	return OK;
}
예제 #3
0
/**
* Test runner
*/
int main (int argc, char *argv[])
{
    // test data path
    if (argc < 2)
    {
        std::cerr << "Usage: " << argv[0] << " test_data_path" << std::endl;
        return EXIT_FAILURE;
    }
    const std::string testDataPath = argv[1];

    // run tests
    if( !TestReadWrite(testDataPath) ) return EXIT_FAILURE;

    std::cout << "All tests passed!" << std::endl;
    return EXIT_SUCCESS;
}
예제 #4
0
void TestListAdd(void) {
	LFK_List list = LFK_NewList(3);
	LFK_ForeignKey a = {.id = 1, .llup = 0};
	LFK_ForeignKey b = {.id = 2, .llup = 1};
	LFK_ForeignKey c = {.id = 3, .llup = 2};
	LFK_AddToList(&list, a);
	LFK_AddToList(&list, b);
	LFK_AddToList(&list, c);
	assert(list.len == 3);
	LFK_FreeList(&list);
}

void TestListInsertAndRemove(void) {
	LFK_List list = LFK_NewList(3);
	LFK_ForeignKey a = {.id = 1, .llup = 0};
	LFK_ForeignKey b = {.id = 2, .llup = 1};
	LFK_ForeignKey c = {.id = 3, .llup = 2};
	LFK_InsertInList(&list, 0, a);
	LFK_InsertInList(&list, 0, b);
	LFK_InsertInList(&list, 0, c);
	assert(list.len == 3);
	LFK_RemoveFromListByIndex(&list, 0);
	LFK_RemoveFromListByIndex(&list, 0);
	LFK_RemoveFromListByIndex(&list, 0);
	assert(list.len == 0);	
	LFK_FreeList(&list);
}

int main(int argc, char *argv[]) {
	int i;

	for (i = 0; i < 1; i++) TestDefragmentation();
	for (i = 0; i < 1; i++) TestReadWrite();
	for (i = 0; i < 1; i++) TestExpandTable();
	for (i = 0; i < 1; i++) TestCustomReadWrite();
	for (i = 0; i < 1; i++) TestListAdd();
	for (i = 0; i < 1; i++) TestListInsertAndRemove();
	
	return 0;
}
static long TestFileSystem(Handle<es::Context> root)
{
    long long creationTime;
    long long lastAccessTime;
    long long lastWriteTime;

    Handle<es::File>       file;

    const char* filename = "test.txt";

    // create file.
    DateTime d = DateTime::getNow();
    file = root->bind(filename, 0);
    DateTime end = DateTime::getNow();

    DateTime start = DateTime(d.getYear(), d.getMonth(), d.getDay(),
        d.getHour(), d.getMinute(), d.getSecond(), d.getMillisecond() - d.getMillisecond() % 10);

#ifdef VERBOSE
    DateTime dc(creationTime);
    esReport("creation %d/%d/%d %d:%d:%d.%d\n", dc.getYear(), dc.getMonth(),
                 dc.getDay(), dc.getHour(), dc.getMinute(),
                     dc.getSecond(), dc.getMillisecond());

    esReport("start    %d/%d/%d %d:%d:%d.%d\n", start.getYear(), start.getMonth(),
                 start.getDay(), start.getHour(), start.getMinute(),
                     start.getSecond(), start.getMillisecond());

    esReport("end      %d/%d/%d %d:%d:%d.%d\n", end.getYear(), end.getMonth(),
                 end.getDay(), end.getHour(), end.getMinute(),
                     end.getSecond(), end.getMillisecond());

#endif // VERBOSE

    // check creation time.
    creationTime = file->getCreationTime();

    TEST(start.getTicks() <= creationTime &&
         creationTime <= end.getTicks());

    // read and write data to the file.
    Handle<es::Stream> stream = file->getStream();

    d = DateTime::getNow();
    TestReadWrite(stream);
    end = DateTime::getNow();

    // check the last access time and the last write time.
    DateTime day = DateTime(d.getYear(), d.getMonth(), d.getDay(), 0, 0, 0);
    start = DateTime(d.getYear(), d.getMonth(), d.getDay(), d.getHour(), d.getMinute(),
        d.getSecond() - d.getSecond() % 2);

    lastAccessTime = file->getLastAccessTime();
    lastWriteTime = file->getLastWriteTime();

    TEST(day.getTicks() <= lastAccessTime &&
         lastAccessTime <= end.getTicks());
    TEST(start.getTicks() <= lastWriteTime &&
         lastWriteTime <= end.getTicks());

#ifdef VERBOSE
    DateTime da(lastAccessTime);
    esReport("last access time %d/%d/%d %d:%d:%d.%d\n", da.getYear(), da.getMonth(),
                 da.getDay(), da.getHour(), da.getMinute(),
                     da.getSecond(), da.getMillisecond());
    DateTime dw(lastWriteTime);
    esReport("start            %d/%d/%d %d:%d:%d.%d\n", start.getYear(), start.getMonth(),
                 start.getDay(), start.getHour(), start.getMinute(),
                     start.getSecond(), start.getMillisecond());
    esReport("lastWriteTime    %d/%d/%d %d:%d:%d.%d\n", dw.getYear(), dw.getMonth(),
                 dw.getDay(), dw.getHour(), dw.getMinute(), dw.getSecond(), dw.getMillisecond());
    esReport("end              %d/%d/%d %d:%d:%d.%d\n", end.getYear(), end.getMonth(),
                 end.getDay(), end.getHour(), end.getMinute(),
                     end.getSecond(), end.getMillisecond());
#endif

    // read the file, and check the last write time.
    u8 buf[512];

    d = DateTime::getNow();
    stream->read(buf, sizeof(buf));
    end = DateTime::getNow();

    start = DateTime(d.getYear(), d.getMonth(), d.getDay(),
        d.getHour(), d.getMinute(), d.getSecond());

    long long lastWriteTime2;
    lastWriteTime2 = file->getLastWriteTime();
    TEST(lastWriteTime == lastWriteTime2);

    long long creationTime2;
    creationTime2 = file->getCreationTime();
    TEST(creationTime == creationTime2);

    d = DateTime::getNow();
    DateTime now = DateTime(d.getYear(), d.getMonth(), d.getDay(),
        d.getHour(), d.getMinute(), d.getSecond(), d.getMillisecond() - d.getMillisecond() % 10);

    // check setCreationTime, setLastAccessTime and setLastWriteTime.
    file->setCreationTime(now.getTicks());
    creationTime = file->getCreationTime();
    TEST(now.getTicks() == creationTime);

    now = DateTime(d.getYear(), d.getMonth(), d.getDay(), 0, 0, 0, 0);
    file->setLastAccessTime(now.getTicks());
    lastAccessTime = file->getLastAccessTime();
    TEST(now.getTicks() == lastAccessTime);

    now = DateTime(d.getYear(), d.getMonth(), d.getDay(), d.getHour(), d.getMinute(),
        d.getSecond() - d.getSecond() % 2);
    file->setLastWriteTime(now.getTicks());
    lastWriteTime = file->getLastWriteTime();

    TEST(now.getTicks() == lastWriteTime);

    return 0;
}
예제 #6
0
NTSTATUS
SampleDrvEvtDeviceD0Entry (
    _In_ WDFDEVICE Device,
    _In_ WDF_POWER_DEVICE_STATE PreviousPowerState
    )

/*++

Routine Description:

    This routine is invoked by the framework to program the device to goto
    D0, which is the working state. The framework invokes callback every
    time the hardware needs to be (re-)initialized.  This includes after
    IRP_MN_START_DEVICE, IRP_MN_CANCEL_STOP_DEVICE, IRP_MN_CANCEL_REMOVE_DEVICE,
    and IRP_MN_SET_POWER-D0.

    N.B. This function is not marked pageable because this function is in
         the device power up path. When a function is marked pagable and the
         code section is paged out, it will generate a page fault which could
         impact the fast resume behavior because the client driver will have
         to wait until the system drivers can service this page fault.

Arguments:

    Device - Supplies a handle to the framework device object.

    PreviousPowerState - WDF_POWER_DEVICE_STATE-typed enumerator that identifies
        the device power state that the device was in before this transition
        to D0.

Return Value:

    NTSTATUS code. A failure here will indicate a fatal error and cause the
    framework to tear down the stack.

--*/

{

    BYTE Data;
    NTSTATUS Status;
    WDFIOTARGET ReadTarget;
    WDFIOTARGET WriteTarget;
    PSAMPLE_DRV_DEVICE_EXTENSION SampleDrvExtension;
    UNICODE_STRING ReadString;
    WCHAR ReadStringBuffer[100];
    UNICODE_STRING WriteString;
    WCHAR WriteStringBuffer[100];

    UNREFERENCED_PARAMETER(PreviousPowerState);

    ReadTarget = NULL;
    WriteTarget = NULL;

    SampleDrvExtension = SampleDrvGetDeviceExtension(Device);

    //
    //  For demonstration purporses, the sample device consumes two IO resources,
    //  the first of which will be used for input, and the second for output.
    //

    RtlInitEmptyUnicodeString(&ReadString,
                              ReadStringBuffer,
                              sizeof(ReadStringBuffer));

    RtlInitEmptyUnicodeString(&WriteString,
                              WriteStringBuffer,
                              sizeof(WriteStringBuffer));


    //
    //  Construct full-path string for GPIO read operation
    //

    Status = RESOURCE_HUB_CREATE_PATH_FROM_ID(&ReadString,
                                              SampleDrvExtension->ConnectionIds[0].LowPart,
                                              SampleDrvExtension->ConnectionIds[0].HighPart);

    if (!NT_SUCCESS(Status)) {
        goto Cleanup;
    }

    //
    //  Construct full-path string for GPIO write operation
    //

    Status = RESOURCE_HUB_CREATE_PATH_FROM_ID(&WriteString,
                                              SampleDrvExtension->ConnectionIds[1].LowPart,
                                              SampleDrvExtension->ConnectionIds[1].HighPart);

    if (!NT_SUCCESS(Status)) {
        goto Cleanup;
    }

    //
    // Perform the read operation
    //

    Data = 0x0;
    Status = TestReadWrite(Device, &ReadString, TRUE, &Data, sizeof(Data), &ReadTarget);
    if (!NT_SUCCESS(Status)) {
        goto Cleanup;
    }

    //
    //  Perform the write operation
    //

    Status = TestReadWrite(Device, &WriteString, FALSE, &Data, sizeof(Data), &WriteTarget);
    if (!NT_SUCCESS(Status)) {
        goto Cleanup;
    }

Cleanup:

    if (ReadTarget != NULL) {
        WdfIoTargetClose(ReadTarget);
        WdfObjectDelete(ReadTarget);
    }

    if (WriteTarget != NULL) {
        WdfIoTargetClose(WriteTarget);
        WdfObjectDelete(WriteTarget);
    }

    return Status;
}