Merge "workload-automation: add installation and config for AEP"
diff --git a/automated/linux/badblocks/badblocks.sh b/automated/linux/badblocks/badblocks.sh
new file mode 100755
index 0000000..0698df1
--- /dev/null
+++ b/automated/linux/badblocks/badblocks.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# shellcheck disable=SC1091
+. ../../lib/sh-test-lib
+OUTPUT="$(pwd)/output"
+RESULT_FILE="${OUTPUT}/result.txt"
+export RESULT_FILE
+TEST_SUITE="badblocks"
+BLOCK_DEVICE="default"
+
+usage() {
+    echo "Usage: $0 [-b <block device>] [-p <badblocks params>] [-s <skip install: true|false]" 1>&2
+    exit 1
+}
+
+while getopts "b:h:p:s:" o; do
+  case "$o" in
+    b) BLOCK_DEVICE="${OPTARG}" ;;
+    p) BADBLOCKS_PARAMS="${OPTARG}" ;;
+    s) SKIP_INSTALL="${OPTARG}" ;;
+    h|*) usage ;;
+  esac
+done
+
+install() {
+    dist_name
+    # shellcheck disable=SC2154
+    case "${dist}" in
+      debian|ubuntu) install_deps "e2fsprogs" "${SKIP_INSTALL}";;
+      unknown) warn_msg "Unsupported distro: package install skipped" ;;
+    esac
+}
+
+if [ "${BLOCK_DEVICE}" = "default" ]; then
+  BLOCK_DEVICE=$(mount | grep "on \/ type" | cut -d' ' -f 1)
+fi
+
+create_out_dir "${OUTPUT}"
+install
+
+command -v badblocks
+exit_on_fail "badblocks-existence-check"
+
+if [ ! -z "${BLOCK_DEVICE}" ] && [ -e "${BLOCK_DEVICE}" ]; then
+  info_msg "Running ${TEST_SUITE} test on ${BLOCK_DEVICE}"
+  LOG_FILE="${OUTPUT}/${TEST_SUITE}-output.txt"
+  test_cmd="badblocks -v ${BADBLOCKS_PARAMS} ${BLOCK_DEVICE} 2>&1"
+  pipe0_status "${test_cmd}" "tee ${LOG_FILE}"
+  check_return "${TEST_SUITE}"
+else
+  info_msg "Skipping ${TEST_SUITE} test on ${BLOCK_DEVICE}"
+  echo "${TEST_SUITE} skip" | tee -a "${RESULT_FILE}"
+fi
diff --git a/automated/linux/badblocks/badblocks.yaml b/automated/linux/badblocks/badblocks.yaml
new file mode 100644
index 0000000..99eec2f
--- /dev/null
+++ b/automated/linux/badblocks/badblocks.yaml
@@ -0,0 +1,25 @@
+metadata:
+    name: badblocks
+    format: "Lava-Test-Shell Test Definition 1.0"
+    description: "Run a read-only test for bad blocks"
+    maintainer:
+        - ryan.harkin@linaro.org
+    os:
+        - openembedded
+        - debian
+    scope:
+        - functional
+    devices:
+        - imx7s-warp
+        - sun8i-h2-plus-bananapi-m2-zero
+
+parameters:
+    BLOCK_DEVICE: 'default'
+    BADBLOCKS_PARAMS: ''
+    SKIP_INSTALL: "False"
+
+run:
+    steps:
+        - cd ./automated/linux/badblocks/
+        - ./badblocks.sh -b "${BLOCK_DEVICE}" -p "${BADBLOCKS_PARAMS}" -s "${SKIP_INSTALL}"
+        - ../../utils/send-to-lava.sh ./output/result.txt
diff --git a/automated/linux/ptest/ptest.py b/automated/linux/ptest/ptest.py
index ee38876..13feb4d 100755
--- a/automated/linux/ptest/ptest.py
+++ b/automated/linux/ptest/ptest.py
@@ -61,9 +61,13 @@
     return ptests
 
 
-def filter_ptests(ptests, requested_ptests):
+def filter_ptests(ptests, requested_ptests, exclude):
     filter_ptests = []
 
+    for ptest in exclude:
+        if ptest in ptests:
+            ptests.remove(ptest)
+
     if not requested_ptests:
         return ptests
 
@@ -100,6 +104,8 @@
                                      add_help=False)
     parser.add_argument('-t', '--tests', action='store', nargs='*',
                         help='Ptests to run')
+    parser.add_argument('-e', '--exclude', action='store', nargs='*',
+                        help='Ptests to exclude')
     parser.add_argument('-d', '--ptest-dir',
                         help='Directory where ptests are stored (optional)',
                         action='store')
@@ -129,8 +135,13 @@
     if args.tests:
         tests = [x for x in args.tests if x]
 
+    # filter empty strings caused by -e ""
+    exclude = []
+    if args.exclude:
+        exclude = [e for e in args.exclude if e]
+
     required_ptests = dict.fromkeys(tests, False)
-    ptests_to_run = filter_ptests(ptests, required_ptests)
+    ptests_to_run = filter_ptests(ptests, required_ptests, exclude)
     for ptest_name in ptests_to_run:
         check_ptest(ptest_dir, ptest_name, args.output_log)
 
diff --git a/automated/linux/ptest/ptest.yaml b/automated/linux/ptest/ptest.yaml
index 703358a..854af0b 100644
--- a/automated/linux/ptest/ptest.yaml
+++ b/automated/linux/ptest/ptest.yaml
@@ -16,9 +16,10 @@
 
 params:
     TESTS: ""
+    EXCLUDE: ""
 
 run:
     steps:
         - cd ./automated/linux/ptest
-        - ./ptest.py -o ./result.txt -t ${TESTS}
+        - ./ptest.py -o ./result.txt -t ${TESTS} -e ${EXCLUDE}
         - ../../utils/send-to-lava.sh ./result.txt