Skip to content

Commit 49d8cbe

Browse files
abhisheksinghtomarrarbab
authored andcommitted
core/pldm/test: Add tests for platform poweroff and restart
Introduce tests for the PLDM "SetStateEffecterStates" request to validate platform restart and poweroff functionality. Signed-off-by: Abhishek Singh Tomar <[email protected]> Signed-off-by: Reza Arbab <[email protected]>
1 parent 0a1f868 commit 49d8cbe

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

core/pldm/test/test-pldm-platform.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ enum platform_special_case_code {
1313
NORMAL_CASE = 0x00,
1414
PDR_REPLY_ERROR = 0x02,
1515
PLATFORM_EVENT_ERROR = 0x03,
16-
VERIFY_SHUTDOWN = 0x04
16+
VERIFY_SHUTDOWN = 0x04,
17+
VERIFY_RESTART = 0x05,
18+
VERIFY_POWEROFF,
1719
};
1820

1921
enum platform_special_case_code platform_special_case = NORMAL_CASE;
@@ -325,6 +327,9 @@ int pldm_test_reply_request_platform(void *request_msg, size_t request_len,
325327
uint8_t format_version, tid, event_class;
326328
size_t event_data_offset;
327329
uint32_t next_record_hndl;
330+
uint16_t effecter_id;
331+
uint8_t comp_effecter_count;
332+
set_effecter_state_field field = {0};
328333

329334
/* check pldm command received and reply with appropriate pldm response message */
330335
switch (((struct pldm_msg *)request_msg)->hdr.command) {
@@ -419,6 +424,45 @@ int pldm_test_reply_request_platform(void *request_msg, size_t request_len,
419424

420425
return PLDM_SUCCESS;
421426

427+
case PLDM_SET_STATE_EFFECTER_STATES:
428+
payload_len = request_len - sizeof(struct pldm_msg_hdr);
429+
rc = decode_set_state_effecter_states_req(request_msg, payload_len,
430+
&effecter_id,
431+
&comp_effecter_count,
432+
&field);
433+
if (rc != PLDM_SUCCESS)
434+
return OPAL_PARAMETER;
435+
436+
/*
437+
* Verify if the effecter state matches the expected value.
438+
* If it does not, return OPAL_PARAMETER.
439+
*/
440+
if (platform_special_case == VERIFY_RESTART &&
441+
field.effecter_state !=
442+
PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED){
443+
return OPAL_PARAMETER;
444+
}
445+
if (platform_special_case == VERIFY_POWEROFF
446+
&& field.effecter_state !=
447+
PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL){
448+
return OPAL_PARAMETER;
449+
}
450+
451+
452+
*response_len = sizeof(struct pldm_msg);
453+
*response_msg = malloc(*response_len);
454+
if (*response_msg == NULL) {
455+
perror("PLDM_TEST malloc");
456+
return OPAL_RESOURCE;
457+
}
458+
459+
rc = encode_set_state_effecter_states_resp(
460+
((struct pldm_msg *)request_msg)->hdr.instance_id,
461+
completion_code, *response_msg);
462+
if (rc != PLDM_SUCCESS)
463+
return OPAL_PARAMETER;
464+
return PLDM_SUCCESS;
465+
422466
default:
423467
return OPAL_PARAMETER;
424468

@@ -610,6 +654,40 @@ int test_pldm_platform_initiate_shutdown(void)
610654

611655
}
612656

657+
int test_pldm_platform_restart(void)
658+
{
659+
int rc;
660+
661+
platform_special_case = VERIFY_RESTART;
662+
rc = pldm_platform_restart();
663+
if (rc != OPAL_SUCCESS) {
664+
printf("PLDM_TEST: %s failed :: rc = %d exp %d\n",
665+
__func__, rc, OPAL_SUCCESS);
666+
platform_special_case = NORMAL_CASE;
667+
return OPAL_PARAMETER;
668+
}
669+
platform_special_case = NORMAL_CASE;
670+
return OPAL_SUCCESS;
671+
672+
}
673+
674+
int test_pldm_platform_poweroff(void)
675+
{
676+
int rc;
677+
678+
platform_special_case = VERIFY_POWEROFF;
679+
rc = pldm_platform_power_off();
680+
if (rc != OPAL_SUCCESS) {
681+
printf("PLDM_TEST: %s failed :: rc = %d exp %d\n",
682+
__func__, rc, OPAL_SUCCESS);
683+
platform_special_case = NORMAL_CASE;
684+
return OPAL_PARAMETER;
685+
}
686+
platform_special_case = NORMAL_CASE;
687+
return OPAL_SUCCESS;
688+
689+
}
690+
613691
struct test_case {
614692
const char *name;
615693
int (*fn)(void);
@@ -625,6 +703,8 @@ struct test_case test_cases[] = {
625703
TEST_CASE(test_find_pdr_existing_record),
626704
TEST_CASE(test_find_pdr_non_existing_record),
627705
TEST_CASE(test_pldm_platform_initiate_shutdown),
706+
TEST_CASE(test_pldm_platform_restart),
707+
TEST_CASE(test_pldm_platform_poweroff),
628708
{NULL, NULL}
629709
};
630710

0 commit comments

Comments
 (0)