Reenable MapViewOfFile PAL test1 (#11393)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 4 May 2017 20:19:53 +0000 (13:19 -0700)
committerGitHub <noreply@github.com>
Thu, 4 May 2017 20:19:53 +0000 (13:19 -0700)
This change reenables the test that was having problems on systems when the /tmp
is created on tmpfs file system which doesn't support direct access (unbuffered).
The fix is to explicitly use /var/tmp instead (and /data/local/tmp/ on Android).

src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.cpp
src/pal/tests/palsuite/paltestlist.txt

index 6177e0d..6bfb73f 100644 (file)
 **============================================================*/
 #include <palsuite.h>
 #define MAPPINGSIZE 8192
+
+// This test is special - it doesn't work when the file is created on a tmpfs, like the /tmp folder
+// that is the default location for running PAL tests. The reason is that on such filesystem,
+// it is not possible to create file with FILE_FLAG_NO_BUFFERING.
+// So we explicitly use the /var/tmp that cannot be on tmpfs, since it it persistent over reboots.
+
+#ifndef __ANDROID__
+#define TEMP_DIRECTORY_PATH "/var/tmp/"
+#else
+// On Android, "/var/tmp/" doesn't exist; temporary files should go to /data/local/tmp/
+#define TEMP_DIRECTORY_PATH "/data/local/tmp/"
+#endif
+
 int __cdecl main(int argc, char *argv[])
 {
 
     HANDLE  hFile = INVALID_HANDLE_VALUE;
     LPSTR   buf = NULL;
     CHAR    ch[MAPPINGSIZE];
-    CHAR    lpFileName[] = "test.tmp";
+    CHAR    lpFilePath[MAX_PATH];
     DWORD   dwBytesWritten = 0;
     DWORD   dwInitialSize = 0;
     DWORD   dwFinalSize = 0;
@@ -36,9 +49,11 @@ int __cdecl main(int argc, char *argv[])
         return FAIL;
     }
 
+    GetTempFileName(TEMP_DIRECTORY_PATH, "tst", 0, lpFilePath);
+
     /* Create a file handle with CreateFile.
      */
-    hFile = CreateFile( lpFileName,
+    hFile = CreateFile( lpFilePath,
                         GENERIC_WRITE|GENERIC_READ,
                         FILE_SHARE_READ|FILE_SHARE_WRITE,
                         NULL,
@@ -49,7 +64,7 @@ int __cdecl main(int argc, char *argv[])
     if (hFile == INVALID_HANDLE_VALUE)
     {
         Fail( "ERROR: %u :unable to create file \"%s\".\n",
-              GetLastError(), lpFileName);
+              GetLastError(), lpFilePath);
     }
 
     /* Get the initial size of file, for latter tests.
@@ -58,7 +73,7 @@ int __cdecl main(int argc, char *argv[])
     if ( INVALID_FILE_SIZE == dwInitialSize )
     {
         Fail("ERROR:%u: The created file \"%s\" has an invalid "
-             "file size.\n",GetLastError(),lpFileName);
+             "file size.\n",GetLastError(),lpFilePath);
     }
 
     /*
@@ -220,6 +235,9 @@ int __cdecl main(int argc, char *argv[])
     }
     
     VirtualFree( buf, 0, MEM_RELEASE );
+
+    DeleteFile(lpFilePath);
+
     PAL_Terminate();
     return PASS;
 }
index f0dfe3f..1e580cd 100644 (file)
@@ -473,6 +473,7 @@ filemapping_memmgt/LocalFree/test1/paltest_localfree_test1
 filemapping_memmgt/LocalFree/test2/paltest_localfree_test2
 filemapping_memmgt/LockFile/test2/paltest_lockfile_test2
 filemapping_memmgt/LockFile/test7/paltest_lockfile_test7
+filemapping_memmgt/MapViewOfFile/test1/paltest_mapviewoffile_test1
 filemapping_memmgt/MapViewOfFile/test2/paltest_mapviewoffile_test2
 filemapping_memmgt/MapViewOfFile/test3/paltest_mapviewoffile_test3
 filemapping_memmgt/MapViewOfFile/test4/paltest_mapviewoffile_test4