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

Christophe Lombard clombard at linux.vnet.ibm.com
Wed May 11 20:12:14 AEST 2022



Le 07/05/2022 à 08:35, Abhishek Singh Tomar a écrit :
> 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;

length can be used directly.
In the previous patch, it seems that size was not defined before using in
encode_write_file_resp()

> +		*response_msg = malloc(*response_len);

malloc can return a NULL pointer

> +
> +
> +
> +		encode_read_file_resp(((struct pldm_msg *)request_msg)->hdr.instance_id,
> +				PLDM_SUCCESS, size, *response_msg);
> +
ret = encode_read_file_resp

> +		if (ret != PLDM_SUCCESS)
> +			return ret;
> +
> +		struct pldm_read_file_resp *response = (struct pldm_read_file_resp *)
> +			((struct pldm_msg *)*response_msg)->payload;
> +

struct pldm_read_file_resp *response must be defined at the begining of 
the function.

> +		/* 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) {

Be careful. pldm_xxx functions located core/pldm/ folder return an OPAL_ 
return code.

> +		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;

same issue here. PLDM_ and OPAL_ return codes are mixed.

>   }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/skiboot/attachments/20220511/e64b9706/attachment-0001.htm>


More information about the Skiboot mailing list