diff options
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/malloc')
7 files changed, 160 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/malloc/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/malloc/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt new file mode 100644 index 0000000000..4a388ad3d7 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_malloc_test1 + ${SOURCES} +) + +add_dependencies(paltest_malloc_test1 coreclrpal) + +target_link_libraries(paltest_malloc_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c b/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c new file mode 100644 index 0000000000..7ea4dd068f --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/test1/test1.c @@ -0,0 +1,52 @@ +// 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: test1.c +** +** Purpose: Test that malloc returns useable memory +** +** +**==========================================================================*/ + +#include <palsuite.h> + + +int __cdecl main(int argc, char **argv) +{ + + char *testA; + int i; + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* check that malloc really gives us addressable memory */ + testA = (char *)malloc(20 * sizeof(char)); + if (testA == NULL) + { + Fail("Call to malloc failed.\n"); + } + for (i = 0; i < 20; i++) + { + testA[i] = 'a'; + } + for (i = 0; i < 20; i++) + { + if (testA[i] != 'a') + { + Fail("The memory doesn't seem to be properly allocated.\n"); + } + } + free(testA); + + PAL_Terminate(); + + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/malloc/test1/testinfo.dat new file mode 100644 index 0000000000..9060bc6284 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/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 = C Runtime +Function = malloc +Name = Positive Test for malloc +TYPE = DEFAULT +EXE1 = test1 +Description += Tests that malloc properly allocates memory. diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt new file mode 100644 index 0000000000..abbed2aa62 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_malloc_test2 + ${SOURCES} +) + +add_dependencies(paltest_malloc_test2 coreclrpal) + +target_link_libraries(paltest_malloc_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c b/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c new file mode 100644 index 0000000000..5deee0eddb --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/test2/test2.c @@ -0,0 +1,41 @@ +// 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: test2.c +** +** Purpose: Test that malloc(0) returns non-zero value +** +**==========================================================================*/ + +#include <palsuite.h> + + +int __cdecl main(int argc, char **argv) +{ + + char *testA; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + /* check that malloc(0) returns non-zero value */ + testA = (char *)malloc(0); + if (testA == NULL) + { + Fail("Call to malloc(0) failed.\n"); + } + + free(testA); + + PAL_Terminate(); + + return PASS; +} + + + diff --git a/src/pal/tests/palsuite/c_runtime/malloc/test2/testinfo.dat b/src/pal/tests/palsuite/c_runtime/malloc/test2/testinfo.dat new file mode 100644 index 0000000000..1212a8f8f9 --- /dev/null +++ b/src/pal/tests/palsuite/c_runtime/malloc/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 = C Runtime +Function = malloc +Name = Positive Test for malloc +TYPE = DEFAULT +EXE1 = test2 +Description += Test that malloc(0) returns non-zero value |