run.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. invert_check_all_logs() {
  27. if grep -Eq "$1" shadow.data/hosts/*/*.stdout ; then
  28. echo "Found errors via pattern: $1"
  29. ret=1
  30. fi
  31. }
  32. for group in ${!groups[@]} ; do
  33. for name in ${groups[$group]} ; do
  34. echo "$group,$name"
  35. # user sent at least 10 messages to the group
  36. check_one_log "$name,$group,send," 10
  37. # user got at least 10 receipts from the group
  38. check_one_log "$name,$group,receive,.*,receipt" 10
  39. # users got at least 10 receipts from this user in this group
  40. check_all_logs "$group,receive,.*,$name,receipt" 10
  41. # user got at least 10 normal messages from the group
  42. check_one_log "$name,$group,receive,.*,[0-9]+" 10
  43. # users got at least 10 normal messages from this user in this group
  44. check_all_logs "$group,receive,.*,$name,[0-9]+" 10
  45. # users didn't get any errors
  46. invert_check_all_logs "[Ee]rr"
  47. done
  48. done
  49. if [ $ret == 0 ] ; then
  50. echo "All tests passed."
  51. else
  52. echo "At least one test failed."
  53. exit $ret
  54. fi