<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">Le 07/05/2022 à 08:35, Abhishek Singh
Tomar a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">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 <<a class="moz-txt-link-abbreviated" href="mailto:abhishek@linux.ibm.com">abhishek@linux.ibm.com</a>
---
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;</pre>
</blockquote>
<br>
<font size="2">length can be used directly.<br>
In the previous patch, it seems that size was not defined before
using in</font><font size="2"><br>
encode_write_file_resp()</font><br>
<br>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
+ *response_msg = malloc(*response_len);</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">malloc can return a NULL pointer
</pre>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
+
+
+
+ encode_read_file_resp(((struct pldm_msg *)request_msg)->hdr.instance_id,
+ PLDM_SUCCESS, size, *response_msg);
+</pre>
</blockquote>
<font size="2">ret = encode_read_file_resp<br>
<br>
</font>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
+ if (ret != PLDM_SUCCESS)
+ return ret;
+
+ struct pldm_read_file_resp *response = (struct pldm_read_file_resp *)
+ ((struct pldm_msg *)*response_msg)->payload;
+</pre>
</blockquote>
<font size="2"><span class="pl-k"><br>
struct</span> pldm_read_file_resp *response must be defined at
the begining of the function.</font><br>
<br>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
+ /* 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) {</pre>
</blockquote>
<font size="2"><br>
Be careful. pldm_xxx functions located core/pldm/ folder return an
OPAL_ return code.</font><br>
<br>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
+ 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;</pre>
</blockquote>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
+ }
return PLDM_SUCCESS;</pre>
</blockquote>
<font size="2"><br>
same issue here. PLDM_ and OPAL_ return codes are mixed.</font><br>
<br>
<blockquote type="cite"
cite="mid:20220507063602.66309-5-abhishek@linux.ibm.com">
<pre class="moz-quote-pre" wrap="">
}
</pre>
</blockquote>
<br>
</body>
</html>