winfsp-tests: memfs-test, create-test

This commit is contained in:
Bill Zissimopoulos 2016-01-13 16:41:43 -08:00
parent d9464ba88f
commit 08ba86980d
7 changed files with 124 additions and 0 deletions

View File

@ -176,6 +176,8 @@
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">TurnOffAllWarnings</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">TurnOffAllWarnings</WarningLevel>
</ClCompile>
<ClCompile Include="..\..\..\tst\winfsp-tests\create-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs.cpp" />
<ClCompile Include="..\..\..\tst\winfsp-tests\mount-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\path-test.c" />

View File

@ -28,6 +28,12 @@
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\tst\winfsp-tests\create-test.c">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c">
<Filter>Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">

View File

@ -0,0 +1,29 @@
#include <winfsp/winfsp.h>
#include <tlib/testsuite.h>
#include "memfs.h"
void *memfs_start(ULONG Flags);
void memfs_stop(void *data);
extern int WinFspDiskTests;
extern int WinFspNetTests;
void create_dotest(ULONG Flags)
{
void *memfs = memfs_start(Flags);
memfs_stop(memfs);
}
void create_test(void)
{
if (WinFspDiskTests)
create_dotest(MemfsDisk);
if (WinFspNetTests)
create_dotest(MemfsNet);
}
void create_tests(void)
{
TEST(create_test);
}

View File

@ -0,0 +1,79 @@
#include <winfsp/winfsp.h>
#include <tlib/testsuite.h>
#include <process.h>
#include "memfs.h"
extern int WinFspDiskTests;
extern int WinFspNetTests;
struct memfs_data
{
MEMFS *Memfs;
HANDLE Thread;
};
static unsigned __stdcall memfs_thread(void *Memfs0)
{
MEMFS *Memfs = Memfs0;
return FspFileSystemLoop(MemfsFileSystem(Memfs));
}
void *memfs_start(ULONG Flags)
{
struct memfs_data *data;
MEMFS *Memfs;
HANDLE Thread;
NTSTATUS Result;
data = malloc(sizeof *data);
ASSERT(0 != data);
Result = MemfsCreate(Flags, 1000, 65500, &Memfs);
ASSERT(NT_SUCCESS(Result));
ASSERT(0 != Memfs);
Thread = (HANDLE)_beginthreadex(0, 0, memfs_thread, Memfs, 0, 0);
ASSERT(0 != Thread);
data->Memfs = Memfs;
data->Thread = Thread;
return data;
}
void memfs_stop(void *data)
{
MEMFS *Memfs = ((struct memfs_data *)data)->Memfs;
HANDLE Thread = ((struct memfs_data *)data)->Thread;
DWORD ExitCode;
FspFileSystemSetDispatcherResult(MemfsFileSystem(Memfs), STATUS_CANCELLED);
WaitForSingleObject(Thread, INFINITE);
GetExitCodeThread(Thread, &ExitCode);
CloseHandle(Thread);
ASSERT(STATUS_CANCELLED == ExitCode);
MemfsDelete(Memfs);
}
void memfs_dotest(ULONG Flags)
{
void *memfs = memfs_start(Flags);
memfs_stop(memfs);
}
void memfs_test(void)
{
if (WinFspDiskTests)
memfs_dotest(MemfsDisk);
if (WinFspNetTests)
memfs_dotest(MemfsNet);
}
void memfs_tests(void)
{
TEST(memfs_test);
}

View File

@ -419,3 +419,8 @@ VOID MemfsDelete(MEMFS *Memfs)
free(Memfs);
}
FSP_FILE_SYSTEM *MemfsFileSystem(MEMFS *Memfs)
{
return Memfs->FileSystem;
}

View File

@ -26,6 +26,7 @@ enum
NTSTATUS MemfsCreate(ULONG Flags, ULONG MaxFileNodes, ULONG MaxFileSize,
MEMFS **PMemfs);
VOID MemfsDelete(MEMFS *Memfs);
FSP_FILE_SYSTEM *MemfsFileSystem(MEMFS *Memfs);
#ifdef __cplusplus
}

View File

@ -8,6 +8,8 @@ int main(int argc, char *argv[])
TESTSUITE(path_tests);
TESTSUITE(mount_tests);
TESTSUITE(timeout_tests);
TESTSUITE(memfs_tests);
TESTSUITE(create_tests);
tlib_run_tests(argc, argv);
return 0;