benchmark.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/sh
  2. #benchmark.test
  3. if [ "$#" -lt 2 ]; then
  4. echo "Usage: $0 [mode] [num] [clientargs] [serverargs]" >&2
  5. echo " [mode]: 1=Connection Rate (TPS), 2=Throughput Bytes" >&2
  6. echo " [num]: Mode 1=Connection Count, Mode 2=Bytes to TX/RX" >&2
  7. echo " [clientargs]: Passed to client (see \"./example/client/client -?\" for help)" >&2
  8. echo " Example: Use different cipher suite: \"-l DHE-RSA-AES256-SHA\"" >&2
  9. echo " [serverargs]: Passed to server (see \"./example/server/server -?\" for help)" >&2
  10. echo " Example: Disable client certificate check: \"-d\"" >&2
  11. echo "Note: If additional client or server args contains spaces wrap with double quotes" >&2
  12. exit 1
  13. fi
  14. # Use unique benchmark port so it won't conflict with any other tests
  15. bench_port=11113
  16. no_pid=-1
  17. server_pid=$no_pid
  18. counter=0
  19. client_result=-1
  20. remove_ready_file() {
  21. if test -e /tmp/wolfssl_server_ready; then
  22. echo "removing existing server_ready file"
  23. rm /tmp/wolfssl_server_ready
  24. fi
  25. }
  26. do_cleanup() {
  27. echo "in cleanup"
  28. if [ $server_pid != $no_pid ]
  29. then
  30. echo "killing server"
  31. kill -9 $server_pid
  32. fi
  33. remove_ready_file
  34. }
  35. do_trap() {
  36. echo "got trap"
  37. do_cleanup
  38. exit -1
  39. }
  40. trap do_trap INT TERM
  41. # Start server in loop continuous mode (-L) with echo data (-e) enabled and non-blocking (-N)
  42. echo "\nStarting example server for benchmark test"
  43. remove_ready_file
  44. # benchmark connections
  45. if [ $1 -eq 1 ]
  46. then
  47. # start server in loop mode with port
  48. ./examples/server/server -i -p $bench_port $4 &
  49. server_pid=$!
  50. fi
  51. # benchmark throughput
  52. if [ $1 -eq 2 ]
  53. then
  54. # start server in loop mode, non-blocking, benchmark throughput with port
  55. ./examples/server/server -i -N -B $2 -p $bench_port $4 &
  56. server_pid=$!
  57. fi
  58. echo "Waiting for server_ready file..."
  59. while [ ! -s /tmp/wolfssl_server_ready -a "$counter" -lt 20 ]; do
  60. sleep 0.1
  61. counter=$((counter+ 1))
  62. done
  63. # benchmark connections
  64. if [ $1 -eq 1 ]
  65. then
  66. echo "Starting example client to benchmark connection average time"
  67. # start client to benchmark average time for each connection using port
  68. ./examples/client/client -b $2 -p $bench_port $3
  69. client_result=$?
  70. fi
  71. # benchmark throughput
  72. if [ $1 -eq 2 ]
  73. then
  74. echo "Starting example client to benchmark throughput"
  75. # start client in non-blocking mode, benchmark throughput using port
  76. ./examples/client/client -N -B $2 -p $bench_port $3
  77. client_result=$?
  78. fi
  79. if [ $client_result != 0 ]
  80. then
  81. echo "Client failed!"
  82. do_cleanup
  83. exit 1
  84. fi
  85. # End server
  86. kill -6 $server_pid
  87. server_result=$?
  88. remove_ready_file
  89. if [ $server_result != 0 ]
  90. then
  91. echo "Server failed!"
  92. exit 1
  93. fi
  94. echo "\nSuccess!\n"
  95. exit 0