1
0

pkcallbacks.test 2.9 KB

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