feat(debugfs): add oob debugfs test case

Change-Id: I8f00f74e9584c211cf13576d27db7ee385f8ab98
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/tftf/tests/runtime_services/sip_service/test_debugfs.c b/tftf/tests/runtime_services/sip_service/test_debugfs.c
index 39a1bf9..dcc57b2 100644
--- a/tftf/tests/runtime_services/sip_service/test_debugfs.c
+++ b/tftf/tests/runtime_services/sip_service/test_debugfs.c
@@ -360,3 +360,51 @@
 
 	return TEST_RESULT_SUCCESS;
 }
+
+/*
+ * @Test_Aim@ Verify that the I/O layer correctly handles out-of-bounds access.
+ *
+ * This test ensures robustness of seek/read APIs against invalid
+ * offsets and prevents potential memory or file corruption due to invalid
+ * access.
+ */
+test_result_t test_oob_access(void)
+{
+	int ret, fd;
+
+	/* Get debugfs interface version (if implemented)*/
+	ret = version();
+	if (ret != DEBUGFS_VERSION) {
+		/* Likely debugfs feature is not implemented */
+		return TEST_RESULT_SKIPPED;
+	}
+
+	/* Open BL2. */
+	fd = open("/fip/bl2.bin", O_READ);
+	if (fd < 0) {
+		tftf_testcase_printf("open failed fd=%d\n", fd);
+		return TEST_RESULT_FAIL;
+	}
+
+	/* Rewind to negative offset. */
+	ret = seek(fd, -1000, KSEEK_SET);
+
+	/* Reading with out-of-bounds cursor position should fail */
+	ret = read(fd, read_buffer, 128);
+	if (ret != 0) {
+		tftf_testcase_printf("Out-of-bounds read(%d)\n", __LINE__);
+		return TEST_RESULT_FAIL;
+	}
+
+	/* Reset cursor position to valid range. */
+	ret = seek(fd, 0, KSEEK_SET);
+
+	/* Read 128 bytes from start */
+	ret = read(fd, read_buffer, 128);
+	if (ret != 128) {
+		tftf_testcase_printf("read failed(%d) ret=%d\n", __LINE__, ret);
+		return TEST_RESULT_FAIL;
+	}
+
+	return TEST_RESULT_SUCCESS;
+}
\ No newline at end of file
diff --git a/tftf/tests/tests-debugfs.xml b/tftf/tests/tests-debugfs.xml
index 4da3152..61342e8 100644
--- a/tftf/tests/tests-debugfs.xml
+++ b/tftf/tests/tests-debugfs.xml
@@ -12,6 +12,7 @@
   -->
   <testsuite name="DebugFS" description="Test ARM SiP DebugFS service">
     <testcase name="Expose filesystem" function="test_debugfs" />
+    <testcase name="Out-of-bounds accesses" function="test_oob_access" />
   </testsuite>
 
 </testsuites>