Test: Add BL1_1 integration testsuite

Change-Id: I6a9174e08a4d67c7da928b28f18dd9e4a3106f41
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/test/bl1/bl1_1/CMakeLists.txt b/test/bl1/bl1_1/CMakeLists.txt
index 66bcf3b..464af4b 100644
--- a/test/bl1/bl1_1/CMakeLists.txt
+++ b/test/bl1/bl1_1/CMakeLists.txt
@@ -11,6 +11,7 @@
 
 add_subdirectory(suites/crypto)
 add_subdirectory(suites/trng)
+add_subdirectory(suites/integration)
 
 add_library(bl1_1_tests STATIC)
 
@@ -32,4 +33,5 @@
         tfm_log
         bl1_1_test_suite_crypto
         bl1_1_test_suite_trng
+        bl1_1_test_suite_integration
 )
diff --git a/test/bl1/bl1_1/bl1_1_suites.c b/test/bl1/bl1_1/bl1_1_suites.c
index 3ce2c90..9f413c8 100644
--- a/test/bl1/bl1_1/bl1_1_suites.c
+++ b/test/bl1/bl1_1/bl1_1_suites.c
@@ -11,11 +11,13 @@
 
 #include "bl1_1_crypto_tests.h"
 #include "bl1_1_trng_tests.h"
+#include "bl1_1_integration_tests.h"
 
 static struct test_suite_t test_suites[] = {
 
     {&register_testsuite_bl1_crypto_interface, 0, 0, 0},
     {&register_testsuite_bl1_trng_interface, 0, 0, 0},
+    {&register_testsuite_bl1_1_integration, 0, 0, 0},
 
     /* End of test suites */
     {0, 0, 0, 0}
diff --git a/test/bl1/bl1_1/suites/integration/CMakeLists.txt b/test/bl1/bl1_1/suites/integration/CMakeLists.txt
new file mode 100644
index 0000000..2554b4f
--- /dev/null
+++ b/test/bl1/bl1_1/suites/integration/CMakeLists.txt
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+add_library(bl1_1_test_suite_integration)
+
+target_sources(bl1_1_test_suite_integration
+    PRIVATE
+        ./bl1_1_integration_tests.c
+)
+
+target_include_directories(bl1_1_test_suite_integration
+    PUBLIC
+        .
+)
+
+target_link_libraries(bl1_1_test_suite_integration
+    PRIVATE
+        tfm_test_framework_common
+        bl1_1_shared_lib
+)
diff --git a/test/bl1/bl1_1/suites/integration/bl1_1_integration_tests.c b/test/bl1/bl1_1/suites/integration/bl1_1_integration_tests.c
new file mode 100644
index 0000000..e7c8b27
--- /dev/null
+++ b/test/bl1/bl1_1/suites/integration/bl1_1_integration_tests.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "bl1_1_integration_tests.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+
+#include "region_defs.h"
+#include "fih.h"
+#include "otp.h"
+#include "test_framework_helpers.h"
+
+static void tfm_bl1_integration_test_5001(struct test_result_t *ret)
+{
+    fih_int fih_rc;
+    uint8_t *bad_image = (uint8_t*)BL1_2_CODE_START;
+
+    memset(bad_image, 0, BL1_2_CODE_SIZE);
+
+    FIH_CALL(validate_image_at_addr, fih_rc, bad_image);
+    if (fih_eq(fih_rc, FIH_SUCCESS)) {
+        TEST_FAIL("Bad image was successfully validated");
+        return;
+    }
+
+    ret->val = TEST_PASSED;
+    return;
+}
+
+
+static void tfm_bl1_integration_test_5002(struct test_result_t *ret)
+{
+    fih_int fih_rc;
+    uint8_t *bad_image = (uint8_t*)BL1_2_CODE_START;
+
+    FIH_CALL(bl1_read_bl1_2_image, fih_rc, bad_image);
+    if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
+        TEST_FAIL("OTP read failed");
+        return;
+    }
+
+    bad_image[0] ^= 0xFF;
+
+    FIH_CALL(validate_image_at_addr, fih_rc, bad_image);
+    if (fih_eq(fih_rc, FIH_SUCCESS)) {
+        TEST_FAIL("Bad image was successfully validated");
+        return;
+    }
+
+    ret->val = TEST_PASSED;
+    return;
+}
+
+static void tfm_bl1_integration_test_5003(struct test_result_t *ret)
+{
+    fih_int fih_rc;
+    uint8_t *bad_image = (uint8_t*)BL1_2_CODE_START;
+
+    FIH_CALL(bl1_read_bl1_2_image, fih_rc, bad_image);
+    if (fih_not_eq(fih_rc, FIH_SUCCESS)) {
+        TEST_FAIL("OTP read failed");
+        return;
+    }
+
+    bad_image[BL1_2_CODE_SIZE - 1] ^= 0xFF;
+
+    FIH_CALL(validate_image_at_addr, fih_rc, bad_image);
+    if (fih_eq(fih_rc, FIH_SUCCESS)) {
+        TEST_FAIL("Bad image was successfully validated");
+        return;
+    }
+
+    ret->val = TEST_PASSED;
+    return;
+}
+
+static struct test_t integration_tests[] = {
+    {&tfm_bl1_integration_test_5001, "TFM_BL1_1_INTEGRATION_TEST_5001",
+     "INTEGRATION zeroed image test" },
+    {&tfm_bl1_integration_test_5002, "TFM_BL1_1_INTEGRATION_TEST_5002",
+     "INTEGRATION bit-flipped first byte test" },
+    {&tfm_bl1_integration_test_5003, "TFM_BL1_1_INTEGRATION_TEST_5003",
+     "INTEGRATION bit-flipped last byte test" },
+};
+
+void register_testsuite_bl1_1_integration(struct test_suite_t *p_test_suite)
+{
+    uint32_t list_size = (sizeof(integration_tests) / sizeof(integration_tests[0]));
+
+    set_testsuite("INTEGRATION test (TFM_BL1_1_INTEGRATION_TEST_5XXX)",
+                  integration_tests, list_size, p_test_suite);
+}
+
diff --git a/test/bl1/bl1_1/suites/integration/bl1_1_integration_tests.h b/test/bl1/bl1_1/suites/integration/bl1_1_integration_tests.h
new file mode 100644
index 0000000..2eea414
--- /dev/null
+++ b/test/bl1/bl1_1/suites/integration/bl1_1_integration_tests.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef BL1_1_INTEGRATION_TESTS_H
+#define BL1_1_INTEGRATION_TESTS_H
+
+#include "test_framework.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void register_testsuite_bl1_1_integration(struct test_suite_t *p_test_suite);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BL1_1_INTEGRATION_TESTS_H */