[KMTESTS]
authorPierre Schweitzer <pierre@reactos.org>
Fri, 25 Mar 2016 18:53:43 +0000 (18:53 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Fri, 25 Mar 2016 18:53:43 +0000 (18:53 +0000)
- 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

rostests/kmtests/CMakeLists.txt
rostests/kmtests/include/kmt_test.h
rostests/kmtests/kmtest_drv/testlist.c
rostests/kmtests/novp_fsrtl/FsRtlRemoveDotsFromPath.c [new file with mode: 0644]

index 4b25040..0c2c5e3 100644 (file)
@@ -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)
index f63fb25..5560891 100644 (file)
@@ -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
index 485bf56..e8886af 100644 (file)
@@ -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 (file)
index 0000000..263e076
--- /dev/null
@@ -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 <pierre@reactos.org>
+ */
+
+#include <kmt_test.h>
+
+#define NDEBUG
+#include <debug.h>
+
+#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");
+}
+