<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Meng,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 29, 2021 at 4:06 PM tangmeng <<a href="mailto:tangmeng@uniontech.com">tangmeng@uniontech.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: tangmeng <<a href="mailto:tangmeng@uniontech.com" target="_blank">tangmeng@uniontech.com</a>><br>
---<br>
 testcases/kernel/syscalls/link/link04.c | 140 +++++-------------------<br>
 1 file changed, 29 insertions(+), 111 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/link/link04.c b/testcases/kernel/syscalls/link/link04.c<br>
index d9408845e..acc8a7134 100644<br>
--- a/testcases/kernel/syscalls/link/link04.c<br>
+++ b/testcases/kernel/syscalls/link/link04.c<br>
@@ -1,65 +1,32 @@<br>
+// SPDX-License-Identifier: GPL-2.0-or-later<br>
 /*<br>
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.<br>
  *  AUTHOR             : Richard Logan<br>
  *  CO-PILOT           : William Roske<br>
  * Copyright (c) 2014 Cyril Hrubis <<a href="mailto:chrubis@suse.cz" target="_blank">chrubis@suse.cz</a>><br>
- *<br>
- * This program is free software; you can redistribute it and/or modify it<br>
- * under the terms of version 2 of the GNU General Public License as<br>
- * published by the Free Software Foundation.<br>
- *<br>
- * This program is distributed in the hope that it would be useful, but<br>
- * WITHOUT ANY WARRANTY; without even the implied warranty of<br>
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.<br>
- *<br>
- * Further, this software is distributed without any warranty that it is<br>
- * free of the rightful claim of any third person regarding infringement<br>
- * or the like.  Any license provided herein, whether implied or<br>
- * otherwise, applies only to this software file.  Patent licenses, if<br>
- * any, provided herein do not apply to combinations of this program with<br>
- * other software, or any other product whatsoever.<br>
- *<br>
- * You should have received a copy of the GNU General Public License along<br>
- * with this program; if not, write the Free Software Foundation, Inc.,<br>
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.<br>
- *<br>
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,<br>
- * Mountain View, CA  94043, or:<br>
- *<br>
- * <a href="http://www.sgi.com" rel="noreferrer" target="_blank">http://www.sgi.com</a><br>
- *<br>
- * For further information regarding this notice, see:<br>
- *<br>
- * <a href="http://oss.sgi.com/projects/GenInfo/NoticeExplan/" rel="noreferrer" target="_blank">http://oss.sgi.com/projects/GenInfo/NoticeExplan/</a><br>
- *<br>
  */<br>
<br>
-/*<br>
+/*\<br>
+ * [Description]<br>
+ *<br>
  * Negative test cases for link(2).<br>
  *<br>
  * This test program should contain test cases where link will fail regardless<br>
  * of who executed it (i.e. joe-user or root)<br>
  */<br>
-#include <sys/types.h><br>
-#include <fcntl.h><br>
-#include <sys/stat.h><br>
-#include <errno.h><br>
-#include <string.h><br>
-#include <signal.h><br>
 #include <sys/param.h><br>
 #include <sys/mman.h><br>
-#include "test.h"<br>
-#include "safe_macros.h"<br>
+#include "tst_test.h"<br>
<br>
 static char longpath[PATH_MAX + 2];<br>
