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