From d8f1b760e463a5477cd8f04c5171c76607caea36 Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Thu, 2 Feb 2017 15:25:18 +0100 Subject: [PATCH 01/10] Functional test: Add logarithmic format test This patch is adding basic test for Logarithmic format. Signed-off-by: Sebastien Guiriec --- test/functional-tests/CMakeLists.txt | 1 + test/functional-tests/Logarithmic.cpp | 114 ++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 test/functional-tests/Logarithmic.cpp diff --git a/test/functional-tests/CMakeLists.txt b/test/functional-tests/CMakeLists.txt index f0c4d6460..51dcb4524 100644 --- a/test/functional-tests/CMakeLists.txt +++ b/test/functional-tests/CMakeLists.txt @@ -38,6 +38,7 @@ if(BUILD_TESTING) FloatingPoint.cpp FixedPoint.cpp Integer.cpp + Logarithmic.cpp Handle.cpp AutoSync.cpp) diff --git a/test/functional-tests/Logarithmic.cpp b/test/functional-tests/Logarithmic.cpp new file mode 100644 index 000000000..137338e47 --- /dev/null +++ b/test/functional-tests/Logarithmic.cpp @@ -0,0 +1,114 @@ +/* + * 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. + */ + +#include "Config.hpp" +#include "ParameterFramework.hpp" +#include "ElementHandle.hpp" +#include "Test.hpp" +#include "BinaryCopy.hpp" + +#include + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validLogarithmicInstances = Config{ + &Config::instances, + // Size is fixed at 32 and as such is optional */ + R"( + )"}; +const auto &invalidLogarithmicParameters = Tests{ + {"invalid Size(64)", " " + ""}, + {"minimum > maximum", " "}, + {"logBase =1", " " + " " + ""}, + {"logBase negative", " "}}; + +struct LogarithmicsPF : public ParameterFramework +{ + LogarithmicsPF() : ParameterFramework{std::move(validLogarithmicInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid Logarithmic points XML structure", "[Logarithmic Type]") +{ + for (auto &vec : invalidLogarithmicParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(LogarithmicsPF, "Logarithmic points", "[Logarithmic Type]") +{ + 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 Loagaritmic point parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "31"}, {"(too low)", "-145"}, {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "30"}, + {"(lower limit)", "-144"}, + {"(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); + } + } + } + } + } +} +} // namespace parameterFramework From f28f9fe881ec419f01fe9f621beececa929a4b6b Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 09:50:01 +0100 Subject: [PATCH 02/10] Functional test: Check rejection of Integer parameter in double format Integer parameter cannot be set in double format except in case of Linear or Logarithm Adaptation format. Signed-off-by: Sebastien Guiriec --- test/functional-tests/Integer.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/functional-tests/Integer.cpp b/test/functional-tests/Integer.cpp index db39f8428..b4d3e08d7 100644 --- a/test/functional-tests/Integer.cpp +++ b/test/functional-tests/Integer.cpp @@ -154,6 +154,30 @@ SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer types]") } } } + + AND_THEN ("Set/Get double 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{ + {"(upper limit)", 12.0f}, + {"(lower limit)", -50.0f}, + {"(inside range)", 0.0f}, + }) { + GIVEN ("A valid value (rejected not supported)" + vec.title) { + CHECK_THROWS_AS(handle.setAsDouble(vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(too high)", 12.01f}, {"(too low)", -50.01f}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsDouble(vec.payload), Exception); + } + } + } } } } From be4adf73e27bdfa42d36a31a4ba324f02505cfb4 Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 10:29:42 +0100 Subject: [PATCH 03/10] Functional test: Add Linear Adaptation tests. This patch is adding Linear adaptation format unit test for Parameter Framework. Signed-off-by: Sebastien Guiriec --- test/functional-tests/CMakeLists.txt | 1 + test/functional-tests/Linear.cpp | 144 +++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 test/functional-tests/Linear.cpp diff --git a/test/functional-tests/CMakeLists.txt b/test/functional-tests/CMakeLists.txt index 51dcb4524..7f8e24817 100644 --- a/test/functional-tests/CMakeLists.txt +++ b/test/functional-tests/CMakeLists.txt @@ -38,6 +38,7 @@ if(BUILD_TESTING) FloatingPoint.cpp FixedPoint.cpp Integer.cpp + Linear.cpp Logarithmic.cpp Handle.cpp AutoSync.cpp) diff --git a/test/functional-tests/Linear.cpp b/test/functional-tests/Linear.cpp new file mode 100644 index 000000000..363567c06 --- /dev/null +++ b/test/functional-tests/Linear.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2017, 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 + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validLinearInstances = Config{ + &Config::instances, + // Size is fixed at 32 and as such is optional */ + R"( + )"}; +const auto &invalidLinearParameters = Tests{ + {"invalid Size(64)", " " + ""}, + {"minimum > maximum", " "}, + {"SlopeDenominator=0", + " " + " " + ""}}; + +struct LinearsPF : public ParameterFramework +{ + LinearsPF() : ParameterFramework{std::move(validLinearInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid Linear points XML structure", "[Linear Type]") +{ + for (auto &vec : invalidLinearParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(LinearsPF, "Linear points", "[Linear Type]") +{ + 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 Loagaritmic point parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "301"}, + {"(too low)", "-1441"}, + {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "300"}, + {"(lower limit)", "-1440"}, + {"(inside range)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack = "-11"; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + + AND_THEN ("Set/Get double 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)); + REQUIRE_NOTHROW(setRawValueSpace(true)); + + /* nominal is defined as a Num=10,Denum=100 (division by 10). So limits should be 10 + * above Mina dn Max Integer value in order to get exception. */ + for (auto &vec : Tests{ + {"(upper limit)", 3000.0f}, + {"(lower limit)", -14400.0f}, + {"(inside range)", 0.0f}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsDouble(vec.payload)); + double getValueBack = 1.0f; + REQUIRE_NOTHROW(handle.getAsDouble(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + for (auto &vec : Tests{ + {"(too high)", 3010.0f}, {"(too low)", -14410.00f}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsDouble(vec.payload), Exception); + } + } + } + } + } +} +} // namespace parameterFramework From 73a8db82bdc8cc16b497299d47a66f94b5e24c65 Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 13:04:57 +0100 Subject: [PATCH 04/10] Parameter: Boolean: Fix Decimal out of range error. Fix missing false return for backboard synchronization. Signed-off-by: Sebastien Guiriec --- parameter/BooleanParameterType.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/parameter/BooleanParameterType.cpp b/parameter/BooleanParameterType.cpp index 66556d304..c6a5be41f 100644 --- a/parameter/BooleanParameterType.cpp +++ b/parameter/BooleanParameterType.cpp @@ -108,6 +108,7 @@ bool CBooleanParameterType::toBlackboard(uint32_t uiUserValue, uint32_t &uiValue if (uiUserValue > 1) { parameterAccessContext.setError("Value out of range"); + return false; } uiValue = uiUserValue; From 38df9168bd133bfb4862a06c1afc1e3ee93bd5ec Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 13:07:08 +0100 Subject: [PATCH 05/10] Functional test: Add Boolean type parameter tests. This patch is improving Boolean parameter Ynit test for setting in the different possible formats. Signed-off-by: Sebastien Guiriec --- test/functional-tests/Boolean.cpp | 147 +++++++++++++++++++++++++++ test/functional-tests/CMakeLists.txt | 1 + 2 files changed, 148 insertions(+) create mode 100644 test/functional-tests/Boolean.cpp diff --git a/test/functional-tests/Boolean.cpp b/test/functional-tests/Boolean.cpp new file mode 100644 index 000000000..4ade94380 --- /dev/null +++ b/test/functional-tests/Boolean.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2017, 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 + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validBooleanInstances = Config{&Config::instances, + // Default for integers is unsigned/32bits + R"( + )"}; + +struct BooleanPF : public ParameterFramework +{ + BooleanPF() : ParameterFramework{std::move(validBooleanInstances)} {} +}; + +SCENARIO_METHOD(BooleanPF, "Boolean types", "[Boolean 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 Boolean type parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "2"}, {"(too low)", "-1"}, {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "1"}, {"(lower limit)", "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{ + {"(upper limit)", 1}, {"(lower limit)", 0}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsInteger(vec.payload)); + uint32_t getValueBack; + REQUIRE_NOTHROW(handle.getAsInteger(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + for (auto &vec : Tests{ + {"(too high)", 2}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsInteger(vec.payload), Exception); + } + } + } + + AND_THEN ("Set/Get a Boolean type parameter in real value space") { + ElementHandle handle{*this, path}; + REQUIRE_NOTHROW(setRawValueSpace(true)); + + for (auto &vec : Tests{ + {"(too high hexa)", "0x2"}, + {"(too high dec)", "2"}, + {"(too low hexa )", "0xFF"}, + {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(TRUE hexa)", "0x1"}, {"(TRUE dec)", "1"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == "1"); + } + } + for (auto &vec : Tests{ + {"(FALSE hexa)", "0x0"}, {"(FALSE dec)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == "0"); + } + } + } + } + } +} +} diff --git a/test/functional-tests/CMakeLists.txt b/test/functional-tests/CMakeLists.txt index 7f8e24817..9469579d1 100644 --- a/test/functional-tests/CMakeLists.txt +++ b/test/functional-tests/CMakeLists.txt @@ -35,6 +35,7 @@ if(BUILD_TESTING) # Add unit test add_executable(parameterFunctionalTest Basic.cpp + Boolean.cpp FloatingPoint.cpp FixedPoint.cpp Integer.cpp From b5ecca5d33620ecdc304b350e471309847ec99c4 Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 15:08:14 +0100 Subject: [PATCH 06/10] Functional test: Add BitParameter test cases Improve test coverage of BitParameter format. Signed-off-by: Sebastien Guiriec --- test/functional-tests/BitParameter.cpp | 130 +++++++++++++++++++++++++ test/functional-tests/CMakeLists.txt | 1 + 2 files changed, 131 insertions(+) create mode 100644 test/functional-tests/BitParameter.cpp diff --git a/test/functional-tests/BitParameter.cpp b/test/functional-tests/BitParameter.cpp new file mode 100644 index 000000000..8c9d71a55 --- /dev/null +++ b/test/functional-tests/BitParameter.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2017, 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 + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validBitParameterInstances = Config{ + &Config::instances, + // Default for integers is unsigned/32bits + R"()"}; + +const auto &invalidBitParameterParameters = + Tests{{"Too much bits", ""}, + {"Max too high", ""}}; + +struct BitParameterPF : public ParameterFramework +{ + BitParameterPF() : ParameterFramework{std::move(validBitParameterInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid BitParameter types XML structure", "[BitParameter types]") +{ + for (auto &vec : invalidBitParameterParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(BitParameterPF, "BitParameter types", "[BitParameter types]") +{ + GIVEN ("A valid XML structure file") { + THEN ("Start should succeed") { + CHECK_NOTHROW(start()); + REQUIRE_NOTHROW(setTuningMode(true)); + string path = "/test/test/nominal/treebits"; + + AND_THEN ("Set/Get a BitParameter type parameter in real value space") { + + for (auto &vec : Tests{ + {"(too high)", "7"}, {"(too low)", "-1"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "6"}, {"(lower limit)", "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 a BitParameter type parameter in real value space") { + ElementHandle handle{*this, path}; + REQUIRE_NOTHROW(setRawValueSpace(true)); + REQUIRE_NOTHROW(setHexOutputFormat(true)); + + for (auto &vec : Tests{ + {"(too high)", "0x7"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "0x6"}, {"(lower limit)", "0x0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } + } + } +} +} diff --git a/test/functional-tests/CMakeLists.txt b/test/functional-tests/CMakeLists.txt index 9469579d1..08dc9ff55 100644 --- a/test/functional-tests/CMakeLists.txt +++ b/test/functional-tests/CMakeLists.txt @@ -36,6 +36,7 @@ if(BUILD_TESTING) add_executable(parameterFunctionalTest Basic.cpp Boolean.cpp + BitParameter.cpp FloatingPoint.cpp FixedPoint.cpp Integer.cpp From 7d95b4c1f2638cda2d92a0c35c73afa00dca77ec Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 15:53:21 +0100 Subject: [PATCH 07/10] Functional Test: Add Raw Value for Integer test case. Add few additional test for Integer parameter in Hexa format. Signed-off-by: Sebastien Guiriec --- test/functional-tests/Integer.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/functional-tests/Integer.cpp b/test/functional-tests/Integer.cpp index b4d3e08d7..1a44ca3bc 100644 --- a/test/functional-tests/Integer.cpp +++ b/test/functional-tests/Integer.cpp @@ -130,6 +130,31 @@ SCENARIO_METHOD(IntegerPF, "Integer types", "[Integer types]") } } + AND_THEN ("Set/Get a integer type parameter in raw value space") { + REQUIRE_NOTHROW(setRawValueSpace(true)); + REQUIRE_NOTHROW(setHexOutputFormat(true)); + + for (auto &vec : Tests{ + {"(too high)", "0x0D"}, {"(too low)", "0xCD"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "0x0C"}, + {"(lower limit)", "0xCE"}, + {"(inside range)", "0x00"}, + }) { + 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 From 1f578f932a1cbb8eef576a2c50a6f11af465275d Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Fri, 3 Feb 2017 16:51:17 +0100 Subject: [PATCH 08/10] Functional test: Add EnumParameter additional test cases. Improve EnumParameter test coverage. Signed-off-by: Sebastien Guiriec --- test/functional-tests/CMakeLists.txt | 1 + test/functional-tests/EnumParameter.cpp | 166 ++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 test/functional-tests/EnumParameter.cpp diff --git a/test/functional-tests/CMakeLists.txt b/test/functional-tests/CMakeLists.txt index 08dc9ff55..c3d02d0ef 100644 --- a/test/functional-tests/CMakeLists.txt +++ b/test/functional-tests/CMakeLists.txt @@ -37,6 +37,7 @@ if(BUILD_TESTING) Basic.cpp Boolean.cpp BitParameter.cpp + EnumParameter.cpp FloatingPoint.cpp FixedPoint.cpp Integer.cpp diff --git a/test/functional-tests/EnumParameter.cpp b/test/functional-tests/EnumParameter.cpp new file mode 100644 index 000000000..5d1783703 --- /dev/null +++ b/test/functional-tests/EnumParameter.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2017, 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 + +#include + +using std::string; + +namespace parameterFramework +{ + +const auto validEnumParameterInstances = Config{ + &Config::instances, + // Default for integers is unsigned/32bits + R"()"}; + +const auto &invalidEnumParameterParameters = Tests{ + {"No Size", ""}}; + +struct EnumParameterPF : public ParameterFramework +{ + EnumParameterPF() : ParameterFramework{std::move(validEnumParameterInstances)} {} +}; + +SCENARIO_METHOD(LazyPF, "Invalid EnumParameter types XML structure", "[EnumParameter types]") +{ + for (auto &vec : invalidEnumParameterParameters) { + GIVEN ("intentional error: " + vec.title) { + create(Config{&Config::instances, vec.payload}); + THEN ("Start should fail") { + CHECK_THROWS_AS(mPf->start(), Exception); + } + } + } +} + +SCENARIO_METHOD(EnumParameterPF, "EnumParameter types", "[EnumParameter 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 EnumParameter type parameter in real value space") { + + for (auto &vec : Tests{ + {"(not a number)", "foobar"}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "on"}, {"(lower limit)", "off"}, + }) { + 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 a EnumParameter type parameter in raw value space") { + ElementHandle handle{*this, path}; + REQUIRE_NOTHROW(setRawValueSpace(true)); + + for (auto &vec : Tests{{"(too high)", "7"}, {"(too low)", "-1"}}) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "3"}, {"(lower limit)", "0"}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(setParameter(path, vec.payload)); + string getValueBack; + REQUIRE_NOTHROW(getParameter(path, getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + + REQUIRE_NOTHROW(setHexOutputFormat(true)); + + for (auto &vec : Tests{{"(too high)", "0x7"}, {"(too low)", "0xFF"}}) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(setParameter(path, vec.payload), Exception); + } + } + for (auto &vec : Tests{ + {"(upper limit)", "0x03"}, {"(lower limit)", "0x00"}, + }) { + 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 a EnumParameter type parameter in Integer value space") { + 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{ + {"(upper limit)", 3}, {"(lower limit)", 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{ + {"(too high)", 13}, {"(too low)", -51}, + }) { + GIVEN ("An invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsSignedInteger(vec.payload), Exception); + } + } + } + } + } +} +} From 1990be18a7b8b3c5cc04bc53bcace361ab1eb3ff Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Mon, 13 Feb 2017 09:47:33 +0100 Subject: [PATCH 09/10] Functional test: Improve Boolean test. Add missing Boolean type setting test for Blackboard synchronization Signed-off-by: Sebastien Guiriec --- test/functional-tests/Boolean.cpp | 18 ++++++++++++++++++ .../functional-tests/include/ElementHandle.hpp | 3 +++ 2 files changed, 21 insertions(+) diff --git a/test/functional-tests/Boolean.cpp b/test/functional-tests/Boolean.cpp index 4ade94380..c485abad7 100644 --- a/test/functional-tests/Boolean.cpp +++ b/test/functional-tests/Boolean.cpp @@ -81,6 +81,24 @@ SCENARIO_METHOD(BooleanPF, "Boolean types", "[Boolean types]") } } + AND_THEN ("Set/Get boolean 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{ + {"(upper limit)", true}, {"(lower limit)", false}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsBoolean(vec.payload)); + bool getValueBack; + REQUIRE_NOTHROW(handle.getAsBoolean(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 diff --git a/test/functional-tests/include/ElementHandle.hpp b/test/functional-tests/include/ElementHandle.hpp index a2f547540..335ac6781 100644 --- a/test/functional-tests/include/ElementHandle.hpp +++ b/test/functional-tests/include/ElementHandle.hpp @@ -76,6 +76,9 @@ class ElementHandle : private FailureWrapper<::ElementHandle> /** Wrap EH::getAsDouble to throw an exception on failure. */ void getAsDouble(double &value) const { mayFailCall(&EH::getAsDouble, value); } + void setAsBoolean(bool value) { mayFailCall(&EH::setAsBoolean, value); } + void getAsBoolean(bool &value) const { mayFailCall(&EH::getAsBoolean, value); } + void setAsInteger(uint32_t value) { mayFailCall(&EH::setAsInteger, value); } void getAsInteger(uint32_t &value) const { mayFailCall(&EH::getAsInteger, value); } void setAsIntegerArray(const std::vector &value) From 36497d59d79037f1a2ec9b9cf03c052a8543a05b Mon Sep 17 00:00:00 2001 From: Sebastien Guiriec Date: Mon, 13 Feb 2017 13:06:42 +0100 Subject: [PATCH 10/10] Functional test: Improve BitParameter in case of boolean Add BitParamter tests cases for boolean type format. Signed-off-by: Sebastien Guiriec --- test/functional-tests/BitParameter.cpp | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/functional-tests/BitParameter.cpp b/test/functional-tests/BitParameter.cpp index 8c9d71a55..0a0fb9508 100644 --- a/test/functional-tests/BitParameter.cpp +++ b/test/functional-tests/BitParameter.cpp @@ -45,7 +45,7 @@ namespace parameterFramework const auto validBitParameterInstances = Config{ &Config::instances, // Default for integers is unsigned/32bits - R"()"}; + R"()"}; const auto &invalidBitParameterParameters = Tests{{"Too much bits", "{ + {"(upper limit)", true}, {"(lower limit)", false}, + }) { + GIVEN ("Invalid value " + vec.title) { + CHECK_THROWS_AS(handle.setAsBoolean(vec.payload), Exception); + } + } + } + + AND_THEN ("Set/Get a BitParameter type parameter in boolean") { + path = "/test/test/nominal/bool"; + 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{ + {"(upper limit)", true}, {"(lower limit)", false}, + }) { + GIVEN ("A valid value " + vec.title) { + CHECK_NOTHROW(handle.setAsBoolean(vec.payload)); + bool getValueBack; + REQUIRE_NOTHROW(handle.getAsBoolean(getValueBack)); + CHECK(getValueBack == vec.payload); + } + } + } } } }