@@ -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.
@@ -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;
}
@@ -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)
@@ -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)
@@ -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)
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(-)