[Skiboot] [PATCH v3 4/9] core/pldm/test : Read file with PLDM file I/O message
Abhishek Singh Tomar
abhishek at linux.ibm.com
Wed May 18 17:42:59 AEST 2022
The patch contains a test for PLDM read request
implementation using PLDM command PLDM_READ_FILE
Signed-off-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
---
core/pldm/test/test-pldm-fileio.c | 74 +++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/core/pldm/test/test-pldm-fileio.c b/core/pldm/test/test-pldm-fileio.c
index 924db86e..53a2f811 100644
--- a/core/pldm/test/test-pldm-fileio.c
+++ b/core/pldm/test/test-pldm-fileio.c
@@ -115,6 +115,7 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
uint8_t table_type;
uint8_t *file_attr_table;
uint32_t table_size;
+ struct pldm_read_file_resp *response;
/* check command received and reply with appropriate pldm response message */
@@ -195,6 +196,57 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
return OPAL_PARAMETER;
break;
+ case PLDM_READ_FILE:
+
+ payload_len = request_len - sizeof(struct pldm_msg_hdr);
+ rc = decode_read_file_req(request_msg, payload_len, &file_handle, &offset,
+ &length);
+
+ 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 transferred without any distortion in path.
+ */
+ if (file_handle != TEST_FILE_IO_HANDLE) {
+ printf("PLDM_TEST : File Handle not matched");
+ return OPAL_PARAMETER;
+ }
+
+ /*
+ * 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 OPAL_PARAMETER;
+ }
+
+
+ *response_len = sizeof(struct pldm_msg_hdr) +
+ sizeof(struct pldm_read_file_resp) + length - 1;
+
+ *response_msg = malloc(*response_len);
+ if (*response_msg == NULL)
+ return OPAL_RESOURCE;
+
+
+ rc = encode_read_file_resp(((struct pldm_msg *)request_msg)->hdr.instance_id,
+ PLDM_SUCCESS, length, *response_msg);
+ if (rc != PLDM_SUCCESS)
+ return OPAL_PARAMETER;
+
+
+ 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, length);
+ break;
default:
@@ -212,6 +264,7 @@ int pldm_test_reply_request_file_io(void *request_msg, size_t request_len,
int main(void)
{
size_t rc;
+ char buf_read[TEST_FILE_IO_LENGTH];
char buf_write[TEST_FILE_IO_LENGTH] = TEST_FILE_IO_BUF1;
uint64_t size = strlen(buf_write);
@@ -225,6 +278,13 @@ int main(void)
return OPAL_PARAMETER;
}
+ /* Attempt to read using pldm file io before init should return error OPAL_PARAMETER */
+ rc = pldm_file_io_read_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_LENGTH, buf_read, 0, size);
+ if (rc != OPAL_PARAMETER) {
+ printf("PLDM_TEST : pldm_file_io_read_file failed expect=OPAL_PARAMETER\n");
+ return OPAL_PARAMETER;
+ }
+
/* Init PLDM File IO */
rc = pldm_file_io_init();
if (rc != OPAL_SUCCESS) {
@@ -241,6 +301,20 @@ int main(void)
return rc;
}
+
+ /* Attempt to read: using pldm file io should return OPAL SUCCESS after init */
+ rc = pldm_file_io_read_file(TEST_FILE_IO_HANDLE, TEST_FILE_IO_LENGTH, buf_read, 0, size);
+ if (rc != OPAL_SUCCESS) {
+ printf("PLDM_TEST : pldm_file_io_read_file failed expect=OPAL_PARAMETER\n");
+ return rc;
+ }
+
+ /* Test if buffer read same as buffer send */
+ if (strncmp(buf_read, TEST_FILE_IO_BUF1, size) != 0) {
+ perror("PLDM_TEST pldm read string mismatch");
+ return OPAL_PARAMETER;
+ }
+
return OPAL_SUCCESS;
}
--
2.34.1
More information about the Skiboot
mailing list