common/funcs/tst.basename.d*: make it compatible with basename(1)
ClosedPublic

Authored by lwhsu on Jul 23 2017, 11:43 PM.

Details

Summary

In Solaris, basename(1) and basename(3) both return "." while given an empty
string (""), while in BSD (and Linux) basename(1) returns "" and basename(3)
returns "."

This patch accepts basename() in D script returns "" or "."

While here, also:

  • change #!/usr/bin/ksh to #!/usr/bin/env ksh to find ksh in $PATH
  • fix quotation inconsistency
Test Plan

sudo kyua test -k /usr/tests/cddl/usr.sbin/dtrace/common/funcs/Kyuafile t_dtrace_contrib:tst_basename_d

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
lwhsu created this revision.Jul 23 2017, 11:43 PM
Herald added 1 blocking reviewer(s): gnn. · View Herald TranscriptJul 23 2017, 11:43 PM
Herald added a subscriber: imp. · View Herald Transcript
lwhsu edited the summary of this revision. (Show Details)Jul 23 2017, 11:44 PM
lwhsu edited the summary of this revision. (Show Details)
markj accepted this revision.Jul 24 2017, 1:23 AM

Thanks.

cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d
60 ↗(On Diff #31111)

POSIX says that either output is valid, so both Solaris and FreeBSD are behaving correctly. I would phrase the comment this way: "basename(3) and basename(1) return different results for the empty string on FreeBSD, so we need special handling."

ngie retitled this revision from common/funcs/tst.basename.d*: make it compatiable with basename(1) to common/funcs/tst.basename.d*: make it compatible with basename(1).Jul 24 2017, 5:13 PM
ngie edited the summary of this revision. (Show Details)
ngie accepted this revision.Jul 24 2017, 5:16 PM
ngie added inline comments.
cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d.out
4 ↗(On Diff #31111)

While I agree with what you're trying to do below, they're unnecessary stylistic divergences from upstream:

$ echo "\"foo"\"
"foo"
$ echo "\"foo\""
"foo"

Could you please revert all of the style changes in the file?

lwhsu updated this revision to Diff 31140.Jul 24 2017, 9:54 PM
lwhsu edited edge metadata.
  • Update comments
  • Revert unnecessary quotation changes
lwhsu marked 2 inline comments as done.Jul 24 2017, 9:54 PM
ngie added inline comments.Jul 24 2017, 9:56 PM
cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d.out
155 ↗(On Diff #31140)

"." != "." is always false.

lwhsu added inline comments.Jul 24 2017, 10:17 PM
cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/funcs/tst.basename.d.out
155 ↗(On Diff #31140)

Yes, and it guarantees the warning in the next line won't be issued. This line is generated by tst.basename.d D script:

printf("if [ \"`basename \"%s\"`\" != \"%s\" -a \".\" != \"%s\" ]; then\n",
    dir[i], basename(dir[i]), basename(dir[i]));

Where we add another acceptable output of basename(1,3) in POSIX.

gnn accepted this revision.Jul 25 2017, 10:25 AM
This revision is now accepted and ready to land.Jul 25 2017, 10:25 AM
This revision was automatically updated to reflect the committed changes.