1#!/bin/bash
2# Copyright 2006-2008 The FLWOR Foundation.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16zorbaRepos=@zorbaRepos@
17zorbaExecDir=@zorbaExecDir@
18
19error=0
20
21#
22# The environment variable zorbaRepos must be defined. It should point to a
23# directory containing a zorba source repository (e.g., /home/markos/zorba/xquery)
24#
25if [ ! ${zorbaRepos} ]; then
26   echo "ERROR 1 lbkt.sh: zorbaRepos environment variable is not set"
27   exit 1
28fi
29
30
31#
32# The environment variable zorbaExeDir must be defined. It must be set to the
33# full pathname of the directory containig all the test executables
34#
35if [ ! ${zorbaExecDir} ]; then
36   echo "ERROR 1 lbkt.sh: zorbaExecDir environment variable is not set"
37   exit 1
38fi
39
40#
41# testRootDir is the root directory of the test environment. It contains the
42# the scripts, the test queries and their expected results, and the source docs
43# to be loaded. It is also under this directory where all output from the tests
44# is stored.
45#
46testRootDir=${zorbaRepos}/test/rbkt
47
48# The following dirs MUST exist under the testRootDir.
49scriptsDir=${testRootDir}/Scripts
50queriesDir=${testRootDir}/Queries
51expQueryResultsDir=${testRootDir}/ExpQueryResults
52docsDir=${testRootDir}/Documents
53expLoaderResultsDir=${testRootDir}/ExpLoaderResults
54
55# This is the dir where all query results are stored. This dir is created
56# by the buildDirEnv function, if it does not exist already.
57queryResultsDir=${testRootDir}/QueryResults
58
59# This is the dir where all loader results are stored. This dir is created
60# by the buildDirEnv function, if it does not exist already.
61loaderResultsDir=${testRootDir}/LoaderResults
62
63
64#
65# sourcing of common functions
66#
67if [ ! -e ${scriptsDir}/functions.sh ]; then
68   echo "ERROR 3 lbkt.sh: ${scriptsDir}/functions.sh does not exist"
69   exit 3
70fi
71
72source ${scriptsDir}/functions.sh
73
74trap '' 12
75
76#
77# Argument parsing
78#
79bucketName=""
80docName=""
81
82state=0
83while [ $1 ]
84do
85   case $1 in
86   -b)        state=1;;
87   -d)        state=2;;
88   -h)        usage ; exit;;
89    *) case $state in
90       1) bucketName="$1"; state=0 ;;
91       2) docName="$1"; state=0 ;;
92       *) echo "ERROR 6 lbkt.sh: Wrong parameter $1"; usage; exit 6;;
93       esac ;;
94    esac
95    shift
96done
97
98if [ $state -ne 0 ]; then
99  echo "ERROR 7 lbkt.sh: Wrong arg list"; usage; exit 7;
100fi
101
102
103#
104# Building env directories and runtime env
105#
106buildDirEnv
107error=$?
108if [ ${error} -ne 0 ]; then
109  echo "ERROR 10 lbkt.sh: buildDirEnv function failed with error code ${error}"
110  exit ${error}
111fi
112
113
114#
115# Load queries
116#
117#echo; echo "Loading Queries"
118failedDocs=0
119totalDocss=0
120
121rm -f lbkt_summary.txt
122
123if [ "${bucketName}" != "" ]; then
124
125  if [ "${docName}" != "" ]; then
126    load_doc_in_bucket "${bucketName}" "${docName}"
127    error=$?
128    if [ ${error} -ne 0 ]; then
129      echo "ERROR 70 lbkt.sh: load_doc_in_bucket function failed with error code ${error}"
130      exit ${error}
131    fi
132  else
133    echo; echo "Loading bucket ${bucketName}"
134    load_bucket "${bucketName}"
135    error=$?
136    if [ ${error} -ne 0 ]; then
137      echo "ERROR 71 lbkt.sh: run_bucket function failed with error code ${error}"
138      exit ${error}
139    fi
140  fi
141
142else
143  #bucketList=`find "${queriesSDir}" -mindepth 1 -type d -printf "%f\n"`
144  bucketList="test"
145
146  for bucketName in ${bucketList}
147  do
148    echo; echo "Running bucket ${bucketName}"
149    load_bucket "${bucketName}"
150    error=$?
151    if [ ${error} -ne 0 ]; then
152      echo "ERROR 72 lbkt.sh: run_bucket function failed with error code ${error}"
153      exit ${error}
154    fi
155  done
156fi
157
158echo
159echo "lbkt.sh : total number of docs   = $totalDocs"
160echo "lbkt.sh : number of failed docs  = $failedDocs"
161
162echo >> lbkt_summary.txt
163echo "lbkt.sh : total number of docs   = $totalDocs" >> lbkt_summary.txt
164echo "lbkt.sh : number of failed docs  = $failedDocs" >> lbkt_summary.txt
165
166if [ ${failedDocs} -gt 0 ]; then
167  exit 1
168else
169   exit 0
170fi
171