Skip to contentSkip to conversation

Add msync04: verify msync() writes back to file

PATCH New [email protected] 2 participants 2 messages Jul 24, 2017 – Jul 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add msync04: verify msync() writes back to file

From: Veronika Kabatova <[email protected]>

Creating a testcase for checking whether msync() succeeds in writing dirty page back to allocated file. Pagemap interface is used to get information about a successful write because of caching mechanisms.

---
 runtest/syscalls                          |   1 +
 testcases/kernel/syscalls/.gitignore      |   1 +
 testcases/kernel/syscalls/msync/msync04.c | 106 ++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 testcases/kernel/syscalls/msync/msync04.c
runtest/syscalls +1 -0
index 2e79ab9..8e1f587 100644
@@ -705,6 +705,7 @@ msgsnd06 msgsnd06
 msync01 msync01
 msync02 msync02
 msync03 msync03
+msync04 msync04
 
 munlock01 munlock01
 munlock02 munlock02
testcases/kernel/syscalls/.gitignore +1 -0
index fdb01f9..6e0af31 100644
@@ -612,6 +612,7 @@
 /msync/msync01
 /msync/msync02
 /msync/msync03
+/msync/msync04
 /munlock/munlock01
 /munlock/munlock02
 /munlockall/munlockall01
testcases/kernel/syscalls/msync/msync04.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/1 Add msync04: verify msync() writes back to file

Hi!
Pushed with minor changes, thanks.

testcases/kernel/syscalls/msync/msync04.c +1 -1
index 741bcfe20..6ad5b7d12 100644
@@ -61,7 +61,7 @@ static void test_msync(void)
 
        pagesize = (off_t)SAFE_SYSCONF(_SC_PAGESIZE);
        test_fd = SAFE_OPEN("msync04/testfile", O_CREAT | O_TRUNC | O_RDWR);
-       SAFE_WRITE(0, test_fd, STRING_TO_WRITE, strlen(STRING_TO_WRITE));
+       SAFE_WRITE(0, test_fd, STRING_TO_WRITE, sizeof(STRING_TO_WRITE) - 1);
 

The sizeof() - 1 == strlen() for string constants but sizeof() is inherently O(1) rather than O(n). I guess that modern enough compiler will probably replace the strlen with sizeof() when optimizing, but that is not a reason to write suboptimal code...

        mmaped_area = SAFE_MMAP(NULL, pagesize, PROT_READ | PROT_WRITE,
                        MAP_SHARED, test_fd, 0);
        SAFE_CLOSE(test_fd);

@@ -85,11 +85,14 @@ static void test_msync(void)

clean:

        SAFE_MUNMAP(mmaped_area, pagesize);

+ mmaped_area = NULL;
}

static void cleanup(void)
{
- SAFE_MUNMAP(mmaped_area, pagesize);
+ if (mmaped_area)
+ SAFE_MUNMAP(mmaped_area, pagesize);
+

        if (test_fd > 0)
                SAFE_CLOSE(test_fd);

I've changed the cleanup to unmap the pointer only if it was mapped. While unlikely the memory pointer could be teoreticaly reused then we will unmap memory mapped possibly by libc or test library in the cleanup.

}
@@ -99,7 +102,6 @@ static struct tst_test test = {
+ .setup = setup,

        .cleanup = cleanup,
        .needs_tmpdir = 1,
        .needs_root = 1,
-       .format_device = 1,
        .mntpoint = "msync04",
        .mount_device = 1,
        .min_kver = "2.6.25",

The mount_device implies format_device as well, so no need to specify both either.

And finally I've moved the pagesize initialization to a setup function, as we do not need to call it repeately in a case of repeated test runs (see the test -i and -I options).

Signature · 2 lines
Cyril Hrubis
[email protected]