run.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. rm -rf shadow.data/
  3. shadow --pcap-enabled true --template-directory shadow.data.template shadow.yaml > shadow.log ;
  4. ret=$?
  5. declare -A groups
  6. groups[group1]="Alice Bob Carol"
  7. groups[group2]="Alice Bob Dave"
  8. check_one_log() {
  9. counts="$(grep -Ec "$1" shadow.data/hosts/*/*.stdout | cut -d: -f2 | sort -n)"
  10. if [[ $(echo "$counts" | tail -1) -lt $2 ]] ; then
  11. echo "Not enough matches of pattern: $1"
  12. ret=1
  13. fi
  14. if [[ $(echo "$counts" | tail -2 | head -1) -gt 0 ]] ; then
  15. echo "Found matches of pattern in multiple logs: $1"
  16. ret=1
  17. fi
  18. }
  19. check_all_logs() {
  20. counts="$(grep -Ec "$1" shadow.data/hosts/*/*.stdout | cut -d: -f2 | sort -n)"
  21. if [[ $(echo "$counts" | tail -1) -lt $2 ]] ; then
  22. echo "Not enough matches of pattern: $1"
  23. ret=1
  24. fi
  25. }
  26. for group in ${!groups[@]} ; do
  27. for name in ${groups[$group]} ; do
  28. echo "$group,$name"
  29. # user sent at least 10 messages to the group
  30. check_one_log "$name,$group,send," 10
  31. # user got at least 10 receipts from the group
  32. check_one_log "$name,$group,receive,.*,receipt" 10
  33. # users got at least 10 receipts from this user in this group
  34. check_all_logs "$group,receive,.*,$name,receipt" 10
  35. # user got at least 10 normal messages from the group
  36. check_one_log "$name,$group,receive,.*,[0-9]+" 10
  37. # users got at least 10 normal messages from this user in this group
  38. check_all_logs "$group,receive,.*,$name,[0-9]+" 10
  39. done
  40. done
  41. if [ $ret == 0 ] ; then
  42. echo "All tests passed."
  43. else
  44. echo "At least one test failed."
  45. exit $ret
  46. fi