<br>
-struct test_case_t {<br>
+struct tcase_t {<br>
        char *file1;<br>
        char *desc1;<br>
        char *file2;<br>
        char *desc2;<br>
        int exp_errno;<br>
-} test_cases[] = {<br>
+} tcases[] = {<br>
        /* first path is invalid */<br>
        {"nonexistfile", "non-existent file", "nefile", "nefile", ENOENT},<br>
        {"", "path is empty string", "nefile", "nefile", ENOENT},<br>
@@ -81,90 +48,41 @@ struct test_case_t {<br>
        {"regfile", "regfile", "regfile2", "regfile2", EEXIST},<br>
 };<br>
<br>
-char *TCID = "link04";<br>
-int TST_TOTAL = ARRAY_SIZE(test_cases);<br>
+static unsigned int TST_TOTAL = ARRAY_SIZE(tcases);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">There is no need to define an extra global variable for the test loop.</div><div class="gmail_default" style="font-size:small"><br></div>LTP itself <span class="gmail_default" style="font-size:small">has already </span>support<span class="gmail_default" style="font-size:small">ed that</span> to <span class="gmail_default" style="font-size:small"></span>traversing t<span class="gmail_default" style="font-size:small">case</span><span class="gmail_default" style="font-size:small"></span> by .tcnt<span class="gmail_default" style="font-size:small">.</span><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">For your reference:</div><div class="gmail_default" style="font-size:small"><a href="https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise01.c#L117">https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise01.c#L117</a><br></div><br></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>
-static void setup(void);<br>
-static void cleanup(void);<br>
-<br>
-int main(int ac, char **av)<br>
+static void verify_link(void)<br>
 {<br>
-       int lc;<br>
-       char *fname1, *fname2;<br>
-       char *desc1, *desc2;<br>
-       int i;<br>
-<br>
-       tst_parse_opts(ac, av, NULL, NULL);<br>
-<br>
-       setup();<br>
-<br>
-       for (lc = 0; TEST_LOOPING(lc); lc++) {<br>
-<br>
-               tst_count = 0;<br>
-<br>
-               for (i = 0; i < TST_TOTAL; i++) {<br>
-<br>
-                       fname1 = test_cases[i].file1;<br>
-                       desc1 = test_cases[i].desc1;<br>
-                       fname2 = test_cases[i].file2;<br>
-                       desc2 = test_cases[i].desc2;<br>
-<br>
-                       TEST(link(fname1, fname2));<br>
-<br>
-                       if (TEST_RETURN == -1) {<br>
-                               if (TEST_ERRNO == test_cases[i].exp_errno) {<br>
-                                       tst_resm(TPASS | TTERRNO,<br>
-                                                "link(<%s>, <%s>)",<br>
-                                                desc1, desc2);<br>
-                               } else {<br>
-                                       tst_resm(TFAIL | TTERRNO,<br>
-                                                "link(<%s>, <%s>) Failed "<br>
-                                                "expected errno: %d",<br>
-                                                desc1, desc2,<br>
-                                                test_cases[i].exp_errno);<br>
-                               }<br>
-                       } else {<br>
-                               tst_resm(TFAIL,<br>
-                                        "link(<%s>, <%s>) returned %ld, "<br>
-                                        "expected -1, errno:%d",<br>
-                                        desc1, desc2, TEST_RETURN,<br>
-                                        test_cases[i].exp_errno);<br>
-                       }<br>
-               }<br>
+       unsigned int i;<br>
<br>
+       for (i = 0; i < TST_TOTAL; i++) {<br>
+               TST_EXP_FAIL(link(tcases[i].file1, tcases[i].file2),<br>
+                               tcases[i].exp_errno, "link(<%s>, <%s>)",<br>
+                               tcases[i].desc1, tcases[i].desc2);<br>
        }<br>
-<br>
-       cleanup();<br>
-       tst_exit();<br>
 }<br>
<br>
 static void setup(void)<br>
 {<br>
-       int n;<br>
-<br>
-       tst_sig(NOFORK, DEF_HANDLER, cleanup);<br>
-<br>
-       TEST_PAUSE;<br>
-<br>
-       tst_tmpdir();<br>
+       unsigned int i;<br>
<br>
        memset(longpath, 'a', PATH_MAX+1);<br>
-       SAFE_TOUCH(cleanup, "regfile", 0777, NULL);<br>
-       SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);<br>
-       SAFE_MKDIR(cleanup, "dir", 0777);<br>
+       SAFE_TOUCH("regfile", 0777, NULL);<br>
+       SAFE_TOUCH("regfile2", 0777, NULL);<br>
+       SAFE_MKDIR("dir", 0777);<br>
<br>
-       void *bad_addr = tst_get_bad_addr(cleanup);<br>
+       void *bad_addr = tst_get_bad_addr(NULL);<br>
<br>
-       for (n = 0; n < TST_TOTAL; n++) {<br>
-               if (!test_cases[n].file1)<br>
-                       test_cases[n].file1 = bad_addr;<br>
+       for (i = 0; i < TST_TOTAL; i++) {<br>
+               if (!tcases[i].file1)<br>
+                       tcases[i].file1 = bad_addr;<br>
<br>
-               if (!test_cases[n].file2)<br>
-                       test_cases[n].file2 = bad_addr;<br>
+               if (!tcases[i].file2)<br>
+                       tcases[i].file2 = bad_addr;<br>
        }<br>
 }<br>
<br>
-static void cleanup(void)<br>
-{<br>
-       tst_rmdir();<br>
-}<br>
+static struct tst_test test = {<br>
+       .test_all = verify_link,<br>
+       .setup = setup,<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" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>