1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================ |
6 | ** |
7 | ** Source: test.c |
8 | ** |
9 | ** Purpose: Test for CGroup |
10 | ** |
11 | ** |
12 | ** Steps to run this test on ubuntu: |
13 | ** 1. sudo apt-get install cgroup-bin |
14 | ** 2. sudo vi /etc/default/grub |
15 | ** Add cgroup_enable=memory swapaccount=1 to GRUB_CMDLINE_LINUX_DEFAULT |
16 | ** 3. sudo update-grub |
17 | ** 4. reboot |
18 | ** 5. sudo cgcreate -g cpu,memory:/myGroup -a <username>:<username> -t <username>:<username> |
19 | ** 6. echo 4M > /sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes |
20 | ** 7. echo 4M > /sys/fs/cgroup/memory/mygroup/memory.memsw.limit_in_bytes |
21 | ** 8. cgexe -g memory:/mygroup --sticky <application> |
22 | **=========================================================*/ |
23 | |
24 | #include <palsuite.h> |
25 | |
26 | int __cdecl main(int argc,char *argv[]) |
27 | { |
28 | |
29 | /* |
30 | * Initialize the PAL and return FAILURE if this fails |
31 | */ |
32 | |
33 | if(0 != (PAL_Initialize(argc, argv))) |
34 | { |
35 | return FAIL; |
36 | } |
37 | |
38 | size_t mem_limit = PAL_GetRestrictedPhysicalMemoryLimit(); |
39 | |
40 | FILE* file = fopen("/sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes" , "r" ); |
41 | if(file != NULL) |
42 | { |
43 | if(mem_limit != 4194304) |
44 | Fail("Memory limit obtained from PAL_GetRestrictedPhysicalMemory is not 4MB\n" ); |
45 | fclose(file); |
46 | } |
47 | |
48 | PAL_Terminate(); |
49 | return PASS; |
50 | } |
51 | |
52 | |
53 | |
54 | |