From ff069e5e7e41c03fe22a6050a9b5eec291627c83 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Wed, 16 Dec 2015 14:25:44 +0100 Subject: [PATCH 1/7] Remove deprecated hostDomainGenerator.sh and portAllocator.py hostDomainGenerator.sh isn't maintained and we don't know of anyone using it. portAllocator.py is only use by hostDomainGenerator.sh and can be removed too. Signed-off-by: David Wagner --- tools/xmlGenerator/CMakeLists.txt | 4 +- tools/xmlGenerator/README.md | 12 - tools/xmlGenerator/hostDomainGenerator.sh | 308 ---------------------- tools/xmlGenerator/portAllocator.py | 48 ---- 4 files changed, 1 insertion(+), 371 deletions(-) delete mode 100755 tools/xmlGenerator/hostDomainGenerator.sh delete mode 100755 tools/xmlGenerator/portAllocator.py diff --git a/tools/xmlGenerator/CMakeLists.txt b/tools/xmlGenerator/CMakeLists.txt index 5dba83512..b6b274909 100644 --- a/tools/xmlGenerator/CMakeLists.txt +++ b/tools/xmlGenerator/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2014, Intel Corporation +# Copyright (c) 2014-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -30,11 +30,9 @@ install(PROGRAMS domainGenerator.sh domainGenerator.py hostConfig.py - hostDomainGenerator.sh lightRoutingUpdate.sh PfwBaseTranslator.py EddParser.py PFWScriptGenerator.py - portAllocator.py updateRoutageDomains.sh DESTINATION bin) diff --git a/tools/xmlGenerator/README.md b/tools/xmlGenerator/README.md index d7d881224..42e2fd92f 100644 --- a/tools/xmlGenerator/README.md +++ b/tools/xmlGenerator/README.md @@ -246,17 +246,5 @@ InclusiveCriterion Criterion2Name : Criterion2Value1 Criterion2Value2 I.e. One criterion by line, starting by its kind, then its name, followed by a semicolon and then all possible values separated by spaces. -### hostDomainGenerator.sh - -**This script is now deprecated and replaced by domainGenerator.py -(see above).** - -It prints the resulting XML on the standard output. Its syntax is: - - hostDomainGenerator.sh [--validate] - -See domainGenerator.py above for the explanation of the arguments. - - #### How it works TODO diff --git a/tools/xmlGenerator/hostDomainGenerator.sh b/tools/xmlGenerator/hostDomainGenerator.sh deleted file mode 100755 index 5267eff38..000000000 --- a/tools/xmlGenerator/hostDomainGenerator.sh +++ /dev/null @@ -1,308 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2011-2014, Intel Corporation -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation and/or -# other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -set -ueo pipefail - -# In order to dispatch log properly 4 output streams are available: -# - 1 info -# - 2 error -# - 3 (reserved) -# - 4 standard -# - 5 warning - -# Leave standard output unmodified -exec 4>&1 -# If the nonverbose long option is provided, do not output info log lines prefixed on stderr. -if test "$1" == --nonverbose -then - shift - exec 1>/dev/null -else - exec 1> >(sed "s/^/($$) Info: /" >&2) -fi -# Prefix all warning and error log lines and redirect them to stderr -exec 5> >(sed "s/^/($$) Warning: /" >&2) -exec 2> >(sed "s/^/($$) Error: /" >&2) - -# Get script arguments -validationEnabled="false" -if [ "$1" = "--validate" ]; then - validationEnabled="true" - shift -fi -PFWconfigurationFilePath="$1"; shift -CriterionFilePath="$1"; shift -xmlDomainFilePath="$1"; shift - -# Set constant variables -testPlatform="test-platform_host" -remoteProcess="remote-process_host" - -hostConfig="hostConfig.py" -PFWScriptGenerator="PFWScriptGenerator.py" -portAllocator="portAllocator.py" - -TPHost=127.0.0.1 -PFWHost=127.0.0.1 -TPCreated=false - -HostRoot="$ANDROID_HOST_OUT" -TargetRoot="$ANDROID_PRODUCT_OUT/system" - -# Global variables -TPSocket=5003 -PFWSocket=5000 -PFWStartTimeout=60 - -tmpDir=$(mktemp -d) -tmpFile=$(mktemp --tmpdir="$tmpDir") - -# [Workaround] -# The build system does not preserve execution right in external prebuild -for file in "$testPlatform" "$remoteProcess" "$hostConfig" "$PFWScriptGenerator" "$portAllocator" -do - chmod +x "${HostRoot}/bin/${file}" -done - -# Set environment paths -export LD_LIBRARY_PATH="$HostRoot/lib:${LD_LIBRARY_PATH:-}" - -# Setup clean trap, it will be called automatically on exit -clean_up () { - status=$? - set +e # An error should not abort clean up - - # Exit the test-platform only if it was created by this process - if $TPCreated - then - echo "Exiting test-platform listening on port $TPSocket" - $remoteProcess $TPHost $TPSocket exit - fi - - echo "Cleaning $tmpFile ..." - rm "$tmpFile" || true - - if [ "$validationEnabled" = "true" ]; then - echo "Cleaning $tmpDir/schemas ..." - rm -r "$tmpDir/schemas" || true - rmdir "$tmpDir" || true - fi - - echo "Cleaning status: $status ..." - return $status -} - -trap clean_up SIGHUP SIGINT SIGTERM EXIT - -# Create a symlink link to rename a library. -# Eg: /lib/ contains the lib mylib_host.so but it must be found under the name -# mylib.so. linkLibrary mylib_host.so mylib.so will create a symlink in mylib_host.so's folder -# called mylib.so, pointing to mylib_host.so -linkLibrary () { - local src="$1" - local dest="$2" - local path=$(find $HostRoot/lib -name "$src") - - # Check that both names are different, otherwise there is an error - if ! test "$(basename "$path")" != "$dest" - then - echo "Cannot link $dest to $src !" - return 1 - fi - - # Check that destination file does not already exist - if ! test -f "$(dirname "$path")/$dest" - then - # Create the symlink. Do not force if it has been created after the previous - # test, in this case simply ignore the error - ln -s "$src" "$(dirname "$path")/$dest" || true - fi - return 0 -} - -# The retry function will execute the provided command nbRety times util success. -# It also sleep sleepTime second between each retry. -retry() { - local command=$1 - local nbRetry=$2 - local sleepTime=$3 - local retry=0 - while ! $command 2>/dev/null >&2 - do - (($retry < $nbRetry)) || return 1 - retry=$(($retry + 1)) - sleep $sleepTime - done - return 0; -} - -# Configure the PFW main config file for simulation -formatConfigFile () { - "$hostConfig" $PFWSocket "$(readlink -f "$(dirname "$1")")" <"$1" -} - -# The initTestPlatform starts a testPlatform instance with the config file given in argument. -# It will also set the PFWSocket global variable to the PFW remote processor listening socket. -initTestPlatform () { - # Format the PFW config file - formatConfigFile "$1" >"$tmpFile" - - # Start test platform - echo "Starting test-platform on port $TPSocket ..." - $testPlatform -d "$tmpFile" $TPSocket 2>&5 - - res=$? - if test $res -ne 0 - then - echo "Unable to launch the simulation platform (using socket $TPSocket)" >&5 - return 4 - fi - - echo "Test platform successfuly loaded!" - return 0 -} - -# Execute a command for each input line, stopping in case of error -forEachLine () { - xargs -I@ sh -c "echo \> $1;$1 || exit 255" -} - -# Configure test platform (mainly criterion) and start the PFW -launchTestPlatform () { - local TPSendCommand="$remoteProcess $TPHost $TPSocket" - sed -e 's/InclusiveCriterion/createInclusiveSelectionCriterionFromStateList/' \ - -e 's/ExclusiveCriterion/createExclusiveSelectionCriterionFromStateList/' \ - -e 's/[[:space:]]:[[:space:]]/ /g' "$CriterionFilePath" | - forEachLine "$TPSendCommand @" - - $TPSendCommand setFailureOnMissingSubsystem false - $TPSendCommand setFailureOnFailedSettingsLoad false - $TPSendCommand setValidateSchemasOnStart $validationEnabled - - echo "Asking test-platform (port $TPSocket) to start a new PFW instance (listening on port $PFWSocket) ..." - $TPSendCommand start - res=$? - if test $res -ne 0 - then - echo "Unable to launch the parameter framework (using port $PFWSocket)" >&5 - return 5 - fi - - echo "Parameter framework successfully started!" - return 0 -} - -startPFW () { - # Init the test-platform - initTestPlatform "$PFWconfigurationFilePath" || return 1 - TPCreated=true - - # Ask the test-platform to start the PFW - if ! launchTestPlatform "$CriterionFilePath" - then - # If PFW didn't start, exit the current test-platform, and return failure in - # order to choose new socket ports - echo "Exiting test-platform listening on port $TPSocket" - $remoteProcess $TPHost $TPSocket exit - TPCreated=false - return 1 - fi -} - -# Get a new pair of available ports for TP and PFW sockets -changeSocketsPorts() { - TPSocket=$($portAllocator) || return 1 - PFWSocket=$($portAllocator) || return 1 -} - -# Start the pfw using different socket if it fails -safeStartPFW () { - local retry=0 - local nbRetry=1000 # Workaround to avoid build failure, it very very rarely fail this many time - - # Choose a new pair of socket ports - changeSocketsPorts - echo "Trying to start test-platform and PFW, with socket $TPSocket and $PFWSocket" - - while ! startPFW - do - (($retry < $nbRetry)) || return 1 - retry=$(($retry + 1)) - - # Choose a new pair of socket ports - changeSocketsPorts || continue - - echo "Unable to start PFW, try again with socket $TPSocket and $PFWSocket" - done -} - -deleteEscapedNewLines () { - sed -r ':a;/\\$/{N;s/\\\n//;ba}' -} - -copySchemaFiles() { - cp -r "$HostRoot"/etc/parameter-framework/schemas "$tmpDir/schemas" -} - -# Copy the schema files needed for validation -if [ "$validationEnabled" = "true" ]; then - copySchemaFiles -fi - -# The PFW looks for a libremote-processor.so library, not a libremote-processor_host.so -linkLibrary libremote-processor_host.so libremote-processor.so - -# Start test platform and the PFW -# Start the pfw using different socket if it fails -safeStartPFW - -PFWSendCommand="$remoteProcess $PFWHost $PFWSocket" - -$PFWSendCommand setTuningMode on - -# Send the xml domain tunning file -if test -s "$xmlDomainFilePath" -then - echo "Import the xml domain tunning file: $(readlink -e $xmlDomainFilePath)" - $PFWSendCommand importDomainsWithSettingsXML "$(readlink -e $xmlDomainFilePath)" -fi - -# Send the extended domain description routing files converted to pfw commands -m4 "$@" | - "$PFWScriptGenerator" --output-kind pfw | - deleteEscapedNewLines | - forEachLine "$PFWSendCommand @" | sed '/^Done$/d' - -# Export the global xml domains description -$PFWSendCommand getDomainsWithSettingsXML | - # Delete trailing carriage return and format absolute paths - sed -r -e 's/\r$//' \ - -e 's@(xsi:noNamespaceSchemaLocation=")'"$tmpDir"'/?@\1@' >&4 - diff --git a/tools/xmlGenerator/portAllocator.py b/tools/xmlGenerator/portAllocator.py deleted file mode 100755 index 64e117590..000000000 --- a/tools/xmlGenerator/portAllocator.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/python2 -# -# Copyright (c) 2011-2014, Intel Corporation -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation and/or -# other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import sys, socket - -serversock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -try: - # Create a listening socket on a random available port on localhost - serversock.bind(('127.0.0.1',0)) - serversock.listen(0) - - # Print the chosen port - print(serversock.getsockname()[1]) - serversock.close() - -except socket.error, (errno,message): - sys.stderr.write("portAllocator: Socket creation error " + str(errno) + ": " + message + '\n') - if serversock: - serversock.close() - sys.exit(1) - From f8ff6dfd7d214514f09843f76f10106222bd72d6 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Wed, 16 Dec 2015 14:47:47 +0100 Subject: [PATCH 2/7] test-platform: make get/setSchemaUri available Signed-off-by: David Wagner --- test/test-platform/TestPlatform.cpp | 19 +++++++++++++++++++ test/test-platform/TestPlatform.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index b65120fa2..14cc51dff 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -125,6 +125,11 @@ bool CTestPlatform::run(std::string &strError) &CTestPlatform::getter<&CParameterMgrPlatformConnector::getValidateSchemasOnStart>, 0, "", "Get policy for schema validation based on .xsd files."); + commandHandler.addCommandParser("getSchemaUri", &CTestPlatform::getSchemaUri, 0, + "", "Get the directory where schemas can be found."); + commandHandler.addCommandParser("setSchemaUri", &CTestPlatform::setSchemaUri, 1, + "", "Set the directory where schemas can be found."); + return mRemoteProcessorServer.process(commandHandler); } @@ -202,6 +207,20 @@ CTestPlatform::CommandReturn CTestPlatform::getter(const IRemoteCommand & /*comm return CTestPlatform::CCommandHandler::ESucceeded; } +CTestPlatform::CommandReturn CTestPlatform::getSchemaUri(const IRemoteCommand & /*remotecommand*/, + string &result) +{ + result = mParameterMgrPlatformConnector.getSchemaUri(); + return CTestPlatform::CCommandHandler::EDone; +} + +CTestPlatform::CommandReturn CTestPlatform::setSchemaUri(const IRemoteCommand &remotecommand, + string & /*result*/) +{ + mParameterMgrPlatformConnector.setSchemaUri(remotecommand.getArgument(0)); + return CTestPlatform::CCommandHandler::EDone; +} + CTestPlatform::CommandReturn CTestPlatform::setCriterionState(const IRemoteCommand &remoteCommand, string &strResult) { diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 8225ead79..f9c27f747 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -64,6 +64,9 @@ class CTestPlatform CommandReturn createInclusiveSelectionCriterion(const IRemoteCommand &remoteCommand, std::string &strResult); + CommandReturn getSchemaUri(const IRemoteCommand &remotecommand, std::string &result); + CommandReturn setSchemaUri(const IRemoteCommand &remotecommand, std::string &result); + /** Callback to set a criterion's value, see ISelectionCriterionInterface::setCriterionState. * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return * From e97b4d3578cc76d877c16758432e54c465615f18 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 15 Dec 2015 13:31:13 +0100 Subject: [PATCH 3/7] domainGenerator.py: fix a typo causing an AttributeError We don't have any test for this script and so, it was broken without anyone noticing. Signed-off-by: David Wagner --- tools/xmlGenerator/domainGenerator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/xmlGenerator/domainGenerator.py b/tools/xmlGenerator/domainGenerator.py index c5ee78b9c..d13d6a7f3 100755 --- a/tools/xmlGenerator/domainGenerator.py +++ b/tools/xmlGenerator/domainGenerator.py @@ -325,8 +325,8 @@ def info(self, message): # domains) to their location on the target (which may be different than on # the machine that is generating the domains) - if args.target_schema_dir is not None: - pfw.setSchemaUri(args.target_schema_dir) + if args.target_schemas_dir is not None: + pfw.setSchemaUri(args.target_schemas_dir) # Export the resulting settings to the standard output ok, domains, error = pfw.exportDomainsXml("", True, False) From 3475037027ca86e7d700f656b8b13ab26619c175 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 15 Dec 2015 14:26:27 +0100 Subject: [PATCH 4/7] domainGenerator.py: Make directory paths look like directories Add a trailing directory separator to them to disambiguate them from file names (needed by some path-handling functions within the Parameter Framework). Signed-off-by: David Wagner --- tools/xmlGenerator/domainGenerator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/xmlGenerator/domainGenerator.py b/tools/xmlGenerator/domainGenerator.py index d13d6a7f3..7587fcba1 100755 --- a/tools/xmlGenerator/domainGenerator.py +++ b/tools/xmlGenerator/domainGenerator.py @@ -270,7 +270,9 @@ def info(self, message): if args.validate: pfw.setValidateSchemasOnStart(True) if args.schemas_dir is not None: - schemas_dir = args.schemas_dir + # Force the path to represent a folder (e.g. add a trailing / + # if necessary) + schemas_dir = os.path.join(args.schemas_dir, "") pfw.setSchemaUri(schemas_dir) logger = PfwLogger() @@ -326,7 +328,10 @@ def info(self, message): # the machine that is generating the domains) if args.target_schemas_dir is not None: - pfw.setSchemaUri(args.target_schemas_dir) + # Force the path to represent a folder (e.g. add a trailing / + # if necessary) + target_schemas_dir = os.path.join(args.target_schemas_dir, "") + pfw.setSchemaUri(target_schemas_dir) # Export the resulting settings to the standard output ok, domains, error = pfw.exportDomainsXml("", True, False) From 01f531c2efde30083c172c743389be4f7a1cd484 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 15 Dec 2015 14:25:11 +0100 Subject: [PATCH 5/7] When scanning included files, transmit the schema base URI If the base URI is not transmitted to files included with "FileIncluder" (i.e. SubsystemInclude tags), schema validation cannot take place. Signed-off-by: David Wagner --- parameter/FileIncluderElementBuilder.h | 9 ++++++--- parameter/ParameterMgr.cpp | 3 ++- parameter/XmlFileIncluderElement.cpp | 11 +++++++++-- parameter/XmlFileIncluderElement.h | 3 ++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/parameter/FileIncluderElementBuilder.h b/parameter/FileIncluderElementBuilder.h index 2412b9ecc..b4566d4d7 100644 --- a/parameter/FileIncluderElementBuilder.h +++ b/parameter/FileIncluderElementBuilder.h @@ -41,17 +41,20 @@ class CFileIncluderElementBuilder : public CElementBuilder { public: - CFileIncluderElementBuilder(bool bValidateWithSchemas) - : CElementBuilder(), _bValidateWithSchemas(bValidateWithSchemas) + CFileIncluderElementBuilder(bool bValidateWithSchemas, const std::string &schemaBaseUri) + : CElementBuilder(), + _bValidateWithSchemas(bValidateWithSchemas), + _schemaBaseUri(schemaBaseUri) { } virtual CElement *createElement(const CXmlElement &xmlElement) const { return new CXmlFileIncluderElement(xmlElement.getNameAttribute(), xmlElement.getType(), - _bValidateWithSchemas); + _bValidateWithSchemas, _schemaBaseUri); } private: bool _bValidateWithSchemas; + const std::string _schemaBaseUri; }; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 28a24db58..4c063070b 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -2814,7 +2814,8 @@ void CParameterMgr::feedElementLibraries() pParameterCreationLibrary->addElementBuilder( "FloatingPointParameter", new TNamedElementBuilderTemplate); pParameterCreationLibrary->addElementBuilder( - "SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart)); + "SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart, + getSchemaUri())); _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary); diff --git a/parameter/XmlFileIncluderElement.cpp b/parameter/XmlFileIncluderElement.cpp index ef7452709..a6c71ac96 100644 --- a/parameter/XmlFileIncluderElement.cpp +++ b/parameter/XmlFileIncluderElement.cpp @@ -38,8 +38,11 @@ #define base CKindElement CXmlFileIncluderElement::CXmlFileIncluderElement(const std::string &strName, const std::string &strKind, - bool bValidateWithSchemas) - : base(strName, strKind), _bValidateSchemasOnStart(bValidateWithSchemas) + bool bValidateWithSchemas, + const std::string &schemaBaseUri) + : base(strName, strKind), + _bValidateSchemasOnStart(bValidateWithSchemas), + _schemaBaseUri(schemaBaseUri) { } @@ -63,6 +66,10 @@ bool CXmlFileIncluderElement::fromXml(const CXmlElement &xmlElement, CXmlDocSource docSource(doc, _bValidateSchemasOnStart, strIncludedElementType); + if (not _schemaBaseUri.empty()) { + docSource.setSchemaBaseUri(_schemaBaseUri); + } + if (!docSource.isParsable()) { elementSerializingContext.setError("Could not parse document \"" + strPath + "\""); diff --git a/parameter/XmlFileIncluderElement.h b/parameter/XmlFileIncluderElement.h index 85cc3a06d..144e078bf 100644 --- a/parameter/XmlFileIncluderElement.h +++ b/parameter/XmlFileIncluderElement.h @@ -38,7 +38,7 @@ class CXmlFileIncluderElement : public CKindElement { public: CXmlFileIncluderElement(const std::string &strName, const std::string &strKind, - bool bValidateWithSchemas); + bool bValidateWithSchemas, const std::string &schemaBaseUri); // From IXmlSink virtual bool fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext); @@ -46,4 +46,5 @@ class CXmlFileIncluderElement : public CKindElement // Element type std::string getIncludedElementType() const; bool _bValidateSchemasOnStart; + const std::string _schemaBaseUri; }; From 89cc7c3ef8640f160c7e7ded8b95369687f017b3 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 15 Dec 2015 14:24:11 +0100 Subject: [PATCH 6/7] Don't rely on xsi:noNamespaceSchemaLocation for schema validation This attribute only makes sense for the XML parser (e.g. libxml2) but since we don't make libxml2 automatically validate our files (we only do it manually), we don't need this attribute. Moreover, this attribute is hard to use: - when it is set to a relative path, the file containing it cannot be moved; - when set to an absolute path, it can't be copied between machines without modifying that attribute. We used to set it to a base name ("FooBard.xsd") which was the name of the root element contatenated with ".xsd" but this is redundant. In tests, it also led to generating documents with this attribute and a root element that does not have a corresponding standalone XSD (e.g. ParameterBlock does not have its own XSD). For instance: When trying to validate a file, just rely on the base dir provided by the user and the root element name in order to find the corresponding XSD file. Signed-off-by: David Wagner --- parameter/ParameterMgr.cpp | 5 ++--- test/functional-tests-legacy/CMakeLists.txt | 5 ++--- .../Util/PfwUnitTestLib.py | 1 + .../xml/XML_Test/Reference_Compliant.xml | 1 - .../xml/XML_Test/Reference_Criteria.xml | 2 +- .../xml/XML_Test/Reference_Split_Domain.xml | 1 - .../xml/XML_Test/Reference_dumpDomains.xml | 1 - .../Uncompliant_OutboundParameter.xml | 1 - ...ompliant_UndeclaredConfigurableElement.xml | 1 - .../Uncompliant_UndeclaredParameter.xml | 1 - ...Uncompliant_UnorderConfigurableElement.xml | 2 +- .../ParameterFrameworkConfiguration.xml | 1 - .../Settings/Test/TestConfigurableDomains.xml | 1 - .../Structure/Test/TestClass.xml | 1 - .../Structure/Test/TestSubsystem.xml.in | 1 - test/functional-tests/Handle.cpp | 4 +--- tools/xmlGenerator/README.md | 5 ----- tools/xmlGenerator/domainGenerator.py | 15 +------------ xmlserializer/XmlDocSource.cpp | 16 ++++++++++++-- xmlserializer/XmlDocSource.h | 22 +++++++++++++------ xmlserializer/XmlMemoryDocSource.cpp | 13 ----------- xmlserializer/XmlMemoryDocSource.h | 6 ++--- 22 files changed, 41 insertions(+), 65 deletions(-) diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 4c063070b..a86704b6c 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -636,8 +636,7 @@ bool CParameterMgr::xmlParse(CXmlElementSerializingContext &elementSerializingCo CXmlDocSource docSource(doc, _bValidateSchemasOnStart, pRootElement->getXmlElementName(), pRootElement->getName(), strNameAttributeName); - // Schema Uri - setSchemaUri(docSource.getSchemaUri()); + docSource.setSchemaBaseUri(getSchemaUri()); // Start clean auto clean = [replace, &pRootElement] { @@ -2644,7 +2643,7 @@ bool CParameterMgr::serializeElement(std::ostream &output, // Use a doc source by loading data from instantiated Configurable Domains CXmlMemoryDocSource memorySource(&element, _bValidateSchemasOnStart, - element.getXmlElementName(), getSchemaUri(), + element.getXmlElementName(), "parameter-framework", getVersion()); // Use a doc sink to write the doc data in a stream diff --git a/test/functional-tests-legacy/CMakeLists.txt b/test/functional-tests-legacy/CMakeLists.txt index 81ba711ca..9fe4c52c5 100644 --- a/test/functional-tests-legacy/CMakeLists.txt +++ b/test/functional-tests-legacy/CMakeLists.txt @@ -32,8 +32,6 @@ if(BUILD_TESTING) set(PFW_ROOT ${PROJECT_BINARY_DIR}/tmp/test-parameters) set(PFW_RESULT ${PFW_ROOT}/result) - file(COPY ${PROJECT_SOURCE_DIR}/schemas/ DESTINATION ${PFW_ROOT}/xml/schemas) - configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/xml/configuration/Structure/Test/TestSubsystem.xml.in ${PFW_ROOT}/xml/configuration/Structure/Test/TestSubsystem.xml @ONLY) @@ -62,5 +60,6 @@ if(BUILD_TESTING) set_test_env(functional-test-legacy) set_property(TEST functional-test-legacy APPEND PROPERTY ENVIRONMENT PFW_ROOT=${PFW_ROOT} - PFW_RESULT=${PFW_RESULT}) + PFW_RESULT=${PFW_RESULT} + PFW_SCHEMAS=${PROJECT_SOURCE_DIR}/schemas) endif() diff --git a/test/functional-tests-legacy/Util/PfwUnitTestLib.py b/test/functional-tests-legacy/Util/PfwUnitTestLib.py index a0bec9425..78b1f76f3 100644 --- a/test/functional-tests-legacy/Util/PfwUnitTestLib.py +++ b/test/functional-tests-legacy/Util/PfwUnitTestLib.py @@ -113,6 +113,7 @@ def createExclusiveCriterion(self, name, nb): # Starts the Pfw def start(self): + self.sendCmd("setSchemaUri", os.environ["PFW_SCHEMAS"]) self.sendCmd("setValidateSchemasOnStart", "true") self.sendCmd("start") self.pfw.setRemoteProcess(self.remoteProcess) diff --git a/test/functional-tests-legacy/xml/XML_Test/Reference_Compliant.xml b/test/functional-tests-legacy/xml/XML_Test/Reference_Compliant.xml index 329dc03c4..29bd3c54f 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Reference_Compliant.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Reference_Compliant.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/XML_Test/Reference_Criteria.xml b/test/functional-tests-legacy/xml/XML_Test/Reference_Criteria.xml index 3cf6bbe01..a2bd7cf81 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Reference_Criteria.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Reference_Criteria.xml @@ -1,5 +1,5 @@ - + diff --git a/test/functional-tests-legacy/xml/XML_Test/Reference_Split_Domain.xml b/test/functional-tests-legacy/xml/XML_Test/Reference_Split_Domain.xml index fdb8e4722..e6dfa559b 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Reference_Split_Domain.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Reference_Split_Domain.xml @@ -1,7 +1,6 @@ diff --git a/test/functional-tests-legacy/xml/XML_Test/Reference_dumpDomains.xml b/test/functional-tests-legacy/xml/XML_Test/Reference_dumpDomains.xml index 7ba67d838..b80cc61b1 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Reference_dumpDomains.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Reference_dumpDomains.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_OutboundParameter.xml b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_OutboundParameter.xml index e09d25e16..f7fd32967 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_OutboundParameter.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_OutboundParameter.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredConfigurableElement.xml b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredConfigurableElement.xml index 26b71afa9..98be4c5ca 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredConfigurableElement.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredConfigurableElement.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredParameter.xml b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredParameter.xml index 533fefda9..01d4507a0 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredParameter.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UndeclaredParameter.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UnorderConfigurableElement.xml b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UnorderConfigurableElement.xml index a8a69b9c1..39af533fe 100644 --- a/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UnorderConfigurableElement.xml +++ b/test/functional-tests-legacy/xml/XML_Test/Uncompliant_UnorderConfigurableElement.xml @@ -1,5 +1,5 @@ - + diff --git a/test/functional-tests-legacy/xml/configuration/ParameterFrameworkConfiguration.xml b/test/functional-tests-legacy/xml/configuration/ParameterFrameworkConfiguration.xml index dfbdc1b9d..d050376dd 100644 --- a/test/functional-tests-legacy/xml/configuration/ParameterFrameworkConfiguration.xml +++ b/test/functional-tests-legacy/xml/configuration/ParameterFrameworkConfiguration.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/configuration/Settings/Test/TestConfigurableDomains.xml b/test/functional-tests-legacy/xml/configuration/Settings/Test/TestConfigurableDomains.xml index 3e3e14217..c53e02741 100644 --- a/test/functional-tests-legacy/xml/configuration/Settings/Test/TestConfigurableDomains.xml +++ b/test/functional-tests-legacy/xml/configuration/Settings/Test/TestConfigurableDomains.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/configuration/Structure/Test/TestClass.xml b/test/functional-tests-legacy/xml/configuration/Structure/Test/TestClass.xml index b72b7089b..f2bd54c59 100644 --- a/test/functional-tests-legacy/xml/configuration/Structure/Test/TestClass.xml +++ b/test/functional-tests-legacy/xml/configuration/Structure/Test/TestClass.xml @@ -1,6 +1,5 @@ diff --git a/test/functional-tests-legacy/xml/configuration/Structure/Test/TestSubsystem.xml.in b/test/functional-tests-legacy/xml/configuration/Structure/Test/TestSubsystem.xml.in index 592129ed2..e7a81552d 100644 --- a/test/functional-tests-legacy/xml/configuration/Structure/Test/TestSubsystem.xml.in +++ b/test/functional-tests-legacy/xml/configuration/Structure/Test/TestSubsystem.xml.in @@ -1,6 +1,5 @@ diff --git a/test/functional-tests/Handle.cpp b/test/functional-tests/Handle.cpp index 6dadf2cb1..ebd8d9e76 100644 --- a/test/functional-tests/Handle.cpp +++ b/test/functional-tests/Handle.cpp @@ -192,9 +192,7 @@ struct AllParamsPF : public ParameterFramework static string rootNode(string name, string attributes, string content) { - return '<' + name + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" - " xsi:noNamespaceSchemaLocation='" + - name + ".xsd'" + ' ' + attributes + '>' + content + "'; + return '<' + name + ' ' + attributes + '>' + content + "'; } }; diff --git a/tools/xmlGenerator/README.md b/tools/xmlGenerator/README.md index 42e2fd92f..78c714d61 100644 --- a/tools/xmlGenerator/README.md +++ b/tools/xmlGenerator/README.md @@ -202,7 +202,6 @@ It prints the resulting XML on the standard output. Its syntax is: [--add-domains XML_DOMAIN_FILE [XML_DOMAIN_FILE ...]] [--add-edds EDD_FILE [EDD_FILE ...]] [--schemas-dir SCHEMAS_DIR] - [--target-schemas-dir TARGET_SCHEMAS_DIR] [--validate] [--verbose] *Explanation:* @@ -222,10 +221,6 @@ It prints the resulting XML on the standard output. Its syntax is: - The optional `--schemas-dir` argument lets you change the directory containing the XML Schemas in the context of the XML generation only (see the `--validate` option). -- The optional `--target-schemas-dir` argument lets you change the directory - containing the XML Schemas on the target device (the one the - parameter-framework will run on) if it is using Schema validation and if - different than the default. - The optional `--validate` option check the validity of all XML files involved in the process. diff --git a/tools/xmlGenerator/domainGenerator.py b/tools/xmlGenerator/domainGenerator.py index 7587fcba1..287f003aa 100755 --- a/tools/xmlGenerator/domainGenerator.py +++ b/tools/xmlGenerator/domainGenerator.py @@ -159,10 +159,7 @@ def info(self, message): validation", default=None) argparser.add_argument('--target-schemas-dir', - help="Directory of parameter-framework XML Schemas on target \ - machine (may be different than generating machine). \ - Defaults to \"schemas\"", - default="schemas/") + help="Ignored. Kept for retro-compatibility") argparser.add_argument('--validate', help="Validate the settings against XML schemas", action='store_true') @@ -323,16 +320,6 @@ def info(self, message): logging.error("Error while importing parsed EDD files.\n") exit(1) - # dirty hack: we change the schema location (right before exporting the - # domains) to their location on the target (which may be different than on - # the machine that is generating the domains) - - if args.target_schemas_dir is not None: - # Force the path to represent a folder (e.g. add a trailing / - # if necessary) - target_schemas_dir = os.path.join(args.target_schemas_dir, "") - pfw.setSchemaUri(target_schemas_dir) - # Export the resulting settings to the standard output ok, domains, error = pfw.exportDomainsXml("", True, False) sys.stdout.write(domains) diff --git a/xmlserializer/XmlDocSource.cpp b/xmlserializer/XmlDocSource.cpp index 29ac940f7..ed366bf26 100644 --- a/xmlserializer/XmlDocSource.cpp +++ b/xmlserializer/XmlDocSource.cpp @@ -84,10 +84,22 @@ string CXmlDocSource::getRootElementAttributeString(const string &strAttributeNa return attribute; } +void CXmlDocSource::setSchemaBaseUri(const string &uri) +{ + _schemaBaseUri = uri; +} + +string CXmlDocSource::getSchemaBaseUri() +{ + return _schemaBaseUri; +} + string CXmlDocSource::getSchemaUri() const { - return mkUri(string((const char *)_pDoc->URL), - getRootElementAttributeString("noNamespaceSchemaLocation")); + // Adding a trailing '/' is a bit dirty but works fine on both Linux and + // Windows in order to make sure that libxml2's URI handling methods + // interpret the base URI as a folder. + return mkUri(_schemaBaseUri + "/", getRootElementName() + ".xsd"); } _xmlDoc *CXmlDocSource::getDoc() const diff --git a/xmlserializer/XmlDocSource.h b/xmlserializer/XmlDocSource.h index dea52b7df..85b41144e 100644 --- a/xmlserializer/XmlDocSource.h +++ b/xmlserializer/XmlDocSource.h @@ -63,7 +63,6 @@ class CXmlDocSource : private utility::NonCopyable * Constructor * * @param[out] pDoc a pointer to the xml document that will be filled by the class - * @param[in] strXmlSchemaFile a string containing the path to the schema file * @param[in] strRootElementType a string containing the root element type * @param[in] strRootElementName a string containing the root element name * @param[in] strNameAttributeName a string containing the name of the root name attribute @@ -102,12 +101,18 @@ class CXmlDocSource : private utility::NonCopyable */ std::string getRootElementName() const; - /** - * Getter method. - * - * @return schema URI - */ - std::string getSchemaUri() const; + /** Get the Schemas' base (folder) URI + */ + std::string getSchemaBaseUri(); + + /** Set the Schema's base (folder) URI + * + * The schema for validating the XML document will be searched for in that + * folder. + * + * @param[in] uri The Schemas' base URI + */ + void setSchemaBaseUri(const std::string &uri); /** * Getter method. @@ -182,6 +187,7 @@ class CXmlDocSource : private utility::NonCopyable * @return true if document is valid, false if any error occures */ bool isInstanceDocumentValid(); + std::string getSchemaUri() const; /** * Element type info @@ -202,4 +208,6 @@ class CXmlDocSource : private utility::NonCopyable * Boolean that enables the validation via xsd files */ bool _bValidateWithSchema; + + std::string _schemaBaseUri; }; diff --git a/xmlserializer/XmlMemoryDocSource.cpp b/xmlserializer/XmlMemoryDocSource.cpp index 74b36b37a..41b5ef23c 100644 --- a/xmlserializer/XmlMemoryDocSource.cpp +++ b/xmlserializer/XmlMemoryDocSource.cpp @@ -36,16 +36,12 @@ CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource *pXmlSource, bool bValidateWithSchema, const std::string &strRootElementType, - const std::string &schemaBaseUri, const std::string &strProduct, const std::string &strVersion) : base(xmlNewDoc(BAD_CAST "1.0"), bValidateWithSchema, xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), _pXmlSource(pXmlSource), _strProduct(strProduct), _strVersion(strVersion) { - // Get Schema file - _strXmlSchemaFile = CXmlDocSource::mkUri(schemaBaseUri, strRootElementType + ".xsd"); - init(); } @@ -71,15 +67,6 @@ bool CXmlMemoryDocSource::populate(CXmlSerializingContext &serializingContext) // Create Xml element with the Doc CXmlElement docElement(_pRootNode); - if (!_strXmlSchemaFile.empty()) { - - // Schema namespace - docElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - - // Schema location - docElement.setAttribute("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile); - } - // Compose the xml document _pXmlSource->toXml(docElement, serializingContext); diff --git a/xmlserializer/XmlMemoryDocSource.h b/xmlserializer/XmlMemoryDocSource.h index 962fc39c6..417fec0a5 100644 --- a/xmlserializer/XmlMemoryDocSource.h +++ b/xmlserializer/XmlMemoryDocSource.h @@ -45,14 +45,14 @@ class CXmlMemoryDocSource : public CXmlDocSource * @param[in] pXmlSource a pointer to a parameter-framework structure that can generate * an xml description of itself * @param[in] strRootElementType a string containing the root element type - * @param[in] strXmlSchemaFile a string containing the path to the schema file * @param[in] strProduct a string containing the product name * @param[in] strVersion a string containing the version number * @param[in] bValidateWithSchema a boolean that toggles schema validation */ - CXmlMemoryDocSource(const IXmlSource *pXmlSource, bool bValidateWithSchema, + CXmlMemoryDocSource(const IXmlSource *pXmlSource, + bool bValidateWithSchema, const std::string &strRootElementType, - const std::string &schemaBaseUri = "", const std::string &strProduct = "", + const std::string &strProduct = "", const std::string &strVersion = ""); /** From 27d0dadb4621ff295ba4510eff53d4bd733b4384 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 26 May 2015 11:13:40 +0200 Subject: [PATCH 7/7] xml generation: introduce tests Introduce basic tests for domainGenerator.py. No error case is covered yet. As it stood, the XML validity checking code wasn't covered. This new test also covers it. Same applies for tags: there wasn't any test suite using them. This one does. Each of these features should have their own test but this is a quick and easy solution. Signed-off-by: David Wagner --- ctest/CTestCustom.cmake | 1 + test/CMakeLists.txt | 1 + test/xml-generator/CMakeLists.txt | 39 ++++ test/xml-generator/Class.xml | 4 + .../ParameterFrameworkConfiguration.xml | 6 + test/xml-generator/Subsystem.xml | 17 ++ test/xml-generator/TuningSettings.xml | 23 +++ test/xml-generator/TuningStructure.xml | 6 + test/xml-generator/criteria.txt | 2 + test/xml-generator/first.pfw | 33 ++++ test/xml-generator/fourth.xml | 25 +++ test/xml-generator/reference.xml | 171 ++++++++++++++++++ test/xml-generator/second.pfw | 29 +++ test/xml-generator/test.py | 61 +++++++ test/xml-generator/third.xml | 25 +++ 15 files changed, 443 insertions(+) create mode 100644 test/xml-generator/CMakeLists.txt create mode 100644 test/xml-generator/Class.xml create mode 100644 test/xml-generator/ParameterFrameworkConfiguration.xml create mode 100644 test/xml-generator/Subsystem.xml create mode 100644 test/xml-generator/TuningSettings.xml create mode 100644 test/xml-generator/TuningStructure.xml create mode 100644 test/xml-generator/criteria.txt create mode 100644 test/xml-generator/first.pfw create mode 100644 test/xml-generator/fourth.xml create mode 100644 test/xml-generator/reference.xml create mode 100644 test/xml-generator/second.pfw create mode 100644 test/xml-generator/test.py create mode 100644 test/xml-generator/third.xml diff --git a/ctest/CTestCustom.cmake b/ctest/CTestCustom.cmake index cad1bcc29..0c0aa72fb 100644 --- a/ctest/CTestCustom.cmake +++ b/ctest/CTestCustom.cmake @@ -4,4 +4,5 @@ SET(CTEST_CUSTOM_MEMCHECK_IGNORE # runing python based tests would be long and useless. fix_point_parameter functional-test-legacy + xml-generator ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1fdbb6c55..48a40e5f7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,3 +35,4 @@ add_subdirectory(test-platform) add_subdirectory(test-subsystem) add_subdirectory(introspection-subsystem) add_subdirectory(tokenizer) +add_subdirectory(xml-generator) diff --git a/test/xml-generator/CMakeLists.txt b/test/xml-generator/CMakeLists.txt new file mode 100644 index 000000000..756a46ccf --- /dev/null +++ b/test/xml-generator/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (c) 2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +if (BUILD_TESTING AND PYTHON_BINDINGS) + + find_package(PythonInterp 2 REQUIRED) + + add_test(NAME xml-generator + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tools/xmlGenerator + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py) + + # Custom function defined in the top-level CMakeLists + set_test_env(xml-generator) +endif() diff --git a/test/xml-generator/Class.xml b/test/xml-generator/Class.xml new file mode 100644 index 000000000..75b55a0e9 --- /dev/null +++ b/test/xml-generator/Class.xml @@ -0,0 +1,4 @@ + + + + diff --git a/test/xml-generator/ParameterFrameworkConfiguration.xml b/test/xml-generator/ParameterFrameworkConfiguration.xml new file mode 100644 index 000000000..2460bf32d --- /dev/null +++ b/test/xml-generator/ParameterFrameworkConfiguration.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/xml-generator/Subsystem.xml b/test/xml-generator/Subsystem.xml new file mode 100644 index 000000000..8c2c5a711 --- /dev/null +++ b/test/xml-generator/Subsystem.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/test/xml-generator/TuningSettings.xml b/test/xml-generator/TuningSettings.xml new file mode 100644 index 000000000..6fbebc40d --- /dev/null +++ b/test/xml-generator/TuningSettings.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + 1 + + + + + diff --git a/test/xml-generator/TuningStructure.xml b/test/xml-generator/TuningStructure.xml new file mode 100644 index 000000000..48bd55068 --- /dev/null +++ b/test/xml-generator/TuningStructure.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/xml-generator/criteria.txt b/test/xml-generator/criteria.txt new file mode 100644 index 000000000..7ab3d99d8 --- /dev/null +++ b/test/xml-generator/criteria.txt @@ -0,0 +1,2 @@ +InclusiveCriterion Colors : Red Green Blue +ExclusiveCriterion Switch : On Off diff --git a/test/xml-generator/first.pfw b/test/xml-generator/first.pfw new file mode 100644 index 000000000..b049459fb --- /dev/null +++ b/test/xml-generator/first.pfw @@ -0,0 +1,33 @@ +domainGroup: EddGroup + Colors Includes Red + + # Only inherits from "EddGroup" domainGroup + domain: First + Colors Includes Blue + + confGroup: Green + Colors Includes Green + + # Inherits from "EddGroup" domainGroup, "First" domain + # and from "Green" confGroup + conf: On + Switch Is On + + component: /Test/test/block/1 + q2.5 = 1.2 + string = some string + + # Inherits from "EddGroup" domainGroup, "First" domain + # and from "Green" confGroup + conf: Off + Switch Is Off + + component: /Test/test/block/1 + q2.5 = 1.2 + string = some string + + # Inherits from "EddGroup" domainGroup and "First" domain + conf: Default + component: /Test/test/block/1 + q2.5 = 0 + string = some other string diff --git a/test/xml-generator/fourth.xml b/test/xml-generator/fourth.xml new file mode 100644 index 000000000..aaeb22e87 --- /dev/null +++ b/test/xml-generator/fourth.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + 1.23 + 200 + blah + + + + + diff --git a/test/xml-generator/reference.xml b/test/xml-generator/reference.xml new file mode 100644 index 000000000..46019af1a --- /dev/null +++ b/test/xml-generator/reference.xml @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + + + + + 1.21875 + 200 + blah + + + + + + + + + + + + + + + + + + + 1.21875 + 200 + blah + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.18750 + + + some string + + + + + 1.18750 + + + some string + + + + + 0.00000 + + + some other string + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + diff --git a/test/xml-generator/second.pfw b/test/xml-generator/second.pfw new file mode 100644 index 000000000..058abb68c --- /dev/null +++ b/test/xml-generator/second.pfw @@ -0,0 +1,29 @@ +domainGroup: EddGroup + Colors Includes Red + + domain: Second + + confType: On + Switch Is On + + confGroup: Blue + Colors Includes Blue + + # Inherits from "EddGroup" domainGroup, "Blue" confGroup + # and from "On" confType + conf: On + /Test/test/block/2/uint8 = 3 + + # Inherits from "EddGroup" domainGroup and "Blue" confGroup + conf: Off + /Test/test/block/2/uint8 = 4 + + # Only inherits from "EddGroup" domainGroup + conf: Green + Colors Includes Green + + /Test/test/block/2/uint8 = 5 + + # Only inherits from "EddGroup" domainGroup + conf: Default + /Test/test/block/2/uint8 = 6 diff --git a/test/xml-generator/test.py b/test/xml-generator/test.py new file mode 100644 index 000000000..528980d91 --- /dev/null +++ b/test/xml-generator/test.py @@ -0,0 +1,61 @@ +#! python2 +# Copyright (c) 2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import sys +import os +import subprocess +import difflib + +basedir = os.path.dirname(sys.argv[0]) +command = [sys.executable, "domainGenerator.py", + "--validate", + "--toplevel-config", os.path.join(basedir, "ParameterFrameworkConfiguration.xml"), + "--criteria", os.path.join(basedir, "criteria.txt"), + "--initial-settings", os.path.join(basedir, "TuningSettings.xml"), + "--add-edds", os.path.join(basedir, "first.pfw"), os.path.join(basedir, "second.pfw"), + "--add-domains", os.path.join(basedir, "third.xml"), os.path.join(basedir, "fourth.xml"), + "--schemas-dir", os.path.join(basedir, "../../schemas")] + +reference = open(os.path.join(basedir, "reference.xml")).read().splitlines() + +process = subprocess.Popen(command, stdout=subprocess.PIPE) +actual = process.stdout.read().splitlines() + +unified = difflib.unified_diff(reference, + actual, + fromfile="reference.xml", + tofile="-", + lineterm="") +diffs = list(unified) +if not diffs: + sys.exit(0) +else: + for d in diffs: + print(d) + sys.exit(1) diff --git a/test/xml-generator/third.xml b/test/xml-generator/third.xml new file mode 100644 index 000000000..730c7ca51 --- /dev/null +++ b/test/xml-generator/third.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + 1.23 + 200 + blah + + + + +