linktest.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) International Business Machines Corp., 2000
  4. # Copyright (c) Linux Test Project, 2012-2019
  5. # Regression test for max links per file
  6. # Author: Ngie Cooper <yaneurabeya@gmail.com>
  7. TST_NEEDS_TMPDIR=1
  8. TST_TESTFUNC=do_test
  9. TST_OPTS="a:s:"
  10. TST_PARSE_ARGS=parse_args
  11. TST_USAGE=usage
  12. . tst_test.sh
  13. hard_links=1000
  14. soft_links=1000
  15. usage()
  16. {
  17. echo "Usage: linktest.sh {-a n} {-s n}"
  18. echo "-a n Hard link count"
  19. echo "-s n Soft link count"
  20. }
  21. parse_args()
  22. {
  23. tst_is_int "$2" || tst_brk TBROK "-$1 must be integer ($2)"
  24. [ "$2" -ge 0 ] || tst_brk TBROK "-$1 must be >= 0 ($2)"
  25. case $1 in
  26. a) hard_links=$2;;
  27. s) soft_links=$2;;
  28. esac
  29. }
  30. do_link()
  31. {
  32. local prefix="$1"
  33. local ln_opts="$2"
  34. local limit="$3"
  35. local prefix_msg="$4"
  36. local lerrors=0
  37. local i=0
  38. local rtype="TFAIL"
  39. tst_res TINFO "test $prefix_msg link, limit: $limit"
  40. cd "${prefix}link.$$"
  41. while [ $i -lt $limit ]; do
  42. if ! ln $ln_opts "$PWD/${prefix}file" ${prefix}file${i}; then
  43. lerrors=$((lerrors + 1))
  44. fi
  45. i=$((i + 1))
  46. done
  47. cd ..
  48. [ $lerrors -eq 0 ] && rtype="TPASS"
  49. tst_res $rtype "errors: $lerrors"
  50. }
  51. do_test()
  52. {
  53. mkdir hlink.$$ slink.$$
  54. touch hlink.$$/hfile slink.$$/sfile
  55. do_link "s" "-s" $soft_links "symbolic"
  56. do_link "h" "" $hard_links "hard"
  57. rm -rf hlink.$$ slink.$$
  58. }
  59. tst_run