[5/6] ntoskrnl.exe/tests: Add test base

Alexander Morozov amorozov at etersoft.ru
Tue Jul 22 03:58:52 CDT 2008


Add a base for ntoskrnl.exe tests.
-------------- next part --------------
From f9492bc33d7fbe303ca6752350bafa27b2e5b2a2 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov at etersoft.ru>
Date: Mon, 21 Jul 2008 19:17:23 +0400
Subject: [PATCH] ntoskrnl.exe/tests: Add test base

---
 dlls/ntoskrnl.exe/tests/Makefile.in       |   37 +++++++
 dlls/ntoskrnl.exe/tests/driver.c          |   37 +++++++
 dlls/ntoskrnl.exe/tests/driver.sys.spec   |    1 +
 dlls/ntoskrnl.exe/tests/ntoskrnl.c        |  152 +++++++++++++++++++++++++++++
 dlls/ntoskrnl.exe/tests/ntoskrnl.rc       |   23 +++++
 dlls/ntoskrnl.exe/tests/ntoskrnl_cross.rc |   23 +++++
 dlls/ntoskrnl.exe/tests/rc.h              |   27 +++++
 7 files changed, 300 insertions(+), 0 deletions(-)
 create mode 100644 dlls/ntoskrnl.exe/tests/Makefile.in
 create mode 100644 dlls/ntoskrnl.exe/tests/driver.c
 create mode 100644 dlls/ntoskrnl.exe/tests/driver.sys.spec
 create mode 100644 dlls/ntoskrnl.exe/tests/ntoskrnl.c
 create mode 100644 dlls/ntoskrnl.exe/tests/ntoskrnl.rc
 create mode 100644 dlls/ntoskrnl.exe/tests/ntoskrnl_cross.rc
 create mode 100644 dlls/ntoskrnl.exe/tests/rc.h

