[LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path
Wei Gao
wegao@suse.com
Thu Aug 1 12:40:04 CEST 2024
Test case will fail with following error if running operation system
which force root path read ONLY.
mkdir: cannot create directory ‘/hugetlb’: Read-only file system
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../cpuset_memory_test/cpuset_memory_test.c | 11 ++++++++---
.../cpuset_memory_test/cpuset_memory_testset.sh | 16 ++++++++--------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
index 9912d8d6a..73770fd3c 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
@@ -177,9 +177,14 @@ void mmap_file(int flag_allocated)
static int fd_hugepage;
int fd_tmp;
+ char path[100];
+ char *tmpdir = getenv("TMPDIR");
+
+ sprintf(path, "%s%s", tmpdir, FILE_HUGEPAGE);
+
if (!flag_allocated) {
if (opt_hugepage) {
- fd_hugepage = open(FILE_HUGEPAGE,
+ fd_hugepage = open(path,
O_CREAT | O_RDWR, 0755);
if (fd_hugepage < 0)
err(1, "open hugepage file failed");
@@ -191,7 +196,7 @@ void mmap_file(int flag_allocated)
MAP_SHARED, fd_tmp, 0);
if (p == MAP_FAILED) {
if (opt_hugepage)
- unlink(FILE_HUGEPAGE);
+ unlink(path);
err(1, "mmap(file) failed");
}
touch_memory_and_echo_node(p, memsize);
@@ -201,7 +206,7 @@ void mmap_file(int flag_allocated)
if (opt_hugepage) {
close(fd_hugepage);
- unlink(FILE_HUGEPAGE);
+ unlink(path);
}
}
}
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..b63425088 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -175,8 +175,8 @@ test6()
return 0
fi
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
+ mkdir ${TMPDIR}/hugetlb
+ mount -t hugetlbfs none ${TMPDIR}/hugetlb
save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
@@ -184,8 +184,8 @@ test6()
cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
simple_getresult $! "$CPUSET/0"
- umount /hugetlb
- rmdir /hugetlb
+ umount ${TMPDIR}/hugetlb
+ rmdir ${TMPDIR}/hugetlb
echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
@@ -214,8 +214,8 @@ test7()
return 0
fi
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
+ mkdir ${TMPDIR}/hugetlb
+ mount -t hugetlbfs none ${TMPDIR}/hugetlb
save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
@@ -223,8 +223,8 @@ test7()
cpuset_memory_test --shm --hugepage -s $HUGEPAGESIZE --key=7 >"$MEMORY_RESULT" &
simple_getresult $! "$CPUSET/0"
- umount /hugetlb
- rmdir /hugetlb
+ umount ${TMPDIR}/hugetlb
+ rmdir ${TMPDIR}/hugetlb
echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
--
2.35.3
More information about the ltp
mailing list