Page MenuHomeFreeBSD

Add tests for ln(1)
ClosedPublic

Authored by shivansh on Jun 7 2017, 6:55 PM.
Tags
None
Referenced Files
F82060247: D11084.id29331.diff
Thu, Apr 25, 3:35 AM
F82060243: D11084.id29305.diff
Thu, Apr 25, 3:35 AM
F82060241: D11084.id29301.diff
Thu, Apr 25, 3:35 AM
F82060239: D11084.id29354.diff
Thu, Apr 25, 3:34 AM
F82060234: D11084.id.diff
Thu, Apr 25, 3:34 AM
F82060231: D11084.id29311.diff
Thu, Apr 25, 3:34 AM
F82060226: D11084.id29345.diff
Thu, Apr 25, 3:34 AM
Unknown Object (File)
Mon, Apr 22, 3:57 AM
Subscribers
None

Details

Summary
  • Verify that when creating a hard link to a symbolic link, '-L' option creates a hard link to the target of the symbolic link
  • Verify that when creating a hard link to a symbolic link, '-P' option creates a hard link to the symbolic link itself
  • Verify that if the target file already exists, '-f' option unlinks it so that link may occur
  • Verify that if the target file or directory is a symbolic link, '-shf' option prevents following the link
  • Verify that if the target file or directory is a symbolic link, '-snf' option prevents following the link
  • Verify that '-s' option creates a symbolic link
  • Verify that '-w' option produces a warning if the source of a symbolic link does not currently exist
Test Plan
  • Run make install from bin/ln/tests.
  • Run kyua test from /usr/tests/bin/ln. All 9 test cases should succeed.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bin/ln/tests/ln_test.sh
31 ↗(On Diff #29301)
  • -e empty / -s exit:0 are implied, so they can be omitted.
  • umask is a shell builtin, so this probably not work as you expect: running atf_check on a shell builtin runs the spawns a new shell and runs the builtin command via atf_check, thus the command applies to the subshell instead of the shell running the test. This would work:
if ! umask 022; then
    atf_fail "setting umask failed"
fi
48 ↗(On Diff #29301)

I see you're copying my pattern from bin/chmod :)...

To be honest, the inode number here is more important than the file mode (my focus in the chmod testcases were with the file mode, and my focus with the chown testcases I'm writing is path ownership). I still need to add symbolic chmod calls to the tests, but that's an aside :)..

Example:

$ ln -s A B; touch A
$ stat -f %i A B
1850138
1850137
$

Testing for inodes are a bit trickier, because you have to read/compare them differently, but you can use something like:

stat_A=$(stat -f %i A)
stat_B=$(stat -f %i B)
atf_check_equal "$stat_A" "$stat_B"

Checking that they aren't equal doesn't have a nice analog, e.g., atf_check_not_equal, yet.

71–72 ↗(On Diff #29301)

A negative case for this should probably be added as well, i.e.,

ln A B
ln A B # would fail
ln -f A B # would pass

Testing with -s could be done as well.

92 ↗(On Diff #29301)

It would be a good idea to check the -sf case as well.

173–176 ↗(On Diff #29301)

Please add -sf testcases.

Address changes pointed by @ngie

  • Update usage of umask.
  • Update checks to compare inode numbers when testing hard links.
  • Add tests for failure of creation of symbolic and hard links when target file already exists and '-f' option is absent.
  • Add test for '-sf' option.

I'm ok with the changes made, but I still think that inodes (and use of test to check file types) should be compared instead of modes.

  • Check file types instead of modes
asomers requested changes to this revision.Jun 8 2017, 3:24 AM
asomers added inline comments.
bin/ln/tests/ln_test.sh
134 ↗(On Diff #29311)

How is "ln -shf" different than "ln -sf" here? Does the "-h" make a difference when the target is not a directory?

217 ↗(On Diff #29311)

You're not testing the right error condition here. By trying to make a hard link, ln actually fails. The "-w" doesn't matter. "-w" only makes a difference when creating a symlink.

This revision now requires changes to proceed.Jun 8 2017, 3:24 AM
shivansh edited edge metadata.

Address changes pointed by @asomers. Thanks for pointing these out!

  • Update the tests for '-shf', '-snf' and '-w' options

Add following test case -

  • Verify that if the source file does not exists, '-s' option creates a broken symbolic link to the source file

LGTM. I'll commit it in a few hours if no other reviewers have comments.

This revision is now accepted and ready to land.Jun 8 2017, 2:42 PM
etc/mtree/BSD.tests.dist
23 ↗(On Diff #29331)

This is sorted incorrectly: ln should be before ls.

shivansh edited edge metadata.
  • Update position of ln in BSD.tests.dist
This revision now requires review to proceed.Jun 8 2017, 5:26 PM
This revision was automatically updated to reflect the committed changes.