--- /dev/null
+#!/usr/bin/env python
+
+"""This script is used to test images on real target devices"""
+
+import os
+import sys
+import glob
+import subprocess
+from common.buildtrigger import trigger_info
+
+
+def dump_result(outcome="TESTER_FAILURE", image="Not found"):
+ """"Saves the results to a file, for injection"""
+ assert outcome in {"TESTER_FAILURE", "PASS", "FAIL"}
+ with open("Results.ENV", "w") as results:
+ results.write("TEST_RESULT=" + outcome + "\n")
+ results.write("IMAGE=" + image + "\n")
+
+
+def fetch_image(url):
+ """Tries to download locally the image that will be tested."""
+ try:
+ command = ["/usr/bin/wget", "-r", "-l1", "-np", "-nd", "-A",
+ os.getenv("TESTABLE_IMAGE_DOWNLOADABLES"), url]
+ subprocess.check_output(command, stderr = subprocess.STDOUT)
+ image = glob.glob(os.getenv("TESTABLE_IMAGE_FILTER"))[0]
+ return image
+ except (IndexError, ValueError, subprocess.CalledProcessError, OSError):
+ dump_result("TESTER_FAILURE")
+ print "Failed to retrieve image."
+ return None
+
+
+def test_image(image):
+ """Flashes the target device and runs the smoke test."""
+ try:
+ command = ["/usr/bin/tztestrobot.run", image]
+ subprocess.check_output(command)
+ except OSError:
+ result = "TESTER_FAILURE"
+ print "Failed to flash the image and run the tests."
+ except (ValueError, subprocess.CalledProcessError):
+ result = "FAIL"
+ print "One or more tests failed."
+ else:
+ result = "PASS"
+ print "All the tests succeeded."
+ dump_result(result, image)
+ return result
+
+def main():
+ """The main body"""
+ # Note: the script, by design, will not return errors
+ # Rather, it will inject the error status in the environment
+
+ content = trigger_info(os.getenv("TRIGGER_INFO"))
+ url = content.get("url", "")
+ image = fetch_image(url)
+
+ if not image:
+ return
+
+ dump_result(test_image(image), image)
+
+
+if __name__ == "__main__":
+ sys.exit(main())