symlink.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. TMP="$(mktemp -d)"
  4. cleanup() {
  5. rm -rf "$TMP"
  6. }
  7. trap cleanup EXIT
  8. start_up
  9. #
  10. # Positive tests:
  11. #
  12. fail=0
  13. TPM2_TOOL="$(which tpm2)"
  14. if [ -z "$TPM2_TOOL" ]; then
  15. echo "unable to locate tpm2 tool"
  16. fail=1
  17. fi
  18. #echo "Using $TPM2_TOOL"
  19. #
  20. # Disabling this test and leaving a note for traceability because
  21. # disabling/ deleting tests without rational is a bad thing.
  22. #
  23. # Executing tpm2 without argument should now execute the man-page.
  24. #
  25. ## no arguments should produce at least ten lines of output
  26. #NUM_TOOLS=$(tpm2 2>&1 | wc -l)
  27. #if [ -z "$NUM_TOOLS" ] || [ "$NUM_TOOLS" -lt 10 ]; then
  28. # echo "tpm2 with no arguments did not produce list of tools"
  29. # fail=1
  30. #fi
  31. # busybox style
  32. if ! tpm2 readclock &>/dev/null ; then
  33. echo "busybox style failed"
  34. fail=1
  35. fi
  36. # with tpm2_ prefix
  37. ln -s "$TPM2_TOOL" "$TMP/tpm2_readclock"
  38. if ! "$TMP/tpm2_readclock" &>/dev/null ; then
  39. echo "tpm2_ prefix style failed"
  40. fail=1
  41. fi
  42. # without prefix
  43. ln -s "$TPM2_TOOL" "$TMP/readclock"
  44. if ! "$TMP/readclock" &>/dev/null ; then
  45. echo "no prefix style failed"
  46. fail=1
  47. fi
  48. #
  49. # Negative tests
  50. #
  51. # command not found, as busybox style
  52. if tpm2 bad-command &>/dev/null ; then
  53. echo "Expected 'tmp2 bad-command' to fail."
  54. fail=1
  55. fi
  56. # command not found, with tpm2_ prefix
  57. ln -s "$TPM2_TOOL" "$TMP/tmp2_bad-command"
  58. if "$TMP/tmp2_bad-command" &>/dev/null ; then
  59. echo "Expected 'tmp2_bad-command' to fail."
  60. fail=1
  61. fi
  62. # command not found, without tpm2_ prefix
  63. ln -s "$TPM2_TOOL" "$TMP/bad-command"
  64. if "$TMP/bad-command" &>/dev/null ; then
  65. echo "Expected 'bad-command' to fail."
  66. fail=1
  67. fi
  68. exit "$fail"