Zebediah Figura : ntoskrnl/tests: Factor out winetest_init() and winetest_cleanup().

Alexandre Julliard julliard at winehq.org
Wed Apr 7 15:48:29 CDT 2021


Module: wine
Branch: master
Commit: 801d116733a2b36b814900321b592a804afc9e8f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=801d116733a2b36b814900321b592a804afc9e8f

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Tue Apr  6 22:42:20 2021 -0500

ntoskrnl/tests: Factor out winetest_init() and winetest_cleanup().

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntoskrnl.exe/tests/driver.c       | 23 +++++------------------
 dlls/ntoskrnl.exe/tests/driver_netio.c | 22 +++++-----------------
 dlls/ntoskrnl.exe/tests/utils.h        | 25 +++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c
index 179d2d5e02d..1d78f576ecf 100644
--- a/dlls/ntoskrnl.exe/tests/driver.c
+++ b/dlls/ntoskrnl.exe/tests/driver.c
@@ -1782,15 +1782,7 @@ static void WINAPI main_test_task(DEVICE_OBJECT *device, void *context)
     test_stack_limits();
     test_completion();
 
-    /* print process report */
-    if (winetest_debug)
-    {
-        kprintf("%04x:ntoskrnl: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
-            PsGetCurrentProcessId(), successes + failures + todo_successes + todo_failures,
-            todo_successes, failures + todo_failures,
-            (failures + todo_failures != 1) ? "failures" : "failure", skipped );
-    }
-    ZwClose(okfile);
+    winetest_cleanup();
 
     *((LONG *)buffer) = failures;
     irp->IoStatus.Status = STATUS_SUCCESS;
@@ -2116,24 +2108,19 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
     ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
     void *buffer = irp->AssociatedIrp.SystemBuffer;
     struct test_input *test_input = (struct test_input *)buffer;
-    OBJECT_ATTRIBUTES attr = {0};
-    UNICODE_STRING pathU;
-    IO_STATUS_BLOCK io;
+    NTSTATUS status;
 
     if (!buffer)
         return STATUS_ACCESS_VIOLATION;
     if (length < sizeof(failures))
         return STATUS_BUFFER_TOO_SMALL;
 
-    attr.Length = sizeof(attr);
-    RtlInitUnicodeString(&pathU, L"\\??\\C:\\windows\\winetest_ntoskrnl_okfile");
     running_under_wine = test_input->running_under_wine;
     winetest_debug = test_input->winetest_debug;
     winetest_report_success = test_input->winetest_report_success;
-    attr.ObjectName = &pathU;
-    attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE; /* needed to be accessible from system threads */
-    ZwOpenFile(&okfile, FILE_APPEND_DATA | SYNCHRONIZE, &attr, &io,
-            FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT);
+
+    if ((status = winetest_init()))
+        return status;
 
     pExEventObjectType = get_proc_address("ExEventObjectType");
     ok(!!pExEventObjectType, "ExEventObjectType not found\n");
diff --git a/dlls/ntoskrnl.exe/tests/driver_netio.c b/dlls/ntoskrnl.exe/tests/driver_netio.c
index 3d783dbef0d..98392c9c7fd 100644
--- a/dlls/ntoskrnl.exe/tests/driver_netio.c
+++ b/dlls/ntoskrnl.exe/tests/driver_netio.c
@@ -468,38 +468,26 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
     ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
     void *buffer = irp->AssociatedIrp.SystemBuffer;
     struct test_input *test_input = buffer;
-    OBJECT_ATTRIBUTES attr = {0};
-    UNICODE_STRING pathU;
-    IO_STATUS_BLOCK io;
+    NTSTATUS status;
 
     if (!buffer)
         return STATUS_ACCESS_VIOLATION;
     if (length < sizeof(failures))
         return STATUS_BUFFER_TOO_SMALL;
 
-    attr.Length = sizeof(attr);
-    RtlInitUnicodeString(&pathU, L"\\??\\C:\\winetest_ntoskrnl_okfile");
     running_under_wine = test_input->running_under_wine;
     winetest_debug = test_input->winetest_debug;
     winetest_report_success = test_input->winetest_report_success;
-    attr.ObjectName = &pathU;
-    attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE; /* needed to be accessible from system threads */
-    ZwOpenFile(&okfile, FILE_APPEND_DATA | SYNCHRONIZE, &attr, &io,
-            FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT);
+
+    if ((status = winetest_init()))
+        return status;
 
     netio_init();
     test_wsk_get_address_info();
     test_wsk_listen_socket();
     test_wsk_connect_socket();
 
-    if (winetest_debug)
-    {
-        kprintf("%04x:ntoskrnl: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
-            PsGetCurrentProcessId(), successes + failures + todo_successes + todo_failures,
-            todo_successes, failures + todo_failures,
-            (failures + todo_failures != 1) ? "failures" : "failure", skipped );
-    }
-    ZwClose(okfile);
+    winetest_cleanup();
 
     *((LONG *)buffer) = failures;
     irp->IoStatus.Information = sizeof(failures);
diff --git a/dlls/ntoskrnl.exe/tests/utils.h b/dlls/ntoskrnl.exe/tests/utils.h
index be0f58f837c..508346ef9bf 100644
--- a/dlls/ntoskrnl.exe/tests/utils.h
+++ b/dlls/ntoskrnl.exe/tests/utils.h
@@ -49,6 +49,31 @@ static inline void WINAPIV kprintf(const char *format, ...)
     __ms_va_end(valist);
 }
 
+static inline NTSTATUS winetest_init(void)
+{
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING string;
+    IO_STATUS_BLOCK io;
+
+    RtlInitUnicodeString(&string, L"\\??\\C:\\windows\\winetest_ntoskrnl_okfile");
+    /* OBJ_KERNEL_HANDLE is necessary for the file to be accessible from system threads */
+    InitializeObjectAttributes(&attr, &string, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 0, NULL);
+    return ZwOpenFile(&okfile, FILE_APPEND_DATA | SYNCHRONIZE, &attr, &io,
+            FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT);
+}
+
+static inline void winetest_cleanup(void)
+{
+    if (winetest_debug)
+    {
+        kprintf("%04x:ntoskrnl: %d tests executed (%d marked as todo, %d %s), %d skipped.\n",
+                PsGetCurrentProcessId(), successes + failures + todo_successes + todo_failures,
+                todo_successes, failures + todo_failures,
+                (failures + todo_failures != 1) ? "failures" : "failure", skipped );
+    }
+    ZwClose(okfile);
+}
+
 static inline void WINAPIV vok_(const char *file, int line, int condition, const char *msg,  __ms_va_list args)
 {
     const char *current_file;




More information about the wine-cvs mailing list