[Skiboot] [PATCH v2 4/9] core/pldm/test : pldm file I/O read file Self test

Abhishek Singh Tomar abhishek at linux.ibm.com
Sat May 7 16:35:57 AEST 2022


The patch contains self test for PLDM file I/O read message.
This patch test codeflow for PLDM command PLDM_READ_FILE.

Signed-off-by: Abhishek Singh Tomar <abhishek at linux.ibm.com
---
 core/pldm/test/test_pldm-fileio.c | 70 +++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/core/pldm/test/test_pldm-fileio.c b/core/pldm/test/test_pldm-fileio.c
index 10011740..79fdd896 100644
--- a/core/pldm/test/test_pldm-fileio.c
+++ b/core/pldm/test/test_pldm-fileio.c
@@ -192,6 +192,56 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 			return ret;
 
 		break;
+	case PLDM_READ_FILE:
+
+		payload_len = request_len - sizeof(struct pldm_msg_hdr);
+		ret = decode_read_file_req(request_msg, payload_len, &file_handle, &offset,
+				&length);
+
+		if (ret != PLDM_SUCCESS)
+			return ret;
+
+		/*
+		 * TEST : if file handle received is same as that we send while making
+		 * call to pldm request (i.e. TEST_FILE_IO_HANDLE).
+		 * then PLDM message are transferred without any distortion in path.
+		 */
+		if (file_handle != TEST_FILE_IO_HANDLE) {
+			perror("TEST :: File Handle not matched");
+			return PLDM_ERROR_INVALID_DATA;
+
+		}
+
+		/*
+		 * check if length + offset < TEST_FILE_IO_LENGTH
+		 * so required data length can be readed
+		 */
+		if (file_handle != TEST_FILE_IO_HANDLE ||
+				length + offset > TEST_FILE_IO_LENGTH) {
+			perror("TEST : length+offset Invalid");
+			return PLDM_ERROR_INVALID_DATA;
+		}
+
+		size = length;
+
+		*response_len = sizeof(struct pldm_msg_hdr) +
+			sizeof(struct pldm_read_file_resp) + size - 1;
+		*response_msg = malloc(*response_len);
+
+
+
+		encode_read_file_resp(((struct pldm_msg *)request_msg)->hdr.instance_id,
+				PLDM_SUCCESS, size, *response_msg);
+
+		if (ret != PLDM_SUCCESS)
+			return ret;
+
+		struct pldm_read_file_resp *response = (struct pldm_read_file_resp *)
+			((struct pldm_msg *)*response_msg)->payload;
+
+		/* Copy required buffer to end of PLDM response */
+		memcpy(response->file_data, pldm_file_io_buff + offset, size);
+		break;
 
 	default:
 		return PLDM_ERROR_INVALID_DATA;
@@ -208,6 +258,7 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 int main(void)
 {
 	size_t ret;
+	char buf_read[TEST_FILE_IO_LENGTH];
 	char buf_write[TEST_FILE_IO_LENGTH] = TEST_FILE_IO_BUF1;
 	uint64_t size = strlen(buf_write);
 
@@ -222,6 +273,12 @@ int main(void)
 		return ret;
 	}
 
+	/* Attempt to read using pldm file io before init should return error OPAL_PARAMTER */
+	ret = pldm_file_io_read_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_LENGTH, buf_read, 0, size);
+	if (ret != OPAL_PARAMETER) {
+		perror("pldm_file_io_write_file");
+		return ret;
+	}
 
 	/* Init PLDM File IO */
 	ret = pldm_file_io_init();
@@ -238,6 +295,19 @@ int main(void)
 		return ret;
 	}
 
+	/* Attempt to  read: using pldm file io should return PLDM SUCCESS after init */
+	ret = pldm_file_io_read_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_LENGTH, buf_read, 0, size);
+	if (ret != PLDM_SUCCESS) {
+		perror("pldm_file_io_write_file");
+		return ret;
+	}
+
+	/* Test if buffer read same as buffer send */
+	if (strncmp(buf_read, TEST_FILE_IO_BUF1, size) != 0) {
+
+		perror("pldm read string mismatch");
+		return OPAL_PARAMETER;
+	}
 
 	return PLDM_SUCCESS;
 }
-- 
2.34.1



More information about the Skiboot mailing list