pkcallbacks.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. #pkcallbacks.test
  3. # if we can, isolate the network namespace to eliminate port collisions.
  4. if [ "${AM_BWRAPPED-}" != "yes" ]; then
  5. bwrap_path="$(command -v bwrap)"
  6. if [ -n "$bwrap_path" ]; then
  7. export AM_BWRAPPED=yes
  8. exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
  9. fi
  10. unset AM_BWRAPPED
  11. fi
  12. exit_code=1
  13. counter=0
  14. # need a unique resume port since may run the same time as testsuite
  15. # use server port zero hack to get one
  16. pk_port=0
  17. #no_pid tells us process was never started if -1
  18. no_pid=-1
  19. #server_pid captured on startup, stores the id of the server process
  20. server_pid=$no_pid
  21. # let's use absolute path to a local dir (make distcheck may be in sub dir)
  22. # also let's add some randomness by adding pid in case multiple 'make check's
  23. # per source tree
  24. ready_file=`pwd`/wolfssl_pk_ready$$
  25. remove_ready_file() {
  26. if test -e $ready_file; then
  27. echo -e "removing existing ready file"
  28. rm $ready_file
  29. fi
  30. }
  31. do_cleanup() {
  32. echo "in cleanup"
  33. if [ $server_pid != $no_pid ]
  34. then
  35. echo "killing server"
  36. kill -9 $server_pid
  37. fi
  38. remove_ready_file
  39. }
  40. # trap this function so if user aborts with ^C or other kill signal we still
  41. # get an exit that will in turn clean up the file system
  42. abort_trap() {
  43. echo "script aborted"
  44. if [ $server_pid != $no_pid ]
  45. then
  46. echo "killing server"
  47. kill -9 $server_pid
  48. fi
  49. exit_code=2 #different exit code in case of user interrupt
  50. echo "got abort signal, exiting with $exit_code"
  51. exit $exit_code
  52. }
  53. trap abort_trap INT TERM
  54. # trap this function so that if we exit on an error the file system will still
  55. # be restored and the other tests may still pass. Never call this function
  56. # instead use "exit <some value>" and this function will run automatically
  57. restore_file_system() {
  58. remove_ready_file
  59. }
  60. trap restore_file_system EXIT
  61. run_test() {
  62. echo -e "\nStarting example server for pkcallbacks test...\n"
  63. remove_ready_file
  64. # starts the server on pk_port, -R generates ready file to be used as a
  65. # mutex lock, -P does pkcallbacks. We capture the processid
  66. # into the variable server_pid
  67. ./examples/server/server -P -R $ready_file -p $pk_port &
  68. server_pid=$!
  69. while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
  70. echo -e "waiting for ready file..."
  71. sleep 0.1
  72. counter=$((counter+ 1))
  73. done
  74. if test -e $ready_file; then
  75. echo -e "found ready file, starting client..."
  76. else
  77. echo -e "NO ready file ending test..."
  78. exit 1
  79. fi
  80. # get created port 0 ephemeral port
  81. pk_port=`cat $ready_file`
  82. # starts client on pk_port with pkcallbacks, captures the output from client
  83. capture_out=$(./examples/client/client -P -p $pk_port 2>&1)
  84. client_result=$?
  85. if [ $client_result != 0 ]
  86. then
  87. echo -e "client failed!"
  88. do_cleanup
  89. exit 1
  90. fi
  91. wait $server_pid
  92. server_result=$?
  93. if [ $server_result != 0 ]
  94. then
  95. echo -e "server failed!"
  96. exit 1
  97. fi
  98. }
  99. ######### begin program #########
  100. # run the test
  101. run_test
  102. # If we get to this, success
  103. echo "Success!"
  104. exit 0
  105. ########## end program ##########