mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 01:32:21 +02:00
kselftest/filelock: report each test in oftlocks separately
The filelock test checks four different things but only reports an overall status, convert to use ksft_test_result() for these individual tests. Each test depends on the previous ones so we still bail out if any of them fail but we get a bit more information from UIs parsing the results. Link: https://lore.kernel.org/20260226-selftest-filelock-ktap-v4-2-db8ae192ff42@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org> Cc: Jeff Layton <jlayton@kernel.org> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
47d020e233
commit
33d5b13098
|
|
@ -39,94 +39,82 @@ int main(void)
|
|||
int fd = open("/tmp/aa", O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
int fd2 = open("/tmp/aa", O_RDONLY);
|
||||
|
||||
ksft_print_header();
|
||||
ksft_set_plan(4);
|
||||
|
||||
unlink("/tmp/aa");
|
||||
assert(fd != -1);
|
||||
assert(fd2 != -1);
|
||||
ksft_print_msg("[INFO] opened fds %i %i\n", fd, fd2);
|
||||
ksft_print_msg("opened fds %i %i\n", fd, fd2);
|
||||
|
||||
/* Set some read lock */
|
||||
fl.l_type = F_RDLCK;
|
||||
fl.l_start = 5;
|
||||
fl.l_len = 3;
|
||||
rc = lock_set(fd, &fl);
|
||||
if (rc == 0) {
|
||||
ksft_print_msg
|
||||
("[SUCCESS] set OFD read lock on first fd\n");
|
||||
} else {
|
||||
ksft_print_msg("[FAIL] to set OFD read lock on first fd\n");
|
||||
return -1;
|
||||
}
|
||||
ksft_test_result(rc == 0, "set OFD read lock on first fd\n");
|
||||
if (rc != 0)
|
||||
ksft_finished();
|
||||
|
||||
/* Make sure read locks do not conflict on different fds. */
|
||||
fl.l_type = F_RDLCK;
|
||||
fl.l_start = 5;
|
||||
fl.l_len = 1;
|
||||
rc = lock_get(fd2, &fl);
|
||||
if (rc != 0)
|
||||
return -1;
|
||||
if (fl.l_type != F_UNLCK) {
|
||||
ksft_print_msg("[FAIL] read locks conflicted\n");
|
||||
return -1;
|
||||
}
|
||||
ksft_finished();
|
||||
if (fl.l_type != F_UNLCK)
|
||||
ksft_exit_fail_msg("read locks conflicted\n");
|
||||
|
||||
/* Make sure read/write locks do conflict on different fds. */
|
||||
fl.l_type = F_WRLCK;
|
||||
fl.l_start = 5;
|
||||
fl.l_len = 1;
|
||||
rc = lock_get(fd2, &fl);
|
||||
if (rc != 0)
|
||||
return -1;
|
||||
if (fl.l_type != F_UNLCK) {
|
||||
ksft_print_msg
|
||||
("[SUCCESS] read and write locks conflicted\n");
|
||||
} else {
|
||||
ksft_print_msg
|
||||
("[SUCCESS] read and write locks not conflicted\n");
|
||||
return -1;
|
||||
}
|
||||
ksft_finished();
|
||||
ksft_test_result(fl.l_type != F_UNLCK,
|
||||
"read and write locks conflicted\n");
|
||||
if (fl.l_type == F_UNLCK)
|
||||
ksft_finished();
|
||||
|
||||
/* Get info about the lock on first fd. */
|
||||
fl.l_type = F_UNLCK;
|
||||
fl.l_start = 5;
|
||||
fl.l_len = 1;
|
||||
rc = lock_get(fd, &fl);
|
||||
if (rc != 0) {
|
||||
ksft_print_msg
|
||||
("[FAIL] F_OFD_GETLK with F_UNLCK not supported\n");
|
||||
return -1;
|
||||
}
|
||||
if (fl.l_type != F_UNLCK) {
|
||||
ksft_print_msg
|
||||
("[SUCCESS] F_UNLCK test returns: locked, type %i pid %i len %zi\n",
|
||||
fl.l_type, fl.l_pid, fl.l_len);
|
||||
} else {
|
||||
ksft_print_msg
|
||||
("[FAIL] F_OFD_GETLK with F_UNLCK did not return lock info\n");
|
||||
return -1;
|
||||
}
|
||||
if (rc != 0)
|
||||
ksft_exit_fail_msg("F_OFD_GETLK with F_UNLCK not supported\n");
|
||||
ksft_test_result(fl.l_type != F_UNLCK,
|
||||
"F_OFD_GETLK with F_UNLCK returned lock info\n");
|
||||
if (fl.l_type == F_UNLCK)
|
||||
ksft_exit_fail();
|
||||
ksft_print_msg("F_UNLCK test returns: locked, type %i pid %i len %zi\n",
|
||||
fl.l_type, fl.l_pid, fl.l_len);
|
||||
|
||||
/* Try the same but by locking everything by len==0. */
|
||||
fl2.l_type = F_UNLCK;
|
||||
fl2.l_start = 0;
|
||||
fl2.l_len = 0;
|
||||
rc = lock_get(fd, &fl2);
|
||||
if (rc != 0) {
|
||||
ksft_print_msg
|
||||
("[FAIL] F_OFD_GETLK with F_UNLCK not supported\n");
|
||||
return -1;
|
||||
}
|
||||
if (rc != 0)
|
||||
ksft_exit_fail_msg
|
||||
("F_OFD_GETLK with F_UNLCK not supported\n");
|
||||
ksft_test_result(memcmp(&fl, &fl2, sizeof(fl)) == 0,
|
||||
"F_UNLCK with len==0 returned the same\n");
|
||||
if (memcmp(&fl, &fl2, sizeof(fl))) {
|
||||
ksft_print_msg
|
||||
("[FAIL] F_UNLCK test returns: locked, type %i pid %i len %zi\n",
|
||||
ksft_exit_fail_msg
|
||||
("F_UNLCK test returns: locked, type %i pid %i len %zi\n",
|
||||
fl.l_type, fl.l_pid, fl.l_len);
|
||||
return -1;
|
||||
}
|
||||
ksft_print_msg("[SUCCESS] F_UNLCK with len==0 returned the same\n");
|
||||
|
||||
/* Get info about the lock on second fd - no locks on it. */
|
||||
fl.l_type = F_UNLCK;
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
lock_get(fd2, &fl);
|
||||
if (fl.l_type != F_UNLCK) {
|
||||
ksft_print_msg
|
||||
("[FAIL] F_OFD_GETLK with F_UNLCK return lock info from another fd\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
ksft_test_result(fl.l_type == F_UNLCK,
|
||||
"F_OFD_GETLK with F_UNLCK return lock info from another fd\n");
|
||||
|
||||
ksft_finished();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user