diff --git a/config/openiotsdk/chip-gn/.gn b/config/openiotsdk/chip-gn/.gn index 4b9894b0f943ac..f2404233d6f74d 100644 --- a/config/openiotsdk/chip-gn/.gn +++ b/config/openiotsdk/chip-gn/.gn @@ -14,6 +14,7 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") # The location of the build configuration file. buildconfig = "//build/config/BUILDCONFIG.gn" @@ -26,4 +27,14 @@ default_args = { target_os = "cmsis-rtos" import("${chip_root}/config/openiotsdk/chip-gn/args.gni") + + pw_sys_io_BACKEND = dir_pw_sys_io_stdio + + pw_assert_BACKEND = dir_pw_assert_log + pw_log_BACKEND = dir_pw_log_basic + + pw_build_LINK_DEPS = [ + "$dir_pw_assert:impl", + "$dir_pw_log:impl", + ] } diff --git a/config/openiotsdk/chip-gn/BUILD.gn b/config/openiotsdk/chip-gn/BUILD.gn index 6e6fb51d404bb1..94e2f28635d114 100644 --- a/config/openiotsdk/chip-gn/BUILD.gn +++ b/config/openiotsdk/chip-gn/BUILD.gn @@ -19,7 +19,10 @@ group("openiotsdk") { deps = [ "${chip_root}/src/lib" ] if (chip_build_tests) { - deps += [ "${chip_root}/src:tests" ] + deps += [ + "${chip_root}/src:tests", + "${chip_root}/src/lib/support:pw_tests_wrapper", + ] } } diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 1c148a5a1f0d1c..dd2368f566d252 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -293,6 +293,7 @@ CHIP_ERROR SilabsMatterConfig::InitWiFi(void) sl_status_t status; if ((status = wfx_wifi_rsi_init()) != SL_STATUS_OK) { + SILABS_LOG("wfx_wifi_rsi_init failed with status: %x", status); ReturnErrorOnFailure((CHIP_ERROR) status); } #endif // SLI_SI91X_MCU_INTERFACE diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c index 079f12f6288cd5..c0cde4d20d3316 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c @@ -68,7 +68,7 @@ bool btn0_pressed = false; #define TRNGKEY_SIZE 4 #endif // SLI_SI91X_MCU_INTERFACE -struct wfx_rsi wfx_rsi; +WfxRsi_t wfx_rsi; /* Declare a variable to hold the data associated with the created event group. */ StaticEventGroup_t rsiDriverEventGroup; @@ -98,6 +98,9 @@ static wfx_wifi_scan_ext_t temp_reset; volatile sl_status_t callback_status = SL_STATUS_OK; +// Scan semaphore +static osSemaphoreId_t sScanSemaphore; + /****************************************************************** * @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap) * @brief @@ -305,8 +308,16 @@ int32_t wfx_wifi_rsi_init(void) status = sl_wifi_init(&config, NULL, sl_wifi_default_event_handler); if (status != SL_STATUS_OK) { - SILABS_LOG("wfx_wifi_rsi_init failed %x", status); + return status; + } + + // Create Sempaphore for scan + sScanSemaphore = osSemaphoreNew(1, 0, NULL); + if (sScanSemaphore == NULL) + { + return SL_STATUS_ALLOCATION_FAILED; } + return status; } @@ -421,6 +432,8 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * #else wfx_rsi.sec.security = WFX_SEC_WPA2; #endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ + + osSemaphoreRelease(sScanSemaphore); return SL_STATUS_FAIL; } wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; @@ -457,6 +470,8 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * } wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED; scan_results_complete = true; + + osSemaphoreRelease(sScanSemaphore); return SL_STATUS_OK; } sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) @@ -501,6 +516,7 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_ { callback_status = show_scan_results(result); bg_scan_results_complete = true; + osSemaphoreRelease(sScanSemaphore); return SL_STATUS_OK; } /*************************************************************************************** @@ -529,12 +545,7 @@ static void wfx_rsi_save_ap_info() // translation #endif if (SL_STATUS_IN_PROGRESS == status) { - const uint32_t start = osKernelGetTickCount(); - while (!scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT_TICK) - { - osThreadYield(); - } - status = scan_results_complete ? callback_status : SL_STATUS_TIMEOUT; + osSemaphoreAcquire(sScanSemaphore, WIFI_SCAN_TIMEOUT_TICK); } } @@ -817,12 +828,7 @@ void wfx_rsi_task(void * arg) status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, NULL, &wifi_scan_configuration); if (SL_STATUS_IN_PROGRESS == status) { - const uint32_t start = osKernelGetTickCount(); - while (!bg_scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT_TICK) - { - osThreadYield(); - } - status = bg_scan_results_complete ? callback_status : SL_STATUS_TIMEOUT; + osSemaphoreAcquire(sScanSemaphore, WIFI_SCAN_TIMEOUT_TICK); } } } diff --git a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h index 998b3ac1ef5d7a..c7642485025815 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h +++ b/examples/platform/silabs/SiWx917/SiWx917/wfx_rsi.h @@ -33,30 +33,37 @@ * Various events fielded by the wfx_rsi task * Make sure that we only use 8 bits (otherwise freeRTOS - may need some changes) */ -#define WFX_EVT_STA_CONN (0x01) -#define WFX_EVT_STA_DISCONN (0x02) -#define WFX_EVT_AP_START (0x04) -#define WFX_EVT_AP_STOP (0x08) -#define WFX_EVT_SCAN (0x10) /* This is used as scan result and start */ -#define WFX_EVT_STA_START_JOIN (0x20) -#define WFX_EVT_STA_DO_DHCP (0x40) -#define WFX_EVT_STA_DHCP_DONE (0x80) +typedef enum +{ + WFX_EVT_STA_CONN = (1 << 0), + WFX_EVT_STA_DISCONN = (1 << 1), + WFX_EVT_AP_START = (1 << 2), + WFX_EVT_AP_STOP = (1 << 3), + WFX_EVT_SCAN = (1 << 4), /* This is used as scan result and start */ + WFX_EVT_STA_START_JOIN = (1 << 5), + WFX_EVT_STA_DO_DHCP = (1 << 6), + WFX_EVT_STA_DHCP_DONE = (1 << 7) +} WfxEventType_e; -#define WFX_RSI_ST_DEV_READY (0x01) -#define WFX_RSI_ST_AP_READY (0x02) -#define WFX_RSI_ST_STA_PROVISIONED (0x04) -#define WFX_RSI_ST_STA_CONNECTING (0x08) -#define WFX_RSI_ST_STA_CONNECTED (0x10) -#define WFX_RSI_ST_STA_DHCP_DONE (0x40) /* Requested to do DHCP after conn */ -#define WFX_RSI_ST_STA_MODE (0x80) /* Enable Station Mode */ -#define WFX_RSI_ST_AP_MODE (0x100) /* Enable AP Mode */ -#define WFX_RSI_ST_STA_READY (WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE) -#define WFX_RSI_ST_STARTED (0x200) /* RSI task started */ -#define WFX_RSI_ST_SCANSTARTED (0x400) /* Scan Started */ -#define WFX_RSI_ST_SLEEP_READY (0x800) /* Notify the M4 to go to sleep*/ +typedef enum +{ + WFX_RSI_ST_DEV_READY = (1 << 0), + WFX_RSI_ST_AP_READY = (1 << 1), + WFX_RSI_ST_STA_PROVISIONED = (1 << 2), + WFX_RSI_ST_STA_CONNECTING = (1 << 3), + WFX_RSI_ST_STA_CONNECTED = (1 << 4), + WFX_RSI_ST_STA_DHCP_DONE = (1 << 6), /* Requested to do DHCP after conn */ + WFX_RSI_ST_STA_MODE = (1 << 7), /* Enable Station Mode */ + WFX_RSI_ST_AP_MODE = (1 << 8), /* Enable AP Mode */ + WFX_RSI_ST_STA_READY = (WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE), + WFX_RSI_ST_STARTED = (1 << 9), /* RSI task started */ + WFX_RSI_ST_SCANSTARTED = (1 << 10), /* Scan Started */ + WFX_RSI_ST_SLEEP_READY = (1 << 11) /* Notify the M4 to go to sleep*/ +} WfxStateType_e; -struct wfx_rsi +typedef struct wfx_rsi_s { + // TODO: Change tp WfxEventType_e once the event queue is implemented EventGroupHandle_t events; TaskHandle_t drv_task; TaskHandle_t wlan_task; @@ -77,9 +84,9 @@ struct wfx_rsi sl_wfx_mac_address_t ap_bssid; /* To which our STA is connected */ uint16_t join_retries; uint8_t ip4_addr[4]; /* Not sure if this is enough */ -}; +} WfxRsi_t; -extern struct wfx_rsi wfx_rsi; +extern WfxRsi_t wfx_rsi; #ifdef __cplusplus extern "C" { #endif diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.c b/examples/platform/silabs/efr32/rs911x/rsi_if.c index d229251a7a5cf9..00efeee09a4efb 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.c +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.c @@ -866,4 +866,4 @@ int32_t wfx_rsi_send_data(void * p, uint16_t len) return status; } -struct wfx_rsi wfx_rsi; +WfxRsi_t wfx_rsi; diff --git a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h index 07217056cef11b..86591df72d36d3 100644 --- a/examples/platform/silabs/efr32/rs911x/wfx_rsi.h +++ b/examples/platform/silabs/efr32/rs911x/wfx_rsi.h @@ -53,7 +53,7 @@ #define WFX_RSI_ST_SCANSTARTED (0x400) /* Scan Started */ #define WFX_RSI_ST_SLEEP_READY (0x800) /* Notify the M4 to go to sleep*/ -struct wfx_rsi +typedef struct wfx_rsi_s { EventGroupHandle_t events; TaskHandle_t drv_task; @@ -76,9 +76,9 @@ struct wfx_rsi sl_wfx_mac_address_t ap_bssid; /* To which our STA is connected */ uint16_t join_retries; uint8_t ip4_addr[4]; /* Not sure if this is enough */ -}; +} WfxRsi_t; -extern struct wfx_rsi wfx_rsi; +extern WfxRsi_t wfx_rsi; #ifdef __cplusplus extern "C" { #endif diff --git a/scripts/examples/openiotsdk_example.sh b/scripts/examples/openiotsdk_example.sh index 36c748cc8d1aa2..a4bfd939289f97 100755 --- a/scripts/examples/openiotsdk_example.sh +++ b/scripts/examples/openiotsdk_example.sh @@ -53,6 +53,8 @@ readarray -t SUPPORTED_APP_NAMES <"$CHIP_ROOT"/examples/platform/openiotsdk/supp SUPPORTED_APP_NAMES+=("unit-tests") readarray -t TEST_NAMES <"$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/test_components.txt +readarray -t TEST_NAMES_NL <"$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +TEST_NAMES+=("${TEST_NAMES_NL[@]}") function show_usage() { cat < 1 0 + ./chip-tool networkcommissioning remove-network hex: 1 0 --Breadcrumb 1 Below is an example: - ./chip-tool networkcommissioning remove-network hex:2111111122222222 22 0 + ./chip-tool networkcommissioning remove-network hex:1111111122222221 22 0 --Breadcrumb 1 Via the TH (chip-tool), Verify the NetworkConfigResponse that contains Networking Status value as 0 (success). @@ -112,11 +112,11 @@ tests: PIXIT.CNET.THREAD_2ND_OPERATIONALDATASET and Breadcrumb field set to 1" PICS: CNET.S.C03.Rsp && CNET.S.C05.Tx verification: | - ./chip-tool networkcommissioning add-or-update-thread-network-network hex: 1 0 + ./chip-tool networkcommissioning add-or-update-thread-network-network hex: 1 0 --Breadcrumb 1 Below is an example: - ./chip-tool networkcommissioning add-or-update-thread-network hex:0e080000000000010000000300000c35060004001fffe0020831111111222222220708fd6958bdf99a83e6051000112233445566778899aabbccddeeff030e4f70656e54687265616444656d6b0102123404101fdf27d94ddb7edc69dc3e72a0ca0ae10c0402a0f7f8 22 0 (second network dataset value) + ./chip-tool networkcommissioning add-or-update-thread-network hex:0e08000000000001000035060004001fffe00708fdd235604ef7ccb50c0402a0f7f8051000112233445566778899aabbccddeeff030f4f70656e54687265616444656d6f3104101dfb97da1e39dc596e886f52cb870a84000300000f0208111111112222222201021234 22 0 --Breadcrumb 1(second network dataset value) Via the TH (chip-tool), Verify the NetworkConfigResponse that contains Networking Status value as 0 (success). @@ -139,7 +139,7 @@ tests: [1659623451.276073][9891:9896] CHIP:TOO: Networks: 1 entries [1659623451.276194][9891:9896] CHIP:TOO: [1]: { - [1659623451.276268][9891:9896] CHIP:TOO: NetworkID: 3111111122222222 + [1659623451.276268][9891:9896] CHIP:TOO: NetworkID: 1111111122222222 [1659623451.276326][9891:9896] CHIP:TOO: Connected: FALSE [1659623451.276381][9891:9896] CHIP:TOO: } disabled: true @@ -150,11 +150,11 @@ tests: field set to 2" PICS: CNET.S.C06.Rsp verification: | - ./chip-tool networkcommissioning connect-network hex: 1 0 + ./chip-tool networkcommissioning connect-network hex: 1 0 --Breadcrumb 2 Below is an example: - ./chip-tool networkcommissioning connect-network hex:3111111122222222 22 0 --Breadcrumb 2 + ./chip-tool networkcommissioning connect-network hex:1111111122222222 22 0 --Breadcrumb 2 Via the TH (chip-tool), Verify the ConnectNetworkResponse that contains Networking Status value as 0 (success). @@ -171,7 +171,17 @@ tests: "Step 8: TH discovers and connects to DUT on the PIXIT.CNET.THREAD_2ND_OPERATIONALDATASET operational network" verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning read networks 22 0 + + Via the TH (chip-tool), Verify: + -the Networks attribute has NetworkID that should be as th_xpan(second network id). + -that the connected status should be the type of bool value as TRUE. + + [1659623451.276073][9891:9896] CHIP:TOO: Networks: 1 entries + [1659623451.276194][9891:9896] CHIP:TOO: [1]: { + [1659623451.276268][9891:9896] CHIP:TOO: NetworkID: 1111111122222222 + [1659623451.276326][9891:9896] CHIP:TOO: Connected: TRUE + [1659623451.276381][9891:9896] CHIP:TOO: } disabled: true - label: @@ -179,9 +189,6 @@ tests: cluster of the DUT" PICS: CNET.S.C06.Rsp verification: | - Mark as not applicable and proceed to next step - - ./chip-tool generalcommissioning read breadcrumb 22 0 Verify "breadcrumb value is set to 2" on the TH(Chip-tool) Log: @@ -195,8 +202,6 @@ tests: "Step 10: TH sends ArmFailSafe command to the DUT with ExpiryLengthSeconds set to 0" verification: | - Mark as not applicable and proceed to next step - ./chip-tool generalcommissioning arm-fail-safe 0 1 22 0 Verify "ArmFailSafeResponse" on the TH(Chip-tool) Log: @@ -214,25 +219,54 @@ tests: "Step 11: TH ensures it can communicate on PIXIT.CNET.THREAD_1ST_OPERATIONALDATASET" verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning read networks 22 0 + + Via the TH (chip-tool), Verify: + -the Networks attribute has NetworkID that should be as th_xpan(first network id). + -that the connected status should be the type of bool value as TRUE. + + [1659623217.387917][9816:9821] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Attribute 0x0000_0001 DataVersion: 4196844346 + [1659623217.388007][9816:9821] CHIP:TOO: Networks: 1 entries + [1659623217.388058][9816:9821] CHIP:TOO: [1]: { + [1659623217.388089][9816:9821] CHIP:TOO: NetworkID: 1111111122222221 + [1659623217.388110][9816:9821] CHIP:TOO: Connected: TRUE + [1659623217.388129][9816:9821] CHIP:TOO: } disabled: true - label: "Step 12: TH discovers and connects to DUT on the PIXIT.CNET.THREAD_1ST_OPERATIONALDATASET operational network" verification: | - Mark as not applicable and proceed to next step - ./chip-tool networkcommissioning read networks 22 0 - Verify "Networks entiries and its status" on the TH(Chip-tool) Log: + Via the TH (chip-tool), Verify: + -the Networks attribute has NetworkID that should be as th_xpan(first network id). + -that the connected status should be the type of bool value as TRUE. + + [1659623217.387917][9816:9821] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Attribute 0x0000_0001 DataVersion: 4196844346 + [1659623217.388007][9816:9821] CHIP:TOO: Networks: 1 entries + [1659623217.388058][9816:9821] CHIP:TOO: [1]: { + [1659623217.388089][9816:9821] CHIP:TOO: NetworkID: 1111111122222221 + [1659623217.388110][9816:9821] CHIP:TOO: Connected: TRUE + [1659623217.388129][9816:9821] CHIP:TOO: } disabled: true - label: "Step 13: TH sends ArmFailSafe command to the DUT with ExpiryLengthSeconds set to 900" verification: | - Mark as not applicable and proceed to next step + ./chip-tool generalcommissioning arm-fail-safe 900 1 22 0 + + Via the TH (chip-tool), Verify the DUT sends ArmFailSafe with timeout as 900 secs to the TH. + + [1657808518.577084][5979:5984] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0030 Command=0x0000_0001 + [1657808518.577181][5979:5984] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0030 Command 0x0000_0001 + [1657808518.577311][5979:5984] CHIP:TOO: ArmFailSafeResponse: { + [1657808518.577409][5979:5984] CHIP:TOO: errorCode: 0 + [1657808518.577466][5979:5984] CHIP:TOO: debugText: + [1657808518.577518][5979:5984] CHIP:TOO: } + [1657808518.577604][5979:5984] CHIP:DMG: ICR moving to [AwaitingDe] + [1657808518.577705][5979:5984] CHIP:EM: Sending Standalone Ack for MessageCounter:240383707 on exchange 56756i disabled: true - label: @@ -240,7 +274,21 @@ tests: field set to th_xpan and Breadcrumb field set to 1" PICS: CNET.S.C04.Rsp && CNET.S.C05.Tx verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning remove-network hex: 1 0 --Breadcrumb 1 + + Below is an example: + + ./chip-tool networkcommissioning remove-network hex:1111111122222221 22 0 --Breadcrumb 1 + + Via the TH (chip-tool), Verify the NetworkConfigResponse that contains Networking Status value as 0 (success). + + [1659623277.664477][9824:9831] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0031 Command=0x0000_0005 + [1659623277.664556][9824:9831] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Command 0x0000_0005 + [1659623277.664667][9824:9831] CHIP:TOO: NetworkConfigResponse: { + [1659623277.664758][9824:9831] CHIP:TOO: networkingStatus: 0 + [1659623277.664810][9824:9831] CHIP:TOO: networkIndex: 0 + [1659623277.664843][9824:9831] CHIP:TOO: } + [1659623277.664907][9824:9831] CHIP:DMG: ICR moving to [AwaitingDe] disabled: true - label: @@ -249,7 +297,20 @@ tests: PIXIT.CNET.THREAD_2ND_OPERATIONALDATASET and Breadcrumb field set to 1" PICS: CNET.S.C03.Rsp && CNET.S.C05.Tx verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning add-or-update-thread-network-network hex: 1 0 --Breadcrumb 1 + + Below is an example: + + ./chip-tool networkcommissioning add-or-update-thread-network hex:0e08000000000001000035060004001fffe00708fdd235604ef7ccb50c0402a0f7f8051000112233445566778899aabbccddeeff030f4f70656e54687265616444656d6f3104101dfb97da1e39dc596e886f52cb870a84000300000f0208111111112222222201021234 22 0 --Breadcrumb 1(second network dataset value) + + Via the TH (chip-tool), Verify the NetworkConfigResponse that contains Networking Status value as 0 (success). + + [1659623353.963125][9870:9875] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Command 0x0000_0005 + [1659623353.963312][9870:9875] CHIP:TOO: NetworkConfigResponse: { + [1659623353.963406][9870:9875] CHIP:TOO: networkingStatus: 0 + [1659623353.963473][9870:9875] CHIP:TOO: networkIndex: 0 + [1659623353.963530][9870:9875] CHIP:TOO: } + [1659623353.963623][9870:9875] CHIP:DMG: ICR moving to [AwaitingDe] disabled: true - label: @@ -258,14 +319,39 @@ tests: PIXIT.CNET.THREAD_2ND_OPERATIONALDATASET and Breadcrumb field set to 3" PICS: CNET.S.C06.Rsp && CNET.S.C07.Tx verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning connect-network hex: 1 0 --Breadcrumb 3 + + Below is an example: + + ./chip-tool networkcommissioning connect-network hex:1111111122222222 22 0 --Breadcrumb 3 + + Via the TH (chip-tool), Verify the ConnectNetworkResponse that contains Networking Status value as 0 (success). + + 1 Command=0x0000_0007 + [1659623520.296630][9903:9908] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Command 0x0000_0007 + [1659623520.296853][9903:9908] CHIP:TOO: ConnectNetworkResponse: { + [1659623520.296935][9903:9908] CHIP:TOO: networkingStatus: 0 + [1659623520.296987][9903:9908] CHIP:TOO: errorValue: null + [1659623520.297037][9903:9908] CHIP:TOO: } + [1659623520.297124][9903:9908] CHIP:DMG: ICR moving to [AwaitingDe] disabled: true - label: "Step 17: TH discovers and connects to DUT on the PIXIT.CNET.THREAD_2ND_OPERATIONALDATASET operational network" verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning read networks 22 0 + + Via the TH (chip-tool), Verify: + -the Networks attribute has NetworkID that should be as th_xpan(Second network id). + -that the connected status should be the type of bool value as TRUE. + + [1659623217.387917][9816:9821] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Attribute 0x0000_0001 DataVersion: 4196844346 + [1659623217.388007][9816:9821] CHIP:TOO: Networks: 1 entries + [1659623217.388058][9816:9821] CHIP:TOO: [1]: { + [1659623217.388089][9816:9821] CHIP:TOO: NetworkID: 1111111122222222 + [1659623217.388110][9816:9821] CHIP:TOO: Connected: TRUE + [1659623217.388129][9816:9821] CHIP:TOO: } disabled: true - label: @@ -273,16 +359,41 @@ tests: cluster of the DUT" PICS: CNET.S.C06.Rsp verification: | - Mark as not applicable and proceed to next step + ./chip-tool generalcommissioning read breadcrumb 22 0 + + Verify "breadcrumb value is set to 3" on the TH(Chip-tool) Log: + + [1659623558.934419][9911:9917] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0030 Attribute 0x0000_0000 DataVersion: 808037534 + [1659623558.934529][9911:9917] CHIP:TOO: Breadcrumb: 3 + [1659623558.934681][9911:9917] CHIP:EM: Sending Standalone Ack for MessageCounter:244248455 on exchange 8477i disabled: true - label: "Step 19: TH sends the CommissioningComplete command to the DUT" verification: | - Mark as not applicable and proceed to next step + ./chip-tool generalcommissioning commissioning-complete 22 0 + + Via the TH (chip-tool), Verify the DUT sends CommissioningComplete command and the errorCode field is 0(OK). + + [1657734803.411199][7802:7808] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0030 Command 0x0000_0005 + [1657734803.411256][7802:7808] CHIP:TOO: CommissioningCompleteResponse: { + [1657734803.411306][7802:7808] CHIP:TOO: errorCode: 0 + [1657734803.411333][7802:7808] CHIP:TOO: debugText: + [1657734803.411356][7802:7808] CHIP:TOO: } disabled: true - label: "Step 20: TH reads Networks attribute from the DUT" PICS: CNET.S.A0001 verification: | - Mark as not applicable and proceed to next step + ./chip-tool networkcommissioning read networks 22 0 + + Via the TH (chip-tool), Verify: + -the Networks attribute has NetworkID that should be as th_xpan(Second network id). + -that the connected status should be the type of bool value as TRUE. + + [1659623217.387917][9816:9821] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0031 Attribute 0x0000_0001 DataVersion: 4196844346 + [1659623217.388007][9816:9821] CHIP:TOO: Networks: 1 entries + [1659623217.388058][9816:9821] CHIP:TOO: [1]: { + [1659623217.388089][9816:9821] CHIP:TOO: NetworkID: 1111111122222222 + [1659623217.388110][9816:9821] CHIP:TOO: Connected: TRUE + [1659623217.388129][9816:9821] CHIP:TOO: } disabled: true diff --git a/src/app/tests/suites/certification/Test_TC_DLOG_2_1.yaml b/src/app/tests/suites/certification/Test_TC_DLOG_2_1.yaml index 8937b63fd15a22..45111b016974d2 100644 --- a/src/app/tests/suites/certification/Test_TC_DLOG_2_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_DLOG_2_1.yaml @@ -29,138 +29,394 @@ tests: - label: "Precondition" verification: | DUT supports BDX + Length of TransferFileDesignator is zero + Length of TransferFileDesignator is within 32 characters + Length of TransferFileDesignator is equal to 32 characters + Length of TransferFileDesignator is greater than 32 characters + To send a message that mismatches the current transfer mode disabled: true - - label: "Step 1: Reboot DUT" + - label: "Step 1: Commission DUT to TH" verification: | disabled: true - - label: "Step 2: Commission DUT to TH" + - label: + "Step 2: TH sends RetrieveLogsRequest Command to DUT with + RequestedProtocol argument as BDX : RetrieveLogsRequest (Intent = + EndUserSupport, RequestedProtocol= BDX, TransferFileDesignator = + TH_LOG_OK_FULL_LENGTH)" + PICS: MCORE.BDX.Initiator + verification: | + diagnosticlogs retrieve-logs-request 0 1 1 0 --TransferFileDesignator Length_123456789123456789123.txt + + On TH(chip-tool), Verify that the DUT sends SendInit message with TransferFileDesignator field set to Length_1234567891234567891 + + 1707966626.594544][10635:10638] CHIP:ATM: SendInit + [1707966626.594550][10635:10638] CHIP:ATM: Proposed Transfer Control: 0x10 + [1707966626.594558][10635:10638] CHIP:ATM: Range Control: 0x0 + [1707966626.594563][10635:10638] CHIP:ATM: Proposed Max Block Size: 1024 + [1707966626.594569][10635:10638] CHIP:ATM: Start Offset: 0x0000000000000000 + [1707966626.594577][10635:10638] CHIP:ATM: Proposed Max Length: 0x0000000000000000 + [1707966626.594584][10635:10638] CHIP:ATM: File Designator Length: 32 + [1707966626.594588][10635:10638] CHIP:ATM: File Designator: Length_123456789123456789123.txt + + Note: end_user_support_log > 1024 bytes so that BDX inititation happens from DUT + SendInitMsgfromDUT = true + disabled: true + + - label: + "Step 3: if (SendInitMsgfromDUT = true) TH Sends BDX SendAccept + message to DUT" + PICS: MCORE.BDX.Initiator + verification: | + On chip-tool TH will send the SendAccept Message to the DUT + + [1707894873.734698][34353:34356] CHIP:ATM: Sending BDX Message + [1707894873.734710][34353:34356] CHIP:ATM: SendAccept + [1707894873.734715][34353:34356] CHIP:ATM: Transfer Control: 0x10 + [1707894873.734720][34353:34356] CHIP:ATM: Max Block Size: 1024 + [1707894874.235405][34353:34356] CHIP:BDX: Got an event MsgToSend + + On TH(chip-tool), verify that the DUT responds by sending RetrieveLogsResponse Command with Success(0) status code to TH after receiving the SendAccept Message + 1707894874.239127][34353:34356] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0032 Command 0x0000_0001 + [1707894874.239189][34353:34356] CHIP:TOO: RetrieveLogsResponse: { + [1707894874.239208][34353:34356] CHIP:TOO: status: 0 + [1707894874.239219][34353:34356] CHIP:TOO: logContent: + [1707894874.239227][34353:34356] CHIP:TOO: } + + Check for the size of the file that was specified in the File Deginator field of the RetrieveLogsRequest Command sent to DUT and verify that the size is greater than 1024 bytes. + The file: Length_123456789123456789123.txt (as mentioned in the file designator field) is transferred to /tmp folder on the build system and the size is > 1024 bytes + + Note: The file can be stored in any location on the build system. The current SDK imlemnetstion stores the log file transferred using BDX protocol in /tmp folder. + disabled: true + + - label: + "Step 4: if (SendInitMsgfromDUT = false) TH does not send BDX + SendAccept message to DUT" + PICS: MCORE.BDX.Initiator + verification: | + As SendInitMsgfromDUT = true this step is not applicable + disabled: true + + - label: + "Step 5: Repeat Steps from 2 to 4 by setting Intent field to + NetworkDiag and CrashLogs" verification: | disabled: true - label: - "Step 3: TH sends RetrieveLogsRequest Command (Intent = - EndUserSupport,TransferFileDesignator = 'test.txt', RequestedProtocol= - BDX) to DUT" + "Step 2a: TH sends RetrieveLogsRequest Command to DUT with + RequestedProtocol argument as BDX : RetrieveLogsRequest (Intent = + EndUserSupport, RequestedProtocol= BDX, TransferFileDesignator = + TH_LOG_OK_FULL_LENGTH)" + PICS: MCORE.BDX.Initiator + verification: | + Repeating steps from 2 to 4 by setting Intent field to NetworkDiag + + diagnosticlogs retrieve-logs-request 1 1 1 0 --TransferFileDesignator Length_123456789123456789123.txt + + Note: nw_log does not exist and DUT does not initiate the BDX transfer + SendInitMsgfromDUT = false + disabled: true + + - label: + "Step 3a: if (SendInitMsgfromDUT = true) TH Sends BDX SendAccept + message to DUT" + PICS: MCORE.BDX.Initiator verification: | - sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 1 "test.txt" 1 0 + SendInitMsgfromDUT = false this step is not applicable + disabled: true + - label: + "Step 4a: if (SendInitMsgfromDUT = false) TH does not send BDX + SendAccept message to DUT" + PICS: MCORE.BDX.Initiator + verification: | + On TH(chip-tool), verify that the DUT responds by sending RetrieveLogsResponse Command with NoLogs(2) status code to TH and LogContent field is empty - [1651207333.385887][2441:2446] CHIP:DMG: StatusIB = - [1651207333.385937][2441:2446] CHIP:DMG: { - [1651207333.385985][2441:2446] CHIP:DMG: status = 0x00 (SUCCESS), - [1651207333.386037][2441:2446] CHIP:DMG: }, + [1707967219.637228][10723:10726] CHIP:TOO: RetrieveLogsResponse: { + [1707967219.637242][10723:10726] CHIP:TOO: status: 2 + [1707967219.637248][10723:10726] CHIP:TOO: logContent: + [1707967219.637253][10723:10726] CHIP:TOO: } disabled: true - label: - "Step 4: Verify that the DUT initiates a BDX Transfer, sending a BDX - SendInit message with the File Designator field of the message set to - the value of the TransferFileDesignator field of the - RetrieveLogsRequest" + "Step 2b: TH sends RetrieveLogsRequest Command to DUT with + RequestedProtocol argument as BDX : RetrieveLogsRequest (Intent = + EndUserSupport, RequestedProtocol= BDX, TransferFileDesignator = + TH_LOG_OK_FULL_LENGTH)" + PICS: MCORE.BDX.Initiator verification: | - Not Verifiable + Repeating steps from 2 to 4 by setting Intent field to CrashLogs + + diagnosticlogs retrieve-logs-request 2 1 1 0 --TransferFileDesignator Length_123456789123456789123.txt + + Note: crash_log < 1024 Bytes and DUT does not inittiate the BDX transfer + SendInitMsgfromDUT = false disabled: true - - label: "Step 5: TH Sends BDX SendAccept message" - PICS: DLOG.S.C01.Tx + - label: + "Step 3b: if (SendInitMsgfromDUT = true) TH Sends BDX SendAccept + message to DUT" + PICS: MCORE.BDX.Initiator verification: | - Not Verifiable + SendInitMsgfromDUT = false this step is not applicable disabled: true - label: - "Step 6: Verify that DUT sends RetrieveLogsResponse Command,Verify - that the Status field is set to Success,If LogContent size < 1024 - octets,Verify that the BDX transfer is not initiated from DUT Verify - that DUT sends RetrieveLogsResponse command with a Status field set to - Exhausted Note: In this case steps 5 and 6 does not hold good. else - Verify that the BDX transfer is initiated from DUT Verify that the - LogContent field of RetrieveLogsResponse is empty Verify that DUT - sends RetrieveLogsResponse command with a Status field set to Success - Verify that UTCTimeStamp is included in the RetrieveLogsResponse - command Verify that TimeSinceBoot is included in the - RetrieveLogsResponse command Note: In this case steps 5 and 6 holds - good." - PICS: DLOG.S.C01.Tx + "Step 4b: if (SendInitMsgfromDUT = false) TH does not send BDX + SendAccept message to DUT" + PICS: MCORE.BDX.Initiator verification: | - sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 1 "test.txt" 1 0 + On TH(chip-tool), verify that the DUT responds by sending RetrieveLogsResponse Command with Exhausted(1) status code to TH and LogContent field of RetrieveLogsResponse contains at most 1024 bytes - [1651207369.743117][2450:2455] CHIP:DMG: StatusIB = - [1651207369.743155][2450:2455] CHIP:DMG: { - [1651207369.743192][2450:2455] CHIP:DMG: status = 0x00 (SUCCESS), - [1651207369.743228][2450:2455] CHIP:DMG: }, + 1707894938.009997][34371:34374] CHIP:TOO: RetrieveLogsResponse: { + [1707894938.010025][34371:34374] CHIP:TOO: status: 1 + [1707894938.010057][34371:34374] CHIP:TOO: logContent: RetrieveLogsResponse: { + [1707967525.484222][10866:10869] CHIP:TOO: status: 1 + [1707967525.484229][10866:10869] CHIP:TOO: logContent: 353535350A + [1707967525.484233][10866:10869] CHIP:TOO: } disabled: true - label: - "Step 7: TH sends RetrieveLogsRequest Command (Intent = - EndUserSupport,TransferFileDesignator = 'test.txt', RequestedProtocol= - BDX) to DUT" + "Step 6: TH sends RetrieveLogsRequest Command to DUT with + RequestedProtocol argument as BDX : RetrieveLogsRequest(Intent = + EndUserSupport, RequestedProtocol= BDX, TransferFileDesignator = + TH_LOG_OK_NORMAL)" + PICS: MCORE.BDX.Initiator verification: | - sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 1 "test.txt" 1 0 + "diagnosticlogs retrieve-logs-request 0 1 1 0 --TransferFileDesignator Length_1234567.txt + + On TH(chip-tool), Verify that the DUT sends SendInit message with TransferFileDesignator field set to Length_1234567891234567891 + [1707967645.770994][10882:10885] CHIP:ATM: SendInit + [1707967645.770997][10882:10885] CHIP:ATM: Proposed Transfer Control: 0x10 + [1707967645.771001][10882:10885] CHIP:ATM: Range Control: 0x0 + [1707967645.771004][10882:10885] CHIP:ATM: Proposed Max Block Size: 1024 + [1707967645.771009][10882:10885] CHIP:ATM: Start Offset: 0x0000000000000000 + [1707967645.771011][10882:10885] CHIP:ATM: Proposed Max Length: 0x0000000000000000 + [1707967645.771014][10882:10885] CHIP:ATM: File Designator Length: 18 + [1707967645.771018][10882:10885] CHIP:ATM: File Designator: Length_1234567.txt - [1651207386.883337][2457:2462] CHIP:DMG: - [1651207386.883383][2457:2462] CHIP:DMG: StatusIB = - [1651207386.883443][2457:2462] CHIP:DMG: { - [1651207386.883498][2457:2462] CHIP:DMG: status = 0x00 (SUCCESS), - [1651207386.883563][2457:2462] CHIP:DMG: }, + Note: end_user_support_log > 1024 bytes so that BDX inititation happens from DUT + SendInitMsgfromDUT = true" disabled: true - label: - "Step 8: Verify that the DUT initiates a BDX Transfer, sending a BDX - SendInit message with the File Designator field of the message set to - the value of the TransferFileDesignator field of the - RetrieveLogsRequest" - PICS: DLOG.S.C01.Tx + "Step 7: if (SendInitMsgfromDUT = true) TH Sends + StatusReport(GeneralCode: FAILURE, ProtocolId: BDX, ProtocolCode: + TH_LOG_ERROR_TRANSFER_METHOD_NOT_SUPPORTED) to DUT" + PICS: MCORE.BDX.Initiator verification: | - Not Verifiable + Not Verifiable. This step requires additional API for error injection.(Not available in the Chip-tool) + disabled: true + + - label: + "Step 8: TH sends RetrieveLogsRequest Command RequestedProtocol as + ResponsePayload : RetrieveLogsRequest(Intent = + EndUserSupport,RequestedProtocol = ResponsePayload) Repeat this step + by setting Intent field to . NetworkDiag . CrashLogs" + PICS: MCORE.BDX.Initiator + verification: | + "diagnosticlogs retrieve-logs-request 0 0 1 0 + + On TH(chip-tool), Verify that the DUT responds with Success(0) status code for the RetrieveLogsResponse command Verify that LogContent field contains at most 1024 bytes + + RetrieveLogsResponse: { + [1707901602.742523][36080:36083] CHIP:TOO: status: 0 + [1707901602.742542][36080:36083] CHIP:TOO: logContent: 31353238303033363031313533353030333730303234303030303234303133653234303230313138333530313331303034373032313533313031316230323330383230323137303630393261383634383836663730643031303730326130383230323038333038323032303430323031303333313064333030623036303936303836343830313635303330343032303133303832303137303036303932613836343838366637306430313037303161303832303136313034383230313564313532343030303132353031663166663336303230353030383030353031383030353032383030353033383030353034383030353035383030353036383030353037383030353038383030353039383030353061383030353062383030353063383030353064383030353065383030353066383030353130383030353131383030353132383030353133383030353134383030353135383030353136383030353137383030353138383030353139383030353161383030353162383030353163383030353164383030353165383030353166383030353230383030353231383030353232383030353233383030353234383030353235383030353236383030353237383030353238383030353239383030353261383030353262383030353263383030353264383030353265383030353266383030353330383030353331383030353332383030353333383030353334383030353335383030353336383030353337383030353338383030353339383030353361383030353362383030353363383030353364383030353365383030353366383030353430383030353431383030353432383030353433383030353434383030353435383030353436383030353437383030353438383030353439383030353461383030353462383030353463383030353464383030353465383030353466383030353530383030353531383030353532383030353533383030353534383030353535383030353536383030353537383030353538383030353539383030353561383030353562383030353563383030353564383030353565383030353566383030353630383030353631383030353632383030353633383031383234303331363263303431333433353334313330333033303330333035333537343333303330333033303330326433303330323430353030323430363030323430373031323430383030313833313763333037613032303130333830313466653334336639353939343737363362363165653435333931333133333834393466653637643865333030623036303936303836343830633733653461363039363038363438303630393630383634383036303936303836343830363039363038363438303630393630383634383036303936303836 + + Repeat this setp by setting Intent filed to NetworkDiag + diagnosticlogs retrieve-logs-request 1 0 1 0 + + On TH(chip-tool), verify that the DUT responds with NoLogs(2) status code to TH for the RetrieveLogsResponse command and LogContent field is empty + + [1707967219.637228][10723:10726] CHIP:TOO: RetrieveLogsResponse: { + [1707967219.637242][10723:10726] CHIP:TOO: status: 2 + [1707967219.637248][10723:10726] CHIP:TOO: logContent: + [1707967219.637253][10723:10726] CHIP:TOO: } + + Repeat this setp by setting Intent filed to Crash_log + diagnosticlogs retrieve-logs-request 2 0 1 0 + + On TH(chip-tool), verify that the DUT responds with success(0) status code to TH for the RetrieveLogsResponse command and LogContent field of RetrieveLogsResponse contains at most 1024 bytes + + [1707982645.639415][11765:11767] CHIP:TOO: RetrieveLogsResponse: { + [1707982645.639457][11765:11767] CHIP:TOO: status: 0 + [1707982645.639489][11765:11767] CHIP:TOO: logContent: logContent: 353535350A + }" disabled: true - label: - "Step 9: TH Sends StatusReport(GeneralCode: FAILURE, ProtocolId: BDX, - ProtocolCode: TRANSFER_METHOD_NOT_SUPPORTED)" + "Step 9: TH sends RetrieveLogsRequest Command to DUT without + TransferFileDesignator argument : RetrieveLogsRequest(Intent = + EndUserSupport, RequestedProtocol= BDX)" + PICS: MCORE.BDX.Initiator verification: | - Not Verifiable + "diagnosticlogs retrieve-logs-request 0 1 1 0 + + On TH(chip-tool), Verify that the DUT responds with INVALID_COMMAND for the RetrieveLogsRequest that was sent without TransferFileDesignator + + [1707924172.241489][42120:42123] CHIP:DMG: InvokeResponseIB = + [1707924172.241494][42120:42123] CHIP:DMG: { + [1707924172.241497][42120:42123] CHIP:DMG: CommandStatusIB = + [1707924172.241500][42120:42123] CHIP:DMG: { + [1707924172.241503][42120:42123] CHIP:DMG: CommandPathIB = + [1707924172.241507][42120:42123] CHIP:DMG: { + [1707924172.241511][42120:42123] CHIP:DMG: EndpointId = 0x0, + [1707924172.241514][42120:42123] CHIP:DMG: ClusterId = 0x32, + [1707924172.241519][42120:42123] CHIP:DMG: CommandId = 0x0, + [1707924172.241527][42120:42123] CHIP:DMG: }, + [1707924172.241536][42120:42123] CHIP:DMG: + [1707924172.241539][42120:42123] CHIP:DMG: StatusIB = + [1707924172.241543][42120:42123] CHIP:DMG: { + [1707924172.241546][42120:42123] CHIP:DMG: status = 0x85 (INVALID_COMMAND), + [1707924172.241549][42120:42123] CHIP:DMG: }, + [1707924172.241553][42120:42123] CHIP:DMG: + [1707924172.241555][42120:42123] CHIP:DMG: }, + [1707924172.241560][42120:42123] CHIP:DMG: + [1707924172.241562][42120:42123] CHIP:DMG: }, + [1707924172.241567][42120:42123] CHIP:DMG: + [1707924172.241573][42120:42123] CHIP:DMG: ], + [1707924172.241577][42120:42123] CHIP:DMG: + [1707924172.241579][42120:42123] CHIP:DMG: InteractionModelRevision = 11 + [1707924172.241582][42120:42123] CHIP:DMG: }," disabled: true - label: - "Step 10: Verify that DUT sends RetrieveLogsResponse command with a - Status field set to Denied" + "Step 10: TH sends RetrieveLogsRequest Command to DUT that does not + support BDX : RetrieveLogsRequest(Intent = EndUserSupport, + RequestedProtocol= BDX, TransferFileDesignator = TH_LOG_OK_NORMAL)" + PICS: "!MCORE.BDX.Initiator" verification: | - Not Verifiable + "diagnosticlogs retrieve-logs-request 0 1 1 0 --TransferFileDesignator Length_1234567.txt + + On TH(chip-tool), Verify that the DUT responds with Exhausted(1) status code for the RetrieveLogsResponse command with the LogContent field containing at most 1024 bytes + + [1707979121.749537][7593:7596] CHIP:TOO: RetrieveLogsResponse: { + [1707979121.749565][7593:7596] CHIP:TOO: status: 1 + [1707979121.749593][7593:7596] CHIP:TOO: logContent: 31353238303033363031313533353030333730303234303030303234303133653234303230313138333530313331303034373032313533313031316230323330383230323137303630393261383634383836663730643031303730326130383230323038333038323032303430323031303333313064333030623036303936303836343830313635303330343032303133303832303137303036303932613836343838366637306430313037303161303832303136313034383230313564313532343030303132353031663166663336303230353030383030353031383030353032383030353033383030353034383030353035383030353036383030353037383030353038383030353039383030353061383030353062383030353063383030353064383030353065383030353066383030353130383030353131383030353132383030353133383030353134383030353135383030353136383030353137383030353138383030353139383030353161383030353162383030353163383030353164383030353165383030353166383030353230383030353231383030353232383030353233383030353234383030353235383030353236383030353237383030353238383030353239383030353261383030353262383030353263383030353264383030353265383030353266383030353330383030353331383030353332383030353333383030353334383030353335383030353336383030353337383030353338383030353339383030353361383030353362383030353363383030353364383030353365383030353366383030353430383030353431383030353432383030353433383030353434383030353435383030353436383030353437383030353438383030353439383030353461383030353462383030353463383030353464383030353465383030353466383030353530383030353531383030353532383030353533383030353534383030353535383030353536383030353537383030353538383030353539383030353561383030353562383030353563383030353564383030353565383030353566383030353630383030353631383030353632383030353633383031383234303331363263303431333433353334313330333033303330333035333537343333303330333033303330326433303330323430353030323430363030323430373031323430383030313833313763333037613032303130333830313466653334336639353939343737363362363165653435333931333133333834393466653637643865333030623036303936303836343830633733653461363039363038363438303630393630383634383036303936303836343830363039363038363438303630393630383634383036303936303836}" disabled: true - label: - "Step 11: TH sends RetrieveLogsRequest Command (Intent = - EndUserSupport, RequestedProtocol = ResponsePayload) to DUT" + "Step 12: TH sends RetrieveLogsRequest Command to DUT with Invalid + RequestedProtocol : RetrieveLogsRequest(Intent = + EndUserSupport,RequestedProtocol= 2, TransferFileDesignator = + TH_LOG_OK_NORMAL)" + PICS: MCORE.BDX.Initiator verification: | - sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 0 "test.txt" 1 0 + "diagnosticlogs retrieve-logs-request 0 2 1 0 --TransferFileDesignator Length_1234567.txt - [1651207416.783607][2465:2470] CHIP:DMG: StatusIB = - [1651207416.783676][2465:2470] CHIP:DMG: { - [1651207416.783722][2465:2470] CHIP:DMG: status = 0x00 (SUCCESS), - [1651207416.783766][2465:2470] CHIP:DMG: }, + On TH(chip-tool), Verify that the DUT responds with INVALID_COMMAND for the RetrieveLogsRequest that was sent Invalid RequestedProtocol(2) + + 707901794.468418][36124:36127] CHIP:DMG: InvokeResponseMessage = + [1707901794.468425][36124:36127] CHIP:DMG: { + [1707901794.468433][36124:36127] CHIP:DMG: suppressResponse = false, + [1707901794.468440][36124:36127] CHIP:DMG: InvokeResponseIBs = + [1707901794.468452][36124:36127] CHIP:DMG: [ + [1707901794.468459][36124:36127] CHIP:DMG: InvokeResponseIB = + [1707901794.468471][36124:36127] CHIP:DMG: { + [1707901794.468477][36124:36127] CHIP:DMG: CommandStatusIB = + [1707901794.468485][36124:36127] CHIP:DMG: { + [1707901794.468492][36124:36127] CHIP:DMG: CommandPathIB = + [1707901794.468501][36124:36127] CHIP:DMG: { + [1707901794.468510][36124:36127] CHIP:DMG: EndpointId = 0x0, + [1707901794.468518][36124:36127] CHIP:DMG: ClusterId = 0x32, + [1707901794.468526][36124:36127] CHIP:DMG: CommandId = 0x0, + [1707901794.468533][36124:36127] CHIP:DMG: }, + [1707901794.468545][36124:36127] CHIP:DMG: + [1707901794.468552][36124:36127] CHIP:DMG: StatusIB = + [1707901794.468560][36124:36127] CHIP:DMG: { + [1707901794.468569][36124:36127] CHIP:DMG: status = 0x85 (INVALID_COMMAND), + [1707901794.468576][36124:36127] CHIP:DMG: }, + [1707901794.468584][36124:36127] CHIP:DMG: + [1707901794.468591][36124:36127] CHIP:DMG: }, + [1707901794.468602][36124:36127] CHIP:DMG: + [1707901794.468608][36124:36127] CHIP:DMG: }, + [1707901794.468619][36124:36127] CHIP:DMG: + [1707901794.468624][36124:36127] CHIP:DMG: ], + [1707901794.468635][36124:36127] CHIP:DMG:" disabled: true - label: - "Step 12: Verify that the BDX transfer is not initiated from DUT, - Verify that the LogContent field of RetrieveLogsResponse has the size - < = 1024 octets" + "Step 13: TH sends RetrieveLogsRequest Command with Invalid + TransferFileDesignator length : RetrieveLogsRequest(Intent = + EndUserSupport,RequestedProtocol= BDX, TransferFileDesignator = + TH_LOG_ERROR_EMPTY)" verification: | - Not Verifiable + "diagnosticlogs retrieve-logs-request 0 1 1 0 --TransferFileDesignator '' + + [1707904517.151453][36678:36681] CHIP:DMG: ICR moving to [ResponseRe] + [1707904517.151489][36678:36681] CHIP:DMG: InvokeResponseMessage = + [1707904517.151501][36678:36681] CHIP:DMG: { + [1707904517.151511][36678:36681] CHIP:DMG: suppressResponse = false, + [1707904517.151522][36678:36681] CHIP:DMG: InvokeResponseIBs = + [1707904517.151541][36678:36681] CHIP:DMG: [ + [1707904517.151548][36678:36681] CHIP:DMG: InvokeResponseIB = + [1707904517.151565][36678:36681] CHIP:DMG: { + [1707904517.151573][36678:36681] CHIP:DMG: CommandStatusIB = + [1707904517.151582][36678:36681] CHIP:DMG: { + [1707904517.151590][36678:36681] CHIP:DMG: CommandPathIB = + [1707904517.151599][36678:36681] CHIP:DMG: { + [1707904517.151613][36678:36681] CHIP:DMG: EndpointId = 0x0, + [1707904517.151627][36678:36681] CHIP:DMG: ClusterId = 0x32, + [1707904517.151640][36678:36681] CHIP:DMG: CommandId = 0x0, + [1707904517.151652][36678:36681] CHIP:DMG: }, + [1707904517.151670][36678:36681] CHIP:DMG: + [1707904517.151681][36678:36681] CHIP:DMG: StatusIB = + [1707904517.151696][36678:36681] CHIP:DMG: { + [1707904517.151708][36678:36681] CHIP:DMG: status = 0x87 (CONSTRAINT_ERROR), + [1707904517.151720][36678:36681] CHIP:DMG: }, + [1707904517.151734][36678:36681] CHIP:DMG: + [1707904517.151745][36678:36681] CHIP:DMG: }, + [1707904517.151763][36678:36681] CHIP:DMG: + [1707904517.151772][36678:36681] CHIP:DMG: }, + [1707904517.151790][36678:36681] CHIP:DMG: + [1707904517.151798][36678:36681] CHIP:DMG: ], + [1707904517.151816][36678:36681] CHIP:DMG: + [1707904517.151824][36678:36681] CHIP:DMG: InteractionModelRevision = 11 + [1707904517.151830][36678:36681] CHIP:DMG: }," disabled: true - label: - "Step 13: Verify that DUT sends RetrieveLogsResponse command with a - Status field set to Success, Verify that UTCTimeStamp is included in - the RetrieveLogsResponse command,Verify that TimeSinceBoot is included - in the RetrieveLogsResponse command" + "Step 14: TH sends RetrieveLogsRequest Command to DUT with Invalid + TransferFileDesignator length : RetrieveLogsRequest(Intent = + EndUserSupport,RequestedProtocol= BDX, TransferFileDesignator = + TH_LOG_BAD_LENGTH)" verification: | - sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 1 "test.txt" 1 0 + "diagnosticlogs retrieve-logs-request 0 1 1 0 --TransferFileDesignator Length_1234567891234567891234567891212345.txt + + On TH(chip-tool), Verify that the DUT responds with CONSTRAINT_ERRORfor the RetrieveLogsRequest that was sent Invalid Invalid TransferFileDesignator length(> 32) - [1651207438.423557][2475:2480] CHIP:DMG: StatusIB = - [1651207438.423594][2475:2480] CHIP:DMG: { - [1651207438.423648][2475:2480] CHIP:DMG: status = 0x00 (SUCCESS), - [1651207438.423708][2475:2480] CHIP:DMG: }, + [1707904517.151453][36678:36681] CHIP:DMG: ICR moving to [ResponseRe] + [1707904517.151489][36678:36681] CHIP:DMG: InvokeResponseMessage = + [1707904517.151501][36678:36681] CHIP:DMG: { + [1707904517.151511][36678:36681] CHIP:DMG: suppressResponse = false, + [1707904517.151522][36678:36681] CHIP:DMG: InvokeResponseIBs = + [1707904517.151541][36678:36681] CHIP:DMG: [ + [1707904517.151548][36678:36681] CHIP:DMG: InvokeResponseIB = + [1707904517.151565][36678:36681] CHIP:DMG: { + [1707904517.151573][36678:36681] CHIP:DMG: CommandStatusIB = + [1707904517.151582][36678:36681] CHIP:DMG: { + [1707904517.151590][36678:36681] CHIP:DMG: CommandPathIB = + [1707904517.151599][36678:36681] CHIP:DMG: { + [1707904517.151613][36678:36681] CHIP:DMG: EndpointId = 0x0, + [1707904517.151627][36678:36681] CHIP:DMG: ClusterId = 0x32, + [1707904517.151640][36678:36681] CHIP:DMG: CommandId = 0x0, + [1707904517.151652][36678:36681] CHIP:DMG: }, + [1707904517.151670][36678:36681] CHIP:DMG: + [1707904517.151681][36678:36681] CHIP:DMG: StatusIB = + [1707904517.151696][36678:36681] CHIP:DMG: { + [1707904517.151708][36678:36681] CHIP:DMG: status = 0x87 (CONSTRAINT_ERROR), + [1707904517.151720][36678:36681] CHIP:DMG: }, + [1707904517.151734][36678:36681] CHIP:DMG: + [1707904517.151745][36678:36681] CHIP:DMG: }, + [1707904517.151763][36678:36681] CHIP:DMG: + [1707904517.151772][36678:36681] CHIP:DMG: }, + [1707904517.151790][36678:36681] CHIP:DMG: + [1707904517.151798][36678:36681] CHIP:DMG: ], + [1707904517.151816][36678:36681] CHIP:DMG: + [1707904517.151824][36678:36681] CHIP:DMG: InteractionModelRevision = 11 + [1707904517.151830][36678:36681] CHIP:DMG: }," disabled: true diff --git a/src/app/tests/suites/certification/Test_TC_DLOG_2_2.yaml b/src/app/tests/suites/certification/Test_TC_DLOG_2_2.yaml deleted file mode 100644 index 800553226d6cf0..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_DLOG_2_2.yaml +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default - -name: - 55.2.2. [TC-DLOG-2.2] Diagnostic Logs Cluster Commands Checks without BDX - [DUT-Server] - -PICS: - - DLOG.S - -config: - nodeId: 0x12344321 - cluster: "Basic Information" - endpoint: 0 - -tests: - - label: "Precondition" - verification: | - DUT does not support BDX - disabled: true - - - label: "Step 1: Commission DUT to TH" - verification: | - - disabled: true - - - label: - "Step 2: TH sends RetrieveLogsRequest Command (Intent = - EndUserSupport,TransferFileDesignator = 'test.txt',RequestedProtocol= - BDX) to DUT" - verification: | - sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 0 "test.txt" 1 0 - - [1646209207.288823][3223:3228] CHIP:DMG: InvokeResponseMessage = - [1646209207.288859][3223:3228] CHIP:DMG: { - [1646209207.288893][3223:3228] CHIP:DMG: suppressResponse = false, - [1646209207.288928][3223:3228] CHIP:DMG: InvokeResponseIBs = - [1646209207.288972][3223:3228] CHIP:DMG: [ - [1646209207.289006][3223:3228] CHIP:DMG: InvokeResponseIB = - [1646209207.289056][3223:3228] CHIP:DMG: { - [1646209207.289096][3223:3228] CHIP:DMG: CommandStatusIB = - [1646209207.289146][3223:3228] CHIP:DMG: { - [1646209207.289189][3223:3228] CHIP:DMG: CommandPathIB = - [1646209207.289237][3223:3228] CHIP:DMG: { - [1646209207.289285][3223:3228] CHIP:DMG: EndpointId = 0x0, - [1646209207.289338][3223:3228] CHIP:DMG: ClusterId = 0x32, - [1646209207.289391][3223:3228] CHIP:DMG: CommandId = 0x0, - [1646209207.289434][3223:3228] CHIP:DMG: }, - [1646209207.289479][3223:3228] CHIP:DMG: - [1646209207.289521][3223:3228] CHIP:DMG: StatusIB = - [1646209207.289573][3223:3228] CHIP:DMG: { - [1646209207.289619][3223:3228] CHIP:DMG: status = 0x0, - [1646209207.289666][3223:3228] CHIP:DMG: }, - [1646209207.289715][3223:3228] CHIP:DMG: - [1646209207.289756][3223:3228] CHIP:DMG: }, - [1646209207.289804][3223:3228] CHIP:DMG: - [1646209207.289842][3223:3228] CHIP:DMG: }, - [1646209207.289889][3223:3228] CHIP:DMG: - [1646209207.289923][3223:3228] CHIP:DMG: ], - [1646209207.289966][3223:3228] CHIP:DMG: - [1646209207.289999][3223:3228] CHIP:DMG: InteractionModelRevision = 1 - [1646209207.290032][3223:3228] CHIP:DMG: }, - [1646209207.290116][3223:3228] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0032 Command=0x0000_0000 Status=0x0 - disabled: true - - - label: - "Step 3: Verify that the BDX transfer is not initiated from DUT,Verify - that DUT sends RetrieveLogsResponse command,Verify that the LogContent - field of RetrieveLogsResponse command has the DUT log entries up to < - = 1024 octets,Verify that Status field is set to Exhausted" - verification: | - ubuntu@ubuntu:~/apps$ sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 0 "test.txt" 1 0 - - [1646209207.288823][3223:3228] CHIP:DMG: InvokeResponseMessage = - [1646209207.288859][3223:3228] CHIP:DMG: { - [1646209207.288893][3223:3228] CHIP:DMG: suppressResponse = false, - [1646209207.288928][3223:3228] CHIP:DMG: InvokeResponseIBs = - [1646209207.288972][3223:3228] CHIP:DMG: [ - [1646209207.289006][3223:3228] CHIP:DMG: InvokeResponseIB = - [1646209207.289056][3223:3228] CHIP:DMG: { - [1646209207.289096][3223:3228] CHIP:DMG: CommandStatusIB = - [1646209207.289146][3223:3228] CHIP:DMG: { - [1646209207.289189][3223:3228] CHIP:DMG: CommandPathIB = - [1646209207.289237][3223:3228] CHIP:DMG: { - [1646209207.289285][3223:3228] CHIP:DMG: EndpointId = 0x0, - [1646209207.289338][3223:3228] CHIP:DMG: ClusterId = 0x32, - [1646209207.289391][3223:3228] CHIP:DMG: CommandId = 0x0, - [1646209207.289434][3223:3228] CHIP:DMG: }, - [1646209207.289479][3223:3228] CHIP:DMG: - [1646209207.289521][3223:3228] CHIP:DMG: StatusIB = - [1646209207.289573][3223:3228] CHIP:DMG: { - [1646209207.289619][3223:3228] CHIP:DMG: status = 0x0, - [1646209207.289666][3223:3228] CHIP:DMG: }, - [1646209207.289715][3223:3228] CHIP:DMG: - [1646209207.289756][3223:3228] CHIP:DMG: }, - [1646209207.289804][3223:3228] CHIP:DMG: - [1646209207.289842][3223:3228] CHIP:DMG: }, - [1646209207.289889][3223:3228] CHIP:DMG: - [1646209207.289923][3223:3228] CHIP:DMG: ], - [1646209207.289966][3223:3228] CHIP:DMG: - [1646209207.289999][3223:3228] CHIP:DMG: InteractionModelRevision = 1 - [1646209207.290032][3223:3228] CHIP:DMG: }, - [1646209207.290116][3223:3228] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0032 Command=0x0000_0000 Status=0x0 - disabled: true diff --git a/src/app/tests/suites/certification/Test_TC_DLOG_3_1.yaml b/src/app/tests/suites/certification/Test_TC_DLOG_3_1.yaml deleted file mode 100644 index 0cba5b0421fa35..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_DLOG_3_1.yaml +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright (c) 2021 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default - -name: 55.3.1. [TC-DLOG-3.1] Diagnostic Logs Cluster Commands Checks[DUT-Client] - -PICS: - - DLOG.C - -config: - nodeId: 0x12344321 - cluster: "Basic Information" - endpoint: 0 - -tests: - - label: "Note" - verification: | - For DUT as client test cases, Chip-tool command used below are an example to verify the functionality. For certification test, we expect DUT should have a capability or way to run the equivalent command. - disabled: true - - - label: "Precondition" - verification: | - DUT supports BDX - TH supports BDX - disabled: true - - - label: "Step 1: Commission DUT to TH" - verification: | - - disabled: true - - - label: "Step 2: DUT sends RetrieveLogsRequest Command to TH" - PICS: DLOG.C.C00.Tx - verification: | - ./chip-tool diagnosticlogs retrieve-logs-request 0 0 "test.txt" 1 0 - - - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] StatusIB = - [1646215088531] [15387:2221674] CHIP: [DMG] { - [1646215088531] [15387:2221674] CHIP: [DMG] status = 0x0, - [1646215088531] [15387:2221674] CHIP: [DMG] }, - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] }, - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] }, - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] ], - [1646215088532] [15387:2221674] CHIP: [DMG] - [1646215088532] [15387:2221674] CHIP: [DMG] InteractionModelRevision = 1 - [1646215088532] [15387:2221674] CHIP: [DMG] }, - [1646215088532] [15387:2221674] CHIP: [DMG] Received Command Response Status for Endpoint=0 Cluster=0x0000_0032 Command=0x0000_0000 Status=0x0 - disabled: true - - - label: "Step 3: In case TH initiates a BDX Transfer" - verification: | - grl_matter@GRL-Matters-MacBook-Air debug % sudo ./chip-tool diagnosticlogs retrieve-logs-request 0 1 "test.txt" 1 0 - - - [1646208340.192138][3171:3176] CHIP:DMG: - [1646208340.192177][3171:3176] CHIP:DMG: StatusIB = - [1646208340.192224][3171:3176] CHIP:DMG: { - [1646208340.192271][3171:3176] CHIP:DMG: status = 0x0, - [1646208340.192319][3171:3176] CHIP:DMG: }, - [1646208340.192362][3171:3176] CHIP:DMG: - [1646208340.192401][3171:3176] CHIP:DMG: }, - [1646208340.192450][3171:3176] CHIP:DMG: - [1646208340.192486][3171:3176] CHIP:DMG: }, - [1646208340.192530][3171:3176] CHIP:DMG: - [1646208340.192562][3171:3176] CHIP:DMG: ], - [1646208340.192602][3171:3176] CHIP:DMG: - [1646208340.192634][3171:3176] CHIP:DMG: InteractionModelRevision = 1 - [1646208340.192665][3171:3176] CHIP:DMG: }, - [1646208340.192744][3171:3176] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0032 Command=0x0000_0000 Status=0x0 - disabled: true - - - label: "Step 4: In case TH does not initiate BDX Transfer" - verification: | - ./chip-tool diagnosticlogs retrieve-logs-request 0 0 "test.txt" 1 0 - - - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] StatusIB = - [1646215088531] [15387:2221674] CHIP: [DMG] { - [1646215088531] [15387:2221674] CHIP: [DMG] status = 0x0, - [1646215088531] [15387:2221674] CHIP: [DMG] }, - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] }, - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] }, - [1646215088531] [15387:2221674] CHIP: [DMG] - [1646215088531] [15387:2221674] CHIP: [DMG] ], - [1646215088532] [15387:2221674] CHIP: [DMG] - [1646215088532] [15387:2221674] CHIP: [DMG] InteractionModelRevision = 1 - [1646215088532] [15387:2221674] CHIP: [DMG] }, - [1646215088532] [15387:2221674] CHIP: [DMG] Received Command Response Status for Endpoint=0 Cluster=0x0000_0032 Command=0x0000_0000 Status=0x0 - disabled: true diff --git a/src/app/tests/suites/certification/Test_TC_EEVSE_2_1.yaml b/src/app/tests/suites/certification/Test_TC_EEVSE_2_1.yaml index a448a969c7e44e..9079aa4a2cfa37 100644 --- a/src/app/tests/suites/certification/Test_TC_EEVSE_2_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_EEVSE_2_1.yaml @@ -88,7 +88,6 @@ tests: constraints: type: amperage_ma minValue: 0 - maxValue: 80000 - label: "Step 8: TH reads from the DUT the MinimumChargeCurrent attribute" PICS: EEVSE.S.A0006 @@ -98,7 +97,6 @@ tests: constraints: type: amperage_ma minValue: 0 - maxValue: 80000 - label: "Step 9: TH reads from the DUT the MaximumChargeCurrent attribute" PICS: EEVSE.S.A0007 @@ -108,7 +106,6 @@ tests: constraints: type: amperage_ma minValue: 0 - maxValue: 80000 - label: "Step 10: TH reads from the DUT the MaximumDischargeCurrent attribute" @@ -119,7 +116,6 @@ tests: constraints: type: amperage_ma minValue: 0 - maxValue: 80000 - label: "Step 11: TH writes to the DUT the UserMaximumChargeCurrent attribute diff --git a/src/app/tests/suites/certification/Test_TC_GRPKEY_2_1.yaml b/src/app/tests/suites/certification/Test_TC_GRPKEY_2_1.yaml index 7bc77c9534bbb0..218e0274f7e75c 100644 --- a/src/app/tests/suites/certification/Test_TC_GRPKEY_2_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_GRPKEY_2_1.yaml @@ -68,34 +68,7 @@ tests: value: [{ FabricIndex: 1, GroupId: 0x0103, GroupKeySetID: 0x01a3 }] - label: - "Step 4: TH sends KeySetWrite command in the GroupKeyManagement - cluster to DUT. GroupKeySet fields are as follows:1)GroupKeySetID: - 0x01a3 2)GroupKeySecurityPolicy: TrustFirst (0) 3)EpochKey0: - d0d1d2d3d4d5d6d7d8d9dadbdcdddedf 4)EpochStartTime0:1 5)EpochKey1: - d1d1d2d3d4d5d6d7d8d9dadbdcdddedf 6)EpochStartTime1: - 18446744073709551613 7)EpochKey2: d2d1d2d3d4d5d6d7d8d9dadbdcdddedf - 8)EpochStartTime2: 18446744073709551614" - PICS: GRPKEY.S.C00.Rsp - command: "KeySetWrite" - arguments: - values: - - name: GroupKeySet - value: - { - GroupKeySetID: 0x01a3, - GroupKeySecurityPolicy: 0, - EpochKey0: "hex:d0d1d2d3d4d5d6d7d8d9dadbdcdddedf", - EpochStartTime0: 1, - EpochKey1: "hex:d1d1d2d3d4d5d6d7d8d9dadbdcdddedf", - EpochStartTime1: "18446744073709551613", - EpochKey2: "hex:d2d1d2d3d4d5d6d7d8d9dadbdcdddedf", - EpochStartTime2: "18446744073709551614", - } - - # Step 5 does not exist in the test plan. - - - label: - "Step 6: TH reads GroupTable attribute from GroupKeyManagement cluster + "Step 4: TH reads GroupTable attribute from GroupKeyManagement cluster on DUT." PICS: GRPKEY.S.A0001 command: "readAttribute" @@ -104,47 +77,7 @@ tests: value: [] - label: - "Step 7a: TH attempts to write to the GroupTable attribute from - GroupKeyManagement cluster on DUT with one entry as follows:1)GroupId: - 0x0104 2)Endpoints: [PIXIT.G.ENDPOINT] 3)GroupName: 'Test Group2'" - PICS: GRPKEY.S.A0001 && G.S.F00 - command: "writeAttribute" - attribute: "GroupTable" - arguments: - value: - [ - { - FabricIndex: 1, - GroupId: 0x0104, - Endpoints: [Groups.Endpoint], - GroupName: "Test Group2", - }, - ] - response: - error: UNSUPPORTED_WRITE - - - label: - "Step 7b: TH attempts to write to the GroupTable attribute from - GroupKeyManagement cluster on DUT with one entry as follows:1)GroupId: - 0x0104 2)Endpoints: [PIXIT.G.ENDPOINT] 3)GroupName: '' " - PICS: GRPKEY.S.A0001 && !G.S.F00 - command: "writeAttribute" - attribute: "GroupTable" - arguments: - value: - [ - { - FabricIndex: 1, - GroupId: 0x0104, - Endpoints: [Groups.Endpoint], - GroupName: "", - }, - ] - response: - error: UNSUPPORTED_WRITE - - - label: - "Step 8: TH reads MaxGroupsPerFabric attribute from GroupKeyManagement + "Step 5: TH reads MaxGroupsPerFabric attribute from GroupKeyManagement cluster on DUT using a fabric-filtered read." PICS: GRPKEY.S.A0002 command: "readAttribute" @@ -158,18 +91,7 @@ tests: maxValue: 65535 - label: - "Step 9: TH attempts to write MaxGroupsPerFabric attribute of - GroupKeyManagement cluster to the same value as read in step 8." - PICS: GRPKEY.S.A0002 - command: "writeAttribute" - attribute: "MaxGroupsPerFabric" - arguments: - value: MaxGroupsPerFabricValue - response: - error: UNSUPPORTED_WRITE - - - label: - "Step 10: TH reads MaxGroupKeysPerFabric attribute from + "Step 6: TH reads MaxGroupKeysPerFabric attribute from GroupKeyManagement cluster on DUT using a fabric-filtered read." PICS: GRPKEY.S.A0003 command: "readAttribute" @@ -181,15 +103,3 @@ tests: type: int16u minValue: 1 maxValue: 65535 - - - label: - "Step 11: TH attempts to write MaxGroupKeysPerFabric attribute of - GroupKeyManagement cluster on DUT to the same value as read in step - 10." - PICS: GRPKEY.S.A0003 - command: "writeAttribute" - attribute: "MaxGroupKeysPerFabric" - arguments: - value: MaxGroupKeysPerFabricValue - response: - error: UNSUPPORTED_WRITE diff --git a/src/app/tests/suites/certification/Test_TC_PWRTL_1_1.yaml b/src/app/tests/suites/certification/Test_TC_PWRTL_1_1.yaml index cfe6fd860be240..da8b19b8bf7e1b 100644 --- a/src/app/tests/suites/certification/Test_TC_PWRTL_1_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_PWRTL_1_1.yaml @@ -117,3 +117,28 @@ tests: constraints: type: list contains: [0, 1] + + - label: "Step 5*: TH reads EventList attribute from DUT" + PICS: PICS_EVENT_LIST_ENABLED + command: "readAttribute" + attribute: "EventList" + response: + value: [] + constraints: + type: list + + - label: "Step 6: TH reads the AcceptedCommandList attribute from the DUT" + command: "readAttribute" + attribute: "AcceptedCommandList" + response: + value: [] + constraints: + type: list + + - label: "Step 7: TH reads the GeneratedCommandList attribute from the DUT" + command: "readAttribute" + attribute: "GeneratedCommandList" + response: + value: [] + constraints: + type: list diff --git a/src/app/tests/suites/certification/Test_TC_TMP_2_1.yaml b/src/app/tests/suites/certification/Test_TC_TMP_2_1.yaml index 7f0af0d3bb9f03..a239c77b01dd05 100644 --- a/src/app/tests/suites/certification/Test_TC_TMP_2_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_TMP_2_1.yaml @@ -50,7 +50,7 @@ tests: saveAs: CurrentMaxMeasured constraints: type: int16s - minValue: CurrentMinMeasured + minValue: CurrentMinMeasured+1 maxValue: 32767 - label: "Step 4: TH reads the MeasuredValue attribute from the DUT" diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 36ec6ed83752a8..f6509557650bee 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -171,44 +171,54 @@ JNI_METHOD(jint, onNOCChainGeneration) ChipLogProgress(Controller, "setNOCChain() called"); jmethodID getRootCertificate; + jmethodID getIntermediateCertificate; + jmethodID getOperationalCertificate; + jmethodID getIpk; + jmethodID getAdminSubject; + + jbyteArray rootCertificate = nullptr; + jbyteArray intermediateCertificate = nullptr; + jbyteArray operationalCertificate = nullptr; + jbyteArray ipk = nullptr; + + Optional adminSubjectOptional; + uint64_t adminSubject = chip::kUndefinedNodeId; + + CommissioningParameters commissioningParams = wrapper->GetCommissioningParameters(); + + Optional ipkOptional; + uint8_t ipkValue[CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES]; + Crypto::IdentityProtectionKeySpan ipkTempSpan(ipkValue); + + VerifyOrExit(controllerParams != nullptr, ChipLogError(Controller, "controllerParams is null!")); + err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getRootCertificate", "()[B", &getRootCertificate); - VerifyOrReturnValue(err == CHIP_NO_ERROR, static_cast(err.AsInteger())); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Find getRootCertificate method fail!")); - jmethodID getIntermediateCertificate; err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIntermediateCertificate", "()[B", &getIntermediateCertificate); - VerifyOrReturnValue(err == CHIP_NO_ERROR, static_cast(err.AsInteger())); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Find getIntermediateCertificate method fail!")); - jmethodID getOperationalCertificate; err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getOperationalCertificate", "()[B", &getOperationalCertificate); - VerifyOrReturnValue(err == CHIP_NO_ERROR, static_cast(err.AsInteger())); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Find getOperationalCertificate method fail!")); - jmethodID getIpk; err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getIpk", "()[B", &getIpk); - VerifyOrReturnValue(err == CHIP_NO_ERROR, static_cast(err.AsInteger())); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Find getIpk method fail!")); - jmethodID getAdminSubject; err = chip::JniReferences::GetInstance().FindMethod(env, controllerParams, "getAdminSubject", "()J", &getAdminSubject); - VerifyOrReturnValue(err == CHIP_NO_ERROR, static_cast(err.AsInteger())); - - jbyteArray rootCertificate = (jbyteArray) env->CallObjectMethod(controllerParams, getRootCertificate); - VerifyOrReturnValue(rootCertificate != nullptr, static_cast(CHIP_ERROR_BAD_REQUEST.AsInteger())); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Find getAdminSubject method fail!")); - jbyteArray intermediateCertificate = (jbyteArray) env->CallObjectMethod(controllerParams, getIntermediateCertificate); - VerifyOrReturnValue(intermediateCertificate != nullptr, static_cast(CHIP_ERROR_BAD_REQUEST.AsInteger())); + rootCertificate = static_cast(env->CallObjectMethod(controllerParams, getRootCertificate)); + VerifyOrExit(rootCertificate != nullptr, err = CHIP_ERROR_BAD_REQUEST); - jbyteArray operationalCertificate = (jbyteArray) env->CallObjectMethod(controllerParams, getOperationalCertificate); - VerifyOrReturnValue(operationalCertificate != nullptr, static_cast(CHIP_ERROR_BAD_REQUEST.AsInteger())); + intermediateCertificate = static_cast(env->CallObjectMethod(controllerParams, getIntermediateCertificate)); + VerifyOrExit(intermediateCertificate != nullptr, err = CHIP_ERROR_BAD_REQUEST); - // use ipk and adminSubject from CommissioningParameters if not set in ControllerParams - CommissioningParameters commissioningParams = wrapper->GetCommissioningParameters(); + operationalCertificate = static_cast(env->CallObjectMethod(controllerParams, getOperationalCertificate)); + VerifyOrExit(operationalCertificate != nullptr, err = CHIP_ERROR_BAD_REQUEST); - Optional ipkOptional; - uint8_t ipkValue[CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES]; - Crypto::IdentityProtectionKeySpan ipkTempSpan(ipkValue); - - jbyteArray ipk = (jbyteArray) env->CallObjectMethod(controllerParams, getIpk); + ipk = static_cast(env->CallObjectMethod(controllerParams, getIpk)); if (ipk != nullptr) { JniByteArray jByteArrayIpk(env, ipk); @@ -217,7 +227,7 @@ JNI_METHOD(jint, onNOCChainGeneration) { ChipLogError(Controller, "Invalid IPK size %u and expect %u", static_cast(jByteArrayIpk.byteSpan().size()), static_cast(sizeof(ipkValue))); - return CHIP_ERROR_INVALID_IPK.AsInteger(); + ExitNow(err = CHIP_ERROR_INVALID_IPK); } memcpy(&ipkValue[0], jByteArrayIpk.byteSpan().data(), jByteArrayIpk.byteSpan().size()); @@ -229,8 +239,7 @@ JNI_METHOD(jint, onNOCChainGeneration) ipkOptional.SetValue(commissioningParams.GetIpk().Value()); } - Optional adminSubjectOptional; - uint64_t adminSubject = static_cast(env->CallLongMethod(controllerParams, getAdminSubject)); + adminSubject = static_cast(env->CallLongMethod(controllerParams, getAdminSubject)); if (adminSubject == kUndefinedNodeId) { // if no value pass in ControllerParams, use value from CommissioningParameters @@ -243,20 +252,27 @@ JNI_METHOD(jint, onNOCChainGeneration) // NOTE: we are allowing adminSubject to not be set since the OnNOCChainGeneration callback makes this field // optional and includes logic to handle the case where it is not set. It would also make sense to return // an error here since that use case may not be realistic. - - JniByteArray jByteArrayRcac(env, rootCertificate); - JniByteArray jByteArrayIcac(env, intermediateCertificate); - JniByteArray jByteArrayNoc(env, operationalCertificate); + { + JniByteArray jByteArrayRcac(env, rootCertificate); + JniByteArray jByteArrayIcac(env, intermediateCertificate); + JniByteArray jByteArrayNoc(env, operationalCertificate); #ifndef JAVA_MATTER_CONTROLLER_TEST - err = wrapper->GetAndroidOperationalCredentialsIssuer()->NOCChainGenerated(CHIP_NO_ERROR, jByteArrayNoc.byteSpan(), - jByteArrayIcac.byteSpan(), jByteArrayRcac.byteSpan(), - ipkOptional, adminSubjectOptional); + err = wrapper->GetAndroidOperationalCredentialsIssuer()->NOCChainGenerated( + CHIP_NO_ERROR, jByteArrayNoc.byteSpan(), jByteArrayIcac.byteSpan(), jByteArrayRcac.byteSpan(), ipkOptional, + adminSubjectOptional); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Controller, "Failed to SetNocChain for the device: %" CHIP_ERROR_FORMAT, err.Format()); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "Failed to SetNocChain for the device: %" CHIP_ERROR_FORMAT, err.Format()); + } + return static_cast(err.AsInteger()); +#endif // JAVA_MATTER_CONTROLLER_TEST } +exit: +#ifndef JAVA_MATTER_CONTROLLER_TEST + err = wrapper->GetAndroidOperationalCredentialsIssuer()->NOCChainGenerated(err, ByteSpan(), ByteSpan(), ByteSpan(), ipkOptional, + adminSubjectOptional); #endif // JAVA_MATTER_CONTROLLER_TEST return static_cast(err.AsInteger()); } diff --git a/src/darwin/Framework/CHIP/MTRDevice.h b/src/darwin/Framework/CHIP/MTRDevice.h index 50ca8d41b272fa..989ed44f7667be 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.h +++ b/src/darwin/Framework/CHIP/MTRDevice.h @@ -64,6 +64,18 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) */ @property (nonatomic, readonly) MTRDeviceState state; +/** + * Is the device cache primed for this device? + * + * This will be true after the deviceCachePrimed: delegate callback has been called, false if not. + * + * Please note if you have a storage delegate implemented, the cache is then stored persistently, so + * the delegate would then only be called once, ever - and this property would basically always be true + * if a subscription has ever been established at any point in the past. + * + */ +@property (readonly) BOOL deviceCachePrimed MTR_NEWLY_AVAILABLE; + /** * The estimated device system start time. * diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index f854242dfbeb1f..4c6b4a21e828d9 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -33,6 +33,7 @@ #import "MTRError_Internal.h" #import "MTREventTLVValueDecoder_Internal.h" #import "MTRLogging_Internal.h" +#import "MTRUnfairLock.h" #import "zap-generated/MTRCommandPayloads_Internal.h" #include "lib/core/CHIPError.h" @@ -2017,6 +2018,12 @@ - (void)setAttributeValues:(NSArray *)attributeValues reportChan os_unfair_lock_unlock(&self->_lock); } +- (BOOL)deviceCachePrimed +{ + std::lock_guard lock(_lock); + return [self _isCachePrimedWithInitialConfigurationData]; +} + // If value is non-nil, associate with expectedValueID // If value is nil, remove only if expectedValueID matches // previousValue is an out parameter diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm index 0495211b76b449..26d68921591f75 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm @@ -329,12 +329,12 @@ - (BOOL)_storeAttributeCacheValue:(id)value forKey:(NSString *)key sharingType:MTRStorageSharingTypeNotShared]; } -- (void)_removeAttributeCacheValueForKey:(NSString *)key +- (BOOL)_removeAttributeCacheValueForKey:(NSString *)key { - [_storageDelegate controller:_controller - removeValueForKey:key - securityLevel:MTRStorageSecurityLevelSecure - sharingType:MTRStorageSharingTypeNotShared]; + return [_storageDelegate controller:_controller + removeValueForKey:key + securityLevel:MTRStorageSecurityLevelSecure + sharingType:MTRStorageSharingTypeNotShared]; } static NSString * sAttributeCacheNodeIndexKey = @"attrCacheNodeIndex"; @@ -349,9 +349,9 @@ - (BOOL)_storeNodeIndex:(NSArray *)nodeIndex return [self _storeAttributeCacheValue:nodeIndex forKey:sAttributeCacheNodeIndexKey]; } -- (void)_deleteNodeIndex +- (BOOL)_deleteNodeIndex { - [self _removeAttributeCacheValueForKey:sAttributeCacheNodeIndexKey]; + return [self _removeAttributeCacheValueForKey:sAttributeCacheNodeIndexKey]; } static NSString * sAttributeCacheEndpointIndexKeyPrefix = @"attrCacheEndpointIndex"; @@ -371,9 +371,9 @@ - (BOOL)_storeEndpointIndex:(NSArray *)endpointIndex forNodeID:(NSNu return [self _storeAttributeCacheValue:endpointIndex forKey:[self _endpointIndexKeyForNodeID:nodeID]]; } -- (void)_deleteEndpointIndexForNodeID:(NSNumber *)nodeID +- (BOOL)_deleteEndpointIndexForNodeID:(NSNumber *)nodeID { - [self _removeAttributeCacheValueForKey:[self _endpointIndexKeyForNodeID:nodeID]]; + return [self _removeAttributeCacheValueForKey:[self _endpointIndexKeyForNodeID:nodeID]]; } static NSString * sAttributeCacheClusterIndexKeyPrefix = @"attrCacheClusterIndex"; @@ -393,9 +393,9 @@ - (BOOL)_storeClusterIndex:(NSArray *)clusterIndex forNodeID:(NSNumb return [self _storeAttributeCacheValue:clusterIndex forKey:[self _clusterIndexKeyForNodeID:nodeID endpointID:endpointID]]; } -- (void)_deleteClusterIndexForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID +- (BOOL)_deleteClusterIndexForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID { - [self _removeAttributeCacheValueForKey:[self _clusterIndexKeyForNodeID:nodeID endpointID:endpointID]]; + return [self _removeAttributeCacheValueForKey:[self _clusterIndexKeyForNodeID:nodeID endpointID:endpointID]]; } static NSString * sAttributeCacheAttributeIndexKeyPrefix = @"attrCacheAttributeIndex"; @@ -415,9 +415,9 @@ - (BOOL)_storeAttributeIndex:(NSArray *)attributeIndex forNodeID:(NS return [self _storeAttributeCacheValue:attributeIndex forKey:[self _attributeIndexKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID]]; } -- (void)_deleteAttributeIndexForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID +- (BOOL)_deleteAttributeIndexForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID { - [self _removeAttributeCacheValueForKey:[self _attributeIndexKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID]]; + return [self _removeAttributeCacheValueForKey:[self _attributeIndexKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID]]; } static NSString * sAttributeCacheAttributeValueKeyPrefix = @"attrCacheAttributeValue"; @@ -437,13 +437,17 @@ - (BOOL)_storeAttributeValue:(NSDictionary *)value forNodeID:(NSNumber *)nodeID return [self _storeAttributeCacheValue:value forKey:[self _attributeValueKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]]; } -- (void)_deleteAttributeValueForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID attributeID:(NSNumber *)attributeID +- (BOOL)_deleteAttributeValueForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID attributeID:(NSNumber *)attributeID { - [self _removeAttributeCacheValueForKey:[self _attributeValueKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]]; + return [self _removeAttributeCacheValueForKey:[self _attributeValueKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]]; } #pragma - Attribute Cache management +#ifndef ATTRIBUTE_CACHE_VERBOSE_LOGGING +#define ATTRIBUTE_CACHE_VERBOSE_LOGGING 0 +#endif + - (nullable NSArray *)getStoredAttributesForNodeID:(NSNumber *)nodeID { __block NSMutableArray * attributesToReturn = nil; @@ -451,6 +455,10 @@ - (void)_deleteAttributeValueForNodeID:(NSNumber *)nodeID endpointID:(NSNumber * // Fetch node index NSArray * nodeIndex = [self _fetchNodeIndex]; +#if ATTRIBUTE_CACHE_VERBOSE_LOGGING + MTR_LOG_INFO("Fetch got %lu values for nodeIndex", static_cast(nodeIndex.count)); +#endif + if (![nodeIndex containsObject:nodeID]) { // Sanity check and delete if nodeID exists in index NSArray * endpointIndex = [self _fetchEndpointIndexForNodeID:nodeID]; @@ -458,6 +466,8 @@ - (void)_deleteAttributeValueForNodeID:(NSNumber *)nodeID endpointID:(NSNumber * MTR_LOG_ERROR("Persistent attribute cache contains orphaned entry for nodeID %@ - deleting", nodeID); [self clearStoredAttributesForNodeID:nodeID]; } + + MTR_LOG_INFO("Fetch got no value for endpointIndex @ node 0x%016llX", nodeID.unsignedLongLongValue); attributesToReturn = nil; return; } @@ -465,17 +475,33 @@ - (void)_deleteAttributeValueForNodeID:(NSNumber *)nodeID endpointID:(NSNumber * // Fetch endpoint index NSArray * endpointIndex = [self _fetchEndpointIndexForNodeID:nodeID]; +#if ATTRIBUTE_CACHE_VERBOSE_LOGGING + MTR_LOG_INFO("Fetch got %lu values for endpointIndex @ node 0x%016llX", static_cast(endpointIndex.count), nodeID.unsignedLongLongValue); +#endif + for (NSNumber * endpointID in endpointIndex) { // Fetch endpoint index NSArray * clusterIndex = [self _fetchClusterIndexForNodeID:nodeID endpointID:endpointID]; +#if ATTRIBUTE_CACHE_VERBOSE_LOGGING + MTR_LOG_INFO("Fetch got %lu values for clusterIndex @ node 0x%016llX %u", static_cast(clusterIndex.count), nodeID.unsignedLongLongValue, endpointID.unsignedShortValue); +#endif + for (NSNumber * clusterID in clusterIndex) { // Fetch endpoint index NSArray * attributeIndex = [self _fetchAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID]; +#if ATTRIBUTE_CACHE_VERBOSE_LOGGING + MTR_LOG_INFO("Fetch got %lu values for attributeIndex @ node 0x%016llX endpoint %u cluster 0x%08lX", static_cast(attributeIndex.count), nodeID.unsignedLongLongValue, endpointID.unsignedShortValue, clusterID.unsignedLongValue); +#endif + for (NSNumber * attributeID in attributeIndex) { NSDictionary * value = [self _fetchAttributeValueForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]; +#if ATTRIBUTE_CACHE_VERBOSE_LOGGING + MTR_LOG_INFO("Fetch got %u values for attribute value @ node 0x%016llX endpoint %u cluster 0x%08lX attribute 0x%08lX", value ? 1 : 0, nodeID.unsignedLongLongValue, endpointID.unsignedShortValue, clusterID.unsignedLongValue, attributeID.unsignedLongValue); +#endif + if (value) { if (!attributesToReturn) { attributesToReturn = [NSMutableArray array]; @@ -495,83 +521,108 @@ - (void)_deleteAttributeValueForNodeID:(NSNumber *)nodeID endpointID:(NSNumber * return attributesToReturn; } +#ifdef DEBUG +- (void)unitTestPruneEmptyStoredAttributesBranches +{ + dispatch_sync(_storageDelegateQueue, ^{ + [self _pruneEmptyStoredAttributesBranches]; + }); +} +#endif + - (void)_pruneEmptyStoredAttributesBranches { dispatch_assert_queue(_storageDelegateQueue); + NSUInteger storeFailures = 0; + // Fetch node index - NSMutableArray * nodeIndex = [self _fetchNodeIndex].mutableCopy; - NSUInteger nodeIndexCount = nodeIndex.count; + NSArray * nodeIndex = [self _fetchNodeIndex]; + NSMutableArray * nodeIndexCopy = [nodeIndex mutableCopy]; - NSUInteger storeFailures = 0; for (NSNumber * nodeID in nodeIndex) { // Fetch endpoint index - NSMutableArray * endpointIndex = [self _fetchEndpointIndexForNodeID:nodeID].mutableCopy; - NSUInteger endpointIndexCount = endpointIndex.count; + NSArray * endpointIndex = [self _fetchEndpointIndexForNodeID:nodeID]; + NSMutableArray * endpointIndexCopy = [endpointIndex mutableCopy]; for (NSNumber * endpointID in endpointIndex) { // Fetch endpoint index - NSMutableArray * clusterIndex = [self _fetchClusterIndexForNodeID:nodeID endpointID:endpointID].mutableCopy; - NSUInteger clusterIndexCount = clusterIndex.count; + NSArray * clusterIndex = [self _fetchClusterIndexForNodeID:nodeID endpointID:endpointID]; + NSMutableArray * clusterIndexCopy = [clusterIndex mutableCopy]; for (NSNumber * clusterID in clusterIndex) { // Fetch endpoint index - NSMutableArray * attributeIndex = [self _fetchAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID].mutableCopy; - NSUInteger attributeIndexCount = attributeIndex.count; + NSArray * attributeIndex = [self _fetchAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + NSMutableArray * attributeIndexCopy = [attributeIndex mutableCopy]; for (NSNumber * attributeID in attributeIndex) { NSDictionary * value = [self _fetchAttributeValueForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]; if (!value) { - [attributeIndex removeObject:attributeID]; + [attributeIndexCopy removeObject:attributeID]; } } - if (!attributeIndex.count) { - [clusterIndex removeObject:clusterID]; - } else if (attributeIndex.count != attributeIndexCount) { - BOOL success = [self _storeAttributeIndex:attributeIndex forNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + if (attributeIndex.count != attributeIndexCopy.count) { + BOOL success; + if (attributeIndexCopy.count) { + success = [self _storeAttributeIndex:attributeIndexCopy forNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + } else { + [clusterIndexCopy removeObject:clusterID]; + success = [self _deleteAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + } if (!success) { storeFailures++; - MTR_LOG_INFO("Store failed for attributeIndex"); + MTR_LOG_INFO("Store failed in _pruneEmptyStoredAttributesBranches for attributeIndex (%lu) @ node 0x%016llX endpoint %u cluster 0x%08lX", static_cast(attributeIndexCopy.count), nodeID.unsignedLongLongValue, endpointID.unsignedShortValue, clusterID.unsignedLongValue); } } } - if (!clusterIndex.count) { - [endpointIndex removeObject:endpointID]; - } else if (clusterIndex.count != clusterIndexCount) { - BOOL success = [self _storeClusterIndex:clusterIndex forNodeID:nodeID endpointID:endpointID]; + if (clusterIndex.count != clusterIndexCopy.count) { + BOOL success; + if (clusterIndexCopy.count) { + success = [self _storeClusterIndex:clusterIndexCopy forNodeID:nodeID endpointID:endpointID]; + } else { + [endpointIndexCopy removeObject:endpointID]; + success = [self _deleteClusterIndexForNodeID:nodeID endpointID:endpointID]; + } if (!success) { storeFailures++; - MTR_LOG_INFO("Store failed for clusterIndex"); + MTR_LOG_INFO("Store failed in _pruneEmptyStoredAttributesBranches for clusterIndex (%lu) @ node 0x%016llX endpoint %u", static_cast(clusterIndexCopy.count), nodeID.unsignedLongLongValue, endpointID.unsignedShortValue); } } } - if (!endpointIndex.count) { - [nodeIndex removeObject:nodeID]; - } else if (endpointIndex.count != endpointIndexCount) { - BOOL success = [self _storeEndpointIndex:endpointIndex forNodeID:nodeID]; + if (endpointIndex.count != endpointIndexCopy.count) { + BOOL success; + if (endpointIndexCopy.count) { + success = [self _storeEndpointIndex:endpointIndexCopy forNodeID:nodeID]; + } else { + [nodeIndexCopy removeObject:nodeID]; + success = [self _deleteEndpointIndexForNodeID:nodeID]; + } if (!success) { storeFailures++; - MTR_LOG_INFO("Store failed for endpointIndex"); + MTR_LOG_INFO("Store failed in _pruneEmptyStoredAttributesBranches for endpointIndex (%lu) @ node 0x%016llX", static_cast(endpointIndexCopy.count), nodeID.unsignedLongLongValue); } } } - if (!nodeIndex.count) { - [self _deleteNodeIndex]; - } else if (nodeIndex.count != nodeIndexCount) { - BOOL success = [self _storeNodeIndex:nodeIndex]; + if (nodeIndex.count != nodeIndexCopy.count) { + BOOL success; + if (nodeIndexCopy.count) { + success = [self _storeNodeIndex:nodeIndexCopy]; + } else { + success = [self _deleteNodeIndex]; + } if (!success) { storeFailures++; - MTR_LOG_INFO("Store failed for nodeIndex"); + MTR_LOG_INFO("Store failed in _pruneEmptyStoredAttributesBranches for nodeIndex (%lu)", static_cast(nodeIndexCopy.count)); } } if (storeFailures) { - MTR_LOG_ERROR("Store failed in _pruneEmptyStoredAttributesBranches: %lu", (unsigned long) storeFailures); + MTR_LOG_ERROR("Store failed in _pruneEmptyStoredAttributesBranches: failure count %lu", static_cast(storeFailures)); } } @@ -584,6 +635,10 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS MTRAttributePath * path = dataValue[MTRAttributePathKey]; NSDictionary * value = dataValue[MTRDataKey]; +#if ATTRIBUTE_CACHE_VERBOSE_LOGGING + MTR_LOG_INFO("Attempt to store attribute value @ node 0x%016llX endpoint %u cluster 0x%08lX attribute 0x%08lX", nodeID.unsignedLongLongValue, path.endpoint.unsignedShortValue, path.cluster.unsignedLongValue, path.attribute.unsignedLongValue); +#endif + BOOL storeFailed = NO; // Ensure node index exists NSArray * nodeIndex = [self _fetchNodeIndex]; @@ -609,7 +664,7 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS } if (storeFailed) { storeFailures++; - MTR_LOG_INFO("Store failed for endpointIndex"); + MTR_LOG_INFO("Store failed for endpointIndex @ node 0x%016llX", nodeID.unsignedLongLongValue); continue; } @@ -623,7 +678,7 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS } if (storeFailed) { storeFailures++; - MTR_LOG_INFO("Store failed for clusterIndex"); + MTR_LOG_INFO("Store failed for clusterIndex @ node 0x%016llX endpoint %u", nodeID.unsignedLongLongValue, path.endpoint.unsignedShortValue); continue; } @@ -640,56 +695,100 @@ - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NS } if (storeFailed) { storeFailures++; - MTR_LOG_INFO("Store failed for attributeIndex"); + MTR_LOG_INFO("Store failed for attributeIndex @ node 0x%016llX endpoint %u cluster 0x%08lX", nodeID.unsignedLongLongValue, path.endpoint.unsignedShortValue, path.cluster.unsignedLongValue); continue; } // Store value - storeFailed = [self _storeAttributeValue:value forNodeID:nodeID endpointID:path.endpoint clusterID:path.cluster attributeID:path.attribute]; + storeFailed = ![self _storeAttributeValue:value forNodeID:nodeID endpointID:path.endpoint clusterID:path.cluster attributeID:path.attribute]; if (storeFailed) { storeFailures++; - MTR_LOG_INFO("Store failed for attribute value"); + MTR_LOG_INFO("Store failed for attribute value @ node 0x%016llX endpoint %u cluster 0x%08lX attribute 0x%08lX", nodeID.unsignedLongLongValue, path.endpoint.unsignedShortValue, path.cluster.unsignedLongValue, path.attribute.unsignedLongValue); } } // In the rare event that store fails, allow all attribute store attempts to go through and prune empty branches at the end altogether. if (storeFailures) { [self _pruneEmptyStoredAttributesBranches]; - MTR_LOG_ERROR("Store failed in -storeAttributeValues:forNodeID: %lu", (unsigned long) storeFailures); + MTR_LOG_ERROR("Store failed in -storeAttributeValues:forNodeID: failure count %lu", static_cast(storeFailures)); } }); } - (void)_clearStoredAttributesForNodeID:(NSNumber *)nodeID { + NSUInteger endpointsClearAttempts = 0; + NSUInteger clustersClearAttempts = 0; + NSUInteger attributesClearAttempts = 0; + NSUInteger endpointsCleared = 0; + NSUInteger clustersCleared = 0; + NSUInteger attributesCleared = 0; + // Fetch endpoint index NSArray * endpointIndex = [self _fetchEndpointIndexForNodeID:nodeID]; + endpointsClearAttempts += endpointIndex.count; for (NSNumber * endpointID in endpointIndex) { // Fetch cluster index NSArray * clusterIndex = [self _fetchClusterIndexForNodeID:nodeID endpointID:endpointID]; + clustersClearAttempts += clusterIndex.count; for (NSNumber * clusterID in clusterIndex) { // Fetch attribute index NSArray * attributeIndex = [self _fetchAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + attributesClearAttempts += attributeIndex.count; for (NSNumber * attributeID in attributeIndex) { - [self _deleteAttributeValueForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]; + BOOL success = [self _deleteAttributeValueForNodeID:nodeID endpointID:endpointID clusterID:clusterID attributeID:attributeID]; + if (!success) { + MTR_LOG_INFO("Delete failed for attribute value @ node 0x%016llX endpoint %u cluster 0x%08lX attribute 0x%08lX", nodeID.unsignedLongLongValue, endpointID.unsignedShortValue, clusterID.unsignedLongValue, attributeID.unsignedLongValue); + } else { + attributesCleared++; + } } - [self _deleteAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + BOOL success = [self _deleteAttributeIndexForNodeID:nodeID endpointID:endpointID clusterID:clusterID]; + if (!success) { + MTR_LOG_INFO("Delete failed for attributeIndex @ node 0x%016llX endpoint %u cluster 0x%08lX", nodeID.unsignedLongLongValue, endpointID.unsignedShortValue, clusterID.unsignedLongValue); + } else { + clustersCleared++; + } } - [self _deleteClusterIndexForNodeID:nodeID endpointID:endpointID]; + BOOL success = [self _deleteClusterIndexForNodeID:nodeID endpointID:endpointID]; + if (!success) { + MTR_LOG_INFO("Delete failed for clusterIndex @ node 0x%016llX endpoint %u", nodeID.unsignedLongLongValue, endpointID.unsignedShortValue); + } else { + endpointsCleared++; + } + } + + BOOL success = [self _deleteEndpointIndexForNodeID:nodeID]; + if (!success) { + MTR_LOG_INFO("Delete failed for endpointrIndex @ node 0x%016llX", nodeID.unsignedLongLongValue); } - [self _deleteEndpointIndexForNodeID:nodeID]; + MTR_LOG_INFO("clearStoredAttributesForNodeID: deleted endpoints %lu/%lu clusters %lu/%lu attributes %lu/%lu", static_cast(endpointsCleared), static_cast(endpointsClearAttempts), static_cast(clustersCleared), static_cast(clustersClearAttempts), static_cast(attributesCleared), static_cast(attributesClearAttempts)); } - (void)clearStoredAttributesForNodeID:(NSNumber *)nodeID { dispatch_async(_storageDelegateQueue, ^{ [self _clearStoredAttributesForNodeID:nodeID]; + NSArray * nodeIndex = [self _fetchNodeIndex]; + NSMutableArray * nodeIndexCopy = [nodeIndex mutableCopy]; + [nodeIndexCopy removeObject:nodeID]; + if (nodeIndex.count != nodeIndexCopy.count) { + BOOL success; + if (nodeIndexCopy.count) { + success = [self _storeNodeIndex:nodeIndexCopy]; + } else { + success = [self _deleteNodeIndex]; + } + if (!success) { + MTR_LOG_INFO("Store failed in clearStoredAttributesForNodeID for nodeIndex (%lu)", static_cast(nodeIndexCopy.count)); + } + } }); } @@ -703,7 +802,10 @@ - (void)clearAllStoredAttributes [self _clearStoredAttributesForNodeID:nodeID]; } - [self _deleteNodeIndex]; + BOOL success = [self _deleteNodeIndex]; + if (!success) { + MTR_LOG_INFO("Delete failed for nodeIndex"); + } }); } diff --git a/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m b/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m index 38795bcc8cef87..efa53d9dabcefb 100644 --- a/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m +++ b/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m @@ -1139,6 +1139,38 @@ - (void)test008_TestDataStoreDirect dataStoreValues = [controller.controllerDataStore getStoredAttributesForNodeID:@(1003)]; XCTAssertEqual(dataStoreValues.count, 0); + // Test MTRDeviceControllerDataStore _pruneEmptyStoredAttributesBranches + // - Clear cache + // - Store an attribute + // - Manually delete it from the test storage delegate + // - Call _pruneEmptyStoredAttributesBranches + [controller.controllerDataStore clearAllStoredAttributes]; + + NSArray * testAttribute = @[ + @{ MTRAttributePathKey : [MTRAttributePath attributePathWithEndpointID:@(1) clusterID:@(1) attributeID:@(1)], MTRDataKey : @ { MTRTypeKey : MTRUnsignedIntegerValueType, MTRValueKey : @(111) } }, + ]; + [controller.controllerDataStore storeAttributeValues:testAttribute forNodeID:@(2001)]; + + // store is async, so remove on the same queue to ensure order + dispatch_sync(_storageQueue, ^{ + NSString * testAttributeValueKey = [controller.controllerDataStore _attributeValueKeyForNodeID:@(2001) endpointID:@(1) clusterID:@(1) attributeID:@(1)]; + [storageDelegate controller:controller removeValueForKey:testAttributeValueKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared]; + }); + [controller.controllerDataStore unitTestPruneEmptyStoredAttributesBranches]; + + // Now check the indexes are pruned + NSString * testAttributeIndexKey = [controller.controllerDataStore _attributeIndexKeyForNodeID:@(2001) endpointID:@(1) clusterID:@(1)]; + id testAttributeIndex = [storageDelegate controller:controller valueForKey:testAttributeIndexKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared]; + XCTAssertNil(testAttributeIndex); + NSString * testClusterIndexKey = [controller.controllerDataStore _clusterIndexKeyForNodeID:@(2001) endpointID:@(1)]; + id testClusterIndex = [storageDelegate controller:controller valueForKey:testClusterIndexKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared]; + XCTAssertNil(testClusterIndex); + NSString * testEndpointIndexKey = [controller.controllerDataStore _endpointIndexKeyForNodeID:@(2001)]; + id testEndpointIndex = [storageDelegate controller:controller valueForKey:testEndpointIndexKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared]; + XCTAssertNil(testEndpointIndex); + id testNodeIndex = [storageDelegate controller:controller valueForKey:@"attrCacheNodeIndex" securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared]; + XCTAssertNil(testNodeIndex); + [controller shutdown]; XCTAssertFalse([controller isRunning]); } diff --git a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestDeclarations.h b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestDeclarations.h index 5b77d0ec06aad7..02a711ee183470 100644 --- a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestDeclarations.h +++ b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestDeclarations.h @@ -28,6 +28,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)storeAttributeValues:(NSArray *)dataValues forNodeID:(NSNumber *)nodeID; - (void)clearStoredAttributesForNodeID:(NSNumber *)nodeID; - (void)clearAllStoredAttributes; +- (void)unitTestPruneEmptyStoredAttributesBranches; +- (NSString *)_endpointIndexKeyForNodeID:(NSNumber *)nodeID; +- (NSString *)_clusterIndexKeyForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID; +- (NSString *)_attributeIndexKeyForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID; +- (NSString *)_attributeValueKeyForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)endpointID clusterID:(NSNumber *)clusterID attributeID:(NSNumber *)attributeID; @end // Declare internal methods for testing diff --git a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt index 1cde881e574bd9..10e55deb8ef06f 100644 --- a/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt +++ b/src/test_driver/openiotsdk/unit-tests/CMakeLists.txt @@ -34,6 +34,7 @@ include(toolchain) project(chip-open-iot-sdk-unit-tests LANGUAGES C CXX ASM) + include(sdk) include(chip) include(linker) @@ -41,13 +42,16 @@ include(linker) add_subdirectory(${OPEN_IOT_SDK_EXAMPLE_COMMON}/app ./app_build) file(STRINGS test_components.txt TEST_NAMES_FROM_FILE) +# TODO [PW_MIGRATION] Remove the following variable once the migration to pw_unit_test is complete. +file(STRINGS test_components_nl.txt TEST_NAMES_FROM_FILE_NL) target_compile_definitions(openiotsdk-startup PRIVATE IOT_SDK_APP_MAIN_STACK_SIZE=20480 ) -foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE) +# TODO [PW_MIGRATION] Remove the following targets once the migration to pw_unit_test is complete. +foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE_NL) set(APP_TARGET ${TEST_NAME}_ns) add_executable(${APP_TARGET}) target_include_directories(${APP_TARGET} @@ -56,6 +60,34 @@ foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE) ${CHIP_ROOT}/third_party/nlunit-test/repo/src ) + target_sources(${APP_TARGET} + PRIVATE + main/main_ns_nl.cpp + ) + + target_link_libraries(${APP_TARGET} + openiotsdk-startup + openiotsdk-app + ) + + # Link the *whole-archives* to keep the static test objects. + target_link_options(${APP_TARGET} + PUBLIC + -Wl,--whole-archive "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/lib${TEST_NAME}.a" + -Wl,--no-whole-archive) + + set_target_link(${APP_TARGET}) + sdk_post_build(${APP_TARGET}) +endforeach() + +foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE) + set(APP_TARGET ${TEST_NAME}_ns) + add_executable(${APP_TARGET}) + target_include_directories(${APP_TARGET} + PRIVATE + main/include + ) + target_sources(${APP_TARGET} PRIVATE main/main_ns.cpp @@ -70,6 +102,7 @@ foreach(TEST_NAME IN LISTS TEST_NAMES_FROM_FILE) target_link_options(${APP_TARGET} PUBLIC -Wl,--whole-archive "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/lib${TEST_NAME}.a" + "${CMAKE_CURRENT_BINARY_DIR}/chip_build/lib/libPWTestsWrapper.a" -Wl,--no-whole-archive) set_target_link(${APP_TARGET}) diff --git a/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp b/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp index a819655c162697..ec45046d343321 100644 --- a/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp +++ b/src/test_driver/openiotsdk/unit-tests/main/main_ns.cpp @@ -20,12 +20,9 @@ #include #include "openiotsdk_platform.h" -#include -#include +#include #include -constexpr nl_test_output_logger_t NlTestLogger::nl_test_logger; - using namespace ::chip; int main() @@ -36,8 +33,6 @@ int main() return EXIT_FAILURE; } - nlTestSetLogger(&NlTestLogger::nl_test_logger); - ChipLogAutomation("Open IoT SDK unit-tests start"); if (openiotsdk_network_init(true)) @@ -47,7 +42,7 @@ int main() } ChipLogAutomation("Open IoT SDK unit-tests run..."); - int status = RunRegisteredUnitTests(); + int status = chip::test::RunAllTests(); ChipLogAutomation("Test status: %d", status); ChipLogAutomation("Open IoT SDK unit-tests completed"); diff --git a/src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp b/src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp new file mode 100644 index 00000000000000..f7e511b8d183cf --- /dev/null +++ b/src/test_driver/openiotsdk/unit-tests/main/main_ns_nl.cpp @@ -0,0 +1,55 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "openiotsdk_platform.h" +#include +#include +#include + +constexpr nl_test_output_logger_t NlTestLogger::nl_test_logger; + +using namespace ::chip; + +int main() +{ + if (openiotsdk_platform_init()) + { + ChipLogAutomation("ERROR: Open IoT SDK platform initialization failed"); + return EXIT_FAILURE; + } + + nlTestSetLogger(&NlTestLogger::nl_test_logger); + + ChipLogAutomation("Open IoT SDK unit-tests start"); + + if (openiotsdk_network_init(true)) + { + ChipLogAutomation("ERROR: Network initialization failed"); + return EXIT_FAILURE; + } + + ChipLogAutomation("Open IoT SDK unit-tests run..."); + int status = RunRegisteredUnitTests(); + ChipLogAutomation("Test status: %d", status); + ChipLogAutomation("Open IoT SDK unit-tests completed"); + + return EXIT_SUCCESS; +} diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt index 03fa4aee9b70f4..e69de29bb2d1d6 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt @@ -1,24 +0,0 @@ -accesstest -AppTests -ASN1Tests -BDXTests -ChipCryptoTests -CoreTests -CredentialsTest -DataModelTests -InetLayerTests -MdnsTests -MessagingLayerTests -MinimalMdnsCoreTests -MinimalMdnsRecordsTests -MinimalMdnsRespondersTests -PlatformTests -RawTransportTests -RetransmitTests -SecureChannelTests -SetupPayloadTests -SupportTests -SystemLayerTests -TestShell -TransportLayerTests -UserDirectedCommissioningTests diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt new file mode 100644 index 00000000000000..03fa4aee9b70f4 --- /dev/null +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -0,0 +1,24 @@ +accesstest +AppTests +ASN1Tests +BDXTests +ChipCryptoTests +CoreTests +CredentialsTest +DataModelTests +InetLayerTests +MdnsTests +MessagingLayerTests +MinimalMdnsCoreTests +MinimalMdnsRecordsTests +MinimalMdnsRespondersTests +PlatformTests +RawTransportTests +RetransmitTests +SecureChannelTests +SetupPayloadTests +SupportTests +SystemLayerTests +TestShell +TransportLayerTests +UserDirectedCommissioningTests diff --git a/src/tracing/metric_macros.h b/src/tracing/metric_macros.h index 4ff85f353701b3..26dde8cd3230a0 100644 --- a/src/tracing/metric_macros.h +++ b/src/tracing/metric_macros.h @@ -27,13 +27,258 @@ #if MATTER_TRACING_ENABLED /** - * @def SuccessOrExitWithMetric(kMetriKey, error) + * @def ReturnErrorOnFailureWithMetric(kMetricKey, expr) + * + * @brief + * This macros emits the specified metric with error code and returns the error code, + * if the expression returns an error. For a CHIP_ERROR expression, this means any value + * other than CHIP_NO_ERROR. For an integer expression, this means non-zero. + * + * Example usage: + * + * @code + * ReturnErrorOnFailureWithMetric(kMetricKey, channel->SendMsg(msg)); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * does not evaluate to CHIP_NO_ERROR. Value of the metric is to the + * result of the expression. + * @param[in] expr An expression to be tested. + */ +#define ReturnErrorOnFailureWithMetric(kMetricKey, expr) \ + do \ + { \ + auto __err = (expr); \ + if (!::chip::ChipError::IsSuccess(__err)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, __err); \ + return __err; \ + } \ + } while (false) + +/** + * @def ReturnLogErrorOnFailureWithMetric(kMetricKey, expr) + * + * @brief + * Returns the error code if the expression returns something different + * than CHIP_NO_ERROR. In addition, a metric is emitted with the specified metric key and + * error code as the value of the metric. + * + * Example usage: + * + * @code + * ReturnLogErrorOnFailureWithMetric(kMetricKey, channel->SendMsg(msg)); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * does not evaluate to CHIP_NO_ERROR. Value of the metric is to the + * result of the expression. + * @param[in] expr A scalar expression to be evaluated against CHIP_NO_ERROR. + */ +#define ReturnLogErrorOnFailureWithMetric(kMetricKey, expr) \ + do \ + { \ + CHIP_ERROR __err = (expr); \ + if (__err != CHIP_NO_ERROR) \ + { \ + MATTER_LOG_METRIC(kMetricKey, __err); \ + ChipLogError(NotSpecified, "%s at %s:%d", ErrorStr(__err), __FILE__, __LINE__); \ + return __err; \ + } \ + } while (false) + +/** + * @def ReturnOnFailureWithMetric(kMetricKey, expr) + * + * @brief + * Returns if the expression returns an error. For a CHIP_ERROR expression, this means any value other + * than CHIP_NO_ERROR. For an integer expression, this means non-zero. If the expression evaluates to + * anything but CHIP_NO_ERROR, a metric with the specified key is emitted along with error as the value. + * + * Example usage: + * + * @code + * ReturnOnFailureWithMetric(kMetricKey, channel->SendMsg(msg)); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * does not evaluate to CHIP_NO_ERROR. Value of the metric is to the + * result of the expression. + * @param[in] expr An expression to be tested. + */ +#define ReturnOnFailureWithMetric(kMetricKey, expr) \ + do \ + { \ + auto __err = (expr); \ + if (!::chip::ChipError::IsSuccess(__err)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, __err); \ + return; \ + } \ + } while (false) + +/** + * @def VerifyOrReturnWithMetric(kMetricKey, expr, ...) + * + * @brief + * Returns from the void function if expression evaluates to false. If the expression evaluates + * to false, a metric with the specified key is emitted. + * + * Example usage: + * + * @code + * VerifyOrReturnWithMetric(kMetricKey, param != nullptr, LogError("param is nullptr")); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * to false. Value of the metric is set to false. + * @param[in] expr A Boolean expression to be evaluated. + * @param[in] ... Statements to execute before returning. Optional. + */ +#define VerifyOrReturnWithMetric(kMetricKey, expr, ...) \ + do \ + { \ + if (!(expr)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, false); \ + __VA_ARGS__; \ + return; \ + } \ + } while (false) + +/** + * @def VerifyOrReturnErrorWithMetric(kMetricKey, expr, code, ...) + * + * @brief + * Returns a specified error code if expression evaluates to false. If the expression evaluates + * to false, a metric with the specified key is emitted with the value set to the code. + * + * Example usage: + * + * @code + * VerifyOrReturnErrorWithMetric(kMetricKey, param != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * to false. Value of the metric is to code. + * @param[in] expr A Boolean expression to be evaluated. + * @param[in] code A value to return if @a expr is false. + * @param[in] ... Statements to execute before returning. Optional. + */ +#define VerifyOrReturnErrorWithMetric(kMetricKey, expr, code, ...) \ + VerifyOrReturnValueWithMetric(kMetricKey, expr, code, ##__VA_ARGS__) + +/** + * @def VerifyOrReturnValueWithMetric(kMetricKey, expr, value, ...) + * + * @brief + * Returns a specified value if expression evaluates to false. If the expression evaluates + * to false, a metric with the specified key is emitted with the value set to value. + * + * Example usage: + * + * @code + * VerifyOrReturnValueWithMetric(kMetricKey, param != nullptr, Foo()); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * to false. Value of the metric is to value. + * @param[in] expr A Boolean expression to be evaluated. + * @param[in] value A value to return if @a expr is false. + * @param[in] ... Statements to execute before returning. Optional. + */ +#define VerifyOrReturnValueWithMetric(kMetricKey, expr, value, ...) \ + do \ + { \ + if (!(expr)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, value); \ + __VA_ARGS__; \ + return (value); \ + } \ + } while (false) + +/** + * @def VerifyOrReturnLogErrorWithMetric(kMetricKey, expr, code) + * + * @brief + * Returns and print a specified error code if expression evaluates to false. + * If the expression evaluates to false, a metric with the specified key is emitted + * with the value set to code. + * + * Example usage: + * + * @code + * VerifyOrReturnLogErrorWithMetric(kMetricKey, param != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * to false. Value of the metric is to code. + * @param[in] expr A Boolean expression to be evaluated. + * @param[in] code A value to return if @a expr is false. + */ +#if CHIP_CONFIG_ERROR_SOURCE +#define VerifyOrReturnLogErrorWithMetric(kMetricKey, expr, code) \ + do \ + { \ + if (!(expr)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, code); \ + ChipLogError(NotSpecified, "%s at %s:%d", ErrorStr(code), __FILE__, __LINE__); \ + return code; \ + } \ + } while (false) +#else // CHIP_CONFIG_ERROR_SOURCE +#define VerifyOrReturnLogErrorWithMetric(kMetricKey, expr, code) \ + do \ + { \ + if (!(expr)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, code); \ + ChipLogError(NotSpecified, "%s:%d false: %" CHIP_ERROR_FORMAT, #expr, __LINE__, code.Format()); \ + return code; \ + } \ + } while (false) +#endif // CHIP_CONFIG_ERROR_SOURCE + +/** + * @def ReturnErrorCodeWithMetricIf(kMetricKey, expr, code) + * + * @brief + * Returns a specified error code if expression evaluates to true + * If the expression evaluates to true, a metric with the specified key is emitted + * with the value set to code. + * + * Example usage: + * + * @code + * ReturnErrorCodeWithMetricIf(kMetricKey, state == kInitialized, CHIP_NO_ERROR); + * ReturnErrorCodeWithMetricIf(kMetricKey, state == kInitialized, CHIP_ERROR_INCORRECT_STATE); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * to true. Value of the metric is to code. + * @param[in] expr A Boolean expression to be evaluated. + * @param[in] code A value to return if @a expr is false. + */ +#define ReturnErrorCodeWithMetricIf(kMetricKey, expr, code) \ + do \ + { \ + if (expr) \ + { \ + MATTER_LOG_METRIC(kMetricKey, code); \ + return code; \ + } \ + } while (false) + +/** + * @def SuccessOrExitWithMetric(kMetricKey, error) * * @brief * This checks for the specified error, which is expected to * commonly be successful (CHIP_NO_ERROR), and branches to * the local label 'exit' if the error is not success. - * If error is not a success, a metric with key kMetriKey is emitted with + * If error is not a success, a metric with key kMetricKey is emitted with * the error code as the value of the metric. * * Example Usage: @@ -100,9 +345,110 @@ #define VerifyOrExitWithMetric(kMetricKey, aCondition, anAction) \ nlEXPECT_ACTION(aCondition, exit, MATTER_LOG_METRIC((kMetricKey), (anAction))) -/* - * Utility Macros to support optional arguments for MATTER_LOG_METRIC_XYZ macros +/** + * @def ExitNowWithMetric(kMetricKey, ...) + * + * @brief + * This unconditionally executes @a ... and branches to the local + * label 'exit'. In addition a metric is emitted with the specified key. + * + * @note The use of this interface implies neither success nor + * failure for the overall exit status of the enclosing function + * body. + * + * Example Usage: + * + * @code + * CHIP_ERROR ReadAll(Reader& reader) + * { + * CHIP_ERROR err; + * + * while (true) + * { + * err = reader.ReadNext(); + * if (err == CHIP_ERROR_AT_END) + * ExitNowWithMetric(kMetricKey, err = CHIP_NO_ERROR); + * SuccessOrExit(err); + * DoSomething(); + * } + * + * exit: + * return err; + * } + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted. + * @param[in] ... Statements to execute. Optional. */ +#define ExitNowWithMetric(kMetricKey, ...) \ + do \ + { \ + MATTER_LOG_METRIC(kMetricKey); \ + __VA_ARGS__; \ + goto exit; \ + } while (0) + +/** + * @def LogErrorOnFailureWithMetric(kMetricKey, expr) + * + * @brief + * Logs a message if the expression returns something different than CHIP_NO_ERROR. + * In addition, a metric is emitted with the specified key and value set to result + * of the expression in case it evaluates to anything other than CHIP_NO_ERROR. + * + * Example usage: + * + * @code + * LogErrorOnFailureWithMetric(kMetricKey, channel->SendMsg(msg)); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted if the expr evaluates + * does not evaluate to CHIP_NO_ERROR. Value of the metric is to the + * result of the expression. + * @param[in] expr A scalar expression to be evaluated against CHIP_NO_ERROR. + */ +#define LogErrorOnFailureWithMetric(kMetricKey, expr) \ + do \ + { \ + CHIP_ERROR __err = (expr); \ + if (__err != CHIP_NO_ERROR) \ + { \ + MATTER_LOG_METRIC(kMetricKey, __err); \ + ChipLogError(NotSpecified, "%s at %s:%d", ErrorStr(__err), __FILE__, __LINE__); \ + } \ + } while (false) + +/** + * @def VerifyOrDoWithMetric(kMetricKey, expr, ...) + * + * @brief + * Do something if expression evaluates to false. If the expression evaluates to false a metric + * with the specified key is emitted with value set to false. + * + * Example usage: + * + * @code + * VerifyOrDoWithMetric(param != nullptr, LogError("param is nullptr")); + * @endcode + * + * @param[in] kMetricKey Metric key for the metric event to be emitted. + * Value of the metric is set to false. + * @param[in] expr A Boolean expression to be evaluated. + * @param[in] ... Statements to execute. + */ +#define VerifyOrDoWithMetric(kMetricKey, expr, ...) \ + do \ + { \ + if (!(expr)) \ + { \ + MATTER_LOG_METRIC(kMetricKey, false); \ + __VA_ARGS__; \ + } \ + } while (false) + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Utility Macros to support optional arguments for MATTER_LOG_METRIC_XYZ macros +//////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Utility to always return the 4th argument from macro parameters #define __GET_4TH_ARG(_a1, _a2, _a3, _a4, ...) _a4 @@ -222,10 +568,32 @@ // Remap Success, Return, and Verify macros to the ones without metrics //////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#define ReturnErrorOnFailureWithMetric(kMetricKey, expr) ReturnErrorOnFailure(expr) + +#define ReturnLogErrorOnFailureWithMetric(kMetricKey, expr) ReturnLogErrorOnFailure(expr) + +#define ReturnOnFailureWithMetric(kMetricKey, expr) ReturnOnFailure(expr) + +#define VerifyOrReturnWithMetric(kMetricKey, expr, ...) VerifyOrReturn(expr, ##__VA_ARGS__) + +#define VerifyOrReturnErrorWithMetric(kMetricKey, expr, code, ...) VerifyOrReturnValue(expr, code, ##__VA_ARGS__) + +#define VerifyOrReturnValueWithMetric(kMetricKey, expr, value, ...) VerifyOrReturnValue(expr, value, ##__VA_ARGS__) + +#define VerifyOrReturnLogErrorWithMetric(kMetricKey, expr, code) VerifyOrReturnLogError(expr, code) + +#define ReturnErrorCodeWithMetricIf(kMetricKey, expr, code) ReturnErrorCodeIf(expr, code) + #define SuccessOrExitWithMetric(kMetricKey, aStatus) SuccessOrExit(aStatus) #define VerifyOrExitWithMetric(kMetricKey, aCondition, anAction) VerifyOrExit(aCondition, anAction) +#define ExitNowWithMetric(kMetricKey, ...) ExitNow(##__VA_ARGS__) + +#define LogErrorOnFailureWithMetric(kMetricKey, expr) LogErrorOnFailure(expr) + +#define VerifyOrDoWithMetric(kMetricKey, expr, ...) VerifyOrDo(expr, ##__VA_ARGS__) + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Map all MATTER_LOG_METRIC_XYZ macros to noops //////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/tracing/tests/TestMetricEvents.cpp b/src/tracing/tests/TestMetricEvents.cpp index c52a5fc91b9e93..72e159df7cf7fa 100644 --- a/src/tracing/tests/TestMetricEvents.cpp +++ b/src/tracing/tests/TestMetricEvents.cpp @@ -324,14 +324,335 @@ void TestSuccessOrExitWithMetric(nlTestSuite * inSuite, void * inContext) inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); } +static CHIP_ERROR InvokeReturnErrorOnFailureWithMetric(MetricKey key, const CHIP_ERROR & error) +{ + ReturnErrorOnFailureWithMetric(key, error); + return CHIP_NO_ERROR; +} + +void TestReturnErrorOnFailureWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + CHIP_ERROR err = InvokeReturnErrorOnFailureWithMetric("event0", CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = InvokeReturnErrorOnFailureWithMetric("event1", CHIP_ERROR_INCORRECT_STATE); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); + + err = InvokeReturnErrorOnFailureWithMetric("event2", CHIP_ERROR_BAD_REQUEST); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BAD_REQUEST); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_INCORRECT_STATE), + MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BAD_REQUEST), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +static CHIP_ERROR InvokeReturnLogErrorOnFailureWithMetric(MetricKey key, const CHIP_ERROR & error) +{ + ReturnLogErrorOnFailureWithMetric(key, error); + return CHIP_NO_ERROR; +} + +void TestReturnLogErrorOnFailureWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + CHIP_ERROR err = InvokeReturnLogErrorOnFailureWithMetric("event0", CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = InvokeReturnLogErrorOnFailureWithMetric("event1", CHIP_ERROR_INCORRECT_STATE); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); + + err = InvokeReturnLogErrorOnFailureWithMetric("event2", CHIP_ERROR_BAD_REQUEST); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BAD_REQUEST); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_INCORRECT_STATE), + MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BAD_REQUEST), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +static void InvokeReturnOnFailureWithMetric(MetricKey key, const CHIP_ERROR & error) +{ + ReturnOnFailureWithMetric(key, error); + return; +} + +void TestReturnOnFailureWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + InvokeReturnOnFailureWithMetric("event0", CHIP_NO_ERROR); + + InvokeReturnOnFailureWithMetric("event1", CHIP_ERROR_INCORRECT_STATE); + + InvokeReturnOnFailureWithMetric("event2", CHIP_ERROR_BAD_REQUEST); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_INCORRECT_STATE), + MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_BAD_REQUEST), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +static void InvokeVerifyOrReturnWithMetric(MetricKey key, bool result) +{ + VerifyOrReturnWithMetric(key, result); + return; +} + +void TestInvokeVerifyOrReturnWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + InvokeVerifyOrReturnWithMetric("event0", DoubleOf(2) == 4); + InvokeVerifyOrReturnWithMetric("event1", DoubleOf(3) == 9); + InvokeVerifyOrReturnWithMetric("event2", DoubleOf(4) == 8); + InvokeVerifyOrReturnWithMetric("event3", DoubleOf(5) == 11); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", false), + MetricEvent(MetricEvent::Type::kInstantEvent, "event3", false), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +static CHIP_ERROR InvokeVerifyOrReturnErrorWithMetric(MetricKey key, bool expr, const CHIP_ERROR & error) +{ + VerifyOrReturnErrorWithMetric(key, expr, error); + return CHIP_NO_ERROR; +} + +void TestVerifyOrReturnErrorWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + CHIP_ERROR err = InvokeVerifyOrReturnErrorWithMetric("event0", DoubleOf(2) == 4, CHIP_ERROR_BAD_REQUEST); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = InvokeVerifyOrReturnErrorWithMetric("event1", DoubleOf(3) == 9, CHIP_ERROR_ACCESS_DENIED); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ACCESS_DENIED); + + err = InvokeVerifyOrReturnErrorWithMetric("event2", DoubleOf(4) == 8, CHIP_ERROR_BUSY); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = InvokeVerifyOrReturnErrorWithMetric("event3", DoubleOf(5) == 11, CHIP_ERROR_CANCELLED); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_CANCELLED); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_ACCESS_DENIED), + MetricEvent(MetricEvent::Type::kInstantEvent, "event3", CHIP_ERROR_CANCELLED), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +template +static return_code_type InvokeVerifyOrReturnValueWithMetric(MetricKey key, bool expr, return_code_type retval) +{ + VerifyOrReturnValueWithMetric(key, expr, retval); + return return_code_type(); +} + +void TestVerifyOrReturnValueWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + auto retval = InvokeVerifyOrReturnValueWithMetric("event0", DoubleOf(2) == 4, 0); + NL_TEST_ASSERT(inSuite, retval == 0); + + auto err = InvokeVerifyOrReturnValueWithMetric("event1", DoubleOf(3) == 9, CHIP_ERROR_ACCESS_DENIED); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_ACCESS_DENIED); + + err = InvokeVerifyOrReturnValueWithMetric("event2", DoubleOf(4) == 8, CHIP_ERROR_BAD_REQUEST); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + retval = InvokeVerifyOrReturnValueWithMetric("event3", DoubleOf(5) == 11, 16); + NL_TEST_ASSERT(inSuite, retval == 16); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_ACCESS_DENIED), + MetricEvent(MetricEvent::Type::kInstantEvent, "event3", 16), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +static CHIP_ERROR InvokeVerifyOrReturnLogErrorWithMetric(MetricKey key, bool expr, const CHIP_ERROR & error) +{ + VerifyOrReturnLogErrorWithMetric(key, expr, error); + return CHIP_NO_ERROR; +} + +void TestVerifyOrReturnLogErrorWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + auto err = InvokeVerifyOrReturnLogErrorWithMetric("event0", DoubleOf(2) == 4, CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = InvokeVerifyOrReturnLogErrorWithMetric("event1", DoubleOf(3) == 9, CHIP_ERROR_CANCELLED); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_CANCELLED); + + err = InvokeVerifyOrReturnLogErrorWithMetric("event2", DoubleOf(4) == 8, CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + err = InvokeVerifyOrReturnLogErrorWithMetric("event3", DoubleOf(5) == 11, CHIP_ERROR_BAD_REQUEST); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BAD_REQUEST); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event1", CHIP_ERROR_CANCELLED), + MetricEvent(MetricEvent::Type::kInstantEvent, "event3", CHIP_ERROR_BAD_REQUEST), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +template +static return_code_type InvokeReturnErrorCodeWithMetricIf(MetricKey key, bool expr, const return_code_type & code) +{ + ReturnErrorCodeWithMetricIf(key, expr, code); + return return_code_type(); +} + +void TestReturnErrorCodeWithMetricIf(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + auto err = InvokeReturnErrorCodeWithMetricIf("event0", DoubleOf(2) == 4, CHIP_ERROR_DUPLICATE_KEY_ID); + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_DUPLICATE_KEY_ID); + + auto retval = InvokeReturnErrorCodeWithMetricIf("event1", DoubleOf(3) == 9, 11); + NL_TEST_ASSERT(inSuite, retval == 0); + + retval = InvokeReturnErrorCodeWithMetricIf("event2", DoubleOf(4) == 8, 22); + NL_TEST_ASSERT(inSuite, retval == 22); + + err = InvokeReturnErrorCodeWithMetricIf("event3", DoubleOf(5) == 11, CHIP_ERROR_ACCESS_DENIED); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event0", CHIP_ERROR_DUPLICATE_KEY_ID), + MetricEvent(MetricEvent::Type::kInstantEvent, "event2", 22), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +void TestExitNowWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + chip::ChipError err = CHIP_NO_ERROR; + + ExitNowWithMetric("event0", err = CHIP_ERROR_BUSY); + +exit: + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event0"), + }; + + NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUSY); + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +void TestLogErrorOnFailureWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + LogErrorOnFailureWithMetric("event0", CHIP_ERROR_BAD_REQUEST); + LogErrorOnFailureWithMetric("event1", CHIP_NO_ERROR); + LogErrorOnFailureWithMetric("event2", CHIP_ERROR_DATA_NOT_ALIGNED); + LogErrorOnFailureWithMetric("event3", CHIP_ERROR_BUSY); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event0", CHIP_ERROR_BAD_REQUEST), + MetricEvent(MetricEvent::Type::kInstantEvent, "event2", CHIP_ERROR_DATA_NOT_ALIGNED), + MetricEvent(MetricEvent::Type::kInstantEvent, "event3", CHIP_ERROR_BUSY), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + +void TestVerifyOrDoWithMetric(nlTestSuite * inSuite, void * inContext) +{ + MetricEventBackend backend; + ScopedRegistration scope(backend); + + VerifyOrDoWithMetric("event0", DoubleOf(2) == 5); + VerifyOrDoWithMetric("event1", DoubleOf(3) == 6); + VerifyOrDoWithMetric("event2", DoubleOf(4) == 7, MATTER_LOG_METRIC("event4", 10)); + VerifyOrDoWithMetric("event3", DoubleOf(5) == 8); + VerifyOrDoWithMetric("event5", DoubleOf(6) == 12); + + std::vector expected = { + MetricEvent(MetricEvent::Type::kInstantEvent, "event0", false), + MetricEvent(MetricEvent::Type::kInstantEvent, "event2", false), + MetricEvent(MetricEvent::Type::kInstantEvent, "event4", 10), + MetricEvent(MetricEvent::Type::kInstantEvent, "event3", false), + }; + + NL_TEST_ASSERT(inSuite, backend.GetMetricEvents().size() == expected.size()); + NL_TEST_ASSERT( + inSuite, std::equal(backend.GetMetricEvents().begin(), backend.GetMetricEvents().end(), expected.begin(), expected.end())); +} + static const nlTest sMetricTests[] = { - NL_TEST_DEF("BasicMetricEvent", TestBasicMetricEvent), // - NL_TEST_DEF("InstantMetricEvent", TestInstantMetricEvent), // - NL_TEST_DEF("BeginEndMetricEvent", TestBeginEndMetricEvent), // - NL_TEST_DEF("ScopedMetricEvent", TestScopedMetricEvent), // - NL_TEST_DEF("VerifyOrExitWithMetric", TestVerifyOrExitWithMetric), // - NL_TEST_DEF("SuccessOrExitWithMetric", TestSuccessOrExitWithMetric), // - NL_TEST_SENTINEL() // + NL_TEST_DEF("BasicMetricEvent", TestBasicMetricEvent), // + NL_TEST_DEF("InstantMetricEvent", TestInstantMetricEvent), // + NL_TEST_DEF("BeginEndMetricEvent", TestBeginEndMetricEvent), // + NL_TEST_DEF("ScopedMetricEvent", TestScopedMetricEvent), // + NL_TEST_DEF("VerifyOrExitWithMetric", TestVerifyOrExitWithMetric), // + NL_TEST_DEF("SuccessOrExitWithMetric", TestSuccessOrExitWithMetric), // + NL_TEST_DEF("ReturnErrorOnFailureWithMetric", TestReturnErrorOnFailureWithMetric), // + NL_TEST_DEF("ReturnLogErrorOnFailureWithMetric", TestReturnLogErrorOnFailureWithMetric), // + NL_TEST_DEF("ReturnOnFailureWithMetric", TestReturnOnFailureWithMetric), // + NL_TEST_DEF("VerifyOrReturnWithMetric", TestInvokeVerifyOrReturnWithMetric), // + NL_TEST_DEF("VerifyOrReturnErrorWithMetric", TestVerifyOrReturnErrorWithMetric), // + NL_TEST_DEF("VerifyOrReturnValueWithMetric", TestVerifyOrReturnValueWithMetric), // + NL_TEST_DEF("VerifyOrReturnLogErrorWithMetric", TestVerifyOrReturnLogErrorWithMetric), // + NL_TEST_DEF("ReturnErrorCodeWithMetricIf", TestReturnErrorCodeWithMetricIf), // + NL_TEST_DEF("ExitNowWithMetric", TestExitNowWithMetric), // + NL_TEST_DEF("LogErrorOnFailureWithMetric", TestLogErrorOnFailureWithMetric), // + NL_TEST_DEF("VerifyOrDoWithMetric", TestVerifyOrDoWithMetric), // + NL_TEST_SENTINEL() // }; } // namespace