From: Tarun Sahu <tsahu@linux.ibm.com>
To: ltp@lists.linux.it
Cc: geetika@linux.ibm.com, sbhat@linux.ibm.com,
aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com,
mike.kravetz@oracle.com
Subject: [LTP] [PATCH v5 1/7] Hugetlb: Add new argument flags in tst_creat_unlinked
Date: Mon, 21 Nov 2022 00:45:27 +0530 [thread overview]
Message-ID: <20221120191533.164848-2-tsahu@linux.ibm.com> (raw)
In-Reply-To: <20221120191533.164848-1-tsahu@linux.ibm.com>
Some test requires custom flags for file opened by tst_creat_unlinked
along with O_CREAT|O_EXCL|O_RDWR. This patch creates support to pass
custom flags in tst_creat_unlinked.
Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
include/tst_test.h | 2 +-
lib/tst_test.c | 16 ++++++++++++----
.../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 2 +-
.../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 2 +-
.../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 2 +-
5 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/include/tst_test.h b/include/tst_test.h
index acf2421de..a62515bfe 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -365,7 +365,7 @@ void tst_set_max_runtime(int max_runtime);
* Create and open a random file inside the given dir path.
* It unlinks the file after opening and return file descriptor.
*/
-int tst_creat_unlinked(const char *path);
+int tst_creat_unlinked(const char *path, int flags);
/*
* Returns path to the test temporary directory in a newly allocated buffer.
diff --git a/lib/tst_test.c b/lib/tst_test.c
index b225ba082..9c4c4f064 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1027,18 +1027,26 @@ static void prepare_and_mount_hugetlb_fs(void)
mntpoint_mounted = 1;
}
-int tst_creat_unlinked(const char *path)
+int tst_creat_unlinked(const char *path, int flags)
{
char template[PATH_MAX];
+ int len, c, range;
int fd;
+ int start[3] = {'0', 'a', 'A'};
snprintf(template, PATH_MAX, "%s/ltp_%.3sXXXXXX",
path, tid);
- fd = mkstemp(template);
- if (fd < 0)
- tst_brk(TBROK | TERRNO, "mkstemp(%s) failed", template);
+ len = strlen(template) - 1;
+ while (template[len] == 'X') {
+ c = rand() % 3;
+ range = start[c] == '0' ? 10 : 26;
+ c = start[c] + (rand() % range);
+ template[len--] = (char)c;
+ }
+ flags |= O_CREAT|O_EXCL|O_RDWR;
+ fd = SAFE_OPEN(template, flags);
SAFE_UNLINK(template);
return fd;
}
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
index bd0fb440a..3122d5b9d 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
@@ -113,7 +113,7 @@ cleanup:
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
- huge_fd = tst_creat_unlinked(MNTPOINT);
+ huge_fd = tst_creat_unlinked(MNTPOINT, 0);
}
static void cleanup(void)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
index ce40e7b69..f66b331dc 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
@@ -118,7 +118,7 @@ static void run_test(unsigned int test_type)
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
- huge_fd = tst_creat_unlinked(MNTPOINT);
+ huge_fd = tst_creat_unlinked(MNTPOINT, 0);
}
static void cleanup(void)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
index 1008395a4..ceb0f64a1 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
@@ -60,7 +60,7 @@ static void run_test(void)
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
- huge_fd = tst_creat_unlinked(MNTPOINT);
+ huge_fd = tst_creat_unlinked(MNTPOINT, 0);
}
static void cleanup(void)
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-11-20 19:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-20 19:15 [LTP] [PATCH v5 0/7][PART 2] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-11-20 19:15 ` Tarun Sahu [this message]
2022-11-24 11:55 ` [LTP] [PATCH v5 1/7] Hugetlb: Add new argument flags in tst_creat_unlinked Cyril Hrubis
2022-11-20 19:15 ` [LTP] [PATCH v5 2/7] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 3/7] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 4/7] Hugetlb: Safe macro for posix_fadvise call Tarun Sahu
2022-11-24 11:59 ` Cyril Hrubis
2022-11-25 17:34 ` Tarun Sahu
2022-11-25 18:59 ` Cyril Hrubis
2022-11-20 19:15 ` [LTP] [PATCH v5 5/7] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-11-20 19:15 ` [LTP] [PATCH v5 6/7] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
2022-11-24 14:51 ` Cyril Hrubis
2022-11-20 19:15 ` [LTP] [PATCH v5 7/7] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu
2022-11-25 22:37 ` [LTP] [PATCH v6 1/2] Hugetlb: Safe macro for posix_fadvise call Tarun Sahu
2022-11-25 22:37 ` [LTP] [PATCH v6 2/2] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-11-29 16:21 ` [LTP] [PATCH v6 1/2] Hugetlb: Safe macro for posix_fadvise call Cyril Hrubis
2022-12-01 8:35 ` Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 0/8][PART 3] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 1/8] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 2/8] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 3/8] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 4/8] Hugetlb: Migrating libhugetlbfs icache-hygiene Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 5/8] Hugetlb: Migrating libhugetlbfs madvise_reserve Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 6/8] Hugetlb: Migrating libhugetlbfs map_high_truncate_2 Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 7/8] Hugetlb: Migrating libhugetlbfs misalign Tarun Sahu
2022-12-01 12:02 ` [LTP] [PATCH 8/8] Hugetlb: Migrating libhugetlbfs misaligned_offset Tarun Sahu
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=20221120191533.164848-2-tsahu@linux.ibm.com \
--to=tsahu@linux.ibm.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=geetika@linux.ibm.com \
--cc=ltp@lists.linux.it \
--cc=mike.kravetz@oracle.com \
--cc=sbhat@linux.ibm.com \
--cc=vaibhav@linux.ibm.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