summaryrefslogtreecommitdiff
path: root/src/pal/tests
diff options
context:
space:
mode:
authorrahul <rahku@github.com>2017-03-08 18:55:24 -0800
committerrahul <rahku@github.com>2017-03-22 23:36:32 -0700
commitb2b4ea22fcf71ef61ff84aa9669da2419c7541a5 (patch)
tree786ca53d1256244eb906b121bcf3a9ad1a5a1ea0 /src/pal/tests
parentfc992064a8746119a5f153279838d0cd791fced7 (diff)
downloadcoreclr-b2b4ea22fcf71ef61ff84aa9669da2419c7541a5.tar.gz
coreclr-b2b4ea22fcf71ef61ff84aa9669da2419c7541a5.tar.bz2
coreclr-b2b4ea22fcf71ef61ff84aa9669da2419c7541a5.zip
memory limit in containers on linux
Diffstat (limited to 'src/pal/tests')
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CGroup/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CGroup/test1/CMakeLists.txt17
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CGroup/test1/test.cpp53
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CGroup/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/miscellaneous/CMakeLists.txt1
5 files changed, 87 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/CGroup/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CGroup/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CGroup/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/miscellaneous/CGroup/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CGroup/test1/CMakeLists.txt
new file mode 100644
index 0000000000..cdd7fa99d0
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CGroup/test1/CMakeLists.txt
@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test.cpp
+)
+
+add_executable(paltest_cgroup_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_cgroup_test1 coreclrpal)
+
+target_link_libraries(paltest_cgroup_test1
+ ${COMMON_TEST_LIBRARIES}
+)
diff --git a/src/pal/tests/palsuite/miscellaneous/CGroup/test1/test.cpp b/src/pal/tests/palsuite/miscellaneous/CGroup/test1/test.cpp
new file mode 100644
index 0000000000..44b970a233
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CGroup/test1/test.cpp
@@ -0,0 +1,53 @@
+// 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: test.c
+**
+** Purpose: Test for CGroup
+**
+**
+** Steps to run this test on ubuntu:
+** 1. sudo apt-get install cgroup-bin
+** 2. sudo vi /etc/default/grub
+** Add cgroup_enable=memory swapaccount=1 to GRUB_CMDLINE_LINUX_DEFAULT
+** 3. sudo update-grub
+** 4. reboot
+** 5. sudo cgcreate -g cpu,memory:/myGroup -a <username>:<username> -t <username>:<username>
+** 6. echo 4M > /sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes
+** 7. echo 4M > /sys/fs/cgroup/memory/mygroup/memory.memsw.limit_in_bytes
+** 8. cgexe -g memory:/mygroup --sticky <application>
+**=========================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc,char *argv[])
+{
+
+ /*
+ * Initialize the PAL and return FAILURE if this fails
+ */
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ size_t mem_limit = PAL_GetRestrictedPhysicalMemoryLimit();
+
+ FILE* file = fopen("/sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes", "r");
+ if(file != NULL)
+ {
+ if(mem_limit != 4194304)
+ Fail("Memory limit obtained from PAL_GetRestrictedPhysicalMemory is not 4MB\n");
+ fclose(file);
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
+
diff --git a/src/pal/tests/palsuite/miscellaneous/CGroup/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/CGroup/test1/testinfo.dat
new file mode 100644
index 0000000000..86da2d1515
--- /dev/null
+++ b/src/pal/tests/palsuite/miscellaneous/CGroup/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 = Miscellaneous
+Function = CGroup
+Name = Positive Test for CGroup
+TYPE = DEFAULT
+EXE1 = test
+Description
+= Test to see if Cgroup memory limit works properly
diff --git a/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt
index 0fd4df8ad5..0b5fd37bbb 100644
--- a/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt
+++ b/src/pal/tests/palsuite/miscellaneous/CMakeLists.txt
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8.12.2)
+add_subdirectory(CGroup)
add_subdirectory(CharNextA)
add_subdirectory(CharNextExA)
add_subdirectory(CloseHandle)