diff options
author | Sebastien Guiriec <sebastien.guiriec@renault.com> | 2017-05-02 14:19:28 +0200 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2019-03-12 17:49:21 -0700 |
commit | d5cdd5fb5966ac9d0f06f61b721b8e5fb12d7ee4 (patch) | |
tree | 525d001b9c50fda88c9d994b527b88aafe14281b | |
parent | 54bdb2158f647a8c8b6af9bc2e2239a6ce7b6bbc (diff) | |
download | parameter-framework-d5cdd5fb5966ac9d0f06f61b721b8e5fb12d7ee4.tar.gz |
[PFW] Integrate PFW core version 3.2.7 release
PFW 3.2.7 release notes:
https://github.com/intel/parameter-framework/releases/tag/v3.2.7
This release contains the following changes:
- Tighter checks on XML attributes
- Travis-related changes
- Documentation fixes
- Fix displaying of syntax errors in EDD files
Bug: 124767636
Test: build
Change-Id: I7b2671156b5275aa2b804246fa65e81613677881
Signed-off-by: Sebastien Guiriec <sebastien.guiriec@renault.com>
22 files changed, 732 insertions, 548 deletions
@@ -166,7 +166,7 @@ cc_library_shared { "upstream/parameter/ParameterMgr.cpp", "upstream/parameter/SelectionCriterionType.cpp", "upstream/parameter/Subsystem.cpp", - "upstream/parameter/IntegerParameterType.cpp", + "upstream/parameter/BaseIntegerParameterType.cpp", "upstream/parameter/BitParameterType.cpp", "upstream/parameter/SelectionCriterion.cpp", "upstream/parameter/XmlElementSerializingContext.cpp", diff --git a/support/android/parameter/version.h b/support/android/parameter/version.h index 6aa1662..589a33f 100644 --- a/support/android/parameter/version.h +++ b/support/android/parameter/version.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Intel Corporation + * Copyright (c) 2016-2017, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,4 +27,4 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define PARAMETER_FRAMEWORK_VERSION "v3.2.6" +#define PARAMETER_FRAMEWORK_VERSION "v3.2.7" diff --git a/upstream/.travis.yml b/upstream/.travis.yml index 343e1ee..cdf4167 100644 --- a/upstream/.travis.yml +++ b/upstream/.travis.yml @@ -63,8 +63,8 @@ install: # This version of catch is known to work. - wget --directory-prefix $PREFIX/include https://raw.github.com/philsquared/Catch/v1.2.1/single_include/catch.hpp - - wget 'https://01.org/sites/default/files/asio-1.10.6.tar.gz' - - tar xf asio-1.10.6.tar.gz -C $PREFIX --strip-components=1 + - wget -O asio-1.10.6.tar.gz https://github.com/chriskohlhoff/asio/archive/asio-1-10-6.tar.gz + - tar xf asio-1.10.6.tar.gz -C $PREFIX --strip-components=2 asio-asio-1-10-6/asio # Current limitations on OSX builds: no testing, no client-simulator # (because we haven't found a straightforward way to have CMake find the # python libraries (find_package(PythonLibs)). @@ -121,7 +121,7 @@ script: # Check that all installed files are in a component (no "unspecified # component" archive created) - (cd build && cpack -G TGZ -D CPACK_ARCHIVE_COMPONENT_INSTALL=ON && - [ ! -a '*-Unspecified.tar.gz' ]) + [ ! -e "*-Unspecified.tar.gz" ]) # Keep this last - ( mkdir build_less_features && cd build_less_features && rm -rf $PREFIX/asio-1.10.6 && diff --git a/upstream/.version b/upstream/.version index c4441fa..02a5dbc 100644 --- a/upstream/.version +++ b/upstream/.version @@ -1 +1 @@ -HEAD -> master, tag: v3.2.6 +tag: v3.2.7 diff --git a/upstream/CMakeLists.txt b/upstream/CMakeLists.txt index 463f45f..c29a8e3 100644 --- a/upstream/CMakeLists.txt +++ b/upstream/CMakeLists.txt @@ -106,8 +106,8 @@ include(ctest/CMakeLists.txt) # Since there is no directory-wide property for linker flags, we can't use # set_property for the link-time coverage flags. if(COVERAGE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") endif() add_subdirectory(xmlserializer) diff --git a/upstream/appveyor.yml b/upstream/appveyor.yml index cd2f0df..8ea45a4 100644 --- a/upstream/appveyor.yml +++ b/upstream/appveyor.yml @@ -32,7 +32,7 @@ install: # Install Windows Installer XML (WiX) to create installer with cpack - cinst wixtoolset - # Download and install external dependancy if they are not in the cache + # Download and install external dependency if they are not in the cache - if not exist libxml2-x86_64 ( wget --no-check-certificate https://01.org/sites/default/files/libxml2-x86_64-3eaedba1b64180668fdab7ad2eba549586017bf3.zip && 7z x libxml2-x86_64-3eaedba1b64180668fdab7ad2eba549586017bf3.zip) diff --git a/upstream/parameter/BaseIntegerParameterType.cpp b/upstream/parameter/BaseIntegerParameterType.cpp new file mode 100644 index 0000000..16c60bf --- /dev/null +++ b/upstream/parameter/BaseIntegerParameterType.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016, 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. + */ + +#include <sstream> +#include <iomanip> + +#include "BaseIntegerParameterType.h" +#include "ParameterAccessContext.h" +#include "ParameterAdaptation.h" + +// Kind +std::string CBaseIntegerParameterType::getKind() const +{ + return "IntegerParameter"; +} + +// Deal with adaption node +bool CBaseIntegerParameterType::childrenAreDynamic() const +{ + return true; +} + +bool CBaseIntegerParameterType::fromBlackboard(uint32_t &uiUserValue, uint32_t uiValue, + CParameterAccessContext & /*ctx*/) const +{ + // Do assign + uiUserValue = uiValue; + + return true; +} +bool CBaseIntegerParameterType::fromBlackboard(int32_t &iUserValue, uint32_t uiValue, + CParameterAccessContext & /*ctx*/) const +{ + int32_t iValue = uiValue; + + // Sign extend + signExtend(iValue); + + // Do assign + iUserValue = iValue; + + return true; +} +// Adaptation element retrieval +const CParameterAdaptation *CBaseIntegerParameterType::getParameterAdaptation() const +{ + return static_cast<const CParameterAdaptation *>(findChildOfKind("Adaptation")); +} diff --git a/upstream/parameter/BaseIntegerParameterType.h b/upstream/parameter/BaseIntegerParameterType.h new file mode 100644 index 0000000..b39816c --- /dev/null +++ b/upstream/parameter/BaseIntegerParameterType.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, 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. + */ +#pragma once + +#include "ParameterType.h" + +#include <string> + +class CParameterAdaptation; + +/** Base class for CIntegerParameterType + * + * CIntegerParameterType is template - this class Contains the parts that do + * not depend on template arguments in order to make the implementation more + * consise. + */ +class CBaseIntegerParameterType : public CParameterType +{ +public: + CBaseIntegerParameterType(const std::string &name) : CParameterType(name){}; + + // CElement + std::string getKind() const override; + + bool fromBlackboard(uint32_t &uiUserValue, uint32_t uiValue, + CParameterAccessContext ¶meterAccessContext) const override; + bool fromBlackboard(int32_t &iUserValue, uint32_t uiValue, + CParameterAccessContext ¶meterAccessContext) const override; + bool fromBlackboard(double &dUserValue, uint32_t uiValue, + CParameterAccessContext ¶meterAccessContext) const override + { + return CParameterType::fromBlackboard(dUserValue, uiValue, parameterAccessContext); + } + bool fromBlackboard(std::string &strValue, const uint32_t &value, + CParameterAccessContext ¶meterAccessContext) const override = 0; + +protected: + // Adaptation element retrieval + const CParameterAdaptation *getParameterAdaptation() const; + +private: + // Returns true if children dynamic creation is to be dealt with + bool childrenAreDynamic() const override; +}; diff --git a/upstream/parameter/CMakeLists.txt b/upstream/parameter/CMakeLists.txt index ca956f5..545f1e4 100644 --- a/upstream/parameter/CMakeLists.txt +++ b/upstream/parameter/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(parameter SHARED ${parameter_OS_SPECIFIC_SRCS} AreaConfiguration.cpp ArrayParameter.cpp + BaseIntegerParameterType.cpp BaseParameter.cpp BitParameterBlock.cpp BitParameterBlockType.cpp @@ -66,7 +67,6 @@ add_library(parameter SHARED HardwareBackSynchronizer.cpp InstanceConfigurableElement.cpp InstanceDefinition.cpp - IntegerParameterType.cpp LinearParameterAdaptation.cpp LogarithmicParameterAdaptation.cpp LoggingElementBuilderTemplate.cpp diff --git a/upstream/parameter/Element.cpp b/upstream/parameter/Element.cpp index 8317299..611951c 100644 --- a/upstream/parameter/Element.cpp +++ b/upstream/parameter/Element.cpp @@ -31,6 +31,7 @@ #include "XmlElementSerializingContext.h" #include "ElementLibrary.h" #include "ErrorContext.hpp" +#include "PfError.hpp" #include <algorithm> #include <assert.h> #include <stdio.h> @@ -140,8 +141,8 @@ string CElement::logValue(utility::ErrorContext & /*ctx*/) const } // From IXmlSink -bool CElement::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) -{ +bool CElement::fromXml(const CXmlElement &xmlElement, + CXmlSerializingContext &serializingContext) try { xmlElement.getAttribute(gDescriptionPropertyName, _strDescription); // Propagate through children @@ -183,6 +184,9 @@ bool CElement::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &se } return true; +} catch (const PfError &e) { + serializingContext.appendLineToError(e.what()); + return false; } void CElement::childrenToXml(CXmlElement &xmlElement, diff --git a/upstream/parameter/IntegerParameterBuilder.h b/upstream/parameter/IntegerParameterBuilder.h new file mode 100644 index 0000000..d6204ac --- /dev/null +++ b/upstream/parameter/IntegerParameterBuilder.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016, 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. + */ +#pragma once + +#include "ElementBuilder.h" +#include "IntegerParameterType.h" + +/** Specialized element builder for IntegerParameterType + * + * Dispatch to the correct template instance according to the signedness and + * size. + */ +class IntegerParameterBuilder : public CElementBuilder +{ +public: + CElement *createElement(const CXmlElement &xmlElement) const override + { + size_t sizeInBits; + sizeInBits = xmlElement.getAttribute("Size", sizeInBits) ? sizeInBits : 32; + + bool isSigned = false; + xmlElement.getAttribute("Signed", isSigned); + + auto name = xmlElement.getNameAttribute(); + + switch (sizeInBits) { + case 8: + if (isSigned) { + return new CIntegerParameterType<true, 8>(name); + } + return new CIntegerParameterType<false, 8>(name); + case 16: + if (isSigned) { + return new CIntegerParameterType<true, 16>(name); + } + return new CIntegerParameterType<false, 16>(name); + case 32: + if (isSigned) { + return new CIntegerParameterType<true, 32>(name); + } + return new CIntegerParameterType<false, 32>(name); + default: + return nullptr; + } + } +}; diff --git a/upstream/parameter/IntegerParameterType.cpp b/upstream/parameter/IntegerParameterType.cpp deleted file mode 100644 index 4899514..0000000 --- a/upstream/parameter/IntegerParameterType.cpp +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright (c) 2011-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. - */ -#include "IntegerParameterType.h" -#include <stdlib.h> -#include <sstream> -#include <iomanip> -#include "ParameterAccessContext.h" -#include <assert.h> -#include "ParameterAdaptation.h" -#include "Utility.h" -#include <errno.h> - -#define base CParameterType - -using std::string; -using std::ostringstream; - -CIntegerParameterType::CIntegerParameterType(const string &strName) : base(strName) -{ -} - -// Kind -string CIntegerParameterType::getKind() const -{ - return "IntegerParameter"; -} - -// Deal with adaption node -bool CIntegerParameterType::childrenAreDynamic() const -{ - return true; -} - -// Element properties -void CIntegerParameterType::showProperties(string &strResult) const -{ - base::showProperties(strResult); - - // Sign - strResult += "Signed: "; - strResult += _bSigned ? "yes" : "no"; - strResult += "\n"; - - // Min - strResult += "Min: "; - strResult += _bSigned ? std::to_string((int32_t)_uiMin) : std::to_string(_uiMin); - strResult += "\n"; - - // Max - strResult += "Max: "; - strResult += _bSigned ? std::to_string((int32_t)_uiMax) : std::to_string(_uiMax); - strResult += "\n"; - - // Check if there's an adaptation object available - const CParameterAdaptation *pParameterAdaption = getParameterAdaptation(); - - if (pParameterAdaption) { - - // Display adaptation properties - strResult += "Adaptation:\n"; - - pParameterAdaption->showProperties(strResult); - } -} - -bool CIntegerParameterType::fromXml(const CXmlElement &xmlElement, - CXmlSerializingContext &serializingContext) -{ - // Sign - xmlElement.getAttribute("Signed", _bSigned); - - // Size in bits - size_t sizeInBits = 0; - xmlElement.getAttribute("Size", sizeInBits); - - // Size - setSize(sizeInBits / 8); - - // Min / Max - // TODO: Make IntegerParameter template - if (_bSigned) { - - // Signed means we have one less util bit - sizeInBits--; - - if (!xmlElement.getAttribute("Min", (int32_t &)_uiMin)) { - - _uiMin = 1U << sizeInBits; - } - - if (!xmlElement.getAttribute("Max", (int32_t &)_uiMax)) { - - _uiMax = (1U << sizeInBits) - 1; - } - signExtend((int32_t &)_uiMin); - signExtend((int32_t &)_uiMax); - } else { - if (!xmlElement.getAttribute("Min", _uiMin)) { - - _uiMin = 0; - } - - if (!xmlElement.getAttribute("Max", _uiMax)) { - - _uiMax = ~0U >> (8 * sizeof(size_t) - sizeInBits); - } - } - - // Base - return base::fromXml(xmlElement, serializingContext); -} - -// Conversion (tuning) -bool CIntegerParameterType::toBlackboard(const string &strValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const -{ - // Hexa - bool bValueProvidedAsHexa = utility::isHexadecimal(strValue); - - // Get integer value from the string provided - int64_t iData; - - if (!convertValueFromString(strValue, iData, parameterAccessContext)) { - - return false; - } - - // Check against Min / Max - if (_bSigned) { - - if (bValueProvidedAsHexa && isEncodable((uint64_t)iData, !bValueProvidedAsHexa)) { - - // Sign extend - signExtend(iData); - } - - if (!checkValueAgainstRange<int64_t>(strValue, iData, (int32_t)_uiMin, (int32_t)_uiMax, - parameterAccessContext, bValueProvidedAsHexa)) { - - return false; - } - } else { - - if (!checkValueAgainstRange<uint64_t>(strValue, iData, _uiMin, _uiMax, - parameterAccessContext, bValueProvidedAsHexa)) { - - return false; - } - } - - uiValue = (uint32_t)iData; - - return true; -} - -bool CIntegerParameterType::fromBlackboard(string &strValue, const uint32_t &value, - CParameterAccessContext ¶meterAccessContext) const -{ - // Check unsigned value is encodable - assert(isEncodable(value, false)); - - // Format - ostringstream stream; - - // Take care of format - if (parameterAccessContext.valueSpaceIsRaw() && parameterAccessContext.outputRawFormatIsHex()) { - - // Hexa display with unecessary bits cleared out - stream << "0x" << std::hex << std::uppercase << std::setw(static_cast<int>(getSize() * 2)) - << std::setfill('0') << value; - } else { - - if (_bSigned) { - - int32_t iValue = value; - - // Sign extend - signExtend(iValue); - - stream << iValue; - } else { - - stream << value; - } - } - - strValue = stream.str(); - - return true; -} - -// Value access -// Integer -bool CIntegerParameterType::toBlackboard(uint32_t uiUserValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const -{ - if (uiUserValue < _uiMin || uiUserValue > _uiMax) { - - parameterAccessContext.setError("Value out of range"); - - return false; - } - // Do assign - uiValue = uiUserValue; - - return true; -} - -bool CIntegerParameterType::fromBlackboard(uint32_t &uiUserValue, uint32_t uiValue, - CParameterAccessContext & /*ctx*/) const -{ - // Do assign - uiUserValue = uiValue; - - return true; -} - -// Signed Integer -bool CIntegerParameterType::toBlackboard(int32_t iUserValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const -{ - if (iUserValue < (int32_t)_uiMin || iUserValue > (int32_t)_uiMax) { - - parameterAccessContext.setError("Value out of range"); - - return false; - } - // Do assign - uiValue = iUserValue; - - return true; -} - -bool CIntegerParameterType::fromBlackboard(int32_t &iUserValue, uint32_t uiValue, - CParameterAccessContext & /*ctx*/) const -{ - int32_t iValue = uiValue; - - // Sign extend - signExtend(iValue); - - // Do assign - iUserValue = iValue; - - return true; -} - -// Double -bool CIntegerParameterType::toBlackboard(double dUserValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const -{ - // Check if there's an adaptation object available - const CParameterAdaptation *pParameterAdaption = getParameterAdaptation(); - - if (!pParameterAdaption) { - - // Reject request and let upper class handle the error - return base::toBlackboard(dUserValue, uiValue, parameterAccessContext); - } - - // Do the conversion - int64_t iConvertedValue = pParameterAdaption->fromUserValue(dUserValue); - - // Check against range - if (_bSigned) { - - if (iConvertedValue < (int32_t)_uiMin || iConvertedValue > (int32_t)_uiMax) { - - parameterAccessContext.setError("Value out of range"); - - return false; - } - } else { - - if (iConvertedValue < _uiMin || iConvertedValue > _uiMax) { - - parameterAccessContext.setError("Value out of range"); - - return false; - } - } - - // Do assign - uiValue = (uint32_t)iConvertedValue; - - return true; -} - -bool CIntegerParameterType::fromBlackboard(double &dUserValue, uint32_t uiValue, - CParameterAccessContext ¶meterAccessContext) const -{ - // Check if there's an adaptation object available - const CParameterAdaptation *pParameterAdaption = getParameterAdaptation(); - - if (!pParameterAdaption) { - - // Reject request and let upper class handle the error - return base::fromBlackboard(dUserValue, uiValue, parameterAccessContext); - } - - int64_t iValueToConvert; - - // Deal with signed data - if (_bSigned) { - - int32_t iValue = uiValue; - - signExtend(iValue); - - iValueToConvert = iValue; - } else { - - iValueToConvert = uiValue; - } - - // Do the conversion - dUserValue = pParameterAdaption->toUserValue(iValueToConvert); - - return true; -} - -// Default value handling (simulation only) -uint32_t CIntegerParameterType::getDefaultValue() const -{ - return _uiMin; -} - -int CIntegerParameterType::toPlainInteger(int iSizeOptimizedData) const -{ - if (_bSigned) { - - signExtend(iSizeOptimizedData); - } - - return base::toPlainInteger(iSizeOptimizedData); -} - -// Convert value provided by the user as a string into an int64 -bool CIntegerParameterType::convertValueFromString( - const string &strValue, int64_t &iData, CParameterAccessContext ¶meterAccessContext) const -{ - - // Reset errno to check if it is updated during the conversion (strtol/strtoul) - errno = 0; - char *pcStrEnd; - - // Convert the input string - if (_bSigned) { - - iData = strtoll(strValue.c_str(), &pcStrEnd, 0); - } else { - - iData = strtoull(strValue.c_str(), &pcStrEnd, 0); - } - - // Conversion error when the input string does not contain only digits or the number is out of - // range (int32_t type) - if (errno || (*pcStrEnd != '\0')) { - - string strError; - strError = "Impossible to convert value " + strValue + " for " + getKind(); - - parameterAccessContext.setError(strError); - - return false; - } - - return true; -} - -// Range checking -template <typename type> -bool CIntegerParameterType::checkValueAgainstRange(const string &strValue, type value, - type minValue, type maxValue, - CParameterAccessContext ¶meterAccessContext, - bool bHexaValue) const -{ - if (value < minValue || value > maxValue) { - - ostringstream stream; - - stream << "Value " << strValue << " standing out of admitted range ["; - - if (bHexaValue) { - - stream << "0x" << std::hex << std::uppercase - << std::setw(static_cast<int>(getSize() * 2)) << std::setfill('0'); - // Format Min - stream << minValue; - // Format Max - stream << maxValue; - - } else { - - stream << minValue << ", " << maxValue; - } - - stream << "] for " << getKind(); - - parameterAccessContext.setError(stream.str()); - - return false; - } - return true; -} - -// Adaptation element retrieval -const CParameterAdaptation *CIntegerParameterType::getParameterAdaptation() const -{ - return static_cast<const CParameterAdaptation *>(findChildOfKind("Adaptation")); -} - -// From IXmlSource -void CIntegerParameterType::toXml(CXmlElement &xmlElement, - CXmlSerializingContext &serializingContext) const -{ - // Sign - xmlElement.setAttribute("Signed", _bSigned); - - if (_bSigned) { - - // Mininmum - xmlElement.setAttribute("Min", (int32_t)_uiMin); - - // Maximum - xmlElement.setAttribute("Max", (int32_t)_uiMax); - - } else { - - // Minimum - xmlElement.setAttribute("Min", _uiMin); - - // Maximum - xmlElement.setAttribute("Max", _uiMax); - } - - // Size - xmlElement.setAttribute("Size", getSize() * 8); - - base::toXml(xmlElement, serializingContext); -} diff --git a/upstream/parameter/IntegerParameterType.h b/upstream/parameter/IntegerParameterType.h index bf7bc97..797cd44 100644 --- a/upstream/parameter/IntegerParameterType.h +++ b/upstream/parameter/IntegerParameterType.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2016, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,79 +29,317 @@ */ #pragma once -#include "ParameterType.h" +#include "BaseIntegerParameterType.h" +#include "ParameterAdaptation.h" +#include "ParameterAccessContext.h" +#include <convert.hpp> + +#include <type_traits> +#include <sstream> #include <string> #include <limits> +#include <iomanip> + +namespace detail +{ +template <bool isSigned, size_t size> +struct IntegerTraits +{ + static_assert(size == 8 or size == 16 or size == 32, + "IntegerParameterType size must be 8, 16 or 32."); + +private: + // Assumes that size is either 8, 16 or 32, which is ensured by the static_assert above. + using Signed = typename std::conditional< + size == 8, int8_t, typename std::conditional<size == 16, int16_t, int32_t>::type>::type; + using Unsigned = typename std::make_unsigned<Signed>::type; -class CParameterAdaptation; +public: + using CType = typename std::conditional<isSigned, Signed, Unsigned>::type; +}; +} // namespace detail -class CIntegerParameterType : public CParameterType +template <bool isSigned, size_t bitSize> +class CIntegerParameterType : public CBaseIntegerParameterType { +private: + using Base = CBaseIntegerParameterType; + using CType = typename detail::IntegerTraits<isSigned, bitSize>::CType; + + template <class UserType> + bool doToBlackboard(UserType userValue, uint32_t &uiValue, + CParameterAccessContext ¶meterAccessContext) const + { + { + if (userValue < static_cast<UserType>(_min) || + userValue > static_cast<UserType>(_max)) { + + parameterAccessContext.setError("Value out of range"); + return false; + } + // Do assign + uiValue = userValue; + + return true; + } + } + public: - CIntegerParameterType(const std::string &strName); + CIntegerParameterType(const std::string &name) : Base(name){}; // From IXmlSink - bool fromXml(const CXmlElement &xmlElement, - CXmlSerializingContext &serializingContext) override; + bool fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) override + { + setSize(bitSize / 8); + + xmlElement.getAttribute("Min", _min); + xmlElement.getAttribute("Max", _max); + + if (_min > _max) { + serializingContext.setError("The range of allowed value is empty (" + + std::to_string(_min) + " > " + std::to_string(_max) + ")."); + return false; + } + + // Base + return Base::fromXml(xmlElement, serializingContext); + } // From IXmlSource - void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const override; + void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const override + { + xmlElement.setAttribute("Signed", isSigned); - /// Conversion - // String - bool toBlackboard(const std::string &strValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const override; - bool fromBlackboard(std::string &strValue, const uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const override; + xmlElement.setAttribute("Min", _min); + xmlElement.setAttribute("Max", _max); + + xmlElement.setAttribute("Size", bitSize); + + Base::toXml(xmlElement, serializingContext); + } + + bool fromBlackboard(std::string &strValue, const uint32_t &value, + CParameterAccessContext ¶meterAccessContext) const override + { + // Format + std::ostringstream stream; + + // Take care of format + if (parameterAccessContext.valueSpaceIsRaw() && + parameterAccessContext.outputRawFormatIsHex()) { + + // Hexa display with unecessary bits cleared out + stream << "0x" << std::hex << std::uppercase + << std::setw(static_cast<int>(getSize() * 2)) << std::setfill('0') << value; + } else { + + if (isSigned) { + + int32_t iValue = value; + + // Sign extend + signExtend(iValue); + + stream << iValue; + } else { + + stream << value; + } + } + + strValue = stream.str(); + + return true; + } + + // Value access // Integer bool toBlackboard(uint32_t uiUserValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const override; - bool fromBlackboard(uint32_t &uiUserValue, uint32_t uiValue, - CParameterAccessContext ¶meterAccessContext) const override; + CParameterAccessContext ¶meterAccessContext) const override + { + return doToBlackboard(uiUserValue, uiValue, parameterAccessContext); + } + // Signed Integer bool toBlackboard(int32_t iUserValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const override; - bool fromBlackboard(int32_t &iUserValue, uint32_t uiValue, - CParameterAccessContext ¶meterAccessContext) const override; + CParameterAccessContext ¶meterAccessContext) const override + { + return doToBlackboard(iUserValue, uiValue, parameterAccessContext); + } + // Double bool toBlackboard(double dUserValue, uint32_t &uiValue, - CParameterAccessContext ¶meterAccessContext) const override; + CParameterAccessContext ¶meterAccessContext) const override + { + // Check if there's an adaptation object available + const CParameterAdaptation *pParameterAdaption = getParameterAdaptation(); + + if (!pParameterAdaption) { + + // Reject request and let upper class handle the error + return Base::toBlackboard(dUserValue, uiValue, parameterAccessContext); + } + + // Do the conversion + int64_t iConvertedValue = pParameterAdaption->fromUserValue(dUserValue); + + if (iConvertedValue < _min || iConvertedValue > _max) { + + parameterAccessContext.setError("Value out of range"); + + return false; + } + + // Do assign + uiValue = (uint32_t)iConvertedValue; + + return true; + } + + template <class T> + bool toBlackboard(const std::string &strValue, uint32_t &uiValue, + CParameterAccessContext ¶meterAccessContext) const + { + T intermediate; + if (not convertTo(strValue, intermediate)) { + std::string strError; + strError = "Impossible to convert value " + strValue + " for " + getKind(); + + parameterAccessContext.setError(strError); + return false; + } + + CType value = static_cast<CType>(intermediate); + if (!checkValueAgainstRange(strValue, intermediate, parameterAccessContext, + utility::isHexadecimal(strValue))) { + return false; + } + uiValue = (uint32_t)value; + + return true; + } + + // String + bool toBlackboard(const std::string &strValue, uint32_t &uiValue, + CParameterAccessContext ¶meterAccessContext) const override + { + if (isSigned and utility::isHexadecimal(strValue)) { + using Intermediate = typename std::make_unsigned<CType>::type; + + return toBlackboard<Intermediate>(strValue, uiValue, parameterAccessContext); + } else { + return toBlackboard<CType>(strValue, uiValue, parameterAccessContext); + } + } + bool fromBlackboard(double &dUserValue, uint32_t uiValue, - CParameterAccessContext ¶meterAccessContext) const override; + CParameterAccessContext ¶meterAccessContext) const override + { + // Check if there's an adaptation object available + const CParameterAdaptation *pParameterAdaption = getParameterAdaptation(); + + if (!pParameterAdaption) { + + // Reject request and let upper class handle the error + return Base::fromBlackboard(dUserValue, uiValue, parameterAccessContext); + } + + int64_t iValueToConvert; + + // Deal with signed data + if (isSigned) { + + int32_t iValue = uiValue; + + signExtend(iValue); + + iValueToConvert = iValue; + } else { + + iValueToConvert = uiValue; + } + + // Do the conversion + dUserValue = pParameterAdaption->toUserValue(iValueToConvert); + + return true; + } // Default value handling (simulation only) - uint32_t getDefaultValue() const override; + uint32_t getDefaultValue() const override { return _min; } // Element properties - void showProperties(std::string &strResult) const override; + void showProperties(std::string &strResult) const override + { + Base::showProperties(strResult); - // Integer conversion - int toPlainInteger(int iSizeOptimizedData) const override; + std::ostringstream stream; + stream << "Signed: " << (isSigned ? "yes" : "no") << "\n" + << "Min: " << _min << "\n" + << "Max: " << _max << "\n"; - // CElement - std::string getKind() const override; + strResult += stream.str(); -private: - // Returns true if children dynamic creation is to be dealt with - bool childrenAreDynamic() const override; + // Check if there's an adaptation object available + const CParameterAdaptation *pParameterAdaption = getParameterAdaptation(); + + if (pParameterAdaption) { + + // Display adaptation properties + strResult += "Adaptation:\n"; + + pParameterAdaption->showProperties(strResult); + } + } + + // Integer conversion + int toPlainInteger(int iSizeOptimizedData) const override + { + if (isSigned) { + + signExtend(iSizeOptimizedData); + } - // Conversion from std::string - bool convertValueFromString(const std::string &strValue, int64_t &iData, - CParameterAccessContext ¶meterAccessContext) const; + return Base::toPlainInteger(iSizeOptimizedData); + } // Range checking - template <typename type> - bool checkValueAgainstRange(const std::string &strValue, type value, type minValue, - type maxValue, CParameterAccessContext ¶meterAccessContext, - bool bHexaValue) const; + bool checkValueAgainstRange(const std::string &strValue, CType value, + CParameterAccessContext ¶meterAccessContext, + bool bHexaValue) const + { + if (value < _min || value > _max) { - // Adaptation element retrieval - const CParameterAdaptation *getParameterAdaptation() const; + std::ostringstream stream; - // Signing - bool _bSigned{false}; + stream << "Value " << strValue << " standing out of admitted range ["; + + if (bHexaValue) { + + stream << "0x" << std::hex << std::uppercase + << std::setw(static_cast<int>(getSize() * 2)) << std::setfill('0'); + // Format Min + stream << _min; + // Format Max + stream << _max; + + } else { + + stream << _min << ", " << _max; + } + + stream << "] for " << getKind(); + + parameterAccessContext.setError(stream.str()); + + return false; + } + return true; + } + +private: // Range - uint32_t _uiMin{0}; - uint32_t _uiMax{std::numeric_limits<uint32_t>::max()}; + CType _min{std::numeric_limits<CType>::min()}; + CType _max{std::numeric_limits<CType>::max()}; }; diff --git a/upstream/parameter/ParameterMgr.cpp b/upstream/parameter/ParameterMgr.cpp index d56277c..debf81d 100644 --- a/upstream/parameter/ParameterMgr.cpp +++ b/upstream/parameter/ParameterMgr.cpp @@ -46,7 +46,7 @@ #include "ComponentInstance.h" #include "ParameterBlockType.h" #include "BooleanParameterType.h" -#include "IntegerParameterType.h" +#include "IntegerParameterBuilder.h" #include "FixedPointParameterType.h" #include "FloatingPointParameterType.h" #include "ParameterBlackboard.h" @@ -2777,8 +2777,7 @@ void CParameterMgr::feedElementLibraries() "ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>()); pParameterCreationLibrary->addElementBuilder( "BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>()); - pParameterCreationLibrary->addElementBuilder( - "IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>()); + pParameterCreationLibrary->addElementBuilder("IntegerParameter", new IntegerParameterBuilder()); pParameterCreationLibrary->addElementBuilder( "LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>()); pParameterCreationLibrary->addElementBuilder( diff --git a/upstream/remote-process/README.md b/upstream/remote-process/README.md index 128dc3f..7341552 100644 --- a/upstream/remote-process/README.md +++ b/upstream/remote-process/README.md @@ -20,12 +20,4 @@ parameter-framework client. remote-process <host> <port> <command> -You can get all available commands with the `help` command. - -You may also run a batch of commands by passing them on remote-process' -standard input: - - remote-process <host> <port> < file - -You should not use this feature in an interactive mode, because the -communication may timeout if you're typing your commands too slowly. +You can get all available commands with the `help` command.
\ No newline at end of file diff --git a/upstream/skeleton-subsystem/CMakeLists.txt b/upstream/skeleton-subsystem/CMakeLists.txt index 4016a41..807a4db 100644 --- a/upstream/skeleton-subsystem/CMakeLists.txt +++ b/upstream/skeleton-subsystem/CMakeLists.txt @@ -26,8 +26,10 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# working on 2.8.12 - broken on older versions -cmake_minimum_required(VERSION 2.8.12) +# Known to work with CMake 3.2.2, might work with older 3.x versions, will not +# work with versions prior to 3.0.0. + +cmake_minimum_required(VERSION 3.2.2) project(parameter-framework-plugins-skeleton) diff --git a/upstream/skeleton-subsystem/SkeletonSubsystem.cpp b/upstream/skeleton-subsystem/SkeletonSubsystem.cpp index 227d71a..9e555d7 100644 --- a/upstream/skeleton-subsystem/SkeletonSubsystem.cpp +++ b/upstream/skeleton-subsystem/SkeletonSubsystem.cpp @@ -32,11 +32,9 @@ #include "SubsystemObjectFactory.h" #include "SkeletonSubsystemObject.h" -#define base CSubsystem - // Implementation CSkeletonSubsystem::CSkeletonSubsystem(const std::string &strName, core::log::Logger &logger) - : base(strName, logger) + : CSubsystem(strName, logger) { // Provide mapping keys to upper layer addContextMappingKey("Owner"); diff --git a/upstream/test/functional-tests/CMakeLists.txt b/upstream/test/functional-tests/CMakeLists.txt index fdc0f69..bece75f 100644 --- a/upstream/test/functional-tests/CMakeLists.txt +++ b/upstream/test/functional-tests/CMakeLists.txt @@ -36,6 +36,7 @@ if(BUILD_TESTING) add_executable(parameterFunctionalTest Basic.cpp FloatingPoint.cpp + Integer.cpp Handle.cpp AutoSync.cpp) diff --git a/upstream/test/functional-tests/Integer.cpp b/upstream/test/functional-tests/Integer.cpp new file mode 100644 index 0000000..db39f84 --- /dev/null +++ b/upstream/test/functional-tests/Integer.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2016, 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. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" +#include "BinaryCopy.hpp" + +#include <catch.hpp> + +#include <string> + +using std::string; + +namespace parameterFramework +{ + +const auto validIntegerInstances = Config{&Config::instances, + // Default for integers is unsigned/32bits + R"(<IntegerParameter Name="Empty"/> + <IntegerParameter Name="trivial" Size="8" Signed="true"/> + <IntegerParameter Name="nominal" Size="8" Signed="true" Min="-50" Max="12"/> + <IntegerParameter Name="negMinMaxS8" Size="8" Signed="true" Min="-120" Max="-110"/> + <IntegerParameter Name="posMinMaxS8" Size="8" Signed="true" Min="90" Max="100"/> + <IntegerParameter Name="defaultMinS8" Size="8" Signed="true" Min="-128"/> + <IntegerParameter Name="defaultMaxS8" Size="8" Signed="true" Max="127"/> + <IntegerParameter Name="defaultMinU8" Size="8" Signed="false" Min="0"/> + <IntegerParameter Name="defaultMaxU8" Size="8" Signed="false" Max="255"/> + <IntegerParameter Name="defaultMinS16" Size="16" Signed="true" Min="-32768"/> + <IntegerParameter Name="defaultMaxS16" Size="16" Signed="true" Max="32767"/> + <IntegerParameter Name="defaultMinU16" Size="16" Signed="false" Min="0"/> + <IntegerParameter Name="defaultMaxU16" Size="16" Signed="false" Max="65535"/> + <IntegerParameter Name="defaultMinS32" Size="32" Signed="true" Min="-2147483648"/> + <IntegerParameter Name="defaultMaxS32" Size="32" Signed="true" Max="2147483647"/> + <IntegerParameter Name="defaultMinU32" Size="32" Signed="false" Min="0"/> + <IntegerParameter Name="defaultMaxU32" Size="32" Signed="false" Max="4294967295"/>)"}; +const auto &invalidIntegerParameters = Tests<string>{ + {"invalid Size(64)", "<IntegerParameter Name='error' Size='64'/>"}, + {"minimum > maximum", "<IntegerParameter Name='error' Min='1' Max='0'/>"}, + {"S8 minimum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='true' Min='128'/>"}, + {"S8 minimum < MinRange", "<IntegerParameter Name='error' Size='8' Signed='true' Min='-129'/>"}, + {"S8 maximum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='true' Max='128'/>"}, + {"S8 maximum < MinRange", "<IntegerParameter Name='error' Size='8' Signed='true' Max='-129'/>"}, + {"U8 minimum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='false' Min='256'/>"}, + {"U8 maximum > MaxRange", "<IntegerParameter Name='error' Size='8' Signed='false' Max='256'/>"}, + {"S16 minimum > MaxRange", + "<IntegerParameter Name='error' Size='16' Signed='true' Min='32768'/>"}, + {"S16 minimum < MinRange", + "<IntegerParameter Name='error' Size='16' Signed='true' Min='-32769'/>"}, + {"S16 maximum > MaxRange", + "<IntegerParameter Name='error' Size='16' Signed='true' Max='32768'/>"}, + {"S16 maximum < MinRange", + "<IntegerParameter Name='error' Size='16' Signed='true' Max='-32769'/>"}, + {"U16 minimum > MaxRange", + "<IntegerParameter Name='error' Size='16' Signed='false' Min='65536'/>"}, + {"U16 maximum > MaxRange", + "<IntegerParameter Name='error' Size='16' Signed='false' Max='65536'/>"}}; + +struct IntegerPF : public ParameterFramework +{ + IntegerPF() : ParameterFramework{std::move(validIntegerInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid Integer types XML structure", "[Integer types]") +{ + for (auto &vec : invalidIntegerParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer types]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal"; + + AND_THEN ("Set/Get a integer type parameter in real value space") { + + for (auto &vec : Tests<string>{ + {"(too high)", "13"}, {"(too low)", "-51"}, {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests<string>{ + {"(upper limit)", "12"}, {"(lower limit)", "-50"}, {"(inside range)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get integer type parameter handle") { + ElementHandle handle{*this, path}; + /** @FIXME: 'set' operations on a ParameterHandle are silently + * ignored in tuning mode. Does it make sense ? */ + REQUIRE_NOTHROW(setTuningMode(false)); + + for (auto &vec : Tests<int32_t>{ + {"(upper limit)", 12}, {"(lower limit)", -50}, {"(inside range)", 0}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsSignedInteger(vec.payload)); + int32_t getValueBack; + REQUIRE_NOTHROW(handle.getAsSignedInteger(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + for (auto &vec : Tests<int32_t>{ + {"(too high)", 13}, {"(too low)", -51}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsSignedInteger(vec.payload), Exception); + } + } + } + } + } +} +} diff --git a/upstream/tools/xmlGenerator/EddParser.py b/upstream/tools/xmlGenerator/EddParser.py index 6465758..7f8a5b9 100755 --- a/upstream/tools/xmlGenerator/EddParser.py +++ b/upstream/tools/xmlGenerator/EddParser.py @@ -886,7 +886,7 @@ the rest is the rest of the line.""" if verbose : sys.stderr.write("{}\n".format(ex)) - except MySyntaxErro as ex : + except MySyntaxError as ex : ex.setLine(line, num + 1) raise diff --git a/upstream/utility/PfError.hpp b/upstream/utility/PfError.hpp new file mode 100644 index 0000000..233cfcb --- /dev/null +++ b/upstream/utility/PfError.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016, 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. + */ +#pragma once + +#include <stdexcept> + +struct PfError : public std::runtime_error +{ + using std::runtime_error::runtime_error; +}; diff --git a/upstream/xmlserializer/XmlElement.cpp b/upstream/xmlserializer/XmlElement.cpp index 5fac6d4..9c3950d 100644 --- a/upstream/xmlserializer/XmlElement.cpp +++ b/upstream/xmlserializer/XmlElement.cpp @@ -28,9 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "XmlElement.h" +#include "PfError.hpp" #include <libxml/tree.h> #include "convert.hpp" #include <stdlib.h> +#include <stdexcept> using std::string; @@ -79,10 +81,6 @@ bool CXmlElement::hasAttribute(const string &strAttributeName) const template <> bool CXmlElement::getAttribute<std::string>(const string &name, string &value) const { - if (!hasAttribute(name)) { - return false; - } - string backup = value; xmlChar *pucXmlValue = xmlGetProp((xmlNode *)_pXmlElement, (const xmlChar *)name.c_str()); if (pucXmlValue == nullptr) { @@ -108,7 +106,7 @@ bool CXmlElement::getAttribute(const std::string &name, T &value) const T backup = value; if (!convertTo<T>(rawValue, value)) { value = backup; - return false; + throw PfError("\'" + rawValue + "\' could not be parsed as the requested type."); } return true; @@ -266,6 +264,8 @@ bool CXmlElement::CChildIterator::next(CXmlElement &xmlChildElement) template bool CXmlElement::getAttribute(const std::string &name, std::string &value) const; template bool CXmlElement::getAttribute(const std::string &name, bool &value) const; +template bool CXmlElement::getAttribute(const std::string &name, signed char &value) const; +template bool CXmlElement::getAttribute(const std::string &name, unsigned char &value) const; template bool CXmlElement::getAttribute(const std::string &name, short &value) const; template bool CXmlElement::getAttribute(const std::string &name, unsigned short &value) const; template bool CXmlElement::getAttribute(const std::string &name, int &value) const; @@ -279,6 +279,8 @@ template bool CXmlElement::getAttribute(const std::string &name, double &value) template void CXmlElement::setAttribute(const std::string &name, const std::string &value); template void CXmlElement::setAttribute(const std::string &name, const bool &value); +template void CXmlElement::setAttribute(const std::string &name, const signed char &value); +template void CXmlElement::setAttribute(const std::string &name, const unsigned char &value); template void CXmlElement::setAttribute(const std::string &name, const short &value); template void CXmlElement::setAttribute(const std::string &name, const unsigned short &value); template void CXmlElement::setAttribute(const std::string &name, const int &value); |