[Skiboot] [PATCH v2 3/9] core/pldm/test : pldm file I/O write file Self test

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


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

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

diff --git a/core/pldm/test/test_pldm-fileio.c b/core/pldm/test/test_pldm-fileio.c
index 722a8bf6..10011740 100644
--- a/core/pldm/test/test_pldm-fileio.c
+++ b/core/pldm/test/test_pldm-fileio.c
@@ -103,13 +103,20 @@ int pldm_test_reply_request(void *request_msg, size_t request_len,
 int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 			void **response_msg, size_t *response_len)
 {
+	int size = 0;
 	int ret;
+	void *payload_data;
 	int  payload_len = 0;
+	uint32_t offset;      //!< Offset to file where write starts
+	uint32_t length;
+	uint32_t file_handle; //!< Handle to file
+	size_t file_data_offset = 0;
 	uint32_t transfer_handle;
 	uint8_t transfer_opflag;
 	uint8_t table_type;
 	uint8_t *file_attr_table;
 	uint32_t table_size;
+	struct pldm_write_file_req file_req;
 
 
 	/* check command received and reply with appropriate pldm response message */
@@ -140,6 +147,51 @@ 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);
+
+
+		ret = decode_write_file_req(request_msg, payload_len, &file_handle,
+					&offset, &length, &file_data_offset);
+		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 recieved without any distortion in path.
+		 */
+		if (file_handle != TEST_FILE_IO_HANDLE)
+			return PLDM_ERROR_INVALID_DATA;
+
+		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("TEST :: String not matched");
+			return PLDM_ERROR_INVALID_DATA;
+		}
+		*response_len = sizeof(struct pldm_msg_hdr) +
+			sizeof(struct pldm_write_file_resp);
+		*response_msg = malloc(*response_len);
+
+		ret = encode_write_file_resp(
+				((struct pldm_msg *)request_msg)->hdr.instance_id,
+				PLDM_SUCCESS, size, *response_msg);
+		if (ret != PLDM_SUCCESS)
+			return ret;
+
+		break;
 
 	default:
 		return PLDM_ERROR_INVALID_DATA;
@@ -156,11 +208,21 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
 int main(void)
 {
 	size_t ret;
+	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_PARAMTER */
+	ret = pldm_file_io_write_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_BUF1, 0, size);
+	if (ret != OPAL_PARAMETER) {
+		perror("pldm_file_io_write_file");
+		return ret;
+	}
+
+
 	/* Init PLDM File IO */
 	ret = pldm_file_io_init();
 	if (ret != PLDM_SUCCESS) {
@@ -168,6 +230,15 @@ int main(void)
 		return ret;
 	}
 
+	/* Attempt to  write using pldm file io should return PLDM SUCCESS after init */
+	ret = pldm_file_io_write_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_BUF1,
+			0, size);
+	if (ret != PLDM_SUCCESS) {
+		perror("pldm_file_io_write_file");
+		return ret;
+	}
+
+
 	return PLDM_SUCCESS;
 }
 
-- 
2.34.1



More information about the Skiboot mailing list