Skip to content

Commit

Permalink
Fix Java CI (#25644)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Nov 15, 2023
1 parent b50d277 commit 3b9e0e2
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ jobs:
--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-cluster "im" \
--tool-args "onnetwork-long-im-invoke --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--factoryreset \
'
Expand All @@ -621,7 +621,7 @@ jobs:
--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-cluster "im" \
--tool-args "onnetwork-long-im-read --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--factoryreset \
'
Expand All @@ -633,7 +633,7 @@ jobs:
--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-cluster "im" \
--tool-args "onnetwork-long-im-write --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--factoryreset \
'
Expand All @@ -645,7 +645,7 @@ jobs:
--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-cluster "im" \
--tool-args "onnetwork-long-im-subscribe --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--factoryreset \
'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ JNI_METHOD(jboolean, contentLauncher_1subscribeToSupportedStreamingProtocols)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ContentLauncher_SupportedStreamingProtocols).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) {
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ContentLauncher_SupportedStreamingProtocols).Handle();
});

Expand Down Expand Up @@ -584,7 +584,9 @@ JNI_METHOD(jboolean, levelControl_1subscribeToCurrentLevel)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_CurrentLevel).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_CurrentLevel).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_CurrentLevel).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -628,7 +630,9 @@ JNI_METHOD(jboolean, levelControl_1subscribeToMinLevel)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_MinLevel).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MinLevel).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MinLevel).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -672,7 +676,9 @@ JNI_METHOD(jboolean, levelControl_1subscribeToMaxLevel)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_MaxLevel).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MaxLevel).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MaxLevel).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1054,7 +1060,9 @@ JNI_METHOD(jboolean, mediaPlayback_1subscribeToCurrentState)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_CurrentState).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_CurrentState).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_CurrentState).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1099,7 +1107,9 @@ JNI_METHOD(jboolean, mediaPlayback_1subscribeToDuration)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_Duration).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_Duration).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_Duration).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1146,7 +1156,9 @@ JNI_METHOD(jboolean, mediaPlayback_1subscribeToSampledPosition)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SampledPosition).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SampledPosition).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SampledPosition).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1192,7 +1204,9 @@ JNI_METHOD(jboolean, mediaPlayback_1subscribeToPlaybackSpeed)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_PlaybackSpeed).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_PlaybackSpeed).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_PlaybackSpeed).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1238,7 +1252,9 @@ JNI_METHOD(jboolean, mediaPlayback_1subscribeToSeekRangeEnd)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SeekRangeEnd).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeEnd).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeEnd).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1285,7 +1301,9 @@ JNI_METHOD(jboolean, mediaPlayback_1subscribeToSeekRangeStart)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SeekRangeStart).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeStart).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeStart).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1467,7 +1485,9 @@ JNI_METHOD(jboolean, targetNavigator_1subscribeToCurrentTarget)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(TargetNavigator_CurrentTarget).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(TargetNavigator_CurrentTarget).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(TargetNavigator_CurrentTarget).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1513,7 +1533,9 @@ JNI_METHOD(jboolean, targetNavigator_1subscribeToTargetList)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(TargetNavigator_TargetList).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(TargetNavigator_TargetList).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(TargetNavigator_TargetList).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1587,7 +1609,9 @@ JNI_METHOD(jboolean, applicationBasic_1subscribeToVendorName)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_VendorName).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_VendorName).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_VendorName).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1633,7 +1657,9 @@ JNI_METHOD(jboolean, applicationBasic_1subscribeToVendorID)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_VendorID).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_VendorID).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_VendorID).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1680,7 +1706,9 @@ JNI_METHOD(jboolean, applicationBasic_1subscribeToApplicationName)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_ApplicationName).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_ApplicationName).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_ApplicationName).Handle();
});

VerifyOrExit(CHIP_NO_ERROR == err,
ChipLogError(AppServer, "CastingServer.applicationBasic_subscribeToApplicationName failed %" CHIP_ERROR_FORMAT,
Expand Down Expand Up @@ -1726,7 +1754,9 @@ JNI_METHOD(jboolean, applicationBasic_1subscribeToProductID)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_ProductID).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) { TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_ProductID).Handle(); });
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_ProductID).Handle();
});

VerifyOrExit(
CHIP_NO_ERROR == err,
Expand Down Expand Up @@ -1774,7 +1804,7 @@ JNI_METHOD(jboolean, applicationBasic_1subscribeToApplicationVersion)
TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_ApplicationVersion).Handle(err);
},
static_cast<uint16_t>(minInterval), static_cast<uint16_t>(maxInterval),
[](void * context) {
[](void * context, chip::SubscriptionId) {
TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_ApplicationVersion).Handle();
});

Expand Down
120 changes: 120 additions & 0 deletions scripts/tests/java/im_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env python3

#
# Copyright (c) 2022 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.
#

import argparse
import logging
import queue
import subprocess
import threading
import typing

from colorama import Fore, Style
from java.base import DumpProgramOutputToQueue


class IMTest:
def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queue, cmd: [], args: str):
self.thread_list = thread_list
self.queue = queue
self.command = cmd

