#!/bin/bash

REPEAT=30
CYCLES=50

function test() {
  echo $@
  for c in $(seq 1 $CYCLES); do
    for i in $(seq 1 $REPEAT); do
      echo "cycles: $((c * 100)) ($i/$REPEAT)"
      $@ $((c * 100))
      sleep 1
    done
  done
}

rm -f /tmp/test.ok.sock /tmp/test.return.sock /tmp/intercept.performance.ok.sock /tmp/intercept.performance.return.sock
./server /tmp/test.ok.sock 'ok' &
./server /tmp/test.return.sock 'return 0' &

test ./main
cd ../intercept
test ./intercept -o -i - -- ../perf/main
test ./intercept -o -i stderr -- ../perf/main
test ./intercept -o -i file:out.log -- ../perf/main

cd ../server/src
./performance -m ok &
./performance -m return &
cd ../../intercept
sleep 1
test ./intercept -o -i unix:/tmp/test.ok.sock -- ../perf/main
test ./intercept -o -i unix:/tmp/test.return.sock -- ../perf/main
test ./intercept -o -i unix:/tmp/intercept.performance.ok.sock -- ../perf/main
test ./intercept -o -i unix:/tmp/intercept.performance.return.sock -- ../perf/main
