[Skiboot] [PATCH v3 3/9] core/pldm/test : Write file with PLDM file I/O message

Abhishek Singh Tomar abhishek at linux.ibm.com
Wed May 18 17:42:58 AEST 2022


The patch contains a test for PLDM write request
implementation using PLDM command PLDM_WRITE_FILE

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

diff --git a/core/pldm/test/test-pldm-fileio.c b/core/pldm/test/test-pldm-fileio.c
index e14f6df7..924db86e 100644
--- a/core/pldm/test/test-pldm-fileio.c
+++ b/core/pldm/test/test-pldm-fileio.c
@@ -8,6 +8,7 @@
 #define TEST_FILE_IO_LENGTH 50
 #define TEST_FILE_IO_BUF1 "This is Test buffer Open power Foundation"
 
+void *pldm_file_io_buff[TEST_FILE_IO_LENGTH];
 uint32_t get_test_filetable_entry(uint8_t **file_attr_table, int *size);
 int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 			void **response_msg, size_t *response_len);
@@ -102,7 +103,13 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 			void **response_msg, size_t *response_len)
 {
 	int rc;
+	void *payload_data;
+	uint32_t offset;      //!< Offset to file where write starts
+	uint32_t length;
+	uint32_t file_handle; //!< Handle to file
 	int  payload_len = 0;
+	size_t file_data_offset = 0;
+	struct pldm_write_file_req file_req;
 	uint32_t transfer_handle;
 	uint8_t transfer_opflag;
 	uint8_t table_type;
@@ -143,6 +150,52 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 		free(file_attr_table);
 
 		break;
+	case PLDM_WRITE_FILE:
+		payload_len = request_len - sizeof(struct pldm_msg_hdr);
+
+		rc = decode_write_file_req(request_msg, payload_len, &file_handle,
+				&offset, &length, &file_data_offset);
+		if (rc != PLDM_SUCCESS)
+			return OPAL_PARAMETER;
+
+		/*
+		 * 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 received without any distortion in path.
+		 */
+		if (file_handle != TEST_FILE_IO_HANDLE)
+			return OPAL_PARAMETER;
+
+		payload_data = ((struct pldm_msg *)request_msg)->payload
+			+ sizeof(file_req.file_handle)
+			+ sizeof(file_req.offset)
+			+ sizeof(file_req.length);
+
+		memcpy(pldm_file_io_buff, payload_data, length);
+
+		/*
+		 * TEST if file buff received is same as that we send while making
+		 * call to pldm request (i.e TEST_FILE_IO_BUF1).
+		 * Then PLDM message are transferred without distortion in path.
+		 */
+		if (strncmp(TEST_FILE_IO_BUF1, (char *)payload_data, length) != 0) {
+			perror("PLDM_TEST :strncmp");
+			return OPAL_PARAMETER;
+		}
+		*response_len = sizeof(struct pldm_msg_hdr) +
+			sizeof(struct pldm_write_file_resp);
+		*response_msg = malloc(*response_len);
+		if (*response_msg == NULL)
+			return OPAL_RESOURCE;
+
+		rc = encode_write_file_resp(
+				((struct pldm_msg *)request_msg)->hdr.instance_id,
+				PLDM_SUCCESS, length, *response_msg);
+		if (rc != PLDM_SUCCESS)
+			return OPAL_PARAMETER;
+
+		break;
+
 
 	default:
 		return OPAL_PARAMETER;
@@ -159,7 +212,18 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 int main(void)
 {
 	size_t rc;
+	char buf_write[TEST_FILE_IO_LENGTH] = TEST_FILE_IO_BUF1;
+	uint64_t size = strlen(buf_write);
 
+	/* Initialize test buffer for represent file with 0 */
+	bzero(pldm_file_io_buff, TEST_FILE_IO_LENGTH);
+
+	/* Attempt to write using pldm file io before init should return error OPAL_PARAMETER */
+	rc = pldm_file_io_write_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_BUF1, 0, size);
+	if (rc != OPAL_PARAMETER) {
+		printf("PLDM_TEST : pldm_file_io_write_file failed expect=OPAL_PARAMETER\n");
+		return OPAL_PARAMETER;
+	}
 
 	/* Init PLDM File IO */
 	rc = pldm_file_io_init();
@@ -168,6 +232,15 @@ int main(void)
 		return rc;
 	}
 
+	/* Attempt to  write using pldm file io should return OPAL SUCCESS after init */
+	rc = pldm_file_io_write_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_BUF1,
+			0, size);
+
+	if (rc != OPAL_SUCCESS) {
+		printf("PLDM_TEST : pldm_file_io_write_file failed expect=OPAL_SUCCESS\n");
+		return rc;
+	}
+
 	return OPAL_SUCCESS;
 }
 
-- 
2.34.1



More information about the Skiboot mailing list