parser = argparse.ArgumentParser(description='Process pairing arguments.')

parser.add_argument('command', help="Command name")
parser.add_argument('-t', '--timeout', help="The program will return with timeout after specified seconds", default='200')
parser.add_argument('-a', '--address', help="Address of the device")
parser.add_argument('-p', '--port', help="Port of the remote device", default='5540')
parser.add_argument('-s', '--setup-payload', dest='setup_payload',
help="Setup Payload (manual pairing code or QR code content)")
parser.add_argument('-c', '--setup-pin-code', dest='setup_pin_code',
help=("Setup PIN code which can be used for password-authenticated "
"session establishment (PASE) with the Commissionee"))
parser.add_argument('-n', '--nodeid', help="The Node ID issued to the device", default='1')
parser.add_argument('-d', '--discriminator', help="Discriminator of the device", default='3840')
parser.add_argument('-u', '--paa-trust-store-path', dest='paa_trust_store_path',
help="Path that contains valid and trusted PAA Root Certificates")

args = parser.parse_args(args.split())

self.command_name = args.command
self.nodeid = args.nodeid
self.address = args.address
self.port = args.port
self.setup_payload = args.setup_payload
self.setup_pin_code = args.setup_pin_code
self.discriminator = args.discriminator
self.timeout = args.timeout

logging.basicConfig(level=logging.INFO)

def TestCmdOnnetworkLongImInvoke(self, nodeid, setuppin, discriminator, timeout):
java_command = self.command + ['im', 'onnetwork-long-im-invoke', nodeid, setuppin, discriminator, timeout]
logging.info(f"Execute: {java_command}")
java_process = subprocess.Popen(
java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
return java_process.wait()

def TestCmdOnnetworkLongImWrite(self, nodeid, setuppin, discriminator, timeout):
java_command = self.command + ['im', 'onnetwork-long-im-write', nodeid, setuppin, discriminator, timeout]
logging.info(f"Execute: {java_command}")
java_process = subprocess.Popen(
java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
return java_process.wait()

def TestCmdOnnetworkLongImRead(self, nodeid, setuppin, discriminator, timeout):
java_command = self.command + ['im', 'onnetwork-long-im-read', nodeid, setuppin, discriminator, timeout]
logging.info(f"Execute: {java_command}")
java_process = subprocess.Popen(
java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
return java_process.wait()

def TestCmdOnnetworkLongImSubscribe(self, nodeid, setuppin, discriminator, timeout):
java_command = self.command + ['im', 'onnetwork-long-im-subscribe', nodeid, setuppin, discriminator, timeout]
logging.info(f"Execute: {java_command}")
java_process = subprocess.Popen(
java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
return java_process.wait()

def RunTest(self):
if self.command_name == 'onnetwork-long-im-invoke':
logging.info("Testing pairing onnetwork-long-im-invoke")
code = self.TestCmdOnnetworkLongImInvoke(self.nodeid, self.setup_pin_code, self.discriminator, self.timeout)
if code != 0:
raise Exception(f"Testing pairing onnetwork-long-im-invoke failed with error {code}")
elif self.command_name == 'onnetwork-long-im-write':
logging.info("Testing pairing onnetwork-long-im-write")
code = self.TestCmdOnnetworkLongImWrite(self.nodeid, self.setup_pin_code, self.discriminator, self.timeout)
if code != 0:
raise Exception(f"Testing pairing onnetwork-long-im-write failed with error {code}")
elif self.command_name == 'onnetwork-long-im-read':
logging.info("Testing pairing onnetwork-long-im-read")
code = self.TestCmdOnnetworkLongImRead(self.nodeid, self.setup_pin_code, self.discriminator, self.timeout)
if code != 0:
raise Exception(f"Testing pairing onnetwork-long-im-read failed with error {code}")
elif self.command_name == 'onnetwork-long-im-subscribe':
logging.info("Testing pairing onnetwork-long-im-subscribe")
code = self.TestCmdOnnetworkLongImSubscribe(self.nodeid, self.setup_pin_code, self.discriminator, self.timeout)
if code != 0:
raise Exception(f"Testing pairing onnetwork-long-im-subscribe failed with error {code}")
else:
raise Exception(f"Unsupported command {self.command_name}")
10 changes: 10 additions & 0 deletions scripts/tests/run_java_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from java.base import DumpProgramOutputToQueue
from java.commissioning_test import CommissioningTest
from java.discover_test import DiscoverTest
from java.im_test import IMTest


@click.command()
Expand Down Expand Up @@ -107,6 +108,15 @@ def main(app: str, app_args: str, tool_path: str, tool_cluster: str, tool_args:
except Exception as e:
logging.error(e)
sys.exit(1)
elif tool_cluster == 'im':
logging.info("Testing IM")

test = IMTest(log_cooking_threads, log_queue, command, tool_args)
try:
test.RunTest()
except Exception as e:
logging.error(e)
sys.exit(1)

app_exit_code = 0
if app_process:
Expand Down

0 comments on commit 3b9e0e2

Please sign in to comment.