--- /dev/null
+#!/bin/sh
+
+# Large message size default arbitrarily set to 16 kB. Allows to get an idea of
+# how the latency values differ from the latencies for small message sizes.
+# Could easily be overriden with the `-l` option if necessary.
+LARGE_MSG_SIZE=16384
+
+# Small message size default arbitrarily set to 32 bytes. Assuming that D-Bus
+# header contains more information for the communication via the daemon than for
+# the peer to peer, 32 bytes seems to be the reasonable choice for a very small
+# message. However, the differences between 32, 64 and 128 byte messages are
+# negligible. Could be overriden with the `-s` option if necessary.
+SMALL_MSG_SIZE=32
+
+# Number of real tries. Should be at least 100000 if we want to make a
+# reasonable distribution graph of the latency values.
+REAL_TRIES=100000
+
+run_ipc_tests() {
+ if [ ! -d $1 ]; then
+ if mkdir $1; then
+ echo "Subdirectory '$1' created" 1>&2
+ else
+ echo "Cannot create '$1' subdirectory" 1>&2
+ exit 1
+ fi
+ fi
+
+ p2p-gdbus -m $2 -l -r -t $3
+ gdbus -m $2 -l -r -t $3
+ libdbus -m $2 -l -r -t $3
+ libdbus-p2p-server -r &
+ # Give the server some time to run and start listening for a connection.
+ # Arbitrarily chosen 10 second delay seems to do the trick, even on
+ # a heavily loaded system.
+ sleep 10
+ LIBDBUS_P2P_TRY_COUNT=`expr $3 + 1000`
+ libdbus-p2p-client -m $2 -t $LIBDBUS_P2P_TRY_COUNT -d 50
+ pipe -m $2 -l -r -t $3
+ socket -m $2 -l -r -t $3
+ sharedmem -m $2 -l -r -t $3
+
+ mv p2pgdbus-latency.csv $1/
+ mv gdbus-latency.csv $1/
+ mv libdbus-latency.csv $1/
+ mv libdbus-p2p-latency.csv $1/
+ mv pipe-latency.csv $1/
+ mv socket-latency.csv $1/
+ mv sharedmem-latency.csv $1/
+}
+
+while [ $# -gt 0 ]
+do
+ case $1 in
+ -h) printf "Usage: $0 [-l large_msg_size] [-s small_msg_size] [-r real_tries]\n"
+ exit 1
+ ;;
+ -l) LARGE_MSG_SIZE=$2
+ shift
+ ;;
+ -s) SMALL_MSG_SIZE=$2
+ shift
+ ;;
+ -r) REAL_TRIES=$2
+ shift
+ ;;
+ -*) printf "Wrong option: $1. Type \`$0 -h\` for help.\n" 1>&2
+ break
+ ;;
+ esac
+ shift
+done
+
+# tests without load
+run_ipc_tests no_load_small $SMALL_MSG_SIZE $REAL_TRIES
+run_ipc_tests no_load_large $LARGE_MSG_SIZE $REAL_TRIES
+
+# perfrom tests under load only when hackbench is present
+if [ ! -x /usr/bin/hackbench ]; then
+ echo "hackbench not installed. Cannot perform tests with load." 1>&2
+ exit 1
+fi
+
+# tests under heavy load
+
+# hackbench produces 40 processes times the value,
+# the resulting 560 processes is arbitrary but "a lot"
+readonly PROCESS_COUNT=14
+
+# enough messages to keep the rest of the system busy
+# throughout the entire dbus test
+readonly MESSAGE_COUNT=9900000
+
+hackbench --pipe --groups $PROCESS_COUNT --loops $MESSAGE_COUNT &
+HACKBENCH_PID=$!
+
+run_ipc_tests load_small $SMALL_MSG_SIZE $REAL_TRIES
+run_ipc_tests load_large $LARGE_MSG_SIZE $REAL_TRIES
+
+# since hackbench's managing process handles SIGTERM by broadcasting the signal
+# to every child process, it's enough to kill the main instance
+kill $HACKBENCH_PID
+