LTP: Add skipgen skipfile support to ltp

Create a helper function in sh-test-lib to handle the mechanics of
generating a skipfile, that will be re-usable by kselftest.

Add the following arguments to ltp.sh:
    [-b board]
    [-g branch]
    [-e environment]

When the skipfile argument passed via -S ends in ".yaml", a skipfile
will be generated using skipgen. Board, branch, and environment are
optional arguments that get passed to skipgen.

The resulting skipfile is automatically printed to stdout after being
generated.

Change-Id: Ib45d11acfa85241dbe5dfa7173e75cb7754a6892
Signed-off-by: Dan Rue <dan.rue@linaro.org>
diff --git a/automated/linux/ltp/ltp.sh b/automated/linux/ltp/ltp.sh
index cb4a1ac..789b56e 100755
--- a/automated/linux/ltp/ltp.sh
+++ b/automated/linux/ltp/ltp.sh
@@ -15,6 +15,11 @@
 TST_CMDFILES=""
 # List of test cases to be skipped
 SKIPFILE=""
+# List of test cases to be skipped in yaml/skipgen format
+SKIPFILE_YAML=""
+BOARD=""
+BRANCH=""
+ENVIRONMENT=""
 # LTP version
 LTP_VERSION="20170929"
 LTP_TMPDIR=/ltp-tmp
@@ -24,6 +29,9 @@
 usage() {
     echo "Usage: ${0} [-T mm,math,syscalls]
                       [-S skipfile-lsk-juno]
+                      [-b board]
+                      [-g branch]
+                      [-e environment]
                       [-s True|False]
                       [-v LTP_VERSION]
                       [-M Timeout_Multiplier]
@@ -31,7 +39,7 @@
     exit 0
 }
 
-while getopts "M:T:S:s:v:R:" arg; do
+while getopts "M:T:S:b:g:e:s:v:R:" arg; do
    case "$arg" in
      T)
         TST_CMDFILES="${OPTARG}"
@@ -39,17 +47,38 @@
         LOG_FILE=$(echo "${OPTARG}"| sed 's,\/,_,')
         ;;
      S)
-        OPT=$(echo "${OPTARG}" | grep "http")
-        if [ -z "${OPT}" ] ; then
-        # LTP skipfile
-          SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
+        if [ -z "${OPTARG##*http*}" ]; then
+          if [ -z "${OPTARG##*yaml*}" ]; then
+            # Skipfile is of type yaml
+            SKIPFILE_TMP="http-skipfile.yaml"
+            SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}"
+          else
+            # Skipfile is normal skipfile
+            SKIPFILE_TMP="http-skipfile"
+            SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE_TMP}"
+          fi
+          # Download LTP skipfile from specified URL
+          if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then
+            error_msg "Failed to fetch ${OPTARG}"
+            exit 1
+          fi
+        elif [ "${OPTARG##*.}" = "yaml" ]; then
+          # yaml skipfile; use skipgen to generate a skipfile
+          SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}"
         else
-        # Download LTP skipfile from speficied URL
-          wget "${OPTARG}" -O "skipfile"
-          SKIPFILE="skipfile"
-          SKIPFILE="-S ${SCRIPTPATH}/${SKIPFILE}"
+          # Regular LTP skipfile
+          SKIPFILE="-S ${SCRIPTPATH}/${OPTARG}"
         fi
         ;;
+     b)
+        export BOARD="${OPTARG}"
+        ;;
+     g)
+        export BRANCH="${OPTARG}"
+        ;;
+     e)
+        export ENVIRONMENT="${OPTARG}"
+        ;;
      # SKIP_INSTALL is true in case of Open Embedded builds
      # SKIP_INSTALL is flase in case of Debian builds
      s) SKIP_INSTALL="${OPTARG}";;
@@ -60,6 +89,16 @@
   esac
 done
 
+if [ -n "${SKIPFILE_YAML}" ]; then
+    export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile"
+    generate_skipfile
+    if [ ! -f "${SKIPFILE_PATH}" ]; then
+        error_msg "Skipfile ${SKIPFILE} does not exist";
+        exit 1
+    fi
+    SKIPFILE="-S ${SKIPFILE_PATH}"
+fi
+
 # Install LTP test suite
 install_ltp() {
     rm -rf /opt/ltp
diff --git a/automated/linux/ltp/ltp.yaml b/automated/linux/ltp/ltp.yaml
index dd15eaf..13f65b3 100644
--- a/automated/linux/ltp/ltp.yaml
+++ b/automated/linux/ltp/ltp.yaml
@@ -20,14 +20,24 @@
     # LTP version
     LTP_VERSION: 20170929
     TST_CMDFILES: syscalls,mm,math,timers,fcntl-locktests,ipc,fsx,fs,hugetlb,io,nptl,pty,containers,fs_bind,filecaps,admin_tools,connectors
-    # TST_CMDFILES: math,timers
-    # SKIPFILE can be a filename from dir ./automated/linux/ltp/ or an open URL
-    # SKIPFILE: "skipfile-lsk-juno"
-    # "skipfile-lsk-juno" is a known file present in dir ./automated/linux/ltp/
-    # or
-    # SKIPFILE: "http://people.linaro.org/~naresh.kamboju/skipfile"
-    # NOTE: busybox wget may not work with https link so pefer to use http
+
+    # SKIPFILE can be a filename from dir ./automated/linux/ltp/, an http URL,
+    # or a skipgen style yaml file.
+    # Examples:
+    #   SKIPFILE: "skipfile-lsk-juno" # is a known file present in
+    #                                 # dir ./automated/linux/ltp/
+    #   SKIPFILE: "http://people.linaro.org/~naresh.kamboju/skipfile"
+    #   SKIPFILE: "skipfile-lkft.yaml" # yaml file that will be parsed with
+    #                                  # skipgen. Must use "yaml" extention.
+    # NOTE: busybox wget may not work with https link so prefer to use http
     SKIPFILE: ""
+
+    # BOARD, BRANCH, and ENVIRONMENT may be specified and may be used when
+    # generating a skipfile using a yaml skipfile and skipgen.
+    BOARD: ""
+    BRANCH: ""
+    ENVIRONMENT: ""
+
     SKIP_INSTALL: false
     # Slow machines need more timeout Default is 5min and multiply * TIMEOUT_MULTIPLIER
     TIMEOUT_MULTIPLIER: 1
@@ -37,7 +47,7 @@
 run:
     steps:
         - cd ./automated/linux/ltp/
-        - ./ltp.sh -T "${TST_CMDFILES}" -S "${SKIPFILE}" -s "${SKIP_INSTALL}" -v "${LTP_VERSION}" -M "${TIMEOUT_MULTIPLIER}" -R "${ROOT_PASSWD}"
+        - ./ltp.sh -T "${TST_CMDFILES}" -s "${SKIP_INSTALL}" -v "${LTP_VERSION}" -M "${TIMEOUT_MULTIPLIER}" -R "${ROOT_PASSWD}" -b "${BOARD}" -g "${BRANCH}" -e "${ENVIRONMENT}" -S "${SKIPFILE}"
         - ../../utils/send-to-lava.sh ./output/result.txt
 
 parse: