<div dir="ltr"><div class="gmail_quote"><div><div class="gmail_default" style="font-size:small">Hi Meng,</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-static void verify_link(void)<br>
+static void verify_link02(void)<br>
{<br>
struct stat fbuf, lbuf;<br>
<br>
TEST(link(OLDPATH, NEWPATH));<br>
<br>
- if (TEST_RETURN == 0) {<br>
- SAFE_STAT(cleanup, OLDPATH, &fbuf);<br>
- SAFE_STAT(cleanup, NEWPATH, &lbuf);<br>
+ if (TST_RET == 0) {<br>
+ SAFE_STAT(OLDPATH, &fbuf);<br>
+ SAFE_STAT(NEWPATH, &lbuf);<br>
if (fbuf.st_nlink > 1 && lbuf.st_nlink > 1 &&<br>
fbuf.st_nlink == lbuf.st_nlink) {<br>
- tst_resm(TPASS, "link("OLDPATH","NEWPATH") "<br>
+ tst_res(TPASS, "link("OLDPATH","NEWPATH") "<br>
"returned 0 and link counts match");<br>
} else {<br>
- tst_resm(TFAIL, "link("OLDPATH","NEWPATH") returned 0"<br>
+ tst_res(TFAIL, "link("OLDPATH","NEWPATH") returned 0"<br>
" but stat lin count do not match %d %d",<br>
(int)fbuf.st_nlink, (int)lbuf.st_nlink);<br>
}<br>
- SAFE_UNLINK(cleanup, NEWPATH);<br>
} else {<br>
- tst_resm(TFAIL | TTERRNO,<br>
+ tst_res(TFAIL | TTERRNO,<br>
"link("OLDPATH","NEWPATH") returned %ld",<br>
- TEST_RETURN);<br>
- }<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Generally looks good, but I personally hope to decrease the</div><div class="gmail_default" style="font-size:small">layers of brace nesting by reordering the if-conditions.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Something logic like this maybe better:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"> TEST(link(OLDPATH, NEWPATH));<br> if (TST_RET == -1) {<br> ...<br> }<br><br> SAFE_STAT(OLDPATH, &fbuf);<br> SAFE_STAT(NEWPATH, &lbuf);<br><br> if (fbuf.st_nlink > 1 && fbuf.st_nlink == lbuf.st_nlink) {<br> ...<br> } else {<br> ...<br> }<br></div><div class="gmail_default" style="font-size:small"><br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-}<br>
-<br>
-int main(int ac, char **av)<br>
-{<br>
- int lc;<br>
-<br>
- tst_parse_opts(ac, av, NULL, NULL);<br>
-<br>
- setup();<br>
-<br>
- for (lc = 0; TEST_LOOPING(lc); lc++) {<br>
- tst_count = 0;<br>
- verify_link();<br>
+ TST_RET);<br>
}<br>
-<br>
- cleanup();<br>
- tst_exit();<br>
}<br>
<br>
static void setup(void)<br>
{<br>
- tst_sig(NOFORK, DEF_HANDLER, cleanup);<br>
-<br>
- TEST_PAUSE;<br>
-<br>
- tst_tmpdir();<br>
-<br>
- SAFE_TOUCH(cleanup, OLDPATH, 0700, NULL);<br>
+ SAFE_TOUCH(OLDPATH, 0700, NULL);<br>
}<br>
<br>
static void cleanup(void)<br>
{<br>
- tst_rmdir();<br>
+ SAFE_UNLINK(NEWPATH);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">I'd suggest moving this unlink() to verify_link02 to make test</div><div class="gmail_default" style="font-size:small">options '-i N' happy.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Otherwise:</div><div class="gmail_default" style="font-size:small"><br></div># ./link02 -i 2<br>tst_test.c:1365: TINFO: Timeout per run is 0h 05m 00s<br>link02.c:31: TPASS: link(oldpath,newpath) returned 0 and link counts match<br>link02.c:40: TFAIL: link(oldpath,newpath) returned -1: EEXIST (17)<br><div class="gmail_default" style="font-size:small"></div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
}<br>
+<br>
+static struct tst_test test = {<br>
+ .test_all = verify_link02,<br>
+ .setup = setup,<br>
+ .cleanup = cleanup,<br>
+ .needs_tmpdir = 1,<br>
+};<br>
--<br>
2.20.1<br>
<br>
<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>