Store results in sqlite3 database 34/81334/8
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 22 Jul 2016 09:45:22 +0000 (11:45 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 8 Nov 2016 15:08:34 +0000 (16:08 +0100)
Additional argument, $TARGET, is required for tsp/jobs/publish.sh

Change-Id: Iab5728c40e4786425c26dd48e7a70d6221dc90ae
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
tsp/common.sh
tsp/jobs/common_prep_flash_conf.sh
tsp/jobs/img_test_common.sh
tsp/jobs/publish.sh

index 7667bba..82ea38b 100755 (executable)
@@ -34,6 +34,10 @@ WS_WATCHER="${WS}/watcher"
 WS_DOWNLOAD="${WS}/dwn"
 WS_TEST="${WS}/img_test"
 WS_TEST_REMOTE="${WS}/img_test_remote"
+WS_PUBLISH="${WS}/publish"
+
+DBNAME="results.db3"
+DBPATH="${WS_PUBLISH}/${DBNAME}"
 
 TMP_POLL="/tmp/tl-master-poll"
 TMP_MASTER="/tmp/tl-master"
@@ -58,13 +62,15 @@ tsrun_target() {
 check_diff() {
     DIFF_FILE="$1"
     JOB_NR="$2"
+    TARGET="$3"
     test -n "$1" || die "Missing argument: diff file"
     test -n "$2" || die "Missing argument: build nr"
+    test -n "$3" || die "Missing argument: target"
     test -n "${TSP_DIR}" || die "Missing environment variable: TSP_DIR"
     if grep -q "identical" "${DIFF_FILE}"
     then
         echo "Image is unchanged in respect to snapshot"
-        nr=`tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh ${JOB_NR}`
+        nr=`tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh ${JOB_NR} ${TARGET}`
         return 1
     fi
 }
index d41bf67..92720d5 100755 (executable)
@@ -46,7 +46,7 @@ test -n "${FAIL_CNT}" || FAIL_CNT=0
 
 if [ "$FAIL_CNT" -ge 2 ]; then
     # Trigger publish job
-    tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh $1
+    tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh "$1" "$TARGET"
     exit 0
 fi
 
@@ -78,4 +78,4 @@ then
 fi
 
 # Trigger publish job
-tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh $1
+tspwb -L PUBLISH sh ${TSP_DIR}/jobs/publish.sh "$1" "$TARGET"
index b62771a..a412abb 100755 (executable)
@@ -44,7 +44,7 @@ esac
 rm -rf "${WORKDIR}"
 mkdir -p "${WORKDIR}"
 cd "${WORKDIR}"
-if $(check_diff "${DIFF_FILE}" "$1");
+if $(check_diff "${DIFF_FILE}" "$1" "${TARGET}");
 then
     echo "Add common_prep_flash_conf job to the $TARGET queue"
     tsrun_target $TARGET -L "$(echo "$TARGET" | tr 'a-z' 'A-Z')_PREPARE_FLASH_CONF" \
index 24c066c..88ea53d 100755 (executable)
@@ -20,7 +20,13 @@ export TSP_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)/.."
 
 . "${TSP_DIR}/common.sh"
 
+TARGET="$2"
+
 test -n "$1" || die "Missing argument: build nr"
+test -n "$TARGET" || die "Missing argument: target"
+test -d "${WS_PUBLISH}" || mkdir -p "${WS_PUBLISH}"
+
+cd "${WS_PUBLISH}"
 
 IMG_WORKDIR="${WS_TEST}/$1"
 DWN_WORKDIR="${WS_DOWNLOAD}/$1"
@@ -93,8 +99,6 @@ compare_with_snapshot() {
 PROJECT_FILE="`ls ${DWN_WORKDIR}/project-*.conf`"
 DIFF_FILE="`ls ${DWN_WORKDIR}/diff-*.report`"
 SYSCTL_FILE="${IMG_WORKDIR}/sysctl.result"
-TARGET="${PROJECT_FILE%%.conf}"
-TARGET="${TARGET##*-}"
 SNAPSHOT_SYSCTL_FILE="${WS_TEST}/snapshot_sysctl_${TARGET}"
 TAG_FILE="${IMG_WORKDIR}/tag"
 
@@ -115,7 +119,29 @@ else
     fi
 fi
 
-test -n "$TAG" && echo "$TAG" > "$TAG_FILE"
+test -n "$TAG" || TAG="Unclear"
+echo "$TAG" > "$TAG_FILE"
+
+init_db() {
+    # Load schema
+    sqlite3 -batch "${DBPATH}" < "${TSP_DIR}/results-schema.sql"
+    # Load initial values to tables 'device' and 'result'
+    sqlite3 -batch "${DBPATH}" < "${TSP_DIR}/results-values-device.sql"
+    sqlite3 -batch "${DBPATH}" < "${TSP_DIR}/results-values-result.sql"
+}
+
+test -f "${DBPATH}" || init_db
+
+SR="`head -n 1 ${PROJECT_FILE}`"
+
+echo "SR: $SR"
+echo "TAG: $TAG"
+echo "TARGET: $TARGET"
+
+# Publish to database
+sqlite3 "${DBPATH}" "insert into test values (NULL,'$SR', CURRENT_TIMESTAMP,\
+    (select r.rid from result r where r.rname='$TAG'),\
+    (select d.did from device d where d.dname='$TARGET'));"
 
 # Clean up workspace
 ssh tl-pwb "rm -rf \"${WORKSPACE}\"; mkdir -p \"${WORKSPACE}\"" || echo "rm failed"