Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle [CI] Allow test suite applications to be launched with custom commandline options #17517

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions scripts/tests/chiptest/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ def killAll(self):
for accessory in self.__accessories.values():
accessory.kill()

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

def stop(self, name):
Expand All @@ -69,10 +72,13 @@ def stop(self, name):
return accessory.stop()
return False

def reboot(self, name, discriminator):
def reboot(self, name, args):
accessory = self.__accessories[name]
if accessory:
return accessory.stop() and accessory.start(discriminator)
# 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 False

def factoryResetAll(self):
Expand Down Expand Up @@ -116,3 +122,11 @@ def __startXMLRPCServer(self):

def __stopXMLRPCServer(self):
self.server.shutdown()

def __createCommandLineOptions(self, args):
# args should contain a list of strings in key-value pair, e.g. [option1, value1, option2, value2, ...]
options = {}
if (len(args) % 2) == 0:
# Create a dictionary from the key-value pair list
options = {args[i]: args[i+1] for i in range(0, len(args), 2)}
return options
35 changes: 15 additions & 20 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ def __init__(self, runner, command):
self.cv_stopped = threading.Condition()
self.stopped = False
self.lastLogIndex = 0
self.kvs = '/tmp/chip_kvs'

def start(self, discriminator):
def start(self, options):
if not self.process:
# 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, discriminator)
self.runner, self.command, options)
self.waitForAnyAdvertisement()
self.__updateSetUpCode()
with self.cv_stopped:
Expand All @@ -64,18 +65,9 @@ def stop(self):
return True
return False

def reboot(self, discriminator):
if self.process:
self.stop()
self.start(discriminator)
return True
return False

def factoryReset(self):
storage = '/tmp/chip_kvs'
if os.path.exists(storage):
os.unlink(storage)

if os.path.exists(self.kvs):
os.unlink(self.kvs)
return True

def waitForAnyAdvertisement(self):
Expand Down Expand Up @@ -107,12 +99,15 @@ def wait(self, timeout=None):
while self.stopped:
self.cv_stopped.wait()

def __startServer(self, runner, command, discriminator):
logging.debug(
'Executing application under test with discriminator %s.' %
discriminator)
app_cmd = command + ['--discriminator', str(discriminator)]
app_cmd = app_cmd + ['--interface-id', str(-1)]
def __startServer(self, runner, command, options):
app_cmd = command + ['--interface-id', str(-1)]

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

def __waitFor(self, waitForString, server_process, outpipe):
Expand Down Expand Up @@ -238,7 +233,7 @@ def Run(self, runner, apps_register, paths: ApplicationPaths, pics_file: str):
# Remove server application storage (factory reset),
# so it will be commissionable again.
app.factoryReset()
app.start(str(randrange(1, 4096)))
app.start({})

runner.RunSubprocess(
tool_cmd + ['pairing', 'qrcode', TEST_NODE_ID, app.setupCode] +
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/suites/commands/system/SystemCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CHIP_ERROR SystemCommands::Start(uint16_t discriminator)
constexpr const char * scriptName = "Start.py";

char command[128];
VerifyOrReturnError(snprintf(command, sizeof(command), "%s%s %u", scriptDir, scriptName, discriminator) >= 0,
VerifyOrReturnError(snprintf(command, sizeof(command), "%s%s --discriminator %u", scriptDir, scriptName, discriminator) >= 0,
CHIP_ERROR_INTERNAL);
return RunInternal(command);
}
Expand All @@ -53,7 +53,7 @@ CHIP_ERROR SystemCommands::Reboot(uint16_t discriminator)
constexpr const char * scriptName = "Reboot.py";

char command[128];
VerifyOrReturnError(snprintf(command, sizeof(command), "%s%s %u", scriptDir, scriptName, discriminator) >= 0,
VerifyOrReturnError(snprintf(command, sizeof(command), "%s%s --discriminator %u", scriptDir, scriptName, discriminator) >= 0,
CHIP_ERROR_INTERNAL);
return RunInternal(command);
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/tests/suites/commands/system/scripts/Reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
if sys.platform == 'linux':
IP = '10.10.10.5'

# Passing in sys.argv[1:] gets rid of the script name with the remaining values in the list as
# key-value pairs, e.g. [option1, value1, option2, value2, ...]
with xmlrpc.client.ServerProxy('http://' + IP + ':' + str(PORT) + '/', allow_none=True) as proxy:
proxy.reboot('default', sys.argv[1])
proxy.reboot('default', sys.argv[1:])
4 changes: 3 additions & 1 deletion src/app/tests/suites/commands/system/scripts/Start.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
if sys.platform == 'linux':
IP = '10.10.10.5'

# Passing in sys.argv[1:] gets rid of the script name with the remaining values in the list as
# key-value pairs, e.g. [option1, value1, option2, value2, ...]
with xmlrpc.client.ServerProxy('http://' + IP + ':' + str(PORT) + '/', allow_none=True) as proxy:
proxy.start('default', sys.argv[1])
proxy.start('default', sys.argv[1:])