Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
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
38 changes: 12 additions & 26 deletions tools/clientSimulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ configuration functional tests.

## How to run tests

You can run tests using pfClientSimulator.py.
You can run tests using pfClientSimulator.py. `test-platform` and
`remote-process` need to be in the PATH (e.g. by installing the Parameter
Framework - see the main README file).

You have to run the script with at least the test directory argument:

Expand Down Expand Up @@ -71,41 +73,32 @@ to learn what it is about.

A test directory should contains a `conf.json` file containing:

- The desired command prefix (optional; e.g. `adb shell` in order to execute
tests on an android board or empty to execute locally).
- The desired command prefix (e.g. `adb shell` in order to execute tests on an
android board or empty to execute locally).
- The port on which the test-platform should be started.
- The criterion file path (see
[this README](https://github.com/01org/parameter-framework/tree/master/tools/xmlGenerator#domaingeneratorpy)).
- The absolute path to the Parameter Framework toplevel configuration file.
- The path to the Parameter Framework toplevel configuration file.
- The path to the directory containing the scenario files.
- The path to the scripts definitions file (optional) (see below).
- The path to the actions definitions (aka "ActionGatherer") file (optional)
(see below).
- The absolute path to the log output file (optional).
- A setup script (inline shell) (optional).
- The absolute paths to test-platform and remote-process executables (or the
executables' names if they are in the PATH).
- The host and port on which the test-platform and the Parameter Framework
instance are listening for commands.
- The absolute path to the directory containing the coverage generation tool
- The path to the log output file (optional but needed for coverage).
- The path to the directory containing the coverage generation tool
(optional; for coverage only).
- The path to the html coverage output file (optional; for coverage only).
- The path to the Parameter Framework domain configuration file (optional; for
coverage only).

All these *must* be defined in `conf.json`; when marked "optional", it means
that they *may be empty but still need to be defined*.

Unless otherwise noted, paths in `conf.json` should be relative and will be
evaluated *relative to the test directory*. When we mention absolute path, you
may still fill a relative path but it will be evaluated *relative to the
working directory*.

Relative paths in `conf.json` will be evaluated *relative to the test
directory*.

## Example Client Simulator configuration file

```{.json}
{
"PrefixCommand" : "adb shell",
"TestPlatformPort" : "5001",

"CriterionFile" : "MyCriteria.txt",
"PfwConfFile" : "/home/user/tests/TopLevel.xml",
Expand All @@ -116,13 +109,6 @@ working directory*.

"LogFile" : "tests.log",

"SetupScript" : "echo 'bouh'",

"TestPlatformCommand" : "test-platform",
"RemoteProcessCommand" : "remote-process",
"TestPlatformHost" : "localhost 5001",
"ParameterFramworkHost" : "localhost 5000",

"CoverageDir" : "/home/user/parameter-framework/tools/coverage",
"CoverageFile" : "coverage.html",
"PfwDomainConfFile" : "MyConfigurableDomains.xml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@ def __init__(self, confFileName, testsDirectory, consoleLogger):
with open(confFileName, "r") as testFile:
self.__conf = json.load(testFile)

# Preparing files and directory paths
# Preparing mandatory files and directory paths
for key in ["CriterionFile",
"ScriptsFile",
"SetupScript",
"PfwConfFile",
"ScenariosDirectory"]:
self.__conf[key] = os.path.join(testsDirectory, self.__conf[key])

# Preparing optional files and directory paths
for key in ["ScriptsFile",
"ActionGathererFile",
"ScenariosDirectory",
"LogFile",
"CoverageFile",
"CoverageDir",
"PfwDomainConfFile"]:
self.__conf[key] = os.path.join(testsDirectory, self.__conf[key])
try:
self.__conf[key] = os.path.join(testsDirectory, self.__conf[key])
except KeyError as e:
self.__conf[key] = ""

self.__logger = logging.getLogger(__name__)
self.__logger.addHandler(consoleLogger)
Expand Down
46 changes: 24 additions & 22 deletions tools/clientSimulator/clientsimulator/scenario/Scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import json
import logging
import os


class Scenario:
Expand Down Expand Up @@ -100,37 +99,40 @@ def __parseScenarioActions(self, scenarioFileName, actionGathererFileName):

# Parsing the action Gatherer file which allows defining new
# actions types
with open(actionGathererFileName, "r") as actionGathererFile:
scenarioGatheredActions = json.load(actionGathererFile)
scenarioGatheredActions = {}
if actionGathererFileName:
with open(actionGathererFileName, "r") as actionGathererFile:
scenarioGatheredActions = json.load(actionGathererFile)

for action in scenarioActions:
actionDefinedType = self.__getActionType(action)
if actionDefinedType in self.__actionTypeBehaviour.keys():
continue

try:
actionDefinedType = self.__getActionType(action)
if actionDefinedType not in self.__actionTypeBehaviour.keys():
actionValue = action.pop(actionDefinedType)
actionGatherer = scenarioGatheredActions[actionDefinedType]

if self.__getActionType(actionGatherer) == "script":
raise UngatherableTypeException(
"Unable to redefine {} type, please edit your {} file".format(
self.__getActionType(actionGatherer),
actionGathererFileName))

# Fusion of gathered Actions and other desired actions which
# are directly writed in the scenario's file
actionValue.update(
self.__getActionValue(actionGatherer))

# Change the user defined key which was previously popped
# by the known one
action[self.__getActionType(actionGatherer)] = actionValue
actionValue = action.pop(actionDefinedType)
actionGatherer = scenarioGatheredActions[actionDefinedType]
except KeyError as e:
self.__logger.error(
"Actions {} from {} file is not valid".format(
actionDefinedType,
scenarioFileName))
raise e

if self.__getActionType(actionGatherer) == "script":
raise UngatherableTypeException(
"Unable to redefine {} type, please edit your {} file".format(
self.__getActionType(actionGatherer),
actionGathererFileName))

# Fusion of gathered Actions and other desired actions which
# are directly writed in the scenario's file
actionValue.update(self.__getActionValue(actionGatherer))

# Change the user defined key which was previously popped
# by the known one
action[self.__getActionType(actionGatherer)] = actionValue

return scenarioActions

def __getActionType(self, action):
Expand Down
35 changes: 17 additions & 18 deletions tools/clientSimulator/clientsimulator/testGenerator/TestLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,21 @@ def __init__(self,
self.__configParser = configParser

# Prepare basic commands
halCommand = [configParser["RemoteProcessCommand"],
configParser["TestPlatformHost"]]
halCommand = ["remote-process",
"localhost",
configParser["TestPlatformPort"]]
setCriteriaCommand = halCommand + ["setCriterionState"]
testPlatformHostCommand = [configParser["RemoteProcessCommand"],
configParser["TestPlatformHost"]]
testPlatformHostCommand = ["remote-process",
"localhost",
configParser["TestPlatformPort"]]

self.__logFileName = configParser["LogFile"]

# Commands
self.__startTestPlatformCmd = [configParser["PrefixCommand"],
configParser["TestPlatformCommand"],
configParser["PfwConfFile"]]
"test-platform",
configParser["PfwConfFile"],
configParser["TestPlatformPort"]]

self.__createCriterionCmd = [configParser["PrefixCommand"]]
self.__createCriterionCmd.extend(testPlatformHostCommand)
Expand All @@ -85,12 +88,10 @@ def __init__(self,
self.__applyConfigurationsCmd.extend(halCommand)
self.__applyConfigurationsCmd.append("applyConfigurations")

self.__setupScript = [configParser["SetupScript"]]

# Command used to generate coverage
self.__coverageCmd = [
"eval",
configParser["CoverageDir"] + "/aplog2coverage.sh",
os.path.join(configParser["CoverageDir"], "aplog2coverage.sh"),
"-d",
configParser["PfwDomainConfFile"],
"-e.",
Expand All @@ -102,8 +103,10 @@ def __init__(self,

# Prepare script Commands
# Loading possible scripts
with open(configParser["ScriptsFile"], 'r') as scriptFile:
self.__rawScripts = json.load(scriptFile)
self.__rawScripts = {}
if configParser["ScriptsFile"]:
with open(configParser["ScriptsFile"], 'r') as scriptFile:
self.__rawScripts = json.load(scriptFile)

self.__availableLaunchType = ["asynchronous", "synchronous"]

Expand All @@ -118,11 +121,6 @@ def scripts(self):
def init(self, criterionClasses, isVerbose):
""" Initialise the Pseudo HAL """

# Use user script to setup environment as requested before to do
# anything
self.__logger.info("Launching Setup script")
self.__call_process(self.__setupScript)

self.__logger.info("Pseudo Hal Initialisation")
# Test platform is launched asynchronously and not as script
self.__call_process(self.__startTestPlatformCmd, True)
Expand Down Expand Up @@ -175,9 +173,10 @@ def executeScript(self, scriptName):
launchType = self.__availableLaunchType[0]

# Create and launch the command to use the desired script
# A script's path is absolute or relative to the "ScriptsFile" file.
self.__call_process(
["eval", "{}/{}".format(
os.path.split(self.__configParser["ScriptsFile"])[0],
["eval", os.path.join(
os.path.dirname(self.__configParser["ScriptsFile"]),
script)],
launchType == self.__availableLaunchType[0],
True)
Expand Down
66 changes: 0 additions & 66 deletions tools/clientSimulator/clientsimulator/testGenerator/TestVector.py

This file was deleted.

Loading