Skip to content

Commit

Permalink
[CI] Allow test suite applications to be launched with custom command…
Browse files Browse the repository at this point in the history
… line options
  • Loading branch information
carol-apple committed Apr 19, 2022
1 parent 8793870 commit 517c061
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
24 changes: 20 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:] Start.py and should contain a list of strings in
# key-value pair, e.g. [option1, value1, option2, value2, ...]
commandLineOptions = self.__createCommandLineOptions(args)
return accessory.start(commandLineOptions)
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:] Reboot.py and should contain a list of strings in
# key-value pair, e.g. [option1, value1, option2, value2, ...]
commandLineOptions = self.__createCommandLineOptions(args)
return accessory.stop() and accessory.start(commandLineOptions)
return False

def factoryResetAll(self):
Expand Down Expand Up @@ -116,3 +122,13 @@ 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, ...]
commandLineOptions = {}
i = 0
while (i + 1) < len(args):
commandLineOptions[args[i]] = args[i + 1]
i += 2

return commandLineOptions
35 changes: 16 additions & 19 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def __init__(self, runner, command):
self.stopped = False
self.lastLogIndex = 0

def start(self, discriminator):
def start(self, commandLineArgs):
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, commandLineArgs)
self.waitForAnyAdvertisement()
self.__updateSetUpCode()
with self.cv_stopped:
Expand All @@ -64,17 +64,11 @@ 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)
tempFiles = os.listdir("/tmp")
for file in tempFiles:
if not os.path.isdir(file) and "chip_kvs" in file:
os.unlink("/tmp/" + file)

return True

Expand Down Expand Up @@ -107,12 +101,13 @@ 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, commandLineOptions):
app_cmd = command + ['--interface-id', str(-1)]

logging.debug('Executing application under test with the following args:')
for option, value in commandLineOptions.items():
logging.debug(' %s: %s' % (option, value))
app_cmd = app_cmd + [option, value]
return runner.RunSubprocess(app_cmd, name='APP ', wait=False)

def __waitFor(self, waitForString, server_process, outpipe):
Expand Down Expand Up @@ -238,7 +233,9 @@ 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)))
# Create dictionary for command line options for starting the App
commandLineOptions = {"--discriminator": str(randrange(1, 4096))}
app.start(commandLineOptions)

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:])

0 comments on commit 517c061

Please sign in to comment.