run_pec_test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) 2008 FUJITSU LIMITED ##
  5. ## ##
  6. ## This program is free software; you can redistribute it and#or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation; either version 2 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, but ##
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  13. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  14. ## for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program; if not, write to the Free Software ##
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## Author: Li Zefan <lizf@cn.fujitsu.com> ##
  21. ## ##
  22. ################################################################################
  23. NUM_EVENTS=1
  24. EVENT_TEST_CASES=( "fork" "exec" "exit" "uid" "gid" )
  25. cd $LTPROOT/testcases/bin
  26. export TCID="pec01"
  27. export TST_TOTAL=5
  28. export TST_COUNT=1
  29. exit_status=0
  30. if [ $(id -u) != 0 ]; then
  31. tst_brkm TCONF ignored "Test must be run as root"
  32. exit 0;
  33. fi
  34. grep cn_proc /proc/net/connector > /dev/null
  35. if [ $? -ne 0 ]; then
  36. tst_brkm TCONF ignored "Process Event Connector is not supported or kernel is below 2.6.26"
  37. exit 0;
  38. fi
  39. # Run a test case
  40. #
  41. # $1: the test number
  42. # $2: type of event
  43. run_case()
  44. {
  45. export TST_COUNT=$1
  46. log="$LTPROOT/output/log"
  47. mkdir -p $log 2> /dev/null
  48. pec_listener > "$log/listener_$1.log" 2>&1 &
  49. pid=$!
  50. # Wait for pec_listener to start listening
  51. sleep $((1*NUM_EVENTS))
  52. event_generator -e $2 > "$log/generator_$1.log"
  53. ret1=$?
  54. # Sleep until pec_listener has seen and handled all of
  55. # the generated events
  56. sleep $((1*NUM_EVENTS))
  57. kill -s SIGINT $pid 2> /dev/null
  58. wait $pid
  59. ret2=$?
  60. if [ $ret1 -ne 0 -o ! -s "$log/generator_$1.log" ]; then
  61. tst_resm TFAIL "failed to generate process events"
  62. exit_status=1
  63. return 1
  64. fi
  65. if [ $ret2 -eq 2 ]; then
  66. tst_brkm TCONF NULL "connector may not be supported"
  67. exit 0
  68. fi
  69. if [ $ret2 -ne 0 ]; then
  70. tst_resm TFAIL "failed to listen process events"
  71. exit_status=1
  72. return 1
  73. fi
  74. event="`cat $log/generator_$1.log`"
  75. cat "$log/listener_$1.log" | grep "$event" > /dev/null
  76. if [ $? -eq 0 ]; then
  77. tst_resm TPASS "get event - $event"
  78. else
  79. tst_resm TFAIL "expected event - $event"
  80. exit_status=1
  81. fi
  82. }
  83. i=1;
  84. for CASE in "${EVENT_TEST_CASES[@]}" ; do
  85. run_case $i $CASE
  86. ((i++))
  87. done
  88. exit $exit_status