1
0

resume.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/sh
  2. #resume.test
  3. # need a unique resume port since may run the same time as testsuite
  4. # use server port zero hack to get one
  5. resume_string="reused"
  6. resume_sup_string="Resume session"
  7. ems_string="Extended\ Master\ Secret"
  8. resume_port=0
  9. no_pid=-1
  10. server_pid=$no_pid
  11. counter=0
  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_resume_ready$$
  16. echo "ready file $ready_file"
  17. remove_ready_file() {
  18. if test -e $ready_file; then
  19. echo -e "removing existing ready file"
  20. rm $ready_file
  21. fi
  22. }
  23. do_cleanup() {
  24. echo "in cleanup"
  25. if [ $server_pid != $no_pid ]
  26. then
  27. echo "killing server"
  28. kill -9 $server_pid
  29. fi
  30. remove_ready_file
  31. }
  32. do_trap() {
  33. echo "got trap"
  34. do_cleanup
  35. exit -1
  36. }
  37. do_test() {
  38. echo -e "\nStarting example server for resume test...\n"
  39. #make sure we support session resumption (!NO_SESSION_CACHE)
  40. # Check the client for the extended master secret disable option. If
  41. # present we need to run the test twice.
  42. options_check=`./examples/client/client -?`
  43. case "$options_check" in
  44. *$resume_sup_string*)
  45. echo -e "\nResume test supported";;
  46. *)
  47. echo -e "\nResume test not supported with build"
  48. return;;
  49. esac
  50. remove_ready_file
  51. ./examples/server/server -r -R $ready_file -p $resume_port &
  52. server_pid=$!
  53. while [ ! -s $ready_file -a "$counter" -lt 20 ]; do
  54. echo -e "waiting for ready file..."
  55. sleep 0.1
  56. counter=$((counter+ 1))
  57. done
  58. if test -e $ready_file; then
  59. echo -e "found ready file, starting client..."
  60. else
  61. echo -e "NO ready file ending test..."
  62. do_cleanup
  63. exit 1
  64. fi
  65. # get created port 0 ephemeral port
  66. resume_port=`cat $ready_file`
  67. capture_out=$(./examples/client/client $1 -r -p $resume_port 2>&1)
  68. client_result=$?
  69. if [ $client_result != 0 ]
  70. then
  71. echo -e "client failed!\ncapture_out=$capture_out\nclient_result=$client_result"
  72. do_cleanup
  73. exit 1
  74. fi
  75. wait $server_pid
  76. server_result=$?
  77. remove_ready_file
  78. if [ $server_result != 0 ]
  79. then
  80. echo -e "client failed!"
  81. exit 1
  82. fi
  83. case "$capture_out" in
  84. *$resume_string*)
  85. echo "resumed session" ;;
  86. *)
  87. echo "did NOT resume session as expected"
  88. exit 1
  89. ;;
  90. esac
  91. }
  92. trap do_trap INT TERM
  93. ./examples/client/client -? 2>&1 | grep -- 'Client not compiled in!'
  94. if [ $? -ne 0 ]; then
  95. ./examples/server/server -? 2>&1 | grep -- 'Server not compiled in!'
  96. if [ $? -ne 0 ]; then
  97. RUN_TEST="Y"
  98. fi
  99. fi
  100. if [ "$RUN_TEST" = "Y" ]; then
  101. do_test
  102. # Check the client for the extended master secret disable option. If
  103. # present we need to run the test twice.
  104. options_check=`./examples/client/client -?`
  105. case "$options_check" in
  106. *$ems_string*)
  107. echo -e "\nRepeating resume test without extended master secret..."
  108. do_test -n ;;
  109. *)
  110. ;;
  111. esac
  112. fi
  113. echo -e "\nSuccess!\n"
  114. exit 0