1#!/bin/bash
2#====================================================================================================
3#
4# Script Name: runDMTTest
5#
6# General Description: This script generate general test cases, create test directory, execute all
7#                      test cases and provide result
8#
9#====================================================================================================
10# Copyright (C) 2014 The Android Open Source Project
11#
12# Licensed under the Apache License, Version 2.0 (the "License");
13# you may not use this file except in compliance with the License.
14# You may obtain a copy of the License at
15#
16#      http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing, software
19# distributed under the License is distributed on an "AS IS" BASIS,
20# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21# See the License for the specific language governing permissions and
22# limitations under the License.
23#====================================================================================================
24usage () {
25  echo ""
26  echo "========================================================================================="
27  echo ""
28  echo "Usage : "
29  echo ""
30  echo "   runDMTTest fstab Dmt.zip"
31  echo ""
32  echo "Sample:"
33  echo ""
34  echo "  ./runDMTTest /home/e32569/DMT/fstab /home/e32569/DMT/Dmt.zip"
35  echo "=========================================================================================="
36  echo ""
37}
38# validate parameters
39if [ "$#" -ne 2 ]
40then
41  echo ""
42  echo "    Missing requered parameters!!! "
43  usage
44  exit 1
45fi
46
47export LANG=en_US
48export LANGVAR=en_US
49unset LC_ALL
50export LC_CTYPE="en_US.UTF-8"
51
52
53FSTAB_FILE="$1"
54DMT_ZIP="$2"
55CURRENTDIR=`pwd`
56OUTPUTDIR=$CURRENTDIR/test
57TEST_FILE=$OUTPUTDIR/tests.txt
58ERRORS_FILE=$OUTPUTDIR/errors.txt
59RESULT_FILE=$OUTPUTDIR/result.txt
60
61CREATEPKGDIR=/vobs/linuxjava/device_mgmt/dm/core/src/linux_java/buildscripts
62TMP_FOLDER=/tmp/pckg.lj.`whoami`
63TEST_TREE_PATH=$TMP_FOLDER/samples/dmt_data
64TEST_RUN_PATH=$TMP_FOLDER/samples
65
66
67# Do some checking on our environment - we need java & unzip present
68
69if [ -z "$JAVA_HOME" ]
70then
71  echo "Environment variable JAVA_HOME needs to be set!"
72  exit 1
73fi
74
75unzip > /dev/null
76
77if [ "$?" -ne 0 ]
78then
79  echo "Couldn't find unzip - please install it, or put it on your PATH."
80  exit 1
81fi
82
83
84# fstab is reduered file, test if fstab exists and readable
85if [ ! -r $FSTAB_FILE ]
86then
87  echo "Cannot find fstab file with path: $FSTAB_FILE"
88  exit 1
89fi
90
91# fstab is reduered file, test if fstab exists and readable
92if [ ! -r $DMT_ZIP ]
93then
94  echo "Cannot find Dmt.zip file with path: $DMT_ZIP"
95  exit 1
96fi
97
98# Remove output directory if exists
99if [ -d "$OUTPUTDIR" ]
100then
101  echo "Removing output directory ..."
102  rm -rf $OUTPUTDIR
103fi
104
105mkdir $OUTPUTDIR
106
107echo "Unzipping files. Please wait..."
108rm -rf Dmt
109unzip -o $DMT_ZIP > /dev/null;
110
111echo ""
112echo "Generate test file..."
113$JAVA_HOME/bin/java -classpath lib/DMTTest.jar com.mot.treetest.TreeTest testgen `pwd`/Dmt $TEST_FILE
114
115if [ $? -eq 1 ]
116  then
117    echo "An error occured during generation test file..."
118    echo "Cleaning on abort..."
119    rm -rf Dmt
120    rm -rf $OUTPUTDIR
121    exit 1
122fi
123
124#read $dummy
125
126echo ""
127echo "Create package..."
128cd $CREATEPKGDIR
129./createPackage -d
130
131#read $dummy
132
133echo "Generate DM tree ... "
134cd $CURRENTDIR
135./generateDMT -fstab $FSTAB_FILE $DMT_ZIP
136
137#read $dummy
138
139echo ""
140echo "Replace DM tree in the test package ... "
141rm -f $TEST_TREE_PATH/*
142cp -f $CURRENTDIR/treedata/* $TEST_TREE_PATH
143
144echo "Run DMT test..."
145cd $TEST_RUN_PATH
146./run_test <$TEST_FILE >$RESULT_FILE
147
148#read $dummy
149
150echo "Parse and analyze test result..."
151cd $CURRENTDIR
152$JAVA_HOME/bin/java -classpath lib/DMTTest.jar com.mot.treetest.TreeTest testrun $RESULT_FILE $ERRORS_FILE
153
154echo "Cleaning all temporary files..."
155rm -rf Dmt
156
157exit 0
158
159
160
161
162