Message ID | 20231108074935.1409644-1-pvorel@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | [1/2] link05: Return on link() failure | expand |
Hi! LGTM Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> Regards, Andrea On 11/8/23 08:49, Petr Vorel wrote: > If link() fails to be created, the following stat() failed: > > link05.c:39: TBROK: stat(lkfile_1391822_1,0x7ffd61e5f000) failed: > ENOENT (2) > > Therefore skip testing and improve the error message: > 5: link(lkfile_1404879, lkfile_1404879_5) failed: ENOENT (2) > > Also fix cnt and nlinks condition. > > Signed-off-by: Petr Vorel <pvorel@suse.cz> > --- > @Xu, please merge your "link05: Convert docs to docparse" patchset [1] > first, I'll rebase my afterwards. > > Kind regards, > Petr > > [1] https://lore.kernel.org/ltp/20231108053122.GA1383908@pevik/ > > testcases/kernel/syscalls/link/link05.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/testcases/kernel/syscalls/link/link05.c > b/testcases/kernel/syscalls/link/link05.c > index 9b81ef3fd..1d708c6f6 100644 > --- a/testcases/kernel/syscalls/link/link05.c > +++ b/testcases/kernel/syscalls/link/link05.c > @@ -22,13 +22,16 @@ static int nlinks = 1000; > > static void verify_link(void) > { > - int cnt; > + int cnt = 0, created; > char lname[1024]; > struct stat fbuf, lbuf; > > - for (cnt = 1; cnt < nlinks; cnt++) { > - sprintf(lname, "%s_%d", fname, cnt); > - TST_EXP_PASS_SILENT(link(fname, lname), "link(%s, %s)", > fname, lname); > + for (created = 1; created < nlinks; created++) { > + sprintf(lname, "%s_%d", fname, created); > + TST_EXP_PASS_SILENT(link(fname, lname), "%d: link(%s, %s)", > created, > + fname, lname); > + if (!TST_PASS) > + goto cleanup; > } > > SAFE_STAT(fname, &fbuf); > @@ -48,13 +51,14 @@ static void verify_link(void) > } > } > > - if (cnt >= nlinks) { > + if (cnt == nlinks) { > tst_res(TPASS, > "link(%s, %s[1-%d]) ret %ld for %d files, stat linkcounts > match %d", > fname, fname, nlinks, TST_RET, nlinks, (int)fbuf.st_nlink); > } > > - for (cnt = 1; cnt < nlinks; cnt++) { > +cleanup: > + for (cnt = 1; cnt < created; cnt++) { > sprintf(lname, "%s_%d", fname, cnt); > SAFE_UNLINK(lname); > }
diff --git a/testcases/kernel/syscalls/link/link05.c b/testcases/kernel/syscalls/link/link05.c index 9b81ef3fd..1d708c6f6 100644 --- a/testcases/kernel/syscalls/link/link05.c +++ b/testcases/kernel/syscalls/link/link05.c @@ -22,13 +22,16 @@ static int nlinks = 1000; static void verify_link(void) { - int cnt; + int cnt = 0, created; char lname[1024]; struct stat fbuf, lbuf; - for (cnt = 1; cnt < nlinks; cnt++) { - sprintf(lname, "%s_%d", fname, cnt); - TST_EXP_PASS_SILENT(link(fname, lname), "link(%s, %s)", fname, lname); + for (created = 1; created < nlinks; created++) { + sprintf(lname, "%s_%d", fname, created); + TST_EXP_PASS_SILENT(link(fname, lname), "%d: link(%s, %s)", created, + fname, lname); + if (!TST_PASS) + goto cleanup; } SAFE_STAT(fname, &fbuf); @@ -48,13 +51,14 @@ static void verify_link(void) } } - if (cnt >= nlinks) { + if (cnt == nlinks) { tst_res(TPASS, "link(%s, %s[1-%d]) ret %ld for %d files, stat linkcounts match %d", fname, fname, nlinks, TST_RET, nlinks, (int)fbuf.st_nlink); } - for (cnt = 1; cnt < nlinks; cnt++) { +cleanup: + for (cnt = 1; cnt < created; cnt++) { sprintf(lname, "%s_%d", fname, cnt); SAFE_UNLINK(lname); }
If link() fails to be created, the following stat() failed: link05.c:39: TBROK: stat(lkfile_1391822_1,0x7ffd61e5f000) failed: ENOENT (2) Therefore skip testing and improve the error message: 5: link(lkfile_1404879, lkfile_1404879_5) failed: ENOENT (2) Also fix cnt and nlinks condition. Signed-off-by: Petr Vorel <pvorel@suse.cz> --- @Xu, please merge your "link05: Convert docs to docparse" patchset [1] first, I'll rebase my afterwards. Kind regards, Petr [1] https://lore.kernel.org/ltp/20231108053122.GA1383908@pevik/ testcases/kernel/syscalls/link/link05.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)