test(console_log): add tests for FFA_CONSOLE_LOG
Adding two tests:
Test if FFA_CONSOLE_ABI responds SUCCESS to correct message.
Test if FFA_CONSOLE_ABI responds INVALID_PARAMETERS to incorrectly
formatted message.
Signed-off-by: Maksims Svecovs <maksims.svecovs@arm.com>
Change-Id: I7053e48d4c6f365601bd9d9c89165cde11422b04
diff --git a/inc/vmapi/hf/call.h b/inc/vmapi/hf/call.h
index 84d29a4..ef55d8f 100644
--- a/inc/vmapi/hf/call.h
+++ b/inc/vmapi/hf/call.h
@@ -18,6 +18,7 @@
*/
int64_t hf_call(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3);
struct ffa_value ffa_call(struct ffa_value args);
+void memcpy_s(void *dest, size_t destsz, const void *src, size_t count);
/**
* Returns the VM's own ID.
@@ -500,3 +501,25 @@
.arg2 = page_count,
.arg3 = mem_perm});
}
+
+static inline struct ffa_value ffa_console_log_32(const char *src, size_t size)
+{
+ struct ffa_value req = {
+ .func = FFA_CONSOLE_LOG_32,
+ .arg1 = size,
+ };
+ memcpy_s(&req.arg2, sizeof(uint32_t) * 6, src, size);
+
+ return ffa_call(req);
+}
+
+static inline struct ffa_value ffa_console_log_64(const char *src, size_t size)
+{
+ struct ffa_value req = {
+ .func = FFA_CONSOLE_LOG_64,
+ .arg1 = size,
+ };
+ memcpy_s(&req.arg2, sizeof(uint64_t) * 6, src, size);
+
+ return ffa_call(req);
+}
diff --git a/test/vmapi/ffa_secure_partition_only/secure_partition.c b/test/vmapi/ffa_secure_partition_only/secure_partition.c
index 437f66d..8bbab9c 100644
--- a/test/vmapi/ffa_secure_partition_only/secure_partition.c
+++ b/test/vmapi/ffa_secure_partition_only/secure_partition.c
@@ -386,3 +386,35 @@
{
EXPECT_FFA_ERROR(ffa_notification_info_get(), FFA_NOT_SUPPORTED);
}
+
+/*
+ * Validate FFA_CONSOLE_LOG sends a message.
+ */
+TEST(ffa_console_log, successfull_msg_send)
+{
+ const char msg_long[] = "This does not fit in 6x32 bits, only 6x64\n";
+ const char msg_short[] = "This fits in 6x32 bits\n";
+
+ EXPECT_EQ(ffa_console_log_32(msg_short, sizeof(msg_short)).func,
+ FFA_SUCCESS_32);
+
+ EXPECT_EQ(ffa_console_log_64(msg_long, sizeof(msg_long)).func,
+ FFA_SUCCESS_32);
+}
+
+/*
+ * Validate FFA_CONSOLE_LOG reports invalid parameters on inadequate message.
+ */
+TEST(ffa_console_log, invalid_parameters)
+{
+ /* Expecting INVALID_PARAMETERS on zero-length message */
+ struct ffa_value req = {
+ .func = FFA_CONSOLE_LOG_64,
+ .arg1 = 0,
+ };
+ EXPECT_FFA_ERROR(ffa_call(req), FFA_INVALID_PARAMETERS);
+
+ /* Expecting INVALID_PARAMETERS on length > payload message */
+ req.arg1 = 0xffff;
+ EXPECT_FFA_ERROR(ffa_call(req), FFA_INVALID_PARAMETERS);
+}