-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YAML] Expose methods to start/stop/reboot the accessory used for tes…
…ting (#14240) * [Test Suites] Expose methods to start/stop/reboot the accessory used for testing * Add SystemCommands interface to src/app/tests/suites/commands/system * [chip-tool] Add TestSystemCommands.yaml * Update generated test code
- Loading branch information
1 parent
804b3ac
commit 3784453
Showing
16 changed files
with
617 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# | ||
# 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. | ||
|
||
import logging | ||
import time | ||
import threading | ||
import sys | ||
from random import randrange | ||
from xmlrpc.server import SimpleXMLRPCServer | ||
from xmlrpc.client import ServerProxy | ||
|
||
IP = '127.0.0.1' | ||
PORT = 9000 | ||
|
||
if sys.platform == 'linux': | ||
IP = '10.10.10.5' | ||
|
||
|
||
class AppsRegister: | ||
_instance = None | ||
__accessories = {} | ||
|
||
def init(self): | ||
self.__startXMLRPCServer() | ||
|
||
def uninit(self): | ||
self.__stopXMLRPCServer() | ||
|
||
def add(self, name, accessory): | ||
self.__accessories[name] = accessory | ||
|
||
def remove(self, name): | ||
self.__accessories.pop(name) | ||
|
||
def removeAll(self): | ||
self.__accessories = {} | ||
|
||
def poll(self): | ||
for accessory in self.__accessories.values(): | ||
status = accessory.poll() | ||
if status is not None: | ||
return status | ||
return None | ||
|
||
def kill(self, name): | ||
accessory = self.__accessories[name] | ||
if accessory: | ||
accessory.kill() | ||
|
||
def killAll(self): | ||
for accessory in self.__accessories.values(): | ||
accessory.kill() | ||
|
||
def start(self, name, discriminator): | ||
accessory = self.__accessories[name] | ||
if accessory: | ||
return accessory.start(discriminator) | ||
return False | ||
|
||
def stop(self, name): | ||
accessory = self.__accessories[name] | ||
if accessory: | ||
return accessory.stop() | ||
return False | ||
|
||
def reboot(self, name, discriminator): | ||
accessory = self.__accessories[name] | ||
if accessory: | ||
return accessory.stop() and accessory.start(discriminator) | ||
return False | ||
|
||
def ping(self): | ||
return True | ||
|
||
def __startXMLRPCServer(self): | ||
self.server = SimpleXMLRPCServer((IP, PORT)) | ||
|
||
self.server.register_function(self.start, 'start') | ||
self.server.register_function(self.stop, 'stop') | ||
self.server.register_function(self.reboot, 'reboot') | ||
self.server.register_function(self.ping, 'ping') | ||
|
||
self.server_thread = threading.Thread(target=self.__handle_request) | ||
self.server_thread.start() | ||
|
||
def __handle_request(self): | ||
self.__should_handle_requests = True | ||
while self.__should_handle_requests: | ||
self.server.handle_request() | ||
|
||
def __stopXMLRPCServer(self): | ||
self.__should_handle_requests = False | ||
# handle_request will wait until it receives a message, so let's send a ping to the server | ||
client = ServerProxy('http://' + IP + ':' + | ||
str(PORT) + '/', allow_none=True) | ||
client.ping() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) 2022 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. | ||
|
||
name: System Commands Tests | ||
|
||
config: | ||
cluster: "SystemCommands" | ||
endpoint: 0 | ||
|
||
tests: | ||
- label: "Wait for the commissioned device to be retrieved" | ||
cluster: "DelayCommands" | ||
command: "WaitForCommissionee" | ||
|
||
- label: "Stop the accessory" | ||
command: "Stop" | ||
|
||
- label: "Start the accessory with a given discriminator" | ||
command: "Start" | ||
arguments: | ||
values: | ||
- name: "discriminator" | ||
value: 1111 | ||
|
||
- label: "Reboot the accessory with an other given discriminator" | ||
command: "Reboot" | ||
arguments: | ||
values: | ||
- name: "discriminator" | ||
value: 2222 |
Oops, something went wrong.