[LTP] [PATCH] link/link02: Convert to new API

Li Wang liwang@redhat.com
Mon Oct 25 10:30:08 CEST 2021


Hi Meng,


> -static void verify_link(void)
> +static void verify_link02(void)
>  {
>         struct stat fbuf, lbuf;
>
>         TEST(link(OLDPATH, NEWPATH));
>
> -       if (TEST_RETURN == 0) {
> -               SAFE_STAT(cleanup, OLDPATH, &fbuf);
> -               SAFE_STAT(cleanup, NEWPATH, &lbuf);
> +       if (TST_RET == 0) {
> +               SAFE_STAT(OLDPATH, &fbuf);
> +               SAFE_STAT(NEWPATH, &lbuf);
>                 if (fbuf.st_nlink > 1 && lbuf.st_nlink > 1 &&
>                     fbuf.st_nlink == lbuf.st_nlink) {
> -                       tst_resm(TPASS, "link("OLDPATH","NEWPATH") "
> +                       tst_res(TPASS, "link("OLDPATH","NEWPATH") "
>                                  "returned 0 and link counts match");
>                 } else {
> -                       tst_resm(TFAIL, "link("OLDPATH","NEWPATH")
> returned 0"
> +                       tst_res(TFAIL, "link("OLDPATH","NEWPATH") returned
> 0"
>                                  " but stat lin count do not match %d %d",
>                                  (int)fbuf.st_nlink, (int)lbuf.st_nlink);
>                 }
> -               SAFE_UNLINK(cleanup, NEWPATH);
>         } else {
> -               tst_resm(TFAIL | TTERRNO,
> +               tst_res(TFAIL | TTERRNO,
>                          "link("OLDPATH","NEWPATH") returned %ld",
> -                        TEST_RETURN);
> -       }
>

Generally looks good, but I personally hope to decrease the
layers of brace nesting by reordering the if-conditions.

Something logic like this maybe better:

        TEST(link(OLDPATH, NEWPATH));
        if (TST_RET == -1) {
                ...
        }

        SAFE_STAT(OLDPATH, &fbuf);
        SAFE_STAT(NEWPATH, &lbuf);

        if (fbuf.st_nlink > 1 && fbuf.st_nlink == lbuf.st_nlink) {
                ...
        } else {
               ...
        }



> -}
> -
> -int main(int ac, char **av)
> -{
> -       int lc;
> -
> -       tst_parse_opts(ac, av, NULL, NULL);
> -
> -       setup();
> -
> -       for (lc = 0; TEST_LOOPING(lc); lc++) {
> -               tst_count = 0;
> -               verify_link();
> +                        TST_RET);
>         }
> -
> -       cleanup();
> -       tst_exit();
>  }
>
>  static void setup(void)
>  {
> -       tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -       TEST_PAUSE;
> -
> -       tst_tmpdir();
> -
> -       SAFE_TOUCH(cleanup, OLDPATH, 0700, NULL);
> +       SAFE_TOUCH(OLDPATH, 0700, NULL);
>  }
>
>  static void cleanup(void)
>  {
> -       tst_rmdir();
> +    SAFE_UNLINK(NEWPATH);
>

I'd suggest moving this unlink() to verify_link02 to make test
options '-i N' happy.

Otherwise:

# ./link02 -i 2
tst_test.c:1365: TINFO: Timeout per run is 0h 05m 00s
link02.c:31: TPASS: link(oldpath,newpath) returned 0 and link counts match
link02.c:40: TFAIL: link(oldpath,newpath) returned -1: EEXIST (17)

 }
> +
> +static struct tst_test test = {
> +    .test_all = verify_link02,
> +    .setup = setup,
> +    .cleanup = cleanup,
> +    .needs_tmpdir = 1,
> +};
> --
> 2.20.1
>
>
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20211025/58d44223/attachment.htm>


More information about the ltp mailing list