From 66911d6ce14f6f3f8e82d474ea510743b935333e Mon Sep 17 00:00:00 2001
From: Francisco Acosta <f.acosta.ext@kugu-home.com>
Date: Wed, 5 Dec 2018 01:12:14 +0100
Subject: [PATCH] tests/riotboot: add basic automatic test in python

Co-authored-by: Federico Pellegrin <fede@evolware.org>
---
 tests/riotboot/README.md       |  5 ++++-
 tests/riotboot/tests/01-run.py | 41 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 tests/riotboot/tests/01-run.py

diff --git a/tests/riotboot/README.md b/tests/riotboot/README.md
index 09ae0e25f9..c85ed4d5ae 100644
--- a/tests/riotboot/README.md
+++ b/tests/riotboot/README.md
@@ -14,5 +14,8 @@ This test should foremost give you an overview how to use riotboot:
   riotboot and the RIOT image with headers included. This should boot
   as a normal application.
 
-In this test two modules `riot_hdr` and `slot_util` are used to showcase
+In this test two modules `riotboot_hdr` and `riotboot_slot` are used to showcase
 the access to riotboot shared functions.
+
+  - `make test` can be executed to run the automatic Python test that checks
+  basic functionalities of riotboot
diff --git a/tests/riotboot/tests/01-run.py b/tests/riotboot/tests/01-run.py
new file mode 100755
index 0000000000..07ececb93f
--- /dev/null
+++ b/tests/riotboot/tests/01-run.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2018 Federico Pellegrin <fede@evolware.org>
+#
+# This file is subject to the terms and conditions of the GNU Lesser
+# General Public License v2.1. See the file LICENSE in the top level
+# directory for more details.
+
+import sys
+from testrunner import run
+
+
+def testfunc(child):
+    # Ask for current slot, should be 0 (riotboot slot)
+    child.sendline("curslotnr")
+    child.expect_exact("Current slot=0")
+    child.expect('>')
+
+    # Ask for current slot header info and checks for basic output integrity
+    child.sendline("curslothdr")
+    # Magic number is "RIOT" (always in little endian)
+    child.expect_exact("Image magic_number: 0x544f4952")
+    # Other info is hardware/app dependant so we just check basic compliance
+    child.expect("Image Version: 0x[0-9a-fA-F]{8}")
+    child.expect("Image start address: 0x[0-9a-fA-F]{8}")
+    child.expect("Header chksum: 0x[0-9a-fA-F]{8}")
+    child.expect('>')
+
+    # Ask for address of slot 0
+    child.sendline("getslotaddr 0")
+    child.expect("Slot 0 address=0x[0-9a-fA-F]{8}")
+    child.expect('>')
+
+    # Ask for data of all slots
+    child.sendline("dumpaddrs")
+    child.expect("slot 0: metadata: 0x[0-9a-fA-F]{1,8} image: 0x[0-9a-fA-F]{8}")
+    child.expect('>')
+
+
+if __name__ == "__main__":
+    sys.exit(run(testfunc))
-- 
GitLab