From 24429627a930c6610f9f26fa5ea52575a144ad7b Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Sat, 11 Mar 2023 15:28:15 -0800 Subject: [PATCH] add kotlin IM read test and enable im test in CI (#25636) --- .github/workflows/tests.yaml | 48 +++++++++++ examples/java-matter-controller/BUILD.gn | 1 + .../java/src/com/matter/controller/Main.kt | 1 + .../commands/common/FutureResult.java | 2 +- .../PairOnNetworkLongImInvokeCommand.kt | 13 ++- .../pairing/PairOnNetworkLongImReadCommand.kt | 82 +++++++++++++++++++ .../PairOnNetworkLongImWriteCommand.kt | 9 +- 7 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5686eb04e38fc5..3caad23f17badf 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -601,6 +601,54 @@ jobs: --tool-args "onnetwork-long --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \ --factoryreset \ ' + - name: Run IM Invoke Test + timeout-minutes: 10 + run: | + scripts/run_in_build_env.sh \ + './scripts/tests/run_java_test.py \ + --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app \ + --app-args "--discriminator 3840 --interface-id -1" \ + --tool-path out/linux-x64-java-matter-controller \ + --tool-cluster "pairing" \ + --tool-args "onnetwork-long-im-invoke --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \ + --factoryreset \ + ' + - name: Run IM Read Test + timeout-minutes: 10 + run: | + scripts/run_in_build_env.sh \ + './scripts/tests/run_java_test.py \ + --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app \ + --app-args "--discriminator 3840 --interface-id -1" \ + --tool-path out/linux-x64-java-matter-controller \ + --tool-cluster "pairing" \ + --tool-args "onnetwork-long-im-read --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \ + --factoryreset \ + ' + - name: Run IM Write Test + timeout-minutes: 10 + run: | + scripts/run_in_build_env.sh \ + './scripts/tests/run_java_test.py \ + --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app \ + --app-args "--discriminator 3840 --interface-id -1" \ + --tool-path out/linux-x64-java-matter-controller \ + --tool-cluster "pairing" \ + --tool-args "onnetwork-long-im-write --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \ + --factoryreset \ + ' + - name: Run IM Subscribe Test + timeout-minutes: 10 + run: | + scripts/run_in_build_env.sh \ + './scripts/tests/run_java_test.py \ + --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app \ + --app-args "--discriminator 3840 --interface-id -1" \ + --tool-path out/linux-x64-java-matter-controller \ + --tool-cluster "pairing" \ + --tool-args "onnetwork-long-im-subscribe --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \ + --factoryreset \ + ' - name: Run Pairing AlreadyDiscovered Test timeout-minutes: 10 run: | diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index f48c17ff3c9519..d26b0340ab15b0 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -69,6 +69,7 @@ kotlin_binary("java-matter-controller") { "java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.kt", "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt", "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt", "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt", "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt", "java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.kt", diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt index b3604caf582186..051c2f02bfb8d0 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt @@ -62,6 +62,7 @@ private fun getImCommands( credentialsIssuer: CredentialsIssuer ): List { return listOf( + PairOnNetworkLongImReadCommand(controller, credentialsIssuer), PairOnNetworkLongImSubscribeCommand(controller, credentialsIssuer), PairOnNetworkLongImWriteCommand(controller, credentialsIssuer), PairOnNetworkLongImInvokeCommand(controller, credentialsIssuer), diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java index e501ec1afe81a4..188a0000db9141 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/FutureResult.java @@ -57,7 +57,7 @@ public synchronized void waitResult() { } } if (!realResult.get().getResult()) { - logger.log(Level.INFO, "error: %s", realResult.get().getError()); + logger.log(Level.INFO, "error: " + realResult.get().getError()); throw new RuntimeException("received failure test result"); } } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt index a3cfd72d94d1af..7eb38a0d4f950a 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt @@ -24,6 +24,10 @@ import chip.devicecontroller.model.InvokeElement import com.matter.controller.commands.common.CredentialsIssuer import java.util.logging.Level import java.util.logging.Logger +import kotlin.UShort +import chip.tlv.AnonymousTag +import chip.tlv.ContextSpecificTag +import chip.tlv.TlvWriter class PairOnNetworkLongImInvokeCommand( controller: ChipDeviceController, credsIssue: CredentialsIssuer? @@ -68,11 +72,14 @@ class PairOnNetworkLongImInvokeCommand( } override fun runCommand() { - // tlv structure with tag 0, unsigned integer 1 inside, {0: 1} - val intTLV = byteArrayOf(0x15, 0x24, 0x00, 0x01, 0x18) + val number : UShort = 1u + val tlvWriter = TlvWriter() + tlvWriter.startStructure(AnonymousTag) + tlvWriter.put(ContextSpecificTag(0), number) + tlvWriter.endStructure() val element: InvokeElement = InvokeElement.newInstance( /* endpointId= */ - 0L, CLUSTER_ID_IDENTIFY, IDENTIFY_COMMAND, intTLV, null + 0L, CLUSTER_ID_IDENTIFY, IDENTIFY_COMMAND, tlvWriter.getEncoded(), null ) currentCommissioner() diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt new file mode 100644 index 00000000000000..218c1ac5230259 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImReadCommand.kt @@ -0,0 +1,82 @@ +package com.matter.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback +import chip.devicecontroller.ReportCallback +import chip.devicecontroller.model.NodeState +import chip.devicecontroller.model.ChipAttributePath +import chip.devicecontroller.model.ChipEventPath +import com.matter.controller.commands.common.CredentialsIssuer +import java.util.Collections +import java.util.logging.Level +import java.util.logging.Logger + +class PairOnNetworkLongImReadCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-long-im-read", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.LONG_DISCRIMINATOR +) { + private var devicePointer: Long = 0 + + private inner class InternalReportCallback : ReportCallback { + override fun onError(attributePath: ChipAttributePath?, eventPath: ChipEventPath?, e: Exception) { + logger.log(Level.INFO, "Read receive onError") + setFailure("read failure") + } + + override fun onReport(nodeState: NodeState) { + logger.log(Level.INFO, "Read receve onReport") + setSuccess() + } + + } + + private inner class InternalGetConnectedDeviceCallback : GetConnectedDeviceCallback { + override fun onDeviceConnected(devicePointer: Long) { + this@PairOnNetworkLongImReadCommand.devicePointer = devicePointer + logger.log(Level.INFO, "onDeviceConnected") + } + + override fun onConnectionFailure(nodeId: Long, error: Exception?) { + logger.log(Level.INFO, "onConnectionFailure") + } + } + + override fun runCommand() { + val attributePathList = listOf(ChipAttributePath.newInstance( + /* endpointId= */ 0, CLUSTER_ID_BASIC, ATTR_ID_LOCAL_CONFIG_DISABLED)) + + currentCommissioner() + .pairDeviceWithAddress( + getNodeId(), + getRemoteAddr().getHostAddress(), + MATTER_PORT, + getDiscriminator(), + getSetupPINCode(), + null + ) + currentCommissioner().setCompletionListener(this) + waitCompleteMs(getTimeoutMillis()) + currentCommissioner() + .getConnectedDevicePointer(getNodeId(), InternalGetConnectedDeviceCallback()) + clear() + currentCommissioner() + .readPath(InternalReportCallback(), devicePointer, attributePathList, Collections.emptyList(), false) + waitCompleteMs(getTimeoutMillis()) + } + + companion object { + private val logger = Logger.getLogger( + PairOnNetworkLongImReadCommand::class.java.name + ) + + private const val MATTER_PORT = 5540 + private const val CLUSTER_ID_BASIC = 0x0028L + private const val ATTR_ID_LOCAL_CONFIG_DISABLED = 16L + } +} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt index 16c9d0b95a2d0b..97771c1f7c2dff 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt @@ -25,6 +25,9 @@ import chip.devicecontroller.model.ChipAttributePath import com.matter.controller.commands.common.CredentialsIssuer import java.util.logging.Level import java.util.logging.Logger +import chip.tlv.AnonymousTag +import chip.tlv.ContextSpecificTag +import chip.tlv.TlvWriter class PairOnNetworkLongImWriteCommand( controller: ChipDeviceController, credsIssue: CredentialsIssuer? @@ -68,14 +71,14 @@ class PairOnNetworkLongImWriteCommand( } override fun runCommand() { - // boolean true for tlv - val booleanTLV = byteArrayOf(0x09) + val tlvWriter = TlvWriter() + tlvWriter.put(AnonymousTag, true) val attributeList = listOf( AttributeWriteRequest.newInstance( /* endpointId= */ 0, CLUSTER_ID_BASIC, ATTR_ID_LOCAL_CONFIG_DISABLED, - booleanTLV, + tlvWriter.getEncoded(), ) )