diff --git a/dlls/ntoskrnl.exe/tests/Makefile.in b/dlls/ntoskrnl.exe/tests/Makefile.in
new file mode 100644
index 0000000..4802c7e
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/Makefile.in
@@ -0,0 +1,37 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = ntoskrnl.exe
+IMPORTS   = advapi32 kernel32
+
+CTESTS = \
+	ntoskrnl.c
+
+EXTRA_RC_SRCS = \
+	ntoskrnl.rc
+
+CROSS_RC_SRCS = \
+	ntoskrnl_cross.rc
+
+ at MAKE_TEST_RULES@
+
+# Rules for building driver
+
+ntoskrnl.res: winetest.sys.so
+
+ntoskrnl_cross.res: winetest.sys
+
+winetest.sys.so: driver.o driver.sys.spec
+	$(WINEGCC) -B$(TOOLSDIR)/tools/winebuild -shared -Wb,--subsystem,native -o $@ $^ $(LIBPORT) -lntoskrnl.exe
+
+winetest.sys: driver.cross.o driver.def
+	$(CROSSCC) -s -nostartfiles -nostdlib -Wl,--entry,_DriverEntry at 8,--subsystem,native,--file-alignment,0x80,--section-alignment,0x80,--image-base,0x10000 -o $@ $^ -lntoskrnl
+
+driver.def: driver.sys.spec
+	$(WINEBUILD) -w --def -o $@ --export $^
+
+clean::
+	$(RM) driver.def winetest.sys
+
+ at DEPENDENCIES@  # everything below this line is overwritten by make depend
diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c
new file mode 100644
index 0000000..278c8f7
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/driver.c
@@ -0,0 +1,37 @@
+/*
+ * Test driver
+ *
+ * Copyright 2008 Etersoft (Alexander Morozov)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "winternl.h"
+#include "ddk/ntddk.h"
+
+void WINAPI unload(DRIVER_OBJECT *driver)
+{
+}
+
+NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, UNICODE_STRING *regpath)
+{
+    driver->DriverUnload = unload;
+
+    return STATUS_SUCCESS;
+}
diff --git a/dlls/ntoskrnl.exe/tests/driver.sys.spec b/dlls/ntoskrnl.exe/tests/driver.sys.spec
new file mode 100644
index 0000000..6563f2d
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/driver.sys.spec
@@ -0,0 +1 @@
+@ stdcall DriverEntry(ptr ptr)
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
new file mode 100644
index 0000000..3da3100
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
@@ -0,0 +1,152 @@
+/*
+ * Tests for ntoskrnl.exe
+ *
+ * Copyright 2008 Etersoft (Alexander Morozov)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "windows.h"
+#include "wine/test.h"
+#include "rc.h"
+
+#define DRVNAME "winetest"
+
+#ifdef WIN32
+#define DRV_RES WIN_DRIVER_RES
+#else
+#define DRV_RES DRIVER_RES
+#endif
+
+static const CHAR drvpath[] = "system32\\drivers\\" DRVNAME ".sys";
+
+int create_driver_image(CHAR *destpath)
+{
+    HRSRC rsrc;
+    HGLOBAL drv;
+    VOID *pdrv;
+    int del_file = 0;
+
+    rsrc = FindResourceA(NULL, MAKEINTRESOURCE(DRV_RES), RT_RCDATA);
+    drv = LoadResource(NULL, rsrc);
+    pdrv = LockResource(drv);
+    if (NULL != pdrv)
+    {
+        HANDLE hfile;
+        DWORD bytes;
+        BOOL ret;
+
+        hfile = CreateFileA(destpath, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
+        ok(INVALID_HANDLE_VALUE != hfile, "CreateFileA failed: %u\n", GetLastError());
+        if (INVALID_HANDLE_VALUE != hfile)
+        {
+            del_file = 1;
+            ret = WriteFile(hfile, pdrv, SizeofResource(NULL, rsrc), &bytes, NULL);
+            ok(ret, "WriteFile failed: %u\n", GetLastError());
+            CloseHandle(hfile);
+        }
+    }
+    FreeResource(drv);
+
+    return del_file;
+}
+
+void create_service(SC_HANDLE scm)
+{
+    SC_HANDLE service;
+
+    service = CreateServiceA(scm, DRVNAME, NULL, SERVICE_ALL_ACCESS,
+            SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
+            SERVICE_ERROR_NORMAL, drvpath, NULL, NULL, NULL, NULL, NULL);
+    ok(NULL != service, "CreateServiceA failed\n");
+
+    CloseServiceHandle(service);
+}
+
+void delete_service(SC_HANDLE scm)
+{
+    SC_HANDLE service;
+    BOOL ret;
+
+    service = OpenServiceA(scm, DRVNAME, SERVICE_ALL_ACCESS);
+    ok(NULL != service, "OpenServiceA failed\n");
+
+    ret = DeleteService(service);
+    ok(ret, "DeleteService failed\n");
+
+    CloseServiceHandle(service);
+}
+
+void start_service(SC_HANDLE scm)
+{
+    SC_HANDLE service;
+    BOOL ret;
+
+    service = OpenServiceA(scm, DRVNAME, SERVICE_ALL_ACCESS);
+    ok(NULL != service, "OpenServiceA failed\n");
+
+    ret = StartServiceA(service, 0, NULL);
+    ok(ret, "StartServiceA failed\n");
+
+    CloseServiceHandle(service);
+}
+
+void stop_service(SC_HANDLE scm)
+{
+    SC_HANDLE service;
+    SERVICE_STATUS status;
+    BOOL ret;
+
+    service = OpenServiceA(scm, DRVNAME, SERVICE_ALL_ACCESS);
+    ok(NULL != service, "OpenServiceA failed\n");
+
+    ret = ControlService(service, SERVICE_CONTROL_STOP, &status);
+    ok(ret, "ControlService failed\n");
+
+    CloseServiceHandle(service);
+}
+
+START_TEST(ntoskrnl)
+{
+    CHAR destpath[MAX_PATH + 1];
+    SC_HANDLE scm;
+    BOOL ret;
+    int del_file;
+
+    scm = OpenSCManagerA(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
+    if (NULL == scm)
+    {
+        skip("Could not get a handle to the manager\n");
+        return;
+    }
+
+    GetEnvironmentVariableA("windir", destpath, MAX_PATH - lstrlenA(drvpath));
+    lstrcatA(destpath, "\\");
+    lstrcatA(destpath, drvpath);
+    del_file = create_driver_image(destpath);
+
+    create_service(scm);
+    start_service(scm);
+    stop_service(scm);
+    delete_service(scm);
+
+    if (del_file)
+    {
+        ret = DeleteFileA(destpath);
+        ok(ret, "DeleteFileA failed: %u\n", GetLastError());
+    }
+
+    CloseServiceHandle(scm);
+}
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.rc b/dlls/ntoskrnl.exe/tests/ntoskrnl.rc
new file mode 100644
index 0000000..92b486a
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.rc
@@ -0,0 +1,23 @@
+/*
+ * Resource file for ntoskrnl.exe tests
+ *
+ * Copyright 2008 Etersoft (Alexander Morozov)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "rc.h"
+
+DRIVER_RES RCDATA winetest.sys.so
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl_cross.rc b/dlls/ntoskrnl.exe/tests/ntoskrnl_cross.rc
new file mode 100644
index 0000000..d17a8b4
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/ntoskrnl_cross.rc
@@ -0,0 +1,23 @@
+/*
+ * Resource file for ntoskrnl.exe tests
+ *
+ * Copyright 2008 Etersoft (Alexander Morozov)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "rc.h"
+
+WIN_DRIVER_RES RCDATA winetest.sys
diff --git a/dlls/ntoskrnl.exe/tests/rc.h b/dlls/ntoskrnl.exe/tests/rc.h
new file mode 100644
index 0000000..2db3fd4
--- /dev/null
+++ b/dlls/ntoskrnl.exe/tests/rc.h
@@ -0,0 +1,27 @@
+/*
+ * Resource identifiers for ntoskrnl.exe tests
+ *
+ * Copyright 2008 Etersoft (Alexander Morozov)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef NTOSKRNL_TESTS_RC_INCLUDED
+#define NTOSKRNL_TESTS_RC_INCLUDED
+
+#define DRIVER_RES 1
+#define WIN_DRIVER_RES 2
+
+#endif /* NTOSKRNL_TESTS_RC_INCLUDED */
-- 
1.5.4.5.GIT



More information about the wine-patches mailing list