diff options
Diffstat (limited to 'src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW')
30 files changed, 1810 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt new file mode 100644 index 0000000000..85f5c90e2c --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(CreateFileMapping_neg1) +add_subdirectory(test1) + +# TODO: make this test compile +# add_subdirectory(test2) + +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test5) +add_subdirectory(test6) +add_subdirectory(test7) +add_subdirectory(test8) +add_subdirectory(test9) + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt new file mode 100644 index 0000000000..a4ad343ea0 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMapping_neg.c +) + +add_executable(paltest_createfilemappingw_createfilemapping_neg1 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_createfilemapping_neg1 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_createfilemapping_neg1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c new file mode 100644 index 0000000000..8cf79b3c57 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c @@ -0,0 +1,93 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemapping_neg.c +** +** Purpose: Negative test the CreateFileMapping API. +** Call CreateFileMapping to create a unnamed +** file-mapping object with PAGE_READONLY +** protection and try to map a zero length file +** in UNICODE +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE FileHandle; + HANDLE FileMappingHandle; + int err; + WCHAR *lpFileName = NULL; + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + + //conver string to a unicode one + lpFileName = convert("temp.txt"); + + + //create a file and return the file handle + FileHandle = CreateFile(lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_ARCHIVE, + NULL); + + //free this memory + free(lpFileName); + + if(INVALID_HANDLE_VALUE == FileHandle) + { + Fail("Failed to call CreateFile to create a file\n"); + } + + //create a unnamed file-mapping object with file handle FileHandle + //and with PAGE_READONLY protection + //try to map a file which is zero length. + FileMappingHandle = CreateFileMapping( + FileHandle, //File Handle + NULL, //not inherited + PAGE_READONLY, //access protection + 0, //high-order of object size + 0, //low-orger of object size + NULL); //unnamed object + + + if(NULL != FileMappingHandle || ERROR_FILE_INVALID != GetLastError()) + {//no error occurred + Trace("\nFailed to call CreateFileMapping API for a negative test!\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + Fail(""); + } + + //close the file handle + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat new file mode 100644 index 0000000000..a09487d4b9 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat @@ -0,0 +1,12 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMapping +Name = Negative test for CreateFileMappingW - with a zero length file +TYPE = DEFAULT +EXE1 = createfilemapping_neg +Description +=Test the CreateFileMapping to try to map a zero length file diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt new file mode 100644 index 0000000000..0c569ec9b6 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMappingW.c +) + +add_executable(paltest_createfilemappingw_test1 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test1 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c new file mode 100644 index 0000000000..4263a3ad29 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c @@ -0,0 +1,174 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 1) +** +** Purpose: Positive test the CreateFileMappingW API. +** Call CreateFileMappingW with access PAGE_READONLY. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + DWORD dwBytesWritten; + BOOL err; + int RetVal = PASS; + + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Flush to the hard-drive. + */ + FlushFileBuffers(hFile); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and wite*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_READ, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + 0); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat new file mode 100644 index 0000000000..464679a456 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW +Name = CreateFileMappingW with PAGE_READONLY +TYPE = DEFAULT +EXE1 = createfilemappingw +Description +=Test the CreateFileMappingW to create a unnamed file-mapping object +=and with PAGE_READONLY protection diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt new file mode 100644 index 0000000000..992645f48c --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMappingW.c +) + +add_executable(paltest_createfilemappingw_test2 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test2 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c new file mode 100644 index 0000000000..11ff967dfd --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c @@ -0,0 +1,124 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c +** +** Purpose: Positive test the CreateFileMapping API. +** Call CreateFileMapping to create a unnamed +** file-mapping object with PAGE_READONLY +** protection and SEC_IMAGE attribute in UNICODE +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE FileHandle; + HANDLE FileMappingHandle; + int err; + WCHAR *wpFileName = NULL; + char executableFileName[256]=""; + + + //Initialize the PAL environment + err = PAL_Initialize(argc, argv); + if(0 != err) + { + ExitProcess(FAIL); + } + +#if WIN32 + sprintf(executableFileName,"%s","executable.exe"); +#else + sprintf(executableFileName,"%s","executable"); +#endif + + //conver string to a unicode one + wpFileName = convert(executableFileName); + + + //create a file and return the file handle + FileHandle = CreateFile(wpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_ARCHIVE, + NULL); + + //free this memory + free(wpFileName); + + if(INVALID_HANDLE_VALUE == FileHandle) + { + Fail("Failed to call CreateFile to create a file\n"); + } + + //create a unnamed file-mapping object with file handle FileHandle + //and with PAGE_READONLY protection + FileMappingHandle = CreateFileMapping( + FileHandle, //File Handle + NULL, //not inherited + PAGE_READONLY|SEC_IMAGE, //access protection and section attribute + 0, //high-order of object size + 0, //low-orger of object size + NULL); //unnamed object + + + if(NULL == FileMappingHandle) + { + Trace("\nFailed to call CreateFileMapping to create a mapping object!\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API\n"); + } + Fail(""); + } + if(GetLastError() == ERROR_ALREADY_EXISTS) + { + Trace("\nFile mapping object already exists!\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Trace("\nFailed to call CloseHandle API to close a file handle\n"); + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a mapping object handle\n"); + } + Fail(""); + } + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a mapping object handle\n"); + } + Fail(""); + } + err = CloseHandle(FileMappingHandle); + if(0 == err) + { + Trace("\nFailed to call CloseHandle API to close a mapping object handle\n"); + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a file handle\n"); + } + Fail(""); + } + err = CloseHandle(FileHandle); + if(0 == err) + { + Fail("\nFailed to call CloseHandle API to close a file handle\n"); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt new file mode 100644 index 0000000000..87832ffd9b --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMappingW.c +) + +add_executable(paltest_createfilemappingw_test3 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test3 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c new file mode 100644 index 0000000000..1cbeff94a7 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c @@ -0,0 +1,156 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 3) +** +** Purpose: Positive test the CreateFileMappingW API. +** Call CreateFileMapping with access PAGE_READWRITE. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + int RetVal = PASS; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and wite*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /*high order offset*/ + 0, /*low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map view. + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map view. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat new file mode 100644 index 0000000000..1077316618 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW +Name = CreateFileMappingW with PAGE_READWRITE +TYPE = DEFAULT +EXE1 = createfilemappingw +Description +=Test the CreateFileMappingW to create a unnamed file-mapping object +=and with PAGE_READWRITE protection diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt new file mode 100644 index 0000000000..f8a5c9041f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMappingW.c +) + +add_executable(paltest_createfilemappingw_test4 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test4 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c new file mode 100644 index 0000000000..265a317b2f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c @@ -0,0 +1,182 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 4) +** +** Purpose: Positive test the CreateFileMappingW API. +** Call CreateFileMappingW with access PAGE_WRITECOPY. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + char buf[] = "this is a test string"; + char ch[2048]; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + HANDLE hFileMapping; + LPVOID lpMapViewAddress; + int RetVal = PASS; + int err; + DWORD dwBytesWritten; + + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile. + */ + hFile = CreateFile( lpFileName, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Write to the File handle. + */ + err = WriteFile(hFile, + buf, + strlen(buf), + &dwBytesWritten, + NULL); + + if (err == FALSE) + { + Trace("ERROR: %u :unable to write to file handle " + "hFile=0x%lx\n", + GetLastError(), + hFile); + RetVal = FAIL; + goto CleanUpOne; + } + + /* Flush to the hard-drive. + */ + FlushFileBuffers(hFile); + + /* Initialize the buffers. + */ + memset(ch, 0, MAPPINGSIZE); + + /* Create a unnamed file-mapping object with file handle FileHandle + * and with PAGE_WRITECOPY protection. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_WRITECOPY, /*write copy*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMapping) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewAddress = MapViewOfFile( + hFileMapping, + FILE_MAP_COPY, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + 0); /* number of bytes for map */ + + if(NULL == lpMapViewAddress) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write to the Map view.3 + */ + memcpy(lpMapViewAddress, buf, strlen(buf)); + + /* Read from the Map view. + */ + memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE); + + /* Copy the MapViewOfFile to buffer, so we can + * compare with value read from file directly. + */ + if (memcmp(ch, buf, strlen(buf))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + ch, buf); + RetVal = FAIL; + goto CleanUpThree; + } + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewAddress) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewAddress); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapping) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapping); + RetVal = FAIL; + } + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFile) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFile); + RetVal = FAIL; + } + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat new file mode 100644 index 0000000000..472b857eff --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW +Name = CreateFileMappingW with PAGE_WRITECOPY. +TYPE = DEFAULT +EXE1 = createfilemappingw +Description +=Test the CreateFileMapping to create a unnamed file-mapping object +=and with PAGE_WRITE protection diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt new file mode 100644 index 0000000000..8391fbd721 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMappingW.c +) + +add_executable(paltest_createfilemappingw_test5 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test5 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test5 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c new file mode 100644 index 0000000000..21bf7c6d76 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c @@ -0,0 +1,194 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 5) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test CreateFileMappingW to a "swap" handle with +** access PAGE_READONLY. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + int RetVal = FAIL; + char results[2048]; + + HANDLE hFileMapRO; + HANDLE hFileMapRW; + LPVOID lpMapViewRO; + LPVOID lpMapViewRW; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + hFileMapRO = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READONLY, /*read and write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRO) + { + Trace("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRO = MapViewOfFile( + hFileMapRO, + FILE_MAP_READ, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRO) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpFour; + } + + /* Test was successful. + */ + RetVal = PASS; + +CleanUpFour: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRO); + RetVal = FAIL; + } + +CleanUpThree: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapRO) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRO); + RetVal = FAIL; + } + + +CleanUpTwo: + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to opend file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat new file mode 100644 index 0000000000..87e16d3d79 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW +Name = CreateFileMappingW - PAGE_READWRITE +TYPE = DEFAULT +EXE1 = createfilemappingw +Description += Positive test the CreateFileMappingW API. += Test CreateFileMappingW to create a named += "swap" handle with access PAGE_READONLY. diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt new file mode 100644 index 0000000000..abb62ad950 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileMappingW.c +) + +add_executable(paltest_createfilemappingw_test6 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test6 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c new file mode 100644 index 0000000000..acf3ac6dff --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c @@ -0,0 +1,165 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 6) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test CreateFileMappingW to a "swap" handle with +** access PAGE_READWRITE. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + char results[2048]; + int RetVal = PASS; + + HANDLE hFileMapRW; + LPVOID lpMapViewRW; + LPVOID lpMapViewRW2; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*named object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* Create a map view of the READWRITE file mapping. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS,/* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + /* maps a view of a file into the address space of the calling process. + */ + lpMapViewRW2 = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW2) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Test successful. + */ + RetVal = PASS; + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW2) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW2); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat new file mode 100644 index 0000000000..7afae68f16 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMapping +Name = CreateFileMappingA - with PAGE_READONLY +TYPE = DEFAULT +EXE1 = createfilemappingw +Description += Positive test the CreateFileMappingW API. += Test CreateFileMappingW to create a named += "swap" handle with access PAGE_READWRITE. diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt new file mode 100644 index 0000000000..b40cfeae96 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + createfilemapping.c +) + +add_executable(paltest_createfilemappingw_test7 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test7 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test7 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c new file mode 100644 index 0000000000..e49b9f688d --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c @@ -0,0 +1,165 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 7) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test CreateFileMappingW to a "swap" handle with +** access PAGE_READWRITE. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + char testString[] = "this is a test string"; + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + char results[2048]; + int RetVal = PASS; + + HANDLE hFileMapRW; + LPVOID lpMapViewRW; + LPVOID lpMapViewRO; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Initialize the buffers. + */ + memset(results, 0, MAPPINGSIZE); + + /* Create a named file-mapping object with file handle FileHandle + * and with PAGE_READWRITE protection. + */ + hFileMapRW = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + lpObjectName); /*unnamed object*/ + + if(NULL == hFileMapRW) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + /* Create a map view to the READWRITE file mapping. + */ + lpMapViewRW = MapViewOfFile( + hFileMapRW, + FILE_MAP_ALL_ACCESS,/* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRW) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpOne; + } + + + /* Create a map view to the READWRITE file mapping. + */ + lpMapViewRO = MapViewOfFile( + hFileMapRW, + FILE_MAP_READ, /* access code */ + 0, /* high order offset*/ + 0, /* low order offset*/ + MAPPINGSIZE); /* number of bytes for map */ + + if(NULL == lpMapViewRO) + { + Trace("ERROR:%u: Failed to call MapViewOfFile " + "API to map a view of file!\n", + GetLastError()); + RetVal = FAIL; + goto CleanUpTwo; + } + + /* Write the test string to the Map view. + */ + memcpy(lpMapViewRW, testString, strlen(testString)); + + /* Read from the second Map view. + */ + memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE); + + /* Verify the contents of the file mapping, + * by comparing what was written to what was read. + */ + if (memcmp(results, testString, strlen(testString))!= 0) + { + Trace("ERROR: MapViewOfFile not equal to file contents " + "retrieved \"%s\", expected \"%s\".\n", + results, + testString); + RetVal = FAIL; + goto CleanUpThree; + } + + /* Test successful. + */ + RetVal = PASS; + +CleanUpThree: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRO) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRO); + RetVal = FAIL; + } + +CleanUpTwo: + + /* Unmap the view of file. + */ + if ( UnmapViewOfFile(lpMapViewRW) == FALSE ) + { + Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n", + GetLastError(), + lpMapViewRW); + RetVal = FAIL; + } + + +CleanUpOne: + + /* Close Handle to create file mapping. + */ + if ( CloseHandle(hFileMapRW) == FALSE ) + { + Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n", + GetLastError(), + hFileMapRW); + RetVal = FAIL; + } + + + /* Terminate the PAL. + */ + PAL_TerminateEx(RetVal); + return RetVal; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat new file mode 100644 index 0000000000..a68a665d74 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW +Name = CreateFileMappingW - PAGE_COPYWRITE +TYPE = DEFAULT +EXE1 = createfilemapping +Description += Positive test the CreateFileMappingW API. += Test CreateFileMappingW to create a named += "swap" handle with access PAGE_READWRITE diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt new file mode 100644 index 0000000000..96658c163a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + createfilemapping.c +) + +add_executable(paltest_createfilemappingw_test8 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test8 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test8 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c new file mode 100644 index 0000000000..1ff137d8d3 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemappingw.c (test 8) +** +** Purpose: Positive test the CreateFileMappingW API. +** Test the un-verifiable parameter combinations. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; +HANDLE SWAP_HANDLE = ((VOID *)(-1)); + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'}; + + HANDLE hFileMap; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a READONLY, "swap", un-named file mapping. + * This test is unverifiable since there is no hook back to the file map + * because it is un-named. As well, since it resides in "swap", and is + * initialized to zero, there is nothing to read. + */ + hFileMap = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_READONLY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*un-named object*/ + + if(NULL == hFileMap) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + + /* Create a COPYWRITE, "swap", un-named file mapping. + * This test is unverifiable, here is a quote from MSDN: + * + * Copy on write access. If you create the map with PAGE_WRITECOPY and + * the view with FILE_MAP_COPY, you will receive a view to file. If you + * write to it, the pages are automatically swappable and the modifications + * you make will not go to the original data file. + * + */ + hFileMap = CreateFileMapping( + SWAP_HANDLE, + NULL, /*not inherited*/ + PAGE_WRITECOPY, /*write copy*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL == hFileMap) + { + Fail("ERROR:%u: Failed to create File Mapping.\n", + GetLastError()); + } + + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat new file mode 100644 index 0000000000..475d827af4 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW - Special cases +Name = CreateFileMappingW +TYPE = DEFAULT +EXE1 = createfilemapping +Description += Positive test the CreateFileMappingW API. += Test the un-verifiable parameter combinations. diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt new file mode 100644 index 0000000000..5a55e27b33 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + createfilemapping.c +) + +add_executable(paltest_createfilemappingw_test9 + ${SOURCES} +) + +add_dependencies(paltest_createfilemappingw_test9 coreclrpal) + +target_link_libraries(paltest_createfilemappingw_test9 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c new file mode 100644 index 0000000000..16ae74c126 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c @@ -0,0 +1,151 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================= +** +** Source: createfilemapping.c (test 9) +** +** Purpose: Negative test the CreateFileMappingW API. +** +** +**============================================================*/ +#define UNICODE +#include <palsuite.h> + +const int MAPPINGSIZE = 2048; + +int __cdecl main(int argc, char *argv[]) +{ + + HANDLE hFile; + WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'}; + + HANDLE hFileMapping; + + /* Initialize the PAL environment. + */ + if(0 != PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* Create a file handle with CreateFile, as READONLY + */ + hFile = CreateFile( lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hFile == INVALID_HANDLE_VALUE) + { + Fail("ERROR: %u :unable to create file \"%s\".\n", + GetLastError(), + lpFileName); + } + + /* Attempt to create a unnamed file-mapping object to a READONLY file + * as READWRITE access. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and write*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + + if(NULL != hFileMapping) + { + Trace("ERROR: Able to create READWRITE mapping to a " + "READONLY file.\n" ); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + /* Attempt to create a unnamed file-mapping object to a zero lenght + * file. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READWRITE, /*read and write*/ + 0, /*high-order size*/ + 0, /*low-order size*/ + NULL); /*unnamed object*/ + + if( NULL != hFileMapping ) + { + Trace("ERROR: Able to create READWRITE mapping to a " + "READONLY file.\n" ); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + if(GetLastError() != ERROR_ACCESS_DENIED) + { + Trace("ERROR: Expected GetLastError() to return " + "ERROR_FILE_INVALID (%d), it returned %u.\n", + ERROR_FILE_INVALID, + GetLastError()); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + /* Attempt to create a file mapping that is larger than + * the file. + */ + hFileMapping = CreateFileMapping( + hFile, + NULL, /*not inherited*/ + PAGE_READONLY, /*read only*/ + 0, /*high-order size*/ + MAPPINGSIZE, /*low-order size*/ + NULL); /*unnamed object*/ + if(NULL != hFileMapping) + { + Trace("ERROR: Able to create file mapping of size %d to " + "file of size 0.\n", + MAPPINGSIZE); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY ) + { + Trace("ERROR: Expected GetLastError() to return " + "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n", + ERROR_NOT_ENOUGH_MEMORY, + GetLastError()); + if( 0 == CloseHandle(hFile) ) + { + Trace("Unexpected Error: Unable to close file handle\n"); + } + Fail(""); + } + + if( 0 == CloseHandle(hFile) ) + { + Fail("Unexpected Error: Unable to close file handle\n"); + } + + /* Terminate the PAL. + */ + PAL_Terminate(); + return PASS; +} + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat new file mode 100644 index 0000000000..2a7ecdbab7 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat @@ -0,0 +1,12 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Filemapping_memmgt +Function = CreateFileMappingW +Name = CreateFileMappingW negative testing +TYPE = DEFAULT +EXE1 = createfilemapping +Description += Negative test the CreateFileMapping API. |