summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc')
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c100
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c59
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c62
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat12
10 files changed, 320 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt
new file mode 100644
index 0000000000..1962ade358
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt
new file mode 100644
index 0000000000..3a64a0c58a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapAlloc.c
+)
+
+add_executable(paltest_heapalloc_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapalloc_test1 coreclrpal)
+
+target_link_libraries(paltest_heapalloc_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c
new file mode 100644
index 0000000000..04de274e80
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c
@@ -0,0 +1,100 @@
+// 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: heapalloc.c
+**
+** Purpose: Positive test the HeapAlloc API.
+** Call HeapAlloc by pssing zero as control flag
+** Call HeapAlloc by passing HEAP_ZERO_MEMORY as control flag
+** Call HeapAlloc to allocate one byte heap memory
+** Call HeapAlloc to allocate maximum available heap memory
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 64
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+ /* Initialize the PAL environment */
+ err = PAL_Initialize(argc, argv);
+ if(0 != 0)
+ {
+ ExitProcess(FAIL);
+ }
+
+ /* Retrieve the calling process heap handle */
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ /* allocate a heap memory in specified size */
+ lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */
+ 0, /* control flag */
+ HEAPSIZE); /* /specify the heap size */
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API!\n");
+ }
+
+ /* free the heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+
+ /* allocate a heap memory in 1 byte size */
+ lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */
+ 0, /* control flag */
+ 1); /* specify the heap size*/
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API to allocate one byte heap memory!\n");
+ }
+
+ /* free the heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ /* allocate a heap memory and initialize it to zero */
+ lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */
+ HEAP_ZERO_MEMORY,/* control flag */
+ HEAPSIZE); /* specify the heap size */
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API with HEAP_ZERO_MEMORY control flag!\n");
+ }
+
+ /* free the heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat
new file mode 100644
index 0000000000..9b6064349d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/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 = HeapAlloc
+Name = Positive test for HeapAlloc API
+TYPE = DEFAULT
+EXE1 = heapalloc
+Description
+=Test the HeapAlloc by passing zero as the control flag
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt
new file mode 100644
index 0000000000..5253110d8d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapAlloc.c
+)
+
+add_executable(paltest_heapalloc_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapalloc_test2 coreclrpal)
+
+target_link_libraries(paltest_heapalloc_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c
new file mode 100644
index 0000000000..5f4ff90498
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c
@@ -0,0 +1,59 @@
+// 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: heapalloc.c
+**
+** Purpose: Positive test the HeapAlloc API.
+** Call HeapAlloc with HEAP_ZERO_MEMORY control flag
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 64
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Retrieve the calling process heap handle
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle
+ HEAP_ZERO_MEMORY,//control flag
+ HEAPSIZE); //specify the heap size
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API!\n");
+ }
+
+ //free the heap memory
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat
new file mode 100644
index 0000000000..5c6e77d2cc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/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 = HeapAlloc
+Name = Positive test for HeapAlloc API
+TYPE = DEFAULT
+EXE1 = heapalloc
+Description
+=Test the HeapAlloc with HEAP_ZERO_MEMORY control flag
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt
new file mode 100644
index 0000000000..f0b89461d2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapAlloc.c
+)
+
+add_executable(paltest_heapalloc_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapalloc_test3 coreclrpal)
+
+target_link_libraries(paltest_heapalloc_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c
new file mode 100644
index 0000000000..4a74fe8194
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c
@@ -0,0 +1,62 @@
+// 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: heapalloc.c
+**
+** Purpose: Positive test the HeapAlloc API.
+** Call HeapAlloc asking for zero bytes
+** with HEAP_ZERO_MEMORY control flag
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 0
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Retrieve the calling process heap handle
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle
+ HEAP_ZERO_MEMORY,//control flag
+ HEAPSIZE); //specify the heap size
+
+ //lpHeap should be non-NULL pointer
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API, when number of bytes to be allocated is zero!\n");
+ }
+
+ //free the heap memory
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat
new file mode 100644
index 0000000000..c7d67d3b4f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/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 = HeapAlloc
+Name = Positive test for HeapAlloc API
+TYPE = DEFAULT
+EXE1 = heapalloc
+Description
+=Test the HeapAlloc asking for zero bytes with HEAP_ZERO_MEMORY control flag