From: Pierre Schweitzer Date: Fri, 25 Mar 2016 18:53:43 +0000 (+0000) Subject: [KMTESTS] X-Git-Tag: ReactOS-0.4.1~178 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=ef0b98d6fb3ec7f58b37dc1b11a72c2a7432c5f2;ds=sidebyside [KMTESTS] - Define a new macro function KmtGetSystemOrEmbeddedRoutineAddress() which is to be used to get a function address from Mm if it exists system-wide or to fallback to embedded function if it doesn't exist - Use this mechanism to add tests for the newly implemented FsRtlRemoveDotsFromPath() which is Vista+. That allows, with a single build (and thus, same binaries), testing a function in ReactOS and in Windows. svn path=/trunk/; revision=71046 --- diff --git a/rostests/kmtests/CMakeLists.txt b/rostests/kmtests/CMakeLists.txt index 4b250400928..0c2c5e3ffba 100644 --- a/rostests/kmtests/CMakeLists.txt +++ b/rostests/kmtests/CMakeLists.txt @@ -36,6 +36,7 @@ list(APPEND KMTEST_DRV_SOURCE npfs/NpfsHelpers.c npfs/NpfsReadWrite.c npfs/NpfsVolumeInfo.c + novp_fsrtl/FsRtlRemoveDotsFromPath.c ntos_cm/CmSecurity.c ntos_ex/ExCallback.c ntos_ex/ExDoubleList.c @@ -90,7 +91,7 @@ list(APPEND KMTEST_DRV_SOURCE add_library(kmtest_drv SHARED ${KMTEST_DRV_SOURCE}) set_module_type(kmtest_drv kernelmodedriver) -target_link_libraries(kmtest_drv kmtest_printf chkstk memcmp ${PSEH_LIB}) +target_link_libraries(kmtest_drv kmtest_printf chkstk memcmp ntoskrnl_vista ${PSEH_LIB}) add_importlibs(kmtest_drv ntoskrnl hal) add_dependencies(kmtest_drv bugcodes xdk) add_target_compile_definitions(kmtest_drv KMT_KERNEL_MODE NTDDI_VERSION=NTDDI_WS03SP1) diff --git a/rostests/kmtests/include/kmt_test.h b/rostests/kmtests/include/kmt_test.h index f63fb252b22..5560891ad9f 100644 --- a/rostests/kmtests/include/kmt_test.h +++ b/rostests/kmtests/include/kmt_test.h @@ -244,6 +244,16 @@ VOID KmtFreeGuarded(PVOID Pointer); ok_eq_hex(ExceptionStatus, (ExpectedStatus)); \ } +#define KmtGetSystemOrEmbeddedRoutineAddress(RoutineName) \ + p##RoutineName = KmtGetSystemRoutineAddress(L ## #RoutineName); \ + if (!p##RoutineName) \ + { \ + p##RoutineName = RoutineName; \ + trace("Using embedded routine for " #RoutineName "\n"); \ + } \ + else \ + trace("Using system routine for " #RoutineName "\n"); + #if defined KMT_DEFINE_TEST_FUNCTIONS #if defined KMT_KERNEL_MODE diff --git a/rostests/kmtests/kmtest_drv/testlist.c b/rostests/kmtests/kmtest_drv/testlist.c index 485bf562128..e8886af0b8a 100644 --- a/rostests/kmtests/kmtest_drv/testlist.c +++ b/rostests/kmtests/kmtest_drv/testlist.c @@ -24,6 +24,7 @@ KMT_TESTFUNC Test_FsRtlDissect; KMT_TESTFUNC Test_FsRtlExpression; KMT_TESTFUNC Test_FsRtlLegal; KMT_TESTFUNC Test_FsRtlMcb; +KMT_TESTFUNC Test_FsRtlRemoveDotsFromPath; KMT_TESTFUNC Test_FsRtlTunnel; KMT_TESTFUNC Test_IoCreateFile; KMT_TESTFUNC Test_IoDeviceInterface; @@ -91,6 +92,7 @@ const KMT_TEST TestList[] = { "FsRtlExpression", Test_FsRtlExpression }, { "FsRtlLegal", Test_FsRtlLegal }, { "FsRtlMcb", Test_FsRtlMcb }, + { "FsRtlRemoveDotsFromPath", Test_FsRtlRemoveDotsFromPath }, { "FsRtlTunnel", Test_FsRtlTunnel }, { "IoCreateFile", Test_IoCreateFile }, { "IoDeviceInterface", Test_IoDeviceInterface }, diff --git a/rostests/kmtests/novp_fsrtl/FsRtlRemoveDotsFromPath.c b/rostests/kmtests/novp_fsrtl/FsRtlRemoveDotsFromPath.c new file mode 100644 index 00000000000..263e07655f0 --- /dev/null +++ b/rostests/kmtests/novp_fsrtl/FsRtlRemoveDotsFromPath.c @@ -0,0 +1,59 @@ +/* + * PROJECT: ReactOS kernel-mode tests + * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory + * PURPOSE: Tests for FsRtlRemoveDotsFromPath + * PROGRAMMER: Pierre Schweitzer + */ + +#include + +#define NDEBUG +#include + +#define InitConstString(s, c) \ + wcscpy(s.Buffer, c); \ + s.Buffer[sizeof(c) / sizeof(WCHAR) - 1] = 0; \ + s.Length = sizeof(c) - sizeof(UNICODE_NULL) + +NTSTATUS NTAPI FsRtlRemoveDotsFromPath(PWSTR OriginalString, + USHORT PathLength, USHORT *NewLength); + +static +NTSTATUS +(NTAPI *pFsRtlRemoveDotsFromPath)(PWSTR OriginalString, + USHORT PathLength, USHORT *NewLength); + +START_TEST(FsRtlRemoveDotsFromPath) +{ + WCHAR Buf[255]; + UNICODE_STRING TestString; + NTSTATUS Status; + + TestString.Buffer = Buf; + TestString.MaximumLength = sizeof(Buf); + KmtGetSystemOrEmbeddedRoutineAddress(FsRtlRemoveDotsFromPath); + ASSERT(pFsRtlRemoveDotsFromPath); + + InitConstString(TestString, L"\\.."); + Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length); + ok_eq_hex(Status, STATUS_IO_REPARSE_DATA_INVALID); + + InitConstString(TestString, L".."); + Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length); + ok_eq_hex(Status, STATUS_IO_REPARSE_DATA_INVALID); + + InitConstString(TestString, L"..\\anyOtherContent"); + Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length); + ok_eq_hex(Status, STATUS_IO_REPARSE_DATA_INVALID); + + InitConstString(TestString, L"\\\\.."); + Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length); + ok_eq_hex(Status, STATUS_SUCCESS); + ok_eq_wstr(TestString.Buffer, L"\\"); + + InitConstString(TestString, L"\\dir1\\dir2\\..\\dir3\\.\\file.txt"); + Status = pFsRtlRemoveDotsFromPath(TestString.Buffer, TestString.Length, &TestString.Length); + ok_eq_hex(Status, STATUS_SUCCESS); + ok_eq_wstr(TestString.Buffer, L"\\dir1\\dir3\\file.txt"); +} +