[Skiboot] [PATCH v3 8/9] core/pldm/test : Implement PLDM FRU table self test
Abhishek Singh Tomar
abhishek at linux.ibm.com
Wed May 18 17:43:03 AEST 2022
This patch tests:
1. responder implementation for PLDM FRU command
PLDM_GET_FRU_RECORD_TABLE_METADATA when request
sends on behalf of BMC.
2. pldm_fru_get_table() failure case when fru table
not created and pldm_fru_get_table() success case
when fru table already created.
Signed-off-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
---
core/pldm/test/Makefile.check | 3 +-
core/pldm/test/test-pldm-fru.c | 193 +++++++++++++++++++++++++++++++++
2 files changed, 195 insertions(+), 1 deletion(-)
create mode 100644 core/pldm/test/test-pldm-fru.c
diff --git a/core/pldm/test/Makefile.check b/core/pldm/test/Makefile.check
index 0e5706a2..ba74fd00 100644
--- a/core/pldm/test/Makefile.check
+++ b/core/pldm/test/Makefile.check
@@ -1,7 +1,8 @@
# -*-Makefile-*-
PLDM_TEST := core/pldm/test/test-pldm-fileio \
core/pldm/test/test-pldm-bios \
- core/pldm/test/test-pldm-platform
+ core/pldm/test/test-pldm-platform \
+ core/pldm/test/test-pldm-fru
LCOV_EXCLUDE += $(PLDM_TEST:%=%.c)
diff --git a/core/pldm/test/test-pldm-fru.c b/core/pldm/test/test-pldm-fru.c
new file mode 100644
index 00000000..2893248e
--- /dev/null
+++ b/core/pldm/test/test-pldm-fru.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+// Copyright 2022 IBM Corp.
+
+#include "common/test-pldm-common.c"
+
+
+#define TEST_BMC_VERSION "tes_t_1.0"
+
+bool get_fru_record_table_in_progress;
+int pldm_test_verify_response(void *response_msg, size_t response_len);
+int pldm_test_verify_response_fru(void *response_msg, size_t response_len);
+int test_fru_table_metadata_request(void);
+
+
+/*
+ * This function duplicates BMC functionality for Pldm self test
+ * It will only handle PLDM_FRU type response
+ */
+int pldm_test_verify_response(void *response_msg, size_t response_len)
+{
+ switch (((struct pldm_msg *)response_msg)->hdr.type) {
+
+ case PLDM_FRU:
+ return pldm_test_verify_response_fru(response_msg, response_len);
+
+ default:
+ printf("PLDM_TEST: Not equal to PLDM_FRU\n");
+ return OPAL_PARAMETER;
+ }
+
+
+}
+
+
+/*
+ * This function duplicates BMC functionality for Pldm self test
+ * It will only handle PLDM_FRU type response and tries to verify that
+ * PLDM response is same as expected
+ */
+int pldm_test_verify_response_fru(void *response_msg, size_t response_len)
+{
+ uint8_t completion_code;
+ int rc = 0;
+ int payload_len = 0;
+ uint8_t fru_data_major_version;
+ uint8_t fru_data_minor_version;
+ uint32_t fru_table_maximum_size;
+ uint32_t fru_table_length;
+ uint16_t total_record_set_identifiers;
+ uint16_t total_table_records;
+ uint32_t checksum;
+
+ switch (((struct pldm_msg *)response_msg)->hdr.command) {
+ case PLDM_GET_FRU_RECORD_TABLE_METADATA:
+
+ /*
+ * Test that response receive for
+ * PLDM_GET_FRU_RECORD_TABLE_METADATA
+ * only when specific request in progress
+ */
+ if (get_fru_record_table_in_progress != true)
+ return OPAL_PARAMETER;
+
+ payload_len = response_len - sizeof(struct pldm_msg_hdr);
+ rc = decode_get_fru_record_table_metadata_resp(response_msg, payload_len,
+ &(completion_code), &fru_data_major_version,
+ &fru_data_minor_version,
+ &fru_table_maximum_size,
+ &fru_table_length,
+ &total_record_set_identifiers,
+ &total_table_records,
+ &checksum);
+
+ /*
+ * Test if PLDM request completed with success i.e. completion code = PLDM_SUCCESS
+ * and test if other parameter as expected then return OPAL_SUCCESS
+ * else return error OPAL_PARAMETER
+ */
+ if (rc == PLDM_SUCCESS && completion_code == PLDM_SUCCESS &&
+ total_record_set_identifiers == 1
+ && total_table_records == 1)
+ return OPAL_SUCCESS;
+ else
+ return OPAL_PARAMETER;
+ break;
+
+ default:
+ return OPAL_PARAMETER;
+
+ }
+
+ return OPAL_SUCCESS;
+
+
+
+}
+
+
+/*
+ * This function duplicates BMC functionality for Pldm self test
+ * It will only handle PLDM request
+ * or now we don't have any request
+ */
+int pldm_test_reply_request(void *request_msg, size_t request_len,
+ void **response_msg, size_t *response_len)
+{
+ if (request_msg != NULL && response_msg != NULL) {
+ (void)request_len;
+ (void)*response_len;
+ }
+ return OPAL_PARAMETER;
+
+}
+
+/*
+ * This function duplicates BMC functionality for Pldm self test
+ * It tries to send PLDM_GET_FRU_RECORD_TABLE_METADATA on behalf of BMC
+ */
+int test_fru_table_metadata_request(void)
+{
+ void *pldm_req;
+ int size, rc;
+
+ size = sizeof(struct pldm_msg_hdr);
+ pldm_req = malloc(size);
+ /*
+ * Enable flag that indicate PLDM_GET_FRU_RECORD_TABLE_METADATA
+ * request in progress.
+ * This flag is used only for test
+ */
+ get_fru_record_table_in_progress = true;
+
+ /* Encode request on behalf of BMC */
+ rc = encode_get_fru_record_table_metadata_req(0, pldm_req, 0);
+ if (rc != PLDM_SUCCESS)
+ return OPAL_PARAMETER;
+
+ /* initialize responder */
+ rc = pldm_mctp_responder_init();
+ if (rc != OPAL_SUCCESS)
+ return rc;
+
+ /* skip mctp layer directly call handle */
+ rc = pldm_handle(BMC_EID, pldm_req, size);
+ if (rc != OPAL_SUCCESS)
+ return rc;
+
+ /*
+ * Disable flag that indicate PLDM_GET_FRU_RECORD_TABLE_METADATA
+ * request in progress.
+ * This flag is used only for test
+ */
+ get_fru_record_table_in_progress = false;
+
+ return rc;
+
+}
+
+
+int main(void)
+{
+ int rc;
+ void *fru_record_table;
+ uint32_t fru_record_table_size;
+
+ /*
+ * Get fru table when fru table not created
+ * return error OPAL_PARAMETER
+ */
+ rc = pldm_fru_get_table(&fru_record_table, &fru_record_table_size);
+ if (rc != OPAL_PARAMETER) {
+ printf("PLDM_TEST Failed : pldm_fru_get_table",
+ " expected=%d received=%d\n", OPAL_PARAMETER, rc);
+ return OPAL_PARAMETER;
+ }
+
+ /* Sending request in behalf of bmc and checking response */
+ rc = test_fru_table_metadata_request();
+ if (rc != OPAL_SUCCESS) {
+ printf("PLDM_TEST Failed : test_fru_table_metadata_request return=%d\n", rc);
+ return rc;
+ }
+
+ /* Get fru table when fru table created */
+ rc = pldm_fru_get_table(&fru_record_table, &fru_record_table_size);
+ if (rc != OPAL_SUCCESS) {
+ printf("PLDM_TEST Failed : test_fru_table_metadata_request return=%d\n", rc);
+ return rc;
+ }
+
+ return OPAL_SUCCESS;
+}
+
--
2.34.1
More information about the Skiboot
mailing list