Home | History | Annotate | Download | only in dmt-tools
      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 #====================================================================================================
     24 usage () {
     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
     39 if [ "$#" -ne 2 ]
     40 then
     41   echo ""
     42   echo "    Missing requered parameters!!! "
     43   usage
     44   exit 1
     45 fi
     46 
     47 export LANG=en_US
     48 export LANGVAR=en_US
     49 unset LC_ALL
     50 export LC_CTYPE="en_US.UTF-8"
     51 
     52 
     53 FSTAB_FILE="$1"
     54 DMT_ZIP="$2"
     55 CURRENTDIR=`pwd`
     56 OUTPUTDIR=$CURRENTDIR/test
     57 TEST_FILE=$OUTPUTDIR/tests.txt
     58 ERRORS_FILE=$OUTPUTDIR/errors.txt
     59 RESULT_FILE=$OUTPUTDIR/result.txt
     60 
     61 CREATEPKGDIR=/vobs/linuxjava/device_mgmt/dm/core/src/linux_java/buildscripts
     62 TMP_FOLDER=/tmp/pckg.lj.`whoami`
     63 TEST_TREE_PATH=$TMP_FOLDER/samples/dmt_data
     64 TEST_RUN_PATH=$TMP_FOLDER/samples
     65 
     66 
     67 # Do some checking on our environment - we need java & unzip present
     68 
     69 if [ -z "$JAVA_HOME" ]
     70 then
     71   echo "Environment variable JAVA_HOME needs to be set!"
     72   exit 1
     73 fi
     74 
     75 unzip > /dev/null
     76 
     77 if [ "$?" -ne 0 ]
     78 then
     79   echo "Couldn't find unzip - please install it, or put it on your PATH."
     80   exit 1
     81 fi
     82 
     83 
     84 # fstab is reduered file, test if fstab exists and readable
     85 if [ ! -r $FSTAB_FILE ]
     86 then
     87   echo "Cannot find fstab file with path: $FSTAB_FILE"
     88   exit 1
     89 fi
     90 
     91 # fstab is reduered file, test if fstab exists and readable
     92 if [ ! -r $DMT_ZIP ]
     93 then
     94   echo "Cannot find Dmt.zip file with path: $DMT_ZIP"
     95   exit 1
     96 fi
     97 
     98 # Remove output directory if exists
     99 if [ -d "$OUTPUTDIR" ]
    100 then
    101   echo "Removing output directory ..."
    102   rm -rf $OUTPUTDIR
    103 fi
    104 
    105 mkdir $OUTPUTDIR
    106 
    107 echo "Unzipping files. Please wait..."
    108 rm -rf Dmt
    109 unzip -o $DMT_ZIP > /dev/null;
    110 
    111 echo ""
    112 echo "Generate test file..."
    113 $JAVA_HOME/bin/java -classpath lib/DMTTest.jar com.mot.treetest.TreeTest testgen `pwd`/Dmt $TEST_FILE
    114 
    115 if [ $? -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
    122 fi
    123 
    124 #read $dummy
    125 
    126 echo ""
    127 echo "Create package..."
    128 cd $CREATEPKGDIR
    129 ./createPackage -d
    130 
    131 #read $dummy
    132 
    133 echo "Generate DM tree ... "
    134 cd $CURRENTDIR
    135 ./generateDMT -fstab $FSTAB_FILE $DMT_ZIP
    136 
    137 #read $dummy
    138 
    139 echo ""
    140 echo "Replace DM tree in the test package ... "
    141 rm -f $TEST_TREE_PATH/*
    142 cp -f $CURRENTDIR/treedata/* $TEST_TREE_PATH
    143 
    144 echo "Run DMT test..."
    145 cd $TEST_RUN_PATH
    146 ./run_test <$TEST_FILE >$RESULT_FILE
    147 
    148 #read $dummy
    149 
    150 echo "Parse and analyze test result..."
    151 cd $CURRENTDIR
    152 $JAVA_HOME/bin/java -classpath lib/DMTTest.jar com.mot.treetest.TreeTest testrun $RESULT_FILE $ERRORS_FILE
    153 
    154 echo "Cleaning all temporary files..."
    155 rm -rf Dmt
    156 
    157 exit 0
    158 
    159 
    160 
    161 
    162