[LTP] [PATCH 4/5] Add pidfd_getfd01 test

Petr Vorel pvorel@suse.cz
Fri Feb 18 11:15:59 CET 2022


Hi Xu,

...
> >> TEST(kcmp(getpid(), pid, KCMP_FILE, remotefd, targetfd));
> >> if (TST_RET==-1) {
> >> 	tst_res(TFAIL | TTERRNO, "kcmp failed unexpectedly");
> >> 	goto free;
> >> } else {
> >> 	if (TST_RET<  0 || TST_RET>  3)
> > +1 (very nit: instead of if/else I'd use 2x if and (TST_RET<  -1 || TST_RET>  3)
> > - readability).
> Good catch. I add the last "if" otherwise 1,2,3 are ignored.

> TEST(kcmp(getpid(), pid, KCMP_FILE, remotefd, targetfd));
>          if (TST_RET == -1) {
>                  tst_res(TFAIL | TTERRNO, "kcmp failed unexpectedly");
>                  goto free;
>          }
>          if (TST_RET < 0 || TST_RET > 3) {
>                  tst_res(TFAIL, "kcmp invalid returns value(%d)", 
> (int)TST_RET);
>                  goto free;
>          }
>          if (TST_RET != 0) {
>                  tst_res(TFAIL, "kcmp returns unexpected value(%d) 
> instead of 0",
>                                  (int)TST_RET);
>                  goto free;
>          }

>          tst_res(TPASS, "pidfd_getfd(%d, %d, 0) passed", pidfd, targetfd);

FYI Unless we want to have explanations why it failed, we could use TST_EXP_VAL() or
TST_EXP_VAL_SILENT().

Kind regards,
Petr


More information about the ltp mailing list