From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path
Date: Thu, 1 Aug 2024 14:16:31 +0200 [thread overview]
Message-ID: <20240801121631.GA1510503@pevik> (raw)
In-Reply-To: <20240801104004.15514-1-wegao@suse.com>
Hi Wei,
> 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);
FYI, we have custom function, thus no need to detect TMPDIR in the test.
Because this is still the legacy API, could you please use tst_tmpdir_path()?
FYI in the new API We had for a long time tst_get_tmpdir() function needed to
use free() and was used for snprintf(), but Cyril changed that quite recently:
https://github.com/linux-test-project/ltp/commit/c5d95b6d34e2356bd19e6b646da06f1bce66a024
Since that just use tst_tmpdir_path(), no need to free.
IMHO both legacy API and new API do chdir() to the temporary directory, see
lib/tst_tmpdir.c:
if (chdir(TESTDIR) == -1) {
tst_resm(TERRNO, "%s: chdir(%s) failed", __func__, TESTDIR);
Therefore unless there is full path needed (e.g. search in /proc/mounts) we
could use relative path, e.g. add "./" to the definition:
+++ testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
@@ -58,7 +58,7 @@ static int opt_thread;
static int key_id; /* used with opt_shm */
static unsigned long memsize;
-#define FILE_HUGEPAGE "/hugetlb/hugepagefile"
+#define FILE_HUGEPAGE "./hugetlb/hugepagefile"
#define MMAP_ANON (SCHAR_MAX + 1)
#define MMAP_FILE (SCHAR_MAX + 2)
---
Also, the same definition is in
testcases/kernel/controllers/memcg/functional/memcg_process.c, is it affected as
well?
FYI Besides that it's always better to use 'n' sprintf functions (e.g.
snprintf(), because they restrict the write size (man printf(3): "write at most size bytes")
> +
> 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
Could you please use $TMPDIR instead of ${TMPDIR}? (more readable).
> + mount -t hugetlbfs none ${TMPDIR}/hugetlb
And here (there are more places).
BTW just ./hugetlb could work, right? Also, in the shell API we are in the
directory.
And thanks for pointing these tests, once Cyril's effort for mixing C and shell
code is merged, we should adapt these tests to use it.
https://patchwork.ozlabs.org/project/ltp/list/?series=417372&state=*
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-08-01 12:16 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 10:40 [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path Wei Gao via ltp
2024-08-01 12:16 ` Petr Vorel [this message]
2024-08-01 12:20 ` Cyril Hrubis
2024-08-19 4:49 ` [LTP] [PATCH v2] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase Wei Gao via ltp
2024-09-26 6:19 ` [LTP] [PATCH v3] " Wei Gao via ltp
2024-09-27 10:30 ` Cyril Hrubis
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2024-11-01 10:58 ` Petr Vorel
2024-11-05 5:30 ` Wei Gao via ltp
2024-11-05 11:44 ` Petr Vorel
2024-11-07 4:20 ` Wei Gao via ltp
2024-11-08 5:45 ` Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
2025-02-27 16:02 ` Petr Vorel
2024-12-09 6:01 ` [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-02-27 16:04 ` Petr Vorel
2025-03-05 4:29 ` Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
2025-03-06 18:35 ` Petr Vorel
2025-03-10 16:51 ` Cyril Hrubis
2025-03-25 13:36 ` Petr Vorel
2025-03-05 5:08 ` [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-06 18:32 ` Petr Vorel
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
2025-03-25 14:00 ` Petr Vorel
2025-03-26 4:14 ` Wei Gao via ltp
2025-03-26 7:38 ` Li Wang via ltp
2025-03-26 8:26 ` Li Wang via ltp
2025-03-26 9:11 ` Wei Gao via ltp
2025-03-26 11:01 ` Li Wang via ltp
2025-03-26 8:38 ` Li Wang via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-24 15:32 ` Petr Vorel
2025-03-25 3:32 ` Wei Gao via ltp
2025-03-25 3:54 ` Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 1/2] " Wei Gao via ltp
2025-03-28 9:35 ` Li Wang via ltp
2025-03-28 10:20 ` Petr Vorel
2025-03-28 10:57 ` Li Wang via ltp
2025-03-28 11:04 ` Li Wang via ltp
2025-03-28 11:47 ` Petr Vorel
2025-03-28 7:59 ` [LTP] [PATCH v8 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 6:13 ` Wei Gao via ltp
2025-03-31 10:25 ` Petr Vorel
2025-03-31 10:37 ` Petr Vorel
2025-03-31 11:05 ` Li Wang via ltp
2025-03-31 11:30 ` Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 10:58 ` Petr Vorel
2025-03-31 10:21 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Petr Vorel
2025-03-31 13:25 ` [LTP] [PATCH v10 " Wei Gao via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 1/2] " Wei Gao via ltp
2025-04-01 9:58 ` Li Wang via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240801121631.GA1510503@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox