check TMP_DIR path for all runtest.sh scripts

To avoid temporary files are saved in wrong directory when test
script is executed under its own directory, TMP_DIR path should
be identified before the test.

Signed-off-by: Shaoyong Wang <shaoyongx.wang@intel.com>
Signed-off-by: Chen Gong <gong.chen@linux.intel.com>
diff --git a/cases/function/apei-inj/runtest.sh b/cases/function/apei-inj/runtest.sh
index b9d5533..11099a0 100755
--- a/cases/function/apei-inj/runtest.sh
+++ b/cases/function/apei-inj/runtest.sh
@@ -19,7 +19,11 @@
 EOF
 
 TMP="../../../work"
-export TMP_DIR=${TMP_DIR:-$TMP}
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
 
 echo 0 > $TMP_DIR/error.$$
 
diff --git a/cases/function/bsp/runtest.sh b/cases/function/bsp/runtest.sh
index 7640056..9940711 100755
--- a/cases/function/bsp/runtest.sh
+++ b/cases/function/bsp/runtest.sh
@@ -40,6 +40,13 @@
 
 . $ROOT/lib/functions.sh
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 export NUM_CPU=`ls -d /sys/devices/system/cpu/cpu[0-9]* | wc -l`
 export MAX_CPU=`expr $NUM_CPU - 1`
 export BSP_LOG_DIR=$ROOT/cases/function/bsp/log
diff --git a/cases/function/core_recovery/runtest_dcu.sh b/cases/function/core_recovery/runtest_dcu.sh
index 69b653d..8a728c3 100755
--- a/cases/function/core_recovery/runtest_dcu.sh
+++ b/cases/function/core_recovery/runtest_dcu.sh
@@ -16,6 +16,13 @@
 
 EOF
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 echo 0 > $TMP_DIR/error.$$
 
 pushd `dirname $0` > /dev/null
diff --git a/cases/function/core_recovery/runtest_ifu.sh b/cases/function/core_recovery/runtest_ifu.sh
index ab53b6c..1f952c2 100755
--- a/cases/function/core_recovery/runtest_ifu.sh
+++ b/cases/function/core_recovery/runtest_ifu.sh
@@ -16,6 +16,13 @@
 
 EOF
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 echo 0 > $TMP_DIR/error.$$
 
 pushd `dirname $0` > /dev/null
diff --git a/cases/function/einj-ext/runtest.sh b/cases/function/einj-ext/runtest.sh
index c9b0bec..c1652c9 100755
--- a/cases/function/einj-ext/runtest.sh
+++ b/cases/function/einj-ext/runtest.sh
@@ -13,7 +13,11 @@
 EOF
 
 TMP="../../../work"
-export TMP_DIR=${TMP_DIR:-$TMP}
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
 
 echo 0 > $TMP_DIR/error.$$
 
diff --git a/cases/function/erst-inject/runtest.sh b/cases/function/erst-inject/runtest.sh
index 253ebe3..aa81bcf 100755
--- a/cases/function/erst-inject/runtest.sh
+++ b/cases/function/erst-inject/runtest.sh
@@ -60,6 +60,13 @@
 
 EOF
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 ERST=./erst-inject
 LOG=$TMP_DIR/erst.log.$$
 MODSTATUS=0
diff --git a/cases/function/hwpoison/helpers.sh b/cases/function/hwpoison/helpers.sh
index 7b241c8..b9ddcbe 100644
--- a/cases/function/hwpoison/helpers.sh
+++ b/cases/function/hwpoison/helpers.sh
@@ -4,6 +4,13 @@
 . $ROOT/lib/functions.sh
 setup_path
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 executed_testcase=0
 failed_testcase=0
 
diff --git a/cases/function/pfa/runtest.sh b/cases/function/pfa/runtest.sh
index 7428e25..8213e58 100755
--- a/cases/function/pfa/runtest.sh
+++ b/cases/function/pfa/runtest.sh
@@ -17,6 +17,13 @@
 
 EOF
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 echo 0 > $TMP_DIR/error.$$
 
 pushd `dirname $0` > /dev/null
diff --git a/cases/stress/hwpoison/run_hard.sh b/cases/stress/hwpoison/run_hard.sh
index 163f217..3e1f67e 100755
--- a/cases/stress/hwpoison/run_hard.sh
+++ b/cases/stress/hwpoison/run_hard.sh
@@ -34,6 +34,13 @@
 
 EOF
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 echo 0 > $TMP_DIR/error.$$
 
 pushd `dirname $0` > /dev/null
diff --git a/cases/stress/hwpoison/run_soft.sh b/cases/stress/hwpoison/run_soft.sh
index 8e86be1..d316854 100755
--- a/cases/stress/hwpoison/run_soft.sh
+++ b/cases/stress/hwpoison/run_soft.sh
@@ -33,6 +33,13 @@
 
 EOF
 
+TMP="../../../work"
+TMP_DIR=${TMP_DIR:-$TMP}
+if [ ! -d $TMP_DIR ]; then
+	TMP_DIR=$TMP
+fi
+export TMP_DIR
+
 echo 0 > $TMP_DIR/error.$$
 
 pushd `dirname $0` > /dev/null