From patchwork Sat May 7 06:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Singh Tomar X-Patchwork-Id: 1627839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=WzLeZ/M+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KwHmM3TStz9sGV for ; Sat, 7 May 2022 16:37:23 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KwHmM0936z3c5C for ; Sat, 7 May 2022 16:37:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=WzLeZ/M+; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=abhishek@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=WzLeZ/M+; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KwHlk46C2z3c94 for ; Sat, 7 May 2022 16:36:50 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2475fBGL022138 for ; Sat, 7 May 2022 06:36:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=N+XN3reJ/lGfocHnkov8ju/yNb4wpCcmuOFu9vsHrA8=; b=WzLeZ/M+mGhiUH7U9+mkWBAXNKHxdJfaA4jvVqdwxKU7DUsSjRGOH0+J1bjaXN9tm7WT 2fMOf0jgsy89POm8HCZ5Ri45Il6rZjb8yW0nM6UToNIjpdpU7buYzD/pBLmgCWL6S3cZ ToCFf1qZnse+FJIM9xNYRNAmgjEPKltPmOkl7Dhu6Pv4hbCdzZn4wdjgnsXCanrqCHIi lWjyswBuDkRF/WEJ0Dc1a6/0x73n90A2nBTKv3mGPFWQEnwbvn22eZGJ3DbUTspbtboR DrZYe/sDCqPJxuFl3EhC3iCjiU7nQ26fKLKhSc/NEX0ij5YvvfqEelpsD+NVZ50dSzrv kw== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3fwe6puq0g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 07 May 2022 06:36:47 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2476Ybvk020320 for ; Sat, 7 May 2022 06:36:46 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06fra.de.ibm.com with ESMTP id 3fwg1hr4vd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 07 May 2022 06:36:45 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2476agwt42860920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 7 May 2022 06:36:42 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D101952050; Sat, 7 May 2022 06:36:42 +0000 (GMT) Received: from li-22421c4c-355e-11b2-a85c-fdc6c782cba9.ibm.com.com (unknown [9.43.76.43]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 904105204E; Sat, 7 May 2022 06:36:41 +0000 (GMT) From: Abhishek Singh Tomar To: skiboot@lists.ozlabs.org Date: Sat, 7 May 2022 12:06:01 +0530 Message-Id: <20220507063602.66309-9-abhishek@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220507063602.66309-1-abhishek@linux.ibm.com> References: <20220507063602.66309-1-abhishek@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: SBYpB52fm-Ibl4ynkCR81898U8JV48er X-Proofpoint-ORIG-GUID: SBYpB52fm-Ibl4ynkCR81898U8JV48er X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-07_01,2022-05-06_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 clxscore=1015 malwarescore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205070041 Subject: [Skiboot] [PATCH v2 8/9] core/pldm/test : pldm FRU Table selftest X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Abhishek Singh Tomar Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This patch contains: 1. PLDM FRU self test by sending PLDM_GET_FRU_RECORD_TABLE_METADATA request on behalf of BMC. 2. Test pldm_fru_get_table() response before and after fru table created Signed-off-by: Abhishek Singh Tomar --- core/pldm/test/Makefile.check | 1 + core/pldm/test/test_pldm-fru.c | 224 +++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) 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 c184702f..2295a99b 100644 --- a/core/pldm/test/Makefile.check +++ b/core/pldm/test/Makefile.check @@ -2,6 +2,7 @@ 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-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..049dbce8 --- /dev/null +++ b/core/pldm/test/test_pldm-fru.c @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +/* + * Copyright 2013-2019 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); +int pldm_test_reply_request_fru(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); +int pldm_test_generate_reply_field_type_version(uint8_t record_type, uint8_t field_type, + uint8_t **fru_table, size_t *fru_table_size); + + +/* + * This function tries to duplicate 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 tries to duplicate 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 ret = 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); + ret = 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 PLDM_SUCCESS + * else return error PLDM_ERROR_INVALID_DATA + */ + if (ret == OPAL_SUCCESS && completion_code == PLDM_SUCCESS && + total_record_set_identifiers == 1 + && total_table_records == 1) + return PLDM_SUCCESS; + else + return PLDM_ERROR_INVALID_DATA; + break; + + default: + return PLDM_ERROR_INVALID_DATA; + + } + + return PLDM_SUCCESS; + + + +} + + +/* + * This function tries to duplicate BMC functionality for Pldm self test + * It will only handle PLDM_FRU type request + */ +int pldm_test_reply_request(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + switch (((struct pldm_msg *)request_msg)->hdr.type) { + + case PLDM_FRU: + return pldm_test_reply_request_fru(request_msg, request_len, + response_msg, response_len); + + default: + printf("PLDM_TEST: Not equal to PLDM_FRU \n"); + return OPAL_PARAMETER; + } + +} + + +/* + * This function tries to duplicate BMC functionality for Pldm self test + * it tries to handle PLDM_REQUEST for PLDM_FRU and reply with appropriate + * PLDM_RESPONSE message + */ +int pldm_test_reply_request_fru(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + switch (((struct pldm_msg *)request_msg)->hdr.command) { + case PLDM_GET_FRU_RECORD_BY_OPTION: + (void)request_len; + *response_msg = NULL; + *response_len = 0; + + break; + default: + return PLDM_ERROR_INVALID_DATA; + } + + return PLDM_SUCCESS; + +} + + + +/* + * This function tries to duplicate 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, ret; + + 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 */ + ret = encode_get_fru_record_table_metadata_req(0, pldm_req, 0); + if (ret != PLDM_SUCCESS) + return ret; + + /* initialize responder */ + ret = pldm_mctp_responder_init(); + if (ret != PLDM_SUCCESS) + return ret; + + /* skip mctp layer directly call handle */ + ret = pldm_handle(BMC_EID, pldm_req, size); + if (ret != PLDM_SUCCESS) + return ret; + + /* + * 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 ret; + +} + + +int main(void) +{ + int ret; + void *fru_record_table; + uint32_t fru_record_table_size; + + /* + * Trying to get fru table when fru table not created + * @return error OPAL_PARAMETER + */ + ret = pldm_fru_get_table(&fru_record_table, &fru_record_table_size); + if (ret != OPAL_PARAMETER) + return OPAL_PARAMETER; + + /* Sending request in behalf of bmc and checking response */ + ret = test_fru_table_metadata_request(); + if (ret != PLDM_SUCCESS) { + perror("encode_get_fru_record_table_metadata_req"); + return ret; + } + + /* Trying to get fru table when fru table created */ + ret = pldm_fru_get_table(&fru_record_table, &fru_record_table_size); + if (ret != PLDM_SUCCESS) + return OPAL_PARAMETER; + +} +