2004-10-23 Casper S. Hornstrup <chorns@users.sourceforge.net>

* Makefile: Support regtests_implib.
	* rules.mak (REGTESTS_PATH): Define.
	* drivers/net/tcpip/makefile (TARGET_BUILDENV_TEST): Remove.
	* drivers/net/tcpip/tests/Makefile: Update.
	* lib/gdiplus/tests/.cvsignore: Ditto.
	* lib/gdiplus/tests/Makefile: Ditto.
	* lib/kernel32/tests/Makefile: Ditto.
	* lib/kernel32/tests/stubs.tst (HeapAlloc, HeapFree): Add.
	* lib/ws2_32/makefile (TARGET_REGTESTS): Define to yes.
	* regtests/Makefile: Update.
 	* regtests/shared/regtests.c (_alloca): Define.
	(FrameworkGetHook): Move to here.
 	* regtests/shared/regtests.h (_AssertTrue, _AssertFalse): Define.
 	(_GetModuleHandleA, _GetProcAddress, _LoadLibraryA): Define.
 	(FrameworkGetExportedFunctionNameInternal): Define.
 	* subsys/win32k/tests/makefile: Update.
 	* tools/helper.mk: Create dependencies.
 	* tools/regtests.c: Move FrameworkGetHook; Support forwarded exports.
	* lib/ws2_32/tests: New directory.
	* lib/ws2_32/tests/.cvsignore: New file.
	* lib/ws2_32/tests/Makefile: Ditto.
	* lib/ws2_32/tests/stubs.tst: Ditto.
	* lib/ws2_32/tests/tests: New directory.
	* lib/ws2_32/tests/tests/.cvsignore: New file.
	* lib/ws2_32/tests/tests/WinsockEvent.c: New file.
	* regtests/regtests: New directory.
	* regtests/regtests/.cvsignore: New file.
	* regtests/regtests/Makefile: Ditto.
	* regtests/regtests/regtests.c: Ditto.
	* regtests/regtests/regtests.def: Ditto.

svn path=/trunk/; revision=11406
This commit is contained in:
Casper Hornstrup 2004-10-23 21:05:12 +00:00
parent 825e1dc162
commit eae828b789
25 changed files with 441 additions and 124 deletions

View file

