igt: modify test definition for igt_runner

There is a test runner, igt_runner, comes with the newer version of
igt-gpu-tests. We can run the tests with it rather than piglit. Now the
test definition is compatible with both igt_runner and piglit.

Signed-off-by: Arthur She <arthur.she@linaro.org>
diff --git a/automated/linux/igt/igt-test.sh b/automated/linux/igt/igt-test.sh
index 9d6002a..c770e44 100755
--- a/automated/linux/igt/igt-test.sh
+++ b/automated/linux/igt/igt-test.sh
@@ -29,6 +29,15 @@
     ${TEST_SCRIPT} -l | grep chamelium | grep -v "dp\|vga\|suspend\|hibernate" | tee "${IGT_DIR}"/"${TEST_LIST}"
 }
 
+download_piglit() {
+    # Download Piglit
+    git config --global http.postBuffer 157286400
+    if [ ! -d "${IGT_DIR}/piglit" ]; then
+        echo "Download Piglit.."
+        time ${TEST_SCRIPT} -d
+    fi
+}
+
 usage() {
     echo "usage: $0 -d <igt-gpu-tools dir> -t <test-list> [-c <chamelium ip address>] [-h <HDMI device name>]" 1>&2
     exit 1
@@ -56,14 +65,9 @@
 
 export IGT_TEST_ROOT="/usr/libexec/igt-gpu-tools"
 
-# new run-tests.sh needs '-p' to run the tests with piglit
-${TEST_SCRIPT} --help | grep -q '\-p' && TEST_SCRIPT="${TEST_SCRIPT} -p"
-
-# Download Piglit
-git config --global http.postBuffer 157286400
-if [ ! -d "${IGT_DIR}/piglit" ]; then
-    echo "Download Piglit.."
-    time ${TEST_SCRIPT} -d
+if [ ! -f "${IGT_DIR}/runner/igt_runner" ]; then
+    ${TEST_SCRIPT} --help | grep -q '\-p' && TEST_SCRIPT="${TEST_SCRIPT} -p"
+    download_piglit
 fi
 
 if [ "${TEST_LIST}" == "CHAMELIUM" ]; then
@@ -80,5 +84,5 @@
 
 # Run tests
 echo "Run ${TEST_LIST}"
-${TEST_SCRIPT} -T "${IGT_DIR}"/"${TEST_LIST}" -v -s | tee tmp.log
+${TEST_SCRIPT} -T "${IGT_DIR}"/"${TEST_LIST}" -v | tee tmp.log
 grep -e '^pass' -e '^skip' -e '^fail' tmp.log|awk -F':\ ' '{print $2" "$1}' > ${RESULT_LOG}
diff --git a/automated/linux/igt/igt-test.yaml b/automated/linux/igt/igt-test.yaml
index 4339561..a69046f 100644
--- a/automated/linux/igt/igt-test.yaml
+++ b/automated/linux/igt/igt-test.yaml
@@ -47,7 +47,8 @@
         - echo "**********************************************";
         - echo "************ Dump IGT test result ************";
         - echo "**********************************************";
-        - bzcat ${IGT_DIR}/results/results.json.bz2 | python print-test-result.py
+        - if [ -f "${IGT_DIR}/results/results.json.bz2" ]; then bunzip2 ${IGT_DIR}/results/results.json.bz2; fi
+        - python print-test-result.py -f ${IGT_DIR}/results/results.json
         - if [ -n "${ARTIFACTORIAL_TOKEN}" -a -n "${ARTIFACTORIAL_URL}" ]; then
         - UPLOAD_TOOL="../../utils/upload-to-artifactorial.sh"
         - if [ -d "/root/dump-frames/" -a -n "`ls /root/dump-frames/`" ];  then echo "Got error frames.." ; tar -C /root -zcf dump-frames.tar.gz dump-frames/;
diff --git a/automated/linux/igt/print-test-result.py b/automated/linux/igt/print-test-result.py
index 5eefd6f..42a939d 100755
--- a/automated/linux/igt/print-test-result.py
+++ b/automated/linux/igt/print-test-result.py
@@ -5,22 +5,24 @@
 
 
 def print_result(results):
-    try:
-        for test, content in results['tests'].iteritems():
-            print '<LAVA_SIGNAL_STARTTC %s>' % test
-            print '************************************************************************************************************************************'
-            print '%-15s %s' % ('Test:', test)
-            print '%-15s %s' % ('Result:', content['result'])
+    for test, content in results['tests'].iteritems():
+        content = {k: unicode(v).encode("utf-8") for k, v in content.iteritems()}
+        print '<LAVA_SIGNAL_STARTTC %s>' % test
+        print '************************************************************************************************************************************'
+        print '%-15s %s' % ('Test:', test)
+        print '%-15s %s' % ('Result:', content['result'])
+        # Test result generated by igt_runner doesn't have the following values
+        try:
             print '%-15s %s' % ('Command:', content['command'])
             print '%-15s %s' % ('Environment:', content['environment'])
             print '%-15s %s' % ('Returncode:', content['returncode'])
-            print '%-15s %s' % ('Stdout:', content['out'].replace('\n', '\n                '))
-            print '%-15s %s' % ('Stderr:', content['err'].replace('\n', '\n                '))
-            print '%-15s %s' % ('dmesg:', content['dmesg'].replace('\n', '\n                '))
-            print '<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=%s>' % (test, content['result'])
-            print '<LAVA_SIGNAL_ENDTC %s>' % test
-    except KeyError:
-        print "Error: Can not find required data"
+        except KeyError:
+            pass
+        print '%-15s %s' % ('Stdout:', content['out'].replace('\n', '\n                '))
+        print '%-15s %s' % ('Stderr:', content['err'].replace('\n', '\n                '))
+        print '%-15s %s' % ('dmesg:', content['dmesg'].replace('\n', '\n                '))
+        print '<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=%s>' % (test, content['result'])
+        print '<LAVA_SIGNAL_ENDTC %s>' % test
 
 
 if __name__ == '__main__':