2
0

benchmark.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. # NOTE: We sleep for 2 seconds below. If timing the execution of this script
  59. # with "time", bear in mind that those 2 seconds will be reflected in
  60. # the "real" time.
  61. echo "Waiting for server_ready file..."
  62. while [ ! -s /tmp/wolfssl_server_ready -a "$counter" -lt 20 ]; do
  63. sleep 0.1
  64. counter=$((counter+ 1))
  65. done
  66. # benchmark connections
  67. if [ $1 -eq 1 ]
  68. then
  69. echo "Starting example client to benchmark connection average time"
  70. # start client to benchmark average time for each connection using port
  71. ./examples/client/client -b $2 -p $bench_port $3
  72. client_result=$?
  73. fi
  74. # benchmark throughput
  75. if [ $1 -eq 2 ]
  76. then
  77. echo "Starting example client to benchmark throughput"
  78. # start client in non-blocking mode, benchmark throughput using port
  79. ./examples/client/client -N -B $2 -p $bench_port $3
  80. client_result=$?
  81. fi
  82. if [ $client_result != 0 ]
  83. then
  84. echo "Client failed!"
  85. do_cleanup
  86. exit 1
  87. fi
  88. # End server
  89. kill -6 $server_pid
  90. server_result=$?
  91. remove_ready_file
  92. if [ $server_result != 0 ]
  93. then
  94. echo "Server failed!"
  95. exit 1
  96. fi
  97. echo "\nSuccess!\n"
  98. exit 0