# 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: 3.5.1. [TC-IDM-5.1] Timed Request Action from DUT to TH. [DUT_Client]

PICS:
    - MCORE.IDM.C

config:
    nodeId: 0x12344321
    cluster: "Basic Information"
    endpoint: 0

tests:
    - label: "Note"
      verification: |
          Chip-tool command used below are an example to verify the  DUT as client test cases. For certification test, we expect DUT should have a capability or way to run the equivalent command.
          The DUT should have a way of triggering the Timed Request Message for Testing. Test Step #3 might not be testable.
      disabled: true

    - label:
          "Step 1: DUT sends the Timed Request to the TH and then sends an
          Invoke Request Message to the TH after receiving the status response
          message from the TH. The Timed Request Message should contain a
          timeout value in milliseconds. (Example - 200 milliseconds)"
      PICS: MCORE.IDM.C.InvokeRequest
      verification: |
          Product maker needs to provide instructions for how to trigger the command on the DUT. For comparison, the DUT behavior for this test step can be simulated using chip-tool (when DUT is a commissioner/Client)

          ./chip-tool onoff on 1 1 --timedInteractionTimeoutMs 200

          On the TH(all-clusters-app) verify the received timed request message has the timeout value as sent by the DUT(chip-tool) and verify that the message is unicast.
          [1655797318.624018][7331:7331] CHIP:EM: Handling via exchange: 28067r, Delegate: 0xaaaad9aed418
          [1655797318.624129][7331:7331] CHIP:DMG: TimedRequestMessage =
          [1655797318.624185][7331:7331] CHIP:DMG: {
          [1655797318.624235][7331:7331] CHIP:DMG:         TimeoutMs = 0xc8,
          [1655797318.624289][7331:7331] CHIP:DMG:         InteractionModelRevision = 1
          [1655797318.624339][7331:7331] CHIP:DMG: }
          [1655797318.624394][7331:7331] CHIP:DMG: Got Timed Request with timeout 200: handler 0xaaaaf9f93440 exchange 28067r

          On the TH(all-clusters-app)  Verify that the DUT(chip-tool) sends the Invoke Request Message to the TH(all-clusters-app) before the specified timeout value and Invoke Request has TimedRequest set to True.
          [1655797318.626273][7331:7331] CHIP:DMG: Handing timed invoke to IM engine: handler 0xaaaaf9f93440 exchange 28067r
          [1655797318.626358][7331:7331] CHIP:DMG: InvokeRequestMessage =
          [1655797318.626411][7331:7331] CHIP:DMG: {
          [1655797318.626460][7331:7331] CHIP:DMG:         suppressResponse = false,
          [1655797318.626517][7331:7331] CHIP:DMG:         timedRequest = true,
          [1655797318.626569][7331:7331] CHIP:DMG:         InvokeRequests =
          [1655797318.626633][7331:7331] CHIP:DMG:         [
          [1655797318.626684][7331:7331] CHIP:DMG:                 CommandDataIB =
          [1655797318.626742][7331:7331] CHIP:DMG:                 {
          [1655797318.626796][7331:7331] CHIP:DMG:                         CommandPathIB =
          [1655797318.626866][7331:7331] CHIP:DMG:                         {
          [1655797318.626934][7331:7331] CHIP:DMG:                                 EndpointId = 0x1,
          [1655797318.627002][7331:7331] CHIP:DMG:                                 ClusterId = 0x6,
          [1655797318.627037][7331:7331] CHIP:DMG:                                 CommandId = 0x1,
          [1655797318.627070][7331:7331] CHIP:DMG:                         },
          [1655797318.627148][7331:7331] CHIP:DMG:
          [1655797318.627179][7331:7331] CHIP:DMG:                         CommandFields =
          [1655797318.627209][7331:7331] CHIP:DMG:                         {
          [1655797318.627243][7331:7331] CHIP:DMG:                         },
          [1655797318.627274][7331:7331] CHIP:DMG:                 },
          [1655797318.627306][7331:7331] CHIP:DMG:
          [1655797318.627330][7331:7331] CHIP:DMG:         ],
          [1655797318.627359][7331:7331] CHIP:DMG:
          [1655797318.627383][7331:7331] CHIP:DMG:         InteractionModelRevision = 1
          [1655797318.627406][7331:7331] CHIP:DMG: },
          [1655797318.627467][7331:7331] CHIP:DMG: AccessControl: checking f=1 a=c s=0x000000000001B669 t= c=0x0000_0006 e=1 p=o
      disabled: true

    - label:
          "Step 2: DUT sends the Timed Request to the TH and then sends a
          WriteRequestMessage to the TH after receiving the status response
          message from the TH. The Timed Request Message should contain a
          timeout value in milliseconds. (Example - 200 milliseconds)"
      PICS: MCORE.IDM.C.WriteRequest
      verification: |
          Product maker needs to provide instructions for how to trigger the command on the DUT. For comparison, the DUT behavior for this test step can be simulated using chip-tool (when DUT is a commissioner/Client)

           ./chip-tool onoff write  on-time 2 1 1 --timedInteractionTimeoutMs 200


          On the TH(all-clusters-app) verify the received timed request message has the timeout value as sent by the DUT(chip-tool) and verify that the message is unicast.

          [1657459639.597900][11525:11525] CHIP:EM: Handling via exchange: 17116r, Delegate: 0xaaaae00c1430
          [1657459639.598014][11525:11525] CHIP:DMG: TimedRequestMessage =
          [1657459639.598055][11525:11525] CHIP:DMG: {
          [1657459639.598091][11525:11525] CHIP:DMG:      TimeoutMs = 0xc8,
          [1657459639.598147][11525:11525] CHIP:DMG:      InteractionModelRevision = 1
          [1657459639.598174][11525:11525] CHIP:DMG: }
          [1657459639.598204][11525:11525] CHIP:DMG: Got Timed Request with timeout 200: handler 0xaaab1651bac0 exchange 17116r
          [1657459639.598282][11525:11525] CHIP:EM: Piggybacking Ack for MessageCounter:161619532 on exchange: 17116r

          On the TH(all-clusters-app) Verify that the DUT(chip-tool) sends the WriteRequestMessage to the TH(all-clusters-app) before the specified timeout value and WriteRequestMessage has the TimedRequest field set to TRUE.
          [1657459639.599816][11525:11525] CHIP:IM: Received Write request
          [1657459639.599844][11525:11525] CHIP:DMG: IM WH moving to [Initialized]
          [1657459639.599908][11525:11525] CHIP:DMG: WriteRequestMessage =
          [1657459639.599942][11525:11525] CHIP:DMG: {
          [1657459639.599973][11525:11525] CHIP:DMG:      suppressResponse = false,
          [1657459639.600009][11525:11525] CHIP:DMG:      timedRequest = true,
          [1657459639.600041][11525:11525] CHIP:DMG:      AttributeDataIBs =
          [1657459639.600081][11525:11525] CHIP:DMG:      [
          [1657459639.600114][11525:11525] CHIP:DMG:              AttributeDataIB =
          [1657459639.600151][11525:11525] CHIP:DMG:              {
          [1657459639.600185][11525:11525] CHIP:DMG:                      AttributePathIB =
          [1657459639.600231][11525:11525] CHIP:DMG:                      {
          [1657459639.600273][11525:11525] CHIP:DMG:                              Endpoint = 0x1,
          [1657459639.600323][11525:11525] CHIP:DMG:                              Cluster = 0x6,
          [1657459639.600368][11525:11525] CHIP:DMG:                              Attribute = 0x0000_4001,
          [1657459639.600409][11525:11525] CHIP:DMG:                      }
          [1657459639.600452][11525:11525] CHIP:DMG:
          [1657459639.600497][11525:11525] CHIP:DMG:                      Data = 2,
          [1657459639.600535][11525:11525] CHIP:DMG:              },
          [1657459639.600578][11525:11525] CHIP:DMG:
          [1657459639.600610][11525:11525] CHIP:DMG:      ],
          [1657459639.600648][11525:11525] CHIP:DMG:
          [1657459639.600681][11525:11525] CHIP:DMG:      moreChunkedMessages = false,
          [1657459639.600715][11525:11525] CHIP:DMG:      InteractionModelRevision = 1
          [1657459639.600746][11525:11525] CHIP:DMG: },
          [1657459639.600842][11525:11525] CHIP:DMG: AccessControl: checking f=1 a=c s=0x000000000001B669 t= c=0x0000_0006 e=1 p=o
          [1657459639.600888][11525:11525] CHIP:DMG: AccessControl: allowed
          [1657459639.600936][11525:11525] CHIP:DMG: Endpoint 1, Cluster 0x0000_0006 update version to 1979c48
      disabled: true

    - label:
          "Step 3: DUT sends the Timed Request to the TH The Timed Request
          Message should contain a timeout value in milliseconds. (Example - 200
          milliseconds) Force the TH to not send a response back to the DUT for
          the received timed request."
      PICS: MCORE.IDM.C.WriteRequest || MCORE.IDM.C.InvokeRequest
      verification: |
          Mark this as not testable /NA. Out of Scope
      disabled: true