@ -1,3 +1,36 @@
2004-10-23 Casper S. Hornstrup <chorns@users.sourceforge.net>
* Makefile: Support regtests_implib.
* rules.mak (REGTESTS_PATH): Define.
* drivers/net/tcpip/makefile (TARGET_BUILDENV_TEST): Remove.
* drivers/net/tcpip/tests/Makefile: Update.
* lib/gdiplus/tests/.cvsignore: Ditto.
* lib/gdiplus/tests/Makefile: Ditto.
* lib/kernel32/tests/Makefile: Ditto.
* lib/kernel32/tests/stubs.tst (HeapAlloc, HeapFree): Add.
* lib/ws2_32/makefile (TARGET_REGTESTS): Define to yes.
* regtests/Makefile: Update.
* regtests/shared/regtests.c (_alloca): Define.
(FrameworkGetHook): Move to here.
* regtests/shared/regtests.h (_AssertTrue, _AssertFalse): Define.
(_GetModuleHandleA, _GetProcAddress, _LoadLibraryA): Define.
(FrameworkGetExportedFunctionNameInternal): Define.
* subsys/win32k/tests/makefile: Update.
* tools/helper.mk: Create dependencies.
* tools/regtests.c: Move FrameworkGetHook; Support forwarded exports.
* lib/ws2_32/tests: New directory.
* lib/ws2_32/tests/.cvsignore: New file.
* lib/ws2_32/tests/Makefile: Ditto.
* lib/ws2_32/tests/stubs.tst: Ditto.
* lib/ws2_32/tests/tests: New directory.
* lib/ws2_32/tests/tests/.cvsignore: New file.
* lib/ws2_32/tests/tests/WinsockEvent.c: New file.
* regtests/regtests: New directory.
* regtests/regtests/.cvsignore: New file.
* regtests/regtests/Makefile: Ditto.
* regtests/regtests/regtests.c: Ditto.
* regtests/regtests/regtests.def: Ditto.
2004-10-20 Casper S. Hornstrup <chorns@users.sourceforge.net> 2004-10-20 Casper S. Hornstrup <chorns@users.sourceforge.net>
* lib/gdiplus/makefile (TARGET_BUILDENV_TEST): Remove. * lib/gdiplus/makefile (TARGET_BUILDENV_TEST): Remove.

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.254 2004/10/23 17:07:06 weiden Exp $ # $Id: Makefile,v 1.255 2004/10/23 21:05:11 chorns Exp $
# #
# Global makefile # Global makefile
# #
@ -137,7 +137,8 @@ depends: $(LIB_STATIC:%=%_depends) $(LIB_FSLIB:%=%_depends) msvcrt_depends $(DLL
implib: hallib $(LIB_STATIC) $(COMPONENTS:%=%_implib) $(HALS:%=%_implib) $(BUS:%=%_implib) \ implib: hallib $(LIB_STATIC) $(COMPONENTS:%=%_implib) $(HALS:%=%_implib) $(BUS:%=%_implib) \
$(LIB_STATIC:%=%_implib) $(LIB_FSLIB:%=%_implib) msvcrt_implib $(DLLS:%=%_implib) \ $(LIB_STATIC:%=%_implib) $(LIB_FSLIB:%=%_implib) msvcrt_implib $(DLLS:%=%_implib) \
$(KERNEL_DRIVERS:%=%_implib) $(SUBSYS:%=%_implib) \ $(KERNEL_DRIVERS:%=%_implib) $(SUBSYS:%=%_implib) \
$(SYS_APPS:%=%_implib) $(SYS_SVC:%=%_implib) $(EXT_MODULES:%=%_implib) $(SYS_APPS:%=%_implib) $(SYS_SVC:%=%_implib) $(EXT_MODULES:%=%_implib) \
$(REGTESTS:%=%_implib)
test: $(COMPONENTS:%=%_test) $(HALS:%=%_test) $(BUS:%=%_test) \ test: $(COMPONENTS:%=%_test) $(HALS:%=%_test) $(BUS:%=%_test) \
$(LIB_STATIC:%=%_test) $(LIB_FSLIB:%=%_test) msvcrt_test $(DLLS:%=%_test) \ $(LIB_STATIC:%=%_test) $(LIB_FSLIB:%=%_test) msvcrt_test $(DLLS:%=%_test) \
@ -889,6 +890,9 @@ $(SUBSYS:%=%_bootcd): %_bootcd:
$(REGTESTS): %: $(IMPLIB) $(REGTESTS): %: $(IMPLIB)
$(MAKE) --silent -C regtests $(MAKE) --silent -C regtests
$(REGTESTS:%=%_implib): %_implib: dk
$(MAKE) --silent -C regtests implib
$(REGTESTS:%=%_clean): %_clean: $(REGTESTS:%=%_clean): %_clean:
$(MAKE) -C regtests clean $(MAKE) -C regtests clean

View file

@ -1,11 +1,9 @@
# $Id: makefile,v 1.28 2004/10/18 19:11:06 chorns Exp $ # $Id: makefile,v 1.29 2004/10/23 21:05:11 chorns Exp $
PATH_TO_TOP = ../../.. PATH_TO_TOP = ../../..
TARGET_REGTESTS = yes TARGET_REGTESTS = yes
TARGET_BUILDENV_TEST = yes
TARGET_TYPE = export_driver TARGET_TYPE = export_driver
TARGET_NAME = tcpip TARGET_NAME = tcpip

View file

@ -1,8 +1,6 @@
# $Id: Makefile,v 1.3 2004/10/18 19:11:07 chorns Exp $
PATH_TO_TOP = ../../../.. PATH_TO_TOP = ../../../..
TARGET_TYPE = library TARGET_TYPE = test
TARGET_NAME = regtests TARGET_NAME = regtests
@ -14,18 +12,8 @@ TARGET_CFLAGS = -I$(REGTESTS_PATH_INC)
-include Makefile.tests -include Makefile.tests
TARGET_OBJECTS = \ TARGET_OBJECTS = $(addprefix tests/, $(TESTS))
_rtstub.o \
_regtests.o \
_hooks.o \
_stubs.o \
$(addprefix tests/, $(TESTS))
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk include $(TOOLS_PATH)/helper.mk
run: all
@$(CC) -o _runtest.exe _rtstub.o regtests.a $(SDK_PATH_LIB)/rtshared.a $(LIBS) -lntdll
@_runtest.exe
@$(RM) _runtest.exe

View file

@ -1,6 +1,6 @@
_hooks.c
_regtests.c _regtests.c
_rtstub.c _rtstub.c
_hooks.c
_stubs.S _stubs.S
Makefile.tests Makefile.tests
*.d *.d

View file

@ -21,12 +21,7 @@ TARGET_LIBS = ../gdiplus.a
-include Makefile.tests -include Makefile.tests
TARGET_OBJECTS = \ TARGET_OBJECTS = $(addprefix tests/, $(TESTS))
_rtstub.o \
_regtests.o \
_hooks.o \
_stubs.o \
$(addprefix tests/, $(TESTS))
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.3 2004/10/20 20:51:21 chorns Exp $ # $Id: Makefile,v 1.4 2004/10/23 21:05:11 chorns Exp $
PATH_TO_TOP = ../../.. PATH_TO_TOP = ../../..
@ -14,12 +14,7 @@ TARGET_LIBS = ../kernel32.a
-include Makefile.tests -include Makefile.tests
TARGET_OBJECTS = \ TARGET_OBJECTS = $(addprefix tests/, $(TESTS))
_rtstub.o \
_regtests.o \
_hooks.o \
_stubs.o \
$(addprefix tests/, $(TESTS))
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak

View file

@ -3,6 +3,8 @@ ntdll.dll CsrClientCallServer@16
ntdll.dll CsrClientConnectToServer@0 ntdll.dll CsrClientConnectToServer@0
ntdll.dll CsrReleaseParameterBuffer@4 ntdll.dll CsrReleaseParameterBuffer@4
ntdll.dll DbgUiContinue@8 ntdll.dll DbgUiContinue@8
ntdll.dll HeapAlloc@12=RtlAllocateHeap
ntdll.dll HeapFree@12=RtlFreeHeap
ntdll.dll LdrAccessResource@16 ntdll.dll LdrAccessResource@16
ntdll.dll LdrDisableThreadCalloutsForDll@4 ntdll.dll LdrDisableThreadCalloutsForDll@4
ntdll.dll LdrFindResource_U@16 ntdll.dll LdrFindResource_U@16

View file

@ -1,7 +1,9 @@
# $Id: makefile,v 1.16 2004/08/15 18:53:07 chorns Exp $ # $Id: makefile,v 1.17 2004/10/23 21:05:11 chorns Exp $
PATH_TO_TOP = ../.. PATH_TO_TOP = ../..
TARGET_REGTESTS = yes
TARGET_TYPE = dynlink TARGET_TYPE = dynlink
TARGET_NAME = ws2_32 TARGET_NAME = ws2_32

View file

@ -0,0 +1,9 @@
_regtests.c
_rtstub.c
_hooks.c
_stubs.S
Makefile.tests
*.d
*.o
*.a
*.pch

View file

@ -0,0 +1,19 @@
PATH_TO_TOP = ../../..
TARGET_TYPE = test
TARGET_NAME = regtests
TARGET_LIBPATH = .
TARGET_CFLAGS = -I$(REGTESTS_PATH_INC)
TARGET_LIBS = ../ws2_32.a
-include Makefile.tests
TARGET_OBJECTS = $(addprefix tests/, $(TESTS))
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk

View file

@ -0,0 +1,18 @@
kernel32.dll CreateEventW@16
kernel32.dll InitializeCriticalSection@4
kernel32.dll DeleteCriticalSection@4
kernel32.dll EnterCriticalSection@4
kernel32.dll ExitProcess@4
kernel32.dll FreeLibrary@4
kernel32.dll GetLastError@0
kernel32.dll GetProcAddress@8
kernel32.dll GetProcessHeap@0
ntdll.dll HeapAlloc@12=RtlAllocateHeap
ntdll.dll HeapFree@12=RtlFreeHeap
kernel32.dll LeaveCriticalSection@4
kernel32.dll LoadLibraryW@4
kernel32.dll lstrcpyA@8
ntdll.dll ResetEvent@4
ntdll.dll SetEvent@4
ntdll.dll WaitForMultipleObjectsEx@20
kernel32.dll CloseHandle@4

View file

@ -0,0 +1,2 @@
*.d
*.o

View file

@ -0,0 +1,90 @@
#include <windows.h>
#include <winsock2.h>
#include "regtests.h"
#define TestHandle (HANDLE) 1
static BOOL CloseHandleSuccessCalled = FALSE;
static BOOL STDCALL
MockCloseHandleSuccess(HANDLE hObject)
{
CloseHandleSuccessCalled = TRUE;
_AssertEqualValue(TestHandle, hObject);
return TRUE;
}
static HOOK HooksSuccess[] =
{
{"CloseHandle", MockCloseHandleSuccess},
{NULL, NULL}
};
static void
TestWSACloseEventSuccess()
{
BOOL result;
_SetHooks(HooksSuccess);
result = WSACloseEvent(TestHandle);
_AssertTrue(result);
_AssertEqualValue(NO_ERROR, WSAGetLastError());
_AssertTrue(CloseHandleSuccessCalled);
_UnsetAllHooks();
}
static BOOL CloseHandleFailureCalled = FALSE;
static BOOL STDCALL
MockCloseHandleFailure(HANDLE hObject)
{
CloseHandleFailureCalled = TRUE;
return FALSE;
}
static HOOK HooksFailure[] =
{
{"CloseHandle", MockCloseHandleFailure},
{NULL, NULL}
};
static void
TestWSACloseEventFailure()
{
BOOL result;
_SetHooks(HooksFailure);
result = WSACloseEvent(TestHandle);
_AssertFalse(result);
_AssertEqualValue(WSA_INVALID_HANDLE, WSAGetLastError());
_AssertTrue(CloseHandleFailureCalled);
_UnsetAllHooks();
}
static void
TestWSACloseEvent()
{
TestWSACloseEventSuccess();
TestWSACloseEventFailure();
}
extern BOOL
STDCALL
DllMain(HANDLE hInstDll,
ULONG dwReason,
LPVOID lpReserved);
static void
RunTest()
{
WSADATA WSAData;
DllMain(NULL, DLL_PROCESS_ATTACH, NULL);
WSAStartup(MAKEWORD(2, 0), &WSAData);
TestWSACloseEvent();
WSACleanup();
}
DISPATCHER(WinsockeventTest, "Winsock 2 event")

View file

@ -1,14 +1,18 @@
# $Id: Makefile,v 1.5 2004/10/18 19:11:07 chorns Exp $
PATH_TO_TOP = .. PATH_TO_TOP = ..
all: all:
$(MAKE) -C regtests all
$(MAKE) -C shared all $(MAKE) -C shared all
implib:
- $(MAKE) -C regtests implib
clean: clean:
- $(MAKE) -C regtests clean
- $(MAKE) -C shared clean - $(MAKE) -C shared clean
install: install:
$(MAKE) -C regtests install
$(MAKE) -C shared install $(MAKE) -C shared install
.PHONY: all clean install .PHONY: all clean install

View file

@ -0,0 +1,11 @@
temp.exp
*.d
*.a
*.o
*.dll
*.coff
*.sym
*.tmp
*.gch
*.pch
*.map

View file

@ -0,0 +1,16 @@
PATH_TO_TOP = ../..
TARGET_NORC = yes
TARGET_TYPE = dynlink
TARGET_NAME = regtests
TARGET_CFLAGS = -Wall -Werror
TARGET_OBJECTS = \
regtests.o
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk

View file

@ -0,0 +1,28 @@
/*
* PROJECT: ReactOS kernel
* FILE: regtests/regtests/regtests.c
* PURPOSE: Regression testing framework
* PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
* UPDATE HISTORY:
* 23-10-2004 CSH Created
*/
#include <windows.h>
HMODULE STDCALL
_GetModuleHandleA(LPCSTR lpModuleName)
{
return GetModuleHandleA(lpModuleName);
}
FARPROC STDCALL
_GetProcAddress(HMODULE hModule,
LPCSTR lpProcName)
{
return GetProcAddress(hModule, lpProcName);
}
HINSTANCE STDCALL
_LoadLibraryA(LPCSTR lpLibFileName)
{
return LoadLibraryA(lpLibFileName);
}

View file

@ -0,0 +1,5 @@
LIBRARY REGTESTS.DLL
EXPORTS
_GetModuleHandleA@4
_GetProcAddress@8
_LoadLibraryA@4

View file

@ -23,22 +23,20 @@ char *_Buffer;
static LIST_ENTRY AllTests; static LIST_ENTRY AllTests;
int void *_alloca(size_t size)
DriverTest()
{ {
/* Dummy */ void *ret;
return 0;
asm ("movl %1, %%eax\n"
"addl $3, %%eax\n"
"andl $-4, %%eax\n"
"subl %%eax, %%esp\n"
"movl %%esp, %0\n"
: "=m" (ret) : "m" (size) : "eax");
return ret;
} }
int
_regtestsTest()
{
/* Dummy */
return 0;
}
VOID VOID
InitializeTests() InitializeTests()
{ {
@ -83,7 +81,7 @@ PerformTest(TestOutputRoutine OutputRoutine, PROS_TEST Test, LPSTR TestName)
(Test->Routine)(TESTCMD_RUN); (Test->Routine)(TESTCMD_RUN);
#ifdef SEH #ifdef SEH
} __except(EXCEPTION_EXECUTE_HANDLER) { } __except(EXCEPTION_EXECUTE_HANDLER) {
Result = TS_FAILED; _Result = TS_FAILED;
strcpy(Buffer, "Failed due to exception"); strcpy(Buffer, "Failed due to exception");
} }
#endif #endif
@ -128,7 +126,7 @@ AddTest(TestRoutine Routine)
{ {
PROS_TEST Test; PROS_TEST Test;
Test = (PROS_TEST) AllocateMemory(sizeof(ROS_TEST)); Test = (PROS_TEST) malloc(sizeof(ROS_TEST));
if (Test == NULL) if (Test == NULL)
{ {
DbgPrint("Out of memory"); DbgPrint("Out of memory");
@ -139,3 +137,9 @@ AddTest(TestRoutine Routine)
InsertTailList(&AllTests, &Test->ListEntry); InsertTailList(&AllTests, &Test->ListEntry);
} }
PVOID STDCALL
FrameworkGetHook(ULONG index)
{
return FrameworkGetHookInternal(index);
}

View file

@ -50,35 +50,63 @@ AppendAssertion(char *message)
_Result = TS_FAILED; _Result = TS_FAILED;
} }
#define _AssertTrue(_Condition) \
{ \
if (!(_Condition)) \
{ \
char _message[100]; \
sprintf(_message, "Condition was not true at %s:%d", \
__FILE__, __LINE__); \
AppendAssertion(_message); \
} \
}
#define _AssertFalse(_Condition) \
{ \
if (_Condition) \
{ \
char _message[100]; \
sprintf(_message, "Condition was not false at %s:%d", \
__FILE__, __LINE__); \
AppendAssertion(_message); \
} \
}
#define _AssertEqualValue(_Expected, _Actual) \ #define _AssertEqualValue(_Expected, _Actual) \
{ \ { \
if ((_Expected) != (_Actual)) \ ULONG __Expected = (ULONG) (_Expected); \
ULONG __Actual = (ULONG) (_Actual); \
if ((__Expected) != (__Actual)) \
{ \ { \
char _message[100]; \ char _message[100]; \
sprintf(_message, "Expected %d/0x%.08x was %d/0x%.08x at %s:%d", \ sprintf(_message, "Expected %d/0x%.08x was %d/0x%.08x at %s:%d", \
(_Expected), (_Expected), (_Actual), (_Actual), __FILE__, __LINE__); \ (__Expected), (__Expected), (__Actual), (__Actual), __FILE__, __LINE__); \
AppendAssertion(_message); \ AppendAssertion(_message); \
} \ } \
} }
#define _AssertEqualWideString(_Expected, _Actual) \ #define _AssertEqualWideString(_Expected, _Actual) \
{ \ { \
if (wcscmp((_Expected), (_Actual)) != 0) \ LPWSTR __Expected = (LPWSTR) (_Expected); \
LPWSTR __Actual = (LPWSTR) (_Actual); \
if (wcscmp((__Expected), (__Actual)) != 0) \
{ \ { \
char _message[100]; \ char _message[100]; \
sprintf(_message, "Expected %S was %S at %s:%d", \ sprintf(_message, "Expected %S was %S at %s:%d", \
(_Expected), (_Actual), __FILE__, __LINE__); \ (__Expected), (__Actual), __FILE__, __LINE__); \
AppendAssertion(_message); \ AppendAssertion(_message); \
} \ } \
} }
#define _AssertNotEqualValue(_Expected, _Actual) \ #define _AssertNotEqualValue(_Expected, _Actual) \
{ \ { \
if ((_Expected) == (_Actual)) \ ULONG __Expected = (ULONG) (_Excepted); \
ULONG __Actual = (ULONG) (_Actual); \
if ((__Expected) == (__Actual)) \
{ \ { \
char _message[100]; \ char _message[100]; \
sprintf(_message, "Actual value expected to be different from %d/0x%.08x at %s:%d", \ sprintf(_message, "Actual value expected to be different from %d/0x%.08x at %s:%d", \
(_Expected), (_Expected), __FILE__, __LINE__); \ (__Expected), (__Expected), __FILE__, __LINE__); \
AppendAssertion(_message); \ AppendAssertion(_message); \
} \ } \
} }
@ -115,15 +143,12 @@ extern VOID InitializeTests();
extern VOID RegisterTests(); extern VOID RegisterTests();
extern VOID PerformTests(TestOutputRoutine OutputRoutine, LPSTR TestName); extern VOID PerformTests(TestOutputRoutine OutputRoutine, LPSTR TestName);
/* Routines provided by the driver */
extern PVOID AllocateMemory(ULONG Size);
extern VOID FreeMemory(PVOID Base);
typedef struct _API_DESCRIPTION typedef struct _API_DESCRIPTION
{ {
PCHAR FileName; PCHAR FileName;
PCHAR FunctionName; PCHAR FunctionName;
PCHAR ForwardedFunctionName;
PVOID FunctionAddress; PVOID FunctionAddress;
PVOID MockFunctionAddress; PVOID MockFunctionAddress;
} API_DESCRIPTION, *PAPI_DESCRIPTION; } API_DESCRIPTION, *PAPI_DESCRIPTION;
@ -131,33 +156,60 @@ typedef struct _API_DESCRIPTION
extern API_DESCRIPTION ExternalDependencies[]; extern API_DESCRIPTION ExternalDependencies[];
extern ULONG MaxExternalDependency; extern ULONG MaxExternalDependency;
HMODULE STDCALL
_GetModuleHandleA(LPCSTR lpModuleName);
FARPROC STDCALL
_GetProcAddress(HMODULE hModule,
LPCSTR lpProcName);
HINSTANCE STDCALL
_LoadLibraryA(LPCSTR lpLibFileName);
static inline PCHAR
FrameworkGetExportedFunctionNameInternal(PAPI_DESCRIPTION ApiDescription)
{
if (ApiDescription->ForwardedFunctionName != NULL)
{
return ApiDescription->ForwardedFunctionName;
}
else
{
return ApiDescription->FunctionName;
}
}
static inline PVOID static inline PVOID
FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription) FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription)
{ {
HMODULE hModule; HMODULE hModule;
PVOID Function; PVOID function;
PCHAR exportedFunctionName;
hModule = GetModuleHandleA(ApiDescription->FileName); exportedFunctionName = FrameworkGetExportedFunctionNameInternal(ApiDescription);
hModule = _GetModuleHandleA(ApiDescription->FileName);
if (hModule != NULL) if (hModule != NULL)
{ {
Function = GetProcAddress(hModule, ApiDescription->FunctionName); function = _GetProcAddress(hModule, exportedFunctionName);
} }
else else
{ {
hModule = LoadLibraryA(ApiDescription->FileName); hModule = _LoadLibraryA(ApiDescription->FileName);
if (hModule != NULL) if (hModule != NULL)
{ {
Function = GetProcAddress(hModule, ApiDescription->FunctionName); function = _GetProcAddress(hModule, exportedFunctionName);
//FreeLibrary(hModule); //FreeLibrary(hModule);
} }
} }
return Function; return function;
} }
static inline PVOID STDCALL static inline PVOID
FrameworkGetHookInternal(ULONG index) FrameworkGetHookInternal(ULONG index)
{ {
PVOID address; PVOID address;
PCHAR exportedFunctionName;
if (index > MaxExternalDependency) if (index > MaxExternalDependency)
return NULL; return NULL;
@ -168,8 +220,10 @@ FrameworkGetHookInternal(ULONG index)
if (ExternalDependencies[index].FunctionAddress != NULL) if (ExternalDependencies[index].FunctionAddress != NULL)
return ExternalDependencies[index].FunctionAddress; return ExternalDependencies[index].FunctionAddress;
exportedFunctionName = FrameworkGetExportedFunctionNameInternal(&ExternalDependencies[index]);
printf("Calling function '%s' in DLL '%s'.\n", printf("Calling function '%s' in DLL '%s'.\n",
ExternalDependencies[index].FunctionName, exportedFunctionName,
ExternalDependencies[index].FileName); ExternalDependencies[index].FileName);
address = FrameworkGetFunction(&ExternalDependencies[index]); address = FrameworkGetFunction(&ExternalDependencies[index]);
@ -177,7 +231,7 @@ FrameworkGetHookInternal(ULONG index)
if (address == NULL) if (address == NULL)
{ {
printf("Function '%s' not found in DLL '%s'.\n", printf("Function '%s' not found in DLL '%s'.\n",
ExternalDependencies[index].FunctionName, exportedFunctionName,
ExternalDependencies[index].FileName); ExternalDependencies[index].FileName);
} }
ExternalDependencies[index].FunctionAddress = address; ExternalDependencies[index].FunctionAddress = address;
@ -193,7 +247,7 @@ _SetHook(PCHAR name,
PAPI_DESCRIPTION api; PAPI_DESCRIPTION api;
ULONG index; ULONG index;
for (index = 0; index < MaxExternalDependency; index++) for (index = 0; index <= MaxExternalDependency; index++)
{ {
api = &ExternalDependencies[index]; api = &ExternalDependencies[index];
if (strcmp(api->FunctionName, name) == 0) if (strcmp(api->FunctionName, name) == 0)
@ -244,7 +298,7 @@ _UnsetAllHooks()
PAPI_DESCRIPTION api; PAPI_DESCRIPTION api;
ULONG index; ULONG index;
for (index = 0; index < MaxExternalDependency; index++) for (index = 0; index <= MaxExternalDependency; index++)
{ {
api = &ExternalDependencies[index]; api = &ExternalDependencies[index];
api->MockFunctionAddress = NULL; api->MockFunctionAddress = NULL;

View file

@ -178,5 +178,5 @@ export OS2_PATH_LIB=$(OS2_PATH)/lib
export OS2_PATH_INC=$(OS2_PATH)/include export OS2_PATH_INC=$(OS2_PATH)/include
# Other systems integration # Other systems integration
export ROOT_PATH=$(PATH_TO_TOP)/.. export REGTESTS_PATH=$(PATH_TO_TOP)/regtests
export REGTESTS_PATH_INC=$(PATH_TO_TOP)/regtests/shared export REGTESTS_PATH_INC=$(PATH_TO_TOP)/regtests/shared

View file

@ -14,12 +14,7 @@ TARGET_LIBS = ../win32k.a
-include Makefile.tests -include Makefile.tests
TARGET_OBJECTS = \ TARGET_OBJECTS = $(addprefix tests/, $(TESTS))
_rtstub.o \
_regtests.o \
_hooks.o \
_stubs.o \
$(addprefix tests/, $(TESTS))
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak

View file

@ -1,4 +1,4 @@
# $Id: helper.mk,v 1.90 2004/10/21 18:04:48 arty Exp $ # $Id: helper.mk,v 1.91 2004/10/23 21:05:12 chorns Exp $
# #
# Helper makefile for ReactOS modules # Helper makefile for ReactOS modules
# Variables this makefile accepts: # Variables this makefile accepts:
@ -371,6 +371,7 @@ ifeq ($(TARGET_TYPE),test)
MK_BOOTCDDIR := system32 MK_BOOTCDDIR := system32
MK_DISTDIR := # none MK_DISTDIR := # none
MK_RES_BASE := MK_RES_BASE :=
TARGET_OBJECTS := _rtstub.o _regtests.o $(TARGET_OBJECTS)
endif endif
@ -661,6 +662,10 @@ MK_NOSTRIPNAME := $(MK_BASENAME).nostrip$(MK_EXT)
MK_EXTRADEP := $(filter %.h,$(TARGET_OBJECTS)) MK_EXTRADEP := $(filter %.h,$(TARGET_OBJECTS))
ifeq ($(TARGET_TYPE),test)
MK_EXTRADEP += _stubs.o _hooks.o
endif
# We don't want to link header files # We don't want to link header files
MK_OBJECTS := $(filter-out %.h,$(TARGET_OBJECTS)) MK_OBJECTS := $(filter-out %.h,$(TARGET_OBJECTS))
@ -876,8 +881,8 @@ endif # MK_MODE
# Static library target # Static library target
ifeq ($(MK_MODE),static) ifeq ($(MK_MODE),static)
$(MK_FULLNAME): $(TARGET_OBJECTS) $(MK_FULLNAME): $(MK_EXTRADEP) $(MK_OBJECTS)
$(AR) -r $(MK_FULLNAME) $(TARGET_OBJECTS) $(AR) -r $(MK_FULLNAME) $(MK_OBJECTS)
@echo $(MK_BASENAME)$(MK_EXT) was successfully built. @echo $(MK_BASENAME)$(MK_EXT) was successfully built.
# Static libraries dont have a nostrip version # Static libraries dont have a nostrip version
@ -1017,7 +1022,7 @@ endif
REGTEST_TESTS = $(wildcard tests/tests/*.c) REGTEST_TESTS = $(wildcard tests/tests/*.c)
$(REGTEST_TARGETS): $(REGTEST_TESTS) $(REGTEST_TARGETS): $(REGTEST_TESTS) ./tests/stubs.tst
$(REGTESTS) ./tests/tests ./tests/_regtests.c ./tests/Makefile.tests -e ./tests/_rtstub.c $(REGTESTS) ./tests/tests ./tests/_regtests.c ./tests/Makefile.tests -e ./tests/_rtstub.c
$(REGTESTS) -s ./tests/stubs.tst ./tests/_stubs.S ./tests/_hooks.c $(REGTESTS) -s ./tests/stubs.tst ./tests/_stubs.S ./tests/_hooks.c
@ -1064,8 +1069,11 @@ endif
ifeq ($(TARGET_TYPE),test) ifeq ($(TARGET_TYPE),test)
run: all run: all
@$(CC) -o _runtest.exe _rtstub.o regtests.a $(SDK_PATH_LIB)/rtshared.a $(TARGET_LIBS) -lntdll @$(CC) -nostdlib -o _runtest.exe regtests.a $(TARGET_LIBS) _stubs.o \
$(SDK_PATH_LIB)/rtshared.a $(SDK_PATH_LIB)/regtests.a _hooks.o -lmsvcrt -lntdll
@$(CP) $(REGTESTS_PATH)/regtests/regtests.dll regtests.dll
@_runtest.exe @_runtest.exe
@$(RM) regtests.dll
@$(RM) _runtest.exe @$(RM) _runtest.exe
endif endif

View file

@ -515,23 +515,18 @@ static char UMSTUB[] =
static char EXESTUB[] = static char EXESTUB[] =
"/* This file is autogenerated. */\n" "/* This file is autogenerated. */\n"
"\n" "\n"
"#include <stdio.h>\n"
"#include <windows.h>\n"
"#define NTOS_MODE_USER\n"
"#include <ntos.h>\n"
"#include \"regtests.h\"\n" "#include \"regtests.h\"\n"
"\n" "\n"
"PVOID\n" "#if defined(__USE_W32API)\n"
"AllocateMemory(ULONG Size)\n" " #define HANDLE PVOID\n"
"{\n" " #define NTSTATUS ULONG\n"
" return (PVOID) RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);\n"
"}\n"
"\n" "\n"
"VOID\n" " NTSTATUS STDCALL\n"
"FreeMemory(PVOID Base)\n" " NtTerminateProcess(HANDLE ProcessHandle,\n"
"{\n" " NTSTATUS ExitStatus);\n"
" RtlFreeHeap(RtlGetProcessHeap(), 0, Base);\n" "\n"
"}\n" " #define NtCurrentProcess() ((HANDLE) 0xFFFFFFFF)\n"
"#endif\n"
"\n" "\n"
"void\n" "void\n"
"ConsoleWrite(char *Buffer)\n" "ConsoleWrite(char *Buffer)\n"
@ -540,7 +535,10 @@ static char EXESTUB[] =
"}\n" "}\n"
"\n" "\n"
"int\n" "int\n"
"main()\n" "mainCRTStartup(HANDLE hInstance,\n"
" HANDLE hPrevInstance,\n"
" LPSTR lpszCmdParam,\n"
" int nCmdShow)\n"
"{\n" "{\n"
" InitializeTests();\n" " InitializeTests();\n"
" RegisterTests();\n" " RegisterTests();\n"
@ -573,13 +571,7 @@ static char HOOKS_FOOTER[] =
"};\n" "};\n"
"\n" "\n"
"#define ExternalDependencyCount %d\n" "#define ExternalDependencyCount %d\n"
"ULONG MaxExternalDependency = ExternalDependencyCount - 1;\n" "ULONG MaxExternalDependency = ExternalDependencyCount - 1;\n";
"\n"
"PVOID STDCALL\n"
"FrameworkGetHook(ULONG index)\n"
"{\n"
" return FrameworkGetHookInternal(index);\n"
"}\n";
static char HELP[] = static char HELP[] =
"REGTESTS path file makefile [-u umstubfile] [-k kmstubfile] [-e exestubfile]\n" "REGTESTS path file makefile [-u umstubfile] [-k kmstubfile] [-e exestubfile]\n"
@ -616,7 +608,7 @@ write_hooks_footer(FILE *hooks_out, unsigned long nr_stubs)
} }
char * char *
get_undecorate_name(char *buf, get_undecorated_name(char *buf,
char *decoratedname) char *decoratedname)
{ {
int start = 0; int start = 0;
@ -639,20 +631,56 @@ get_undecorate_name(char *buf,
return buf; return buf;
} }
void char *
write_stub(FILE *stubs_out, FILE *hooks_out, char *dllname, get_forwarded_export(char *forwardedexport)
char *decoratedname, unsigned int stub_index)
{ {
char buf[300]; char buf[300];
if (forwardedexport == NULL)
{
strcpy(buf, "NULL");
}
else
{
sprintf(buf, "\"%s\"", forwardedexport);
}
return strdup(buf);
}
void
write_stub(FILE *stubs_out, FILE *hooks_out, char *dllname,
char *decoratedname_and_forward, unsigned int stub_index)
{
char buf[300];
char *p;
char *decoratedname = NULL;
char *forwardedexport = NULL;
p = strtok(decoratedname_and_forward, "=");
if (p != NULL)
{
decoratedname = p;
p = strtok(NULL, "=");
forwardedexport = p;
}
else
{
decoratedname = decoratedname_and_forward;
forwardedexport = decoratedname_and_forward;
}
fprintf(stubs_out, ".globl _%s\n", decoratedname); fprintf(stubs_out, ".globl _%s\n", decoratedname);
fprintf(stubs_out, "_%s:\n", decoratedname); fprintf(stubs_out, "_%s:\n", decoratedname);
fprintf(stubs_out, " pushl $%d\n", stub_index); fprintf(stubs_out, " pushl $%d\n", stub_index);
fprintf(stubs_out, " jmp passthrough\n"); fprintf(stubs_out, " jmp passthrough\n");
fprintf(stubs_out, "\n"); fprintf(stubs_out, "\n");
forwardedexport = get_forwarded_export(forwardedexport);
fprintf(hooks_out, " {\"%s\", \"%s\", NULL, NULL},\n", fprintf(hooks_out, " {\"%s\", \"%s\", %s, NULL, NULL},\n",
dllname, get_undecorate_name(buf, decoratedname)); dllname,
get_undecorated_name(buf, decoratedname),
forwardedexport);
free(forwardedexport);
} }
void void
@ -664,7 +692,7 @@ create_stubs_and_hooks(
char line[INPUT_BUFFER_SIZE]; char line[INPUT_BUFFER_SIZE];
char *s; char *s;
char *dllname; char *dllname;
char *decoratedname; char *decoratedname_and_forward;
int stub_index; int stub_index;
write_stubs_header(stubs_out); write_stubs_header(stubs_out);
@ -679,13 +707,14 @@ create_stubs_and_hooks(
* DLLNAME (e.g. ntdll.dll) * DLLNAME (e.g. ntdll.dll)
* DECORATED NAME (e.g. NtCreateProcess@32, @InterlockedIncrement@4 or printf) * DECORATED NAME (e.g. NtCreateProcess@32, @InterlockedIncrement@4 or printf)
*/ */
stub_index = 0; /* First stub has index zero */
for ( for (
/* First stub has index zero */ ;
stub_index = 0;
/* Go on until EOF or read zero bytes */ /* Go on until EOF or read zero bytes */
((!feof(in)) && (fgets(line, sizeof line, in) != NULL)); ((!feof(in)) && (fgets(line, sizeof line, in) != NULL));
/* Next stub index */ /* Next stub index */
stub_index++) )
{ {
/* /*
* Remove, if present, the trailing LF. * Remove, if present, the trailing LF.
@ -709,16 +738,24 @@ create_stubs_and_hooks(
s = & line[0]; s = & line[0];
if ((*s) != '#' && (*s) != '\0') if ((*s) != '#' && (*s) != '\0')
{ {
/* Extract the DLL name */ /* Extract the DLL name */
dllname = (char *) strtok(s," \t"); dllname = (char *) strtok(s, " \t");
/* Extract the decorated function name */ if (dllname != NULL && strlen(dllname) > 0)
decoratedname = (char *) strtok(NULL," \t"); {
/* Extract the argument count */ /*
write_stub(stubs_out, hooks_out, dllname, decoratedname, stub_index); * Extract the decorated function name and possibly forwarded export.
* Format:
* decoratedname=forwardedexport (no DLL name)
*/
decoratedname_and_forward = (char *) strtok(NULL, " \t");
/* Extract the argument count */
write_stub(stubs_out, hooks_out, dllname, decoratedname_and_forward, stub_index);
stub_index++;
}
} }
} }
write_hooks_footer(hooks_out, stub_index + 1); write_hooks_footer(hooks_out, stub_index);
} }
int run_stubs(int argc, int run_stubs(int argc,