* [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues @ 2026-04-06 13:30 Jinseok Kim 2026-04-06 13:31 ` [LTP] [PATCH 2/2] close: add test for double close EBADF Jinseok Kim 2026-04-09 8:08 ` [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Petr Vorel 0 siblings, 2 replies; 10+ messages in thread From: Jinseok Kim @ 2026-04-06 13:30 UTC (permalink / raw) To: ltp Remove unused headers (<stdio.h>, <errno.h>, <sys/stat.h>) from close01.c and (<stdio.h>, <sys/stat.h>) from close02.c. Also make struct test_case_t static and apply minor style fixes. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/close/close01.c | 6 ++---- testcases/kernel/syscalls/close/close02.c | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/close/close01.c b/testcases/kernel/syscalls/close/close01.c index 4e4f107ef..616752595 100644 --- a/testcases/kernel/syscalls/close/close01.c +++ b/testcases/kernel/syscalls/close/close01.c @@ -8,10 +8,7 @@ * Test that closing a file/pipe/socket works correctly. */ -#include <stdio.h> -#include <errno.h> #include <fcntl.h> -#include <sys/stat.h> #include "tst_test.h" #define FILENAME "close01_testfile" @@ -24,6 +21,7 @@ static int get_fd_file(void) static int get_fd_pipe(void) { int pipefildes[2]; + SAFE_PIPE(pipefildes); SAFE_CLOSE(pipefildes[1]); return pipefildes[0]; @@ -34,7 +32,7 @@ static int get_fd_socket(void) return SAFE_SOCKET(AF_INET, SOCK_STREAM, 0); } -struct test_case_t { +static struct test_case_t { int (*get_fd) (); char *type; } tc[] = { diff --git a/testcases/kernel/syscalls/close/close02.c b/testcases/kernel/syscalls/close/close02.c index 2016453f8..617c48237 100644 --- a/testcases/kernel/syscalls/close/close02.c +++ b/testcases/kernel/syscalls/close/close02.c @@ -8,9 +8,7 @@ * Call close(-1) and expects it to return EBADF. */ -#include <stdio.h> #include <errno.h> -#include <sys/stat.h> #include "tst_test.h" static void run(void) -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [LTP] [PATCH 2/2] close: add test for double close EBADF 2026-04-06 13:30 [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Jinseok Kim @ 2026-04-06 13:31 ` Jinseok Kim 2026-04-09 8:15 ` Petr Vorel 2026-04-09 8:08 ` [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Petr Vorel 1 sibling, 1 reply; 10+ messages in thread From: Jinseok Kim @ 2026-04-06 13:31 UTC (permalink / raw) To: ltp Verify that calling close() on an already closed file descriptor fails with EBADF. The existing close tests cover: - close01: successful close on valid file descriptors - close02: invalid file descriptor (-1) This test adds coverage for a common state transition case where a previously valid file descriptor becomes invalid after close(). Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- runtest/syscalls | 1 + testcases/kernel/syscalls/close/.gitignore | 1 + testcases/kernel/syscalls/close/close03.c | 26 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 testcases/kernel/syscalls/close/close03.c diff --git a/runtest/syscalls b/runtest/syscalls index 5a2e8f048..71c2b9ec5 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -134,6 +134,7 @@ clone304 clone304 close01 close01 close02 close02 +close03 close03 close_range01 close_range01 close_range02 close_range02 diff --git a/testcases/kernel/syscalls/close/.gitignore b/testcases/kernel/syscalls/close/.gitignore index 07d25bccf..1ed7e45cf 100644 --- a/testcases/kernel/syscalls/close/.gitignore +++ b/testcases/kernel/syscalls/close/.gitignore @@ -1,2 +1,3 @@ /close01 /close02 +/close03 diff --git a/testcases/kernel/syscalls/close/close03.c b/testcases/kernel/syscalls/close/close03.c new file mode 100644 index 000000000..38950d00c --- /dev/null +++ b/testcases/kernel/syscalls/close/close03.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ + +/*\ + * Verify that calling close() twice on the same fd returns EBADF on + * the second call. + */ + +#include <errno.h> +#include <fcntl.h> +#include "tst_test.h" + +static void run(void) +{ + int fd = SAFE_OPEN("close03", O_CREAT, 0600); + + TST_EXP_PASS(close(fd)); + TST_EXP_FAIL(close(fd), EBADF); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .test_all = run, +}; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH 2/2] close: add test for double close EBADF 2026-04-06 13:31 ` [LTP] [PATCH 2/2] close: add test for double close EBADF Jinseok Kim @ 2026-04-09 8:15 ` Petr Vorel 2026-04-11 11:04 ` [LTP] [PATCH v2] " Jinseok Kim 0 siblings, 1 reply; 10+ messages in thread From: Petr Vorel @ 2026-04-09 8:15 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp > Verify that calling close() on an already closed file descriptor fails > with EBADF. > The existing close tests cover: > - close01: successful close on valid file descriptors > - close02: invalid file descriptor (-1) > This test adds coverage for a common state transition case where a > previously valid file descriptor becomes invalid after close(). IMHO it'd make sense to add this errno check to close02.c (using .tcnt). ... > --- /dev/null > +++ b/testcases/kernel/syscalls/close/close03.c > @@ -0,0 +1,26 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> > + */ > + > +/*\ > + * Verify that calling close() twice on the same fd returns EBADF on Please instead of close() use: :manpage:`close(2)` That will provide link to man page https://man7.org/linux/man-pages/man2/close.2.html in our test catalog: https://linux-test-project.readthedocs.io/en/latest/users/test_catalog.html Kind regards, Petr > + * the second call. > + */ > + > +#include <errno.h> > +#include <fcntl.h> > +#include "tst_test.h" > + > +static void run(void) > +{ > + int fd = SAFE_OPEN("close03", O_CREAT, 0600); > + > + TST_EXP_PASS(close(fd)); > + TST_EXP_FAIL(close(fd), EBADF); > +} > + > +static struct tst_test test = { > + .needs_tmpdir = 1, > + .test_all = run, > +}; -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v2] close: add test for double close EBADF 2026-04-09 8:15 ` Petr Vorel @ 2026-04-11 11:04 ` Jinseok Kim 2026-04-13 4:33 ` Li Wang 0 siblings, 1 reply; 10+ messages in thread From: Jinseok Kim @ 2026-04-11 11:04 UTC (permalink / raw) To: pvorel; +Cc: ltp Verify that calling close() on an already closed file descriptor fails with EBADF. This test adds coverage for a common state transition case where a previously valid file descriptor becomes invalid after close(). Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- Changes in v2: - Add additional test coverage to close02 instead of creating a separate close03 test. - Link to v1: https://lore.kernel.org/ltp/20260406133134.17238-2-always.starving0@gmail.com --- testcases/kernel/syscalls/close/close02.c | 42 ++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/testcases/kernel/syscalls/close/close02.c b/testcases/kernel/syscalls/close/close02.c index 617c48237..768361e56 100644 --- a/testcases/kernel/syscalls/close/close02.c +++ b/testcases/kernel/syscalls/close/close02.c @@ -5,17 +5,51 @@ */ /*\ - * Call close(-1) and expects it to return EBADF. + * Verify :manpage:`close(2)` failure cases: + * + * 1) close(-1) returns EBADF. + * 2) closing the same fd twice returns EBADF on the second call. */ #include <errno.h> +#include <fcntl.h> + #include "tst_test.h" -static void run(void) +enum case_type { + INVALID_FD, + DOUBLE_CLOSE, +}; + +static struct tcase { + const char *desc; + enum case_type type; +} tcases[] = { + { "close(-1)", INVALID_FD }, + { "close same fd twice", DOUBLE_CLOSE }, +}; + +static void verify_close(unsigned int i) { - TST_EXP_FAIL(close(-1), EBADF); + int fd; + struct tcase *tc = &tcases[i]; + + switch (tc->type) { + case INVALID_FD: + TST_EXP_FAIL(close(-1), EBADF, "%s", tc->desc); + break; + + case DOUBLE_CLOSE: + fd = SAFE_OPEN("close02", O_CREAT, 0600); + + TST_EXP_PASS(close(fd), "%s: first close()", tc->desc); + TST_EXP_FAIL(close(fd), EBADF, "%s: second close()", tc->desc); + break; + } } static struct tst_test test = { - .test_all = run, + .needs_tmpdir = 1, + .tcnt = ARRAY_SIZE(tcases), + .test = verify_close, }; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v2] close: add test for double close EBADF 2026-04-11 11:04 ` [LTP] [PATCH v2] " Jinseok Kim @ 2026-04-13 4:33 ` Li Wang 2026-04-13 11:30 ` Petr Vorel 2026-04-13 16:52 ` [LTP] [PATCH v3] " Jinseok Kim 0 siblings, 2 replies; 10+ messages in thread From: Li Wang @ 2026-04-13 4:33 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp On Sat, 11 Apr 2026 at 19:04, Jinseok Kim <always.starving0@gmail.com> wrote: > > Verify that calling close() on an already closed file descriptor fails > with EBADF. > > This test adds coverage for a common state transition case where a > previously valid file descriptor becomes invalid after close(). > > Signed-off-by: Jinseok Kim <always.starving0@gmail.com> > --- > Changes in v2: > - Add additional test coverage to close02 instead of creating a separate > close03 test. > - Link to v1: https://lore.kernel.org/ltp/20260406133134.17238-2-always.starving0@gmail.com > --- > testcases/kernel/syscalls/close/close02.c | 42 ++++++++++++++++++++--- > 1 file changed, 38 insertions(+), 4 deletions(-) > > diff --git a/testcases/kernel/syscalls/close/close02.c b/testcases/kernel/syscalls/close/close02.c > index 617c48237..768361e56 100644 > --- a/testcases/kernel/syscalls/close/close02.c > +++ b/testcases/kernel/syscalls/close/close02.c > @@ -5,17 +5,51 @@ > */ > > /*\ > - * Call close(-1) and expects it to return EBADF. > + * Verify :manpage:`close(2)` failure cases: > + * > + * 1) close(-1) returns EBADF. > + * 2) closing the same fd twice returns EBADF on the second call. > */ > > #include <errno.h> > +#include <fcntl.h> > + > #include "tst_test.h" > > -static void run(void) > +enum case_type { > + INVALID_FD, > + DOUBLE_CLOSE, > +}; > + > +static struct tcase { > + const char *desc; > + enum case_type type; > +} tcases[] = { > + { "close(-1)", INVALID_FD }, > + { "close same fd twice", DOUBLE_CLOSE }, > +}; > + > +static void verify_close(unsigned int i) > { > - TST_EXP_FAIL(close(-1), EBADF); > + int fd; > + struct tcase *tc = &tcases[i]; > + > + switch (tc->type) { > + case INVALID_FD: > + TST_EXP_FAIL(close(-1), EBADF, "%s", tc->desc); > + break; > + > + case DOUBLE_CLOSE: > + fd = SAFE_OPEN("close02", O_CREAT, 0600); According to the open(2) man page, the flags argument must include one of the access modes: O_RDONLY, O_WRONLY, or O_RDWR. For example: fd = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600); With the flag updated to include an access mode (like O_RDWR), it will look good to me: Reviewed-by: Li Wang <wangli.ahau@gmail.com> -- Regards, Li Wang Email: wangli.ahau@gmail.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v2] close: add test for double close EBADF 2026-04-13 4:33 ` Li Wang @ 2026-04-13 11:30 ` Petr Vorel 2026-04-13 16:52 ` [LTP] [PATCH v3] " Jinseok Kim 1 sibling, 0 replies; 10+ messages in thread From: Petr Vorel @ 2026-04-13 11:30 UTC (permalink / raw) To: Li Wang; +Cc: ltp Hi all, ... > > +static void verify_close(unsigned int i) > > { > > - TST_EXP_FAIL(close(-1), EBADF); > > + int fd; > > + struct tcase *tc = &tcases[i]; > > + > > + switch (tc->type) { > > + case INVALID_FD: > > + TST_EXP_FAIL(close(-1), EBADF, "%s", tc->desc); > > + break; > > + > > + case DOUBLE_CLOSE: > > + fd = SAFE_OPEN("close02", O_CREAT, 0600); > According to the open(2) man page, the flags argument must include one > of the access modes: O_RDONLY, O_WRONLY, or O_RDWR. Good catch, Li. > For example: > fd = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600); > With the flag updated to include an access mode (like O_RDWR), > it will look good to me: > Reviewed-by: Li Wang <wangli.ahau@gmail.com> Agree. Reviewed-by: Petr Vorel <pvorel@suse.cz> And welcome back. Feel free to update .mailmap to the new address. Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3] close: add test for double close EBADF 2026-04-13 4:33 ` Li Wang 2026-04-13 11:30 ` Petr Vorel @ 2026-04-13 16:52 ` Jinseok Kim 2026-04-13 18:04 ` [LTP] " linuxtestproject.agent 2026-04-13 20:45 ` [LTP] [PATCH v3] " Petr Vorel 1 sibling, 2 replies; 10+ messages in thread From: Jinseok Kim @ 2026-04-13 16:52 UTC (permalink / raw) To: wangli.ahau, pvorel; +Cc: ltp Verify that calling close() on an already closed file descriptor fails with EBADF. This test adds coverage for a common state transition case where a previously valid file descriptor becomes invalid after close(). Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- Changes in v3: - Add O_RDWR flag to SAFE_OPEN - Link to v2: https://lore.kernel.org/ltp/20260411110405.7330-1-always.starving0@gmail.com Changes in v2: - Add additional test coverage to close02 instead of creating a separate close03 test. - Link to v1: https://lore.kernel.org/ltp/20260406133134.17238-2-always.starving0@gmail.com --- testcases/kernel/syscalls/close/close02.c | 42 ++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/testcases/kernel/syscalls/close/close02.c b/testcases/kernel/syscalls/close/close02.c index 617c48237..3b3c61b1e 100644 --- a/testcases/kernel/syscalls/close/close02.c +++ b/testcases/kernel/syscalls/close/close02.c @@ -5,17 +5,51 @@ */ /*\ - * Call close(-1) and expects it to return EBADF. + * Verify :manpage:`close(2)` failure cases: + * + * 1) close(-1) returns EBADF. + * 2) closing the same fd twice returns EBADF on the second call. */ #include <errno.h> +#include <fcntl.h> + #include "tst_test.h" -static void run(void) +enum case_type { + INVALID_FD, + DOUBLE_CLOSE, +}; + +static struct tcase { + const char *desc; + enum case_type type; +} tcases[] = { + { "close(-1)", INVALID_FD }, + { "close same fd twice", DOUBLE_CLOSE }, +}; + +static void verify_close(unsigned int i) { - TST_EXP_FAIL(close(-1), EBADF); + int fd; + struct tcase *tc = &tcases[i]; + + switch (tc->type) { + case INVALID_FD: + TST_EXP_FAIL(close(-1), EBADF, "%s", tc->desc); + break; + + case DOUBLE_CLOSE: + fd = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600); + + TST_EXP_PASS(close(fd), "%s: first close()", tc->desc); + TST_EXP_FAIL(close(fd), EBADF, "%s: second close()", tc->desc); + break; + } } static struct tst_test test = { - .test_all = run, + .needs_tmpdir = 1, + .tcnt = ARRAY_SIZE(tcases), + .test = verify_close, }; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] close: add test for double close EBADF 2026-04-13 16:52 ` [LTP] [PATCH v3] " Jinseok Kim @ 2026-04-13 18:04 ` linuxtestproject.agent 2026-04-13 20:45 ` [LTP] [PATCH v3] " Petr Vorel 1 sibling, 0 replies; 10+ messages in thread From: linuxtestproject.agent @ 2026-04-13 18:04 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp, LTP AI Reviewer Hi Jinseok, our agent completed the review of the patch. The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions. On Tue, 14 Apr 2026, Jinseok Kim wrote: > close: add test for double close EBADF Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com> Regards, LTP AI Reviewer -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3] close: add test for double close EBADF 2026-04-13 16:52 ` [LTP] [PATCH v3] " Jinseok Kim 2026-04-13 18:04 ` [LTP] " linuxtestproject.agent @ 2026-04-13 20:45 ` Petr Vorel 1 sibling, 0 replies; 10+ messages in thread From: Petr Vorel @ 2026-04-13 20:45 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi Jinseok, > Verify that calling close() on an already closed file descriptor fails > with EBADF. > This test adds coverage for a common state transition case where a > previously valid file descriptor becomes invalid after close(). > Signed-off-by: Jinseok Kim <always.starving0@gmail.com> > --- > Changes in v3: > - Add O_RDWR flag to SAFE_OPEN > - Link to v2: https://lore.kernel.org/ltp/20260411110405.7330-1-always.starving0@gmail.com > Changes in v2: > - Add additional test coverage to close02 instead of creating a separate > close03 test. > - Link to v1: https://lore.kernel.org/ltp/20260406133134.17238-2-always.starving0@gmail.com > --- > testcases/kernel/syscalls/close/close02.c | 42 ++++++++++++++++++++--- > 1 file changed, 38 insertions(+), 4 deletions(-) > diff --git a/testcases/kernel/syscalls/close/close02.c b/testcases/kernel/syscalls/close/close02.c > index 617c48237..3b3c61b1e 100644 > --- a/testcases/kernel/syscalls/close/close02.c > +++ b/testcases/kernel/syscalls/close/close02.c > @@ -5,17 +5,51 @@ > */ > /*\ > - * Call close(-1) and expects it to return EBADF. > + * Verify :manpage:`close(2)` failure cases: > + * > + * 1) close(-1) returns EBADF. > + * 2) closing the same fd twice returns EBADF on the second call. > */ > #include <errno.h> > +#include <fcntl.h> > + > #include "tst_test.h" > -static void run(void) > +enum case_type { > + INVALID_FD, > + DOUBLE_CLOSE, > +}; > + > +static struct tcase { > + const char *desc; > + enum case_type type; > +} tcases[] = { > + { "close(-1)", INVALID_FD }, > + { "close same fd twice", DOUBLE_CLOSE }, I'd slightly prefer to have fd and errnos here in the struct: int fd; int exp_errno; Specially with other changes below. This way will follow more LTP errno test approach and enum case_type will not be needed. > +}; > + > +static void verify_close(unsigned int i) > { > - TST_EXP_FAIL(close(-1), EBADF); > + int fd; > + struct tcase *tc = &tcases[i]; > + > + switch (tc->type) { > + case INVALID_FD: > + TST_EXP_FAIL(close(-1), EBADF, "%s", tc->desc); > + break; > + > + case DOUBLE_CLOSE: > + fd = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600); > + > + TST_EXP_PASS(close(fd), "%s: first close()", tc->desc); Thinking about it twice, I would move SAFE_OPEN() together with this line converted to SAFE_CLOSE() to setup(). Why? We test errnos, therefore this is really just a preparation. Then, the runtime would really be TST_EXP_PASS(close(tc->fd), "%s", tc->desc); Kind regards, Petr > + TST_EXP_FAIL(close(fd), EBADF, "%s: second close()", tc->desc); > + break; > + } > } > static struct tst_test test = { > - .test_all = run, > + .needs_tmpdir = 1, > + .tcnt = ARRAY_SIZE(tcases), > + .test = verify_close, > }; -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues 2026-04-06 13:30 [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Jinseok Kim 2026-04-06 13:31 ` [LTP] [PATCH 2/2] close: add test for double close EBADF Jinseok Kim @ 2026-04-09 8:08 ` Petr Vorel 1 sibling, 0 replies; 10+ messages in thread From: Petr Vorel @ 2026-04-09 8:08 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi Jinseok, > Remove unused headers (<stdio.h>, <errno.h>, <sys/stat.h>) from close01.c > and (<stdio.h>, <sys/stat.h>) from close02.c. > Also make struct test_case_t static and apply minor style fixes. Thanks, patch merged. Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-04-13 20:45 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-06 13:30 [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Jinseok Kim 2026-04-06 13:31 ` [LTP] [PATCH 2/2] close: add test for double close EBADF Jinseok Kim 2026-04-09 8:15 ` Petr Vorel 2026-04-11 11:04 ` [LTP] [PATCH v2] " Jinseok Kim 2026-04-13 4:33 ` Li Wang 2026-04-13 11:30 ` Petr Vorel 2026-04-13 16:52 ` [LTP] [PATCH v3] " Jinseok Kim 2026-04-13 18:04 ` [LTP] " linuxtestproject.agent 2026-04-13 20:45 ` [LTP] [PATCH v3] " Petr Vorel 2026-04-09 8:08 ` [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Petr Vorel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox