Skip to content

Commit

Permalink
[CI] Add all supported test suites applications to the AppRegister (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored May 3, 2022
1 parent d5c4acc commit 3c17ca5
Show file tree
Hide file tree
Showing 23 changed files with 988 additions and 707 deletions.
10 changes: 5 additions & 5 deletions scripts/tests/chiptest/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def remove(self, name):
def removeAll(self):
self.__accessories = {}

def get(self, name):
return self.__accessories[name]

def kill(self, name):
accessory = self.__accessories[name]
if accessory:
Expand All @@ -73,13 +76,10 @@ def stop(self, name):
return accessory.stop()
return False

def reboot(self, name, args):
def reboot(self, name):
accessory = self.__accessories[name]
if accessory:
# The args param comes directly from the sys.argv[1:] of Reboot.py and should contain a list of strings in
# key-value pair, e.g. [option1, value1, option2, value2, ...]
options = self.__createCommandLineOptions(args)
return accessory.stop() and accessory.start(options)
return accessory.stop() and accessory.start()
return False

def factoryResetAll(self):
Expand Down
65 changes: 45 additions & 20 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ def __init__(self, runner, command):
self.runner = runner
self.command = command
self.cv_stopped = threading.Condition()
self.stopped = False
self.stopped = True
self.lastLogIndex = 0
self.kvs = '/tmp/chip_kvs'
self.kvsPathSet = {'/tmp/chip_kvs'}
self.options = None

def start(self, options=None):
if not self.process:
# Cache command line options to be used for reboots
if options:
self.options = options
# Make sure to assign self.process before we do any operations that
# might fail, so attempts to kill us on failure actually work.
self.process, self.outpipe, errpipe = self.__startServer(
self.runner, self.command, options)
self.runner, self.command)
self.waitForAnyAdvertisement()
self.__updateSetUpCode()
with self.cv_stopped:
Expand All @@ -67,8 +71,9 @@ def stop(self):
return False

def factoryReset(self):
if os.path.exists(self.kvs):
os.unlink(self.kvs)
for kvs in self.kvsPathSet:
if os.path.exists(kvs):
os.unlink(kvs)
return True

def waitForAnyAdvertisement(self):
Expand All @@ -90,6 +95,10 @@ def kill(self):

def wait(self, timeout=None):
while True:
# If the App was never started, wait cannot be called on the process
if self.process == None:
time.sleep(0.1)
continue
code = self.process.wait(timeout)
with self.cv_stopped:
if not self.stopped:
Expand All @@ -100,18 +109,18 @@ def wait(self, timeout=None):
while self.stopped:
self.cv_stopped.wait()

def __startServer(self, runner, command, options):
def __startServer(self, runner, command):
app_cmd = command + ['--interface-id', str(-1)]

if not options:
if not self.options:
logging.debug('Executing application under test with default args')
else:
logging.debug('Executing application under test with the following args:')
for key, value in options.items():
for key, value in self.options.items():
logging.debug(' %s: %s' % (key, value))
app_cmd = app_cmd + [key, value]
if key == '--KVS':
self.kvs = value
self.kvsPathSet.add(value)
return runner.RunSubprocess(app_cmd, name='APP ', wait=False)

def __waitFor(self, waitForString, server_process, outpipe):
Expand Down Expand Up @@ -154,6 +163,9 @@ class ApplicationPaths:
lock_app: typing.List[str]
tv_app: typing.List[str]

def items(self):
return [self.chip_tool, self.all_clusters_app, self.lock_app, self.tv_app]


@dataclass
class CaptureLine:
Expand Down Expand Up @@ -208,15 +220,34 @@ def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str):

try:
if self.target == TestTarget.ALL_CLUSTERS:
app_cmd = paths.all_clusters_app
target_app = paths.all_clusters_app
elif self.target == TestTarget.TV:
app_cmd = paths.tv_app
target_app = paths.tv_app
elif self.target == TestTarget.LOCK:
app_cmd = paths.lock_app
target_app = paths.lock_app
else:
raise Exception("Unknown test target - "
"don't know which application to run")

for path in paths.items():
# Do not add chip-tool to the register
if path == paths.chip_tool:
continue

