]> git.stg.codes - stg.git/blob - functest/test.sh
Added a special project to build all STG libs.
[stg.git] / functest / test.sh
1 #!/bin/sh
2
3 BASEPATH=$1
4
5 source `dirname $0`/functions
6
7 if [ "$BASEPATH" == "" ]
8 then
9     printf "Usage: $0 <path>\n"
10     exit -1
11 fi
12
13 if [ ! -d "$BASEPATH" ]
14 then
15     printf "Path '$BASEPATH' does not exist or not a directory.\n"
16     exit -1
17 fi
18
19 STGPATH="$BASEPATH/stg/projects/stargazer"
20
21 cp "stuff/stargazer-files.conf" "$STGPATH/stargazer.conf"
22 cp "stuff/rules" "$STGPATH/"
23 cp "stuff/OnConnect" "$STGPATH/"
24 cp "stuff/OnDisconnect" "$STGPATH/"
25 cp "stuff/OnChange" "$STGPATH/"
26 cp -R "stuff/db-stub" "$STGPATH/db"
27
28 GROUP=root
29 groups | grep root > /dev/null 2> /dev/null
30 if [ "$?" != "0" ]
31 then
32     groups | grep wheel > /dev/null 2> /dev/null
33     if [ "$?" != "0" ]
34     then
35         printf "Can't find neither 'root' nor 'wheel' group.\n"
36         exit -1
37     fi
38     GROUP=wheel
39 fi
40
41 subst "-STG-PATH-" "$STGPATH" "$STGPATH/stargazer.conf"
42 subst "-STG-GROUP-" "$GROUP" "$STGPATH/stargazer.conf"
43
44 CURPATH=`pwd`
45 LOGFILE="$CURPATH/"`date "+%Y-%m-%d-%H%M%S.console.log"`
46
47 cd "$STGPATH"
48
49 printf "Starting Stargazer... "
50
51 "$STGPATH/stargazer" "$STGPATH" >> "$LOGFILE" 2>&1 &
52
53 COUNT=""
54 while true
55 do
56     grep "Stg started successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
57     if [ "$?" == "0" ]
58     then
59         break
60     fi
61     COUNT="$COUNT."
62     if [ "$COUNT" == "....." ]
63     then
64         printf "Failed to start stg in 5 sec.\n"
65         exit -1
66     fi
67     sleep 1
68 done
69
70 PID=`cat "$STGPATH/stargazer.pid"`
71 printf "Started with pid $PID\n"
72
73 printf "\nTesting admins:\n"
74 "$CURPATH/test_admins.sh" "$BASEPATH"
75 printf "\nTesting services:\n"
76 "$CURPATH/test_services.sh" "$BASEPATH"
77 printf "\n"
78
79 printf "Stopping... "
80 kill $PID
81
82 COUNT=""
83 while true
84 do
85     grep "Stg stopped successfully" "$STGPATH/stargazer.log" > /dev/null 2> /dev/null
86     if [ "$?" == "0" ]
87     then
88         break
89     fi
90     COUNT="$COUNT."
91     if [ "$COUNT" == "....." ]
92     then
93         printf "Failed to stop stg in 5 sec.\n"
94         exit -1
95     fi
96     sleep 1
97 done
98
99 printf "Stopped.\n"