Hi,
My patch with test is producing a strange result in Test Bot.
I'm getting a ERROR_NOT_ENOUGH_MEMORY when calling LoadLibraryExA only in Vista and Win2008 64bit.
Any hint?
Regards,
C.Palminha
On 11-08-2017 11:39, Carlos Palminha wrote:
> Test LIBRARY_SEARCH_* flags when loading libraries.
> Uses helper from path.c to create the test dll file.
>
> Signed-off-by: Carlos Palminha <palminha(a)synopsys.com>
> ---
> v3:
> - Improved check for Win2003 cases
>
> v2:
> - Split the tests affecting different files
> - Tests checks for Win2003 cases
>
> dlls/kernel32/tests/module.c | 132 ++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 131 insertions(+), 1 deletion(-)
>
> diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
> index bb22c24316c..96dd3277c1b 100644
> --- a/dlls/kernel32/tests/module.c
> +++ b/dlls/kernel32/tests/module.c
> @@ -407,6 +407,136 @@ static void testLoadLibraryEx(void)
> FreeLibrary(hmodule);
> }
>
> +/* use some functions and strcutures from loader.c */
> +extern DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
> + const IMAGE_NT_HEADERS *nt_header, const char *dll_name );
> +extern const IMAGE_NT_HEADERS nt_header_template;
> +
> +static void testLoadLibraryExSearchFlags(void)
> +{
> + HMODULE hmodule;
> + char tmpPath[MAX_PATH];
> + char dllName[] = "testFlags.dll";
> + char tmpFullFile[MAX_PATH];
> + char sysFullFile[MAX_PATH];
> + IMAGE_DOS_HEADER dos_header;
> + IMAGE_NT_HEADERS nt_header;
> + ULONG file_size;
> + char fullPath[MAX_PATH];
> + DWORD version;
> + BOOL is_win2003 = FALSE;
> +
> + GetTempPathA(MAX_PATH, tmpPath);
> + lstrcpyA(tmpFullFile, tmpPath);
> + lstrcatA(tmpFullFile, dllName);
> +
> + /* check for required function */
> + if (!pSetDllDirectoryA)
> + {
> + win_skip("SetDllDirectoryA not available\n");
> + return;
> + }
> +
> + /* check if we are in win2003... flags are not supported */
> + version = GetVersion();
> + if ((LOBYTE(LOWORD(version)) == 5) && (HIBYTE(LOWORD(version))==2))
> + is_win2003 = TRUE;
> +
> + /* try to load test dll from test path before creating it*/
> + SetLastError(0xdeadbeef);
> + pSetDllDirectoryA(tmpPath);
> + hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
> + ok (hmodule == NULL, "Test library %s should not be loaded from %s\n", dllName, tmpPath);
> + ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
> + "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x) or ERROR_INVALID_PARAMETER (win2003), got %d\n", GetLastError());
> + FreeLibrary(hmodule);
> + pSetDllDirectoryA(NULL);
> +
> + /* create test library */
> + lstrcpyA(fullPath, tmpPath);
> + lstrcatA(fullPath, dllName);
> +
> + dos_header.e_magic = IMAGE_DOS_SIGNATURE;
> + dos_header.e_lfanew = sizeof(dos_header);
> +
> + nt_header = nt_header_template;
> +
> + nt_header.FileHeader.NumberOfSections = 1;
> + nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
> + nt_header.OptionalHeader.SectionAlignment = 0x1000;
> + nt_header.OptionalHeader.FileAlignment = 0x1000;
> + nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000;
> + nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER);
> +
> + file_size = create_test_dll(&dos_header, sizeof(dos_header), &nt_header, fullPath);
> + ok( file_size, "could not create '%s'\n",fullPath);
> +
> + /* try to load test dll without specifying the test path */
> + SetLastError(0xdeadbeef);
> + pSetDllDirectoryA(NULL);
> + hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
> + ok (hmodule == NULL, "Test library should not be loaded from 'NULL' path\n");
> + ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
> + "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x) or ERROR_INVALID_PARAMETER (win2003), got %d\n", GetLastError());
> + FreeLibrary(hmodule);
> +
> + /* try to load test dll from test path */
> + SetLastError(0xdeadbeef);
> + pSetDllDirectoryA(tmpPath);
> + hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
> + if(is_win2003)
> + ok (hmodule == NULL, "Test library should not be loaded from %s in Win2003 (flag not supported)\n", tmpPath);
> + else
> + ok (hmodule != NULL, "Could not load test library %s from %s\n", dllName, tmpPath);
> + ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_INVALID_PARAMETER,
> + "Expected 0xdeadbeef or ERROR_SUCCESS or ERROR_INVALID_PARAMETER (win2003), got %d\n", GetLastError());
> + FreeLibrary(hmodule);
> + pSetDllDirectoryA(NULL);
> +
> + /* load non-existing test dll from system32 */
> + SetLastError(0xdeadbeef);
> + hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
> + ok(hmodule == NULL, "%s should not be loaded\n", dllName);
> + ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER,
> + "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x) or ERROR_INVALID_PARAMETER (win2003), got %d\n", GetLastError());
> + FreeLibrary(hmodule);
> +
> + /* move library from temp path to system32 and delete from old path */
> + GetWindowsDirectoryA(sysFullFile,MAX_PATH);
> + lstrcatA(sysFullFile,"\\system32\\");
> + lstrcatA(sysFullFile, dllName);
> + MoveFileA(tmpFullFile,sysFullFile);
> + DeleteFileA(tmpFullFile);
> +
> + /* try to load dll using more than one flag */
> + pSetDllDirectoryA(tmpPath);
> + SetLastError(0xdeadbeef);
> + hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS | LOAD_LIBRARY_SEARCH_SYSTEM32);
> + if(is_win2003)
> + ok (hmodule == NULL, "Test library should not be loaded from 'system32' in Win2003 (flag not supported)\n");
> + else
> + ok (hmodule != NULL, "Library %s was expected to be loaded from 'system32'\n", dllName);
> + ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_INVALID_PARAMETER,
> + "Expected 0xdeadbeef or ERROR_SUCCESS or ERROR_INVALID_PARAMETER (win2003), got %d\n", GetLastError());
> + FreeLibrary(hmodule);
> + pSetDllDirectoryA(NULL);
> +
> + /* try to load test dll from system32 */
> + SetLastError(0xdeadbeef);
> + hmodule = LoadLibraryExA(dllName, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
> + if(is_win2003)
> + ok (hmodule == NULL, "Test library should not be loaded from 'system32' in Win2003 (flag not supported)\n");
> + else
> + ok (hmodule != NULL, "Library %s was expected to be loaded from 'system32'\n", dllName);
> + ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_INVALID_PARAMETER,
> + "Expected 0xdeadbeef or ERROR_SUCCESS or ERROR_INVALID_PARAMETER (win2003), got %d\n", GetLastError());
> + FreeLibrary(hmodule);
> +
> + /* delete test dll from system32 directory */
> + DeleteFileA(sysFullFile);
> +
> +}
> +
> static void testGetDllDirectory(void)
> {
> CHAR bufferA[MAX_PATH];
> @@ -744,7 +874,6 @@ START_TEST(module)
> WCHAR filenameW[MAX_PATH];
>
> /* Test if we can use GetModuleFileNameW */
> -
> SetLastError(0xdeadbeef);
> GetModuleFileNameW(NULL, filenameW, MAX_PATH);
> if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
> @@ -766,6 +895,7 @@ START_TEST(module)
> testLoadLibraryA_Wrong();
> testGetProcAddress_Wrong();
> testLoadLibraryEx();
> + testLoadLibraryExSearchFlags();
> testGetModuleHandleEx();
> testK32GetModuleInformation();
> }
>