diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6c5b624..e0578b6 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -27,6 +27,9 @@ jobs:
- name: Build
run: make
+ - name: Run tests
+ run: make tests
+
- name: Package
run: |
mkdir dist
@@ -62,6 +65,9 @@ jobs:
- name: Build
run: make
+ - name: Run tests
+ run: make tests
+
- name: Package
run: |
set -x
diff --git a/Makefile b/Makefile
index 8b3b4ef..2febafb 100644
--- a/Makefile
+++ b/Makefile
@@ -46,3 +46,7 @@ clean:
install: $(QDL) $(RAMDUMP) $(KS_OUT)
install -d $(DESTDIR)$(prefix)/bin
install -m 755 $^ $(DESTDIR)$(prefix)/bin
+
+tests: default
+tests:
+ @./tests/run_tests.sh
diff --git a/tests/data/generate_flat_build.sh b/tests/data/generate_flat_build.sh
new file mode 100755
index 0000000..df7c09c
--- /dev/null
+++ b/tests/data/generate_flat_build.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+
+SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+
+create_file_with_size() {
+ filename="$1"
+ size_kbytes="$2"
+
+ dd if=/dev/zero of="$SCRIPT_PATH/$filename" bs=1024 count="$size_kbytes" status=none
+}
+
+create_file_with_size prog_firehose_ddr.elf 20
+create_file_with_size efi.bin 524288
+create_file_with_size gpt_backup0.bin 20
+create_file_with_size gpt_backup1.bin 20
+create_file_with_size gpt_main0.bin 24
+create_file_with_size gpt_main1.bin 24
+create_file_with_size rootfs.img 512000
+create_file_with_size xbl_config.elf 320
+create_file_with_size xbl.elf 800
diff --git a/tests/data/patch0.xml b/tests/data/patch0.xml
new file mode 100644
index 0000000..e1f60b3
--- /dev/null
+++ b/tests/data/patch0.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/data/patch1.xml b/tests/data/patch1.xml
new file mode 100644
index 0000000..6335a92
--- /dev/null
+++ b/tests/data/patch1.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/data/rawprogram0.xml b/tests/data/rawprogram0.xml
new file mode 100644
index 0000000..8bded57
--- /dev/null
+++ b/tests/data/rawprogram0.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/tests/data/rawprogram1.xml b/tests/data/rawprogram1.xml
new file mode 100644
index 0000000..167c5f8
--- /dev/null
+++ b/tests/data/rawprogram1.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..12369db
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# SPDX-License-Identifier: BSD-3-Clause
+
+set -e
+
+SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+FLAT_BUILD_PATH=$SCRIPT_PATH/data
+
+echo "####### Generate a FLAT build"
+$FLAT_BUILD_PATH/generate_flat_build.sh
+
+echo "####### Run QDL tests"
+cd $SCRIPT_PATH
+for t in test_*.sh; do
+ echo "###### Run $t"
+ bash $t
+ if [ $? -eq 0 ]; then
+ echo "####### Test $t: OK"
+ else
+ echo "####### Test $t: FAIL"
+ failed=1
+ fi
+done
+
+echo "####### Housekeeping"
+rm -f ${FLAT_BUILD_PATH}/*.bin ${FLAT_BUILD_PATH}/*.img
+rm -f ${FLAT_BUILD_PATH}/*.elf
+
+if [ "$failed" == "1" ]; then
+ echo "####### Some test failed"
+ exit 1
+fi
+
+echo "####### All tests passed"
diff --git a/tests/test_vip_generation.sh b/tests/test_vip_generation.sh
new file mode 100755
index 0000000..276c5e0
--- /dev/null
+++ b/tests/test_vip_generation.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# SPDX-License-Identifier: BSD-3-Clause
+
+set -e
+
+SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+
+FLAT_BUILD=${SCRIPT_PATH}/data
+
+REP_ROOT=${SCRIPT_PATH}/..
+VIP_PATH=${FLAT_BUILD}/vip
+EXPECTED_DIGEST="4e13981189ede380172369aa0a4847ca3c9a4e2795733bca90ec1b1e713972ea"
+VIP_TABLE_FILE=${VIP_PATH}/DigestsToSign.bin
+
+mkdir -p $VIP_PATH
+
+cd $FLAT_BUILD
+${REP_ROOT}/qdl --dry-run --create-digests=${VIP_PATH} \
+ prog_firehose_ddr.elf rawprogram*.xml patch*.xml
+
+if command -v sha256sum >/dev/null 2>&1; then
+ shacmd="sha256sum"
+elif command -v shasum >/dev/null 2>&1; then
+ shacmd="shasum -a 256"
+else
+ echo "No SHA-256 checksum tool found (need 'sha256sum' or 'shasum')"
+ exit 1
+fi
+
+actual_digest=`${shacmd} "${VIP_TABLE_FILE}" | cut -d ' ' -f1`
+if [ "$actual_digest" != "${EXPECTED_DIGEST}" ]; then
+ echo "Expected SHA256 digest of ${VIP_TABLE_FILE} file is ${EXPECTED_DIGEST}"
+ echo "Calculated SHA256 digest of ${VIP_TABLE_FILE} file is $actual_digest"
+ echo "VIP table folder contents:"
+ ls -la ${VIP_PATH}
+ exit 1
+fi
+
+echo "VIP tables are generated successfully and validated"
+
+rm -r ${VIP_PATH}/*.bin
+rmdir ${VIP_PATH}