# For the app indicated by self.target, give it the 'default' key to add to the register
if path == target_app:
key = 'default'
else:
key = os.path.basename(path[-1])

app = App(runner, path)
# Add the App to the register immediately, so if it fails during
# start() we will be able to clean things up properly.
apps_register.add(key, app)
# Remove server application storage (factory reset),
# so it will be commissionable again.
app.factoryReset()

tool_cmd = paths.chip_tool

files_to_unlink = [
Expand All @@ -230,19 +261,13 @@ def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str):
if os.path.exists(f):
os.unlink(f)

app = App(runner, app_cmd)
# Add the App to the register immediately, so if it fails during
# start() we will be able to clean things up properly.
apps_register.add("default", app)
# Remove server application storage (factory reset),
# so it will be commissionable again.
app.factoryReset()
# Only start and pair the default app
app = apps_register.get('default')
app.start()
pairing_cmd = tool_cmd + ['pairing', 'qrcode', TEST_NODE_ID, app.setupCode]
if sys.platform != 'darwin':
pairing_cmd.append('--paa-trust-store-path')
pairing_cmd.append(DEVELOPMENT_PAA_LIST)

runner.RunSubprocess(pairing_cmd,
name='PAIR', dependencies=[apps_register])

Expand Down
10 changes: 0 additions & 10 deletions src/app/tests/suites/TestArmFailSafe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@ name: ArmFailSafe Tests
config:
nodeId: 0x12344321
endpoint: 0
discriminator:
type: INT16U
defaultValue: 3840
payload:
type: CHAR_STRING
defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically

tests:
- label: "Reboot target device"
cluster: "SystemCommands"
command: "Reboot"
arguments:
values:
- name: "discriminator"
value: discriminator

- label: "Wait for the alpha device to be retrieved "
cluster: "DelayCommands"
Expand Down
20 changes: 16 additions & 4 deletions src/app/tests/suites/TestDiscovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ config:
defaultValue: 5

tests:
- label: "Reboot target device"
- label: "Stop target device"
cluster: "SystemCommands"
command: "Reboot"
command: "Stop"

- label:
"Start target device with the provided discriminator for basic
commissioning advertisement"
cluster: "SystemCommands"
command: "Start"
arguments:
values:
- name: "discriminator"
Expand Down Expand Up @@ -291,9 +297,15 @@ tests:
constraints:
minValue: 1

- label: "Reboot target device"
- label: "Stop target device"
cluster: "SystemCommands"
command: "Stop"

- label:
"Start target device with the provided discriminator for basic
commissioning advertisement"
cluster: "SystemCommands"
command: "Reboot"
command: "Start"
arguments:
values:
- name: "discriminator"
Expand Down
11 changes: 0 additions & 11 deletions src/app/tests/suites/TestModeSelectCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ config:
nodeId: 0x12344321
cluster: "Mode Select"
endpoint: 1
discriminator:
type: INT16U
defaultValue: 3840

tests:
- label: "Wait for the commissioned device to be retrieved"
Expand Down Expand Up @@ -190,10 +187,6 @@ tests:
- label: "Reboot target device"
cluster: "SystemCommands"
command: "Reboot"
arguments:
values:
- name: "discriminator"
value: discriminator

- label: "Wait for the commissioned device to be retrieved"
cluster: "DelayCommands"
Expand All @@ -220,10 +213,6 @@ tests:
- label: "Reboot target device"
cluster: "SystemCommands"
command: "Reboot"
arguments:
values:
- name: "discriminator"
value: discriminator

- label: "Wait for the commissioned device to be retrieved"
cluster: "DelayCommands"
Expand Down
10 changes: 8 additions & 2 deletions src/app/tests/suites/TestMultiAdmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ config:
defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically

tests:
- label: "Reboot target device"
- label: "Stop target device"
cluster: "SystemCommands"
command: "Reboot"
command: "Stop"

- label:
"Start target device with the provided discriminator for basic
commissioning advertisement"
cluster: "SystemCommands"
command: "Start"
arguments:
values:
- name: "discriminator"
Expand Down
Loading

0 comments on commit 3c17ca5

Please sign in to comment.