aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils.c
diff options
context:
space:
mode:
authorNishanth Aravamudan <nacc@us.ibm.com>2008-04-01 18:57:48 -0700
committerNishanth Aravamudan <nacc@us.ibm.com>2008-04-08 15:59:21 -0700
commitd71e601c426ca56527e7ce91cb554f800ef4564a (patch)
tree9603838df1fa40e9c7a42d305f08b02a3eb624fc /tests/testutils.c
parent1ce352db79491bbd25cbbd7f38621636f5327c5e (diff)
downloadlibhugetlbfs-d71e601c426ca56527e7ce91cb554f800ef4564a.tar.gz
tests: check uid/gid in tests where it matters
`make check`, when run as a normal user, currently produces the following output relevant to permissions: quota (32): mount: Operation not permitted FAIL quota (64): mount: Operation not permitted FAIL This is because we are using mount() when we aren't root. Note, that the counters testcase also will do funny things if the dynamic pool is enabled, but we aren't root (not verified at runtime as I was on SLES10-SP1, but based upon code inspection), as it attempts to change /proc/sys/vm/nr_hugepages. ./run_tests.sh: line 117: /proc/sys/kernel/shmmax: Permission denied set shmmax limit to 335544320 ./run_tests.sh: line 119: /proc/sys/kernel/shmall: Permission denied shm-fork 10 10 (32): FAIL shmget(): Cannot allocate memory shm-fork 10 10 (64): FAIL shmget(): Cannot allocate memory shm-fork 10 20 (32): FAIL shmget(): Cannot allocate memory shm-fork 10 20 (64): FAIL shmget(): Cannot allocate memory shm-getraw 20 /dev/full (32): FAIL shmget(): Cannot allocate memory shm-getraw 20 /dev/full (64): FAIL shmget(): Cannot allocate memory ./run_tests.sh: line 123: /proc/sys/kernel/shmmax: Permission denied ./run_tests.sh: line 124: /proc/sys/kernel/shmall: Permission denied make: *** [stress] Error 1 This is because we are unconditionally writing into a sysctl for the bash errors and within the shm testcases, are using SHM_HUGETLB without verifying our gid is in /proc/sys/vm/hugetlb_shm_group. Add helper functions to testutils to verify we are root and that our gid is the same as that in /proc/sys/vm/hugetlb_shm_group. Now, the same testcase produce: quota (32): Bad configuration: Must be root quota (64): Bad configuration: Must be root counters (32): Bad configuration: Must be root counters (64): Bad configuration: Must be root shm-fork 10 10 (32): Bad configuration: Do not have permission to use SHM_HUGETLB shm-fork 10 10 (64): Bad configuration: Do not have permission to use SHM_HUGETLB shm-fork 10 20 (32): Bad configuration: Do not have permission to use SHM_HUGETLB shm-fork 10 20 (64): Bad configuration: Do not have permission to use SHM_HUGETLB shm-getraw 20 /dev/full (32): Bad configuration: Do not have permission to use SHM_HUGETLB shm-getraw 20 /dev/full (64): Bad configuration: Do not have permission to use SHM_HUGETLB And make no longer fails. Tested as both root and non-root with hugetlbfs mount permissions set to 01777. Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Diffstat (limited to 'tests/testutils.c')
-rw-r--r--tests/testutils.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/testutils.c b/tests/testutils.c
index bd17704..5495785 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -50,6 +50,36 @@ void check_free_huge_pages(int nr_pages_needed)
CONFIG("Must have at least %i free hugepages", nr_pages_needed);
}
+void check_must_be_root(void)
+{
+ uid_t uid = getuid();
+ if (uid != 0)
+ CONFIG("Must be root");
+}
+
+void check_hugetlb_shm_group(void)
+{
+ int fd;
+ ssize_t ret;
+ gid_t hugetlb_shm_group;
+ gid_t gid = getgid();
+ uid_t uid = getuid();
+
+ /* root is an exception */
+ if (uid == 0)
+ return;
+
+ fd = open("/proc/sys/vm/hugetlb_shm_group", O_RDONLY);
+ if (fd < 0)
+ ERROR("Unable to open /proc/sys/vm/hugetlb_shm_group");
+ ret = read(fd, &hugetlb_shm_group, sizeof(hugetlb_shm_group));
+ if (ret < 0)
+ ERROR("Unable to read /proc/sys/vm/hugetlb_shm_group");
+ close(fd);
+ if (hugetlb_shm_group != gid)
+ CONFIG("Do not have permission to use SHM_HUGETLB");
+}
+
void __attribute__((weak)) cleanup(void)
{
}