Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit b5ecca5

Browse files
author
Sebastien Guiriec
committed
Functional test: Add BitParameter test cases
Improve test coverage of BitParameter format. Signed-off-by: Sebastien Guiriec <sebastien.guiriec@intel.com>
1 parent 38df916 commit b5ecca5

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright (c) 2017, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its contributors
16+
* may be used to endorse or promote products derived from this software without
17+
* specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include "Config.hpp"
32+
#include "ParameterFramework.hpp"
33+
#include "ElementHandle.hpp"
34+
#include "Test.hpp"
35+
36+
#include <catch.hpp>
37+
38+
#include <string>
39+
40+
using std::string;
41+
42+
namespace parameterFramework
43+
{
44+
45+
const auto validBitParameterInstances = Config{
46+
&Config::instances,
47+
// Default for integers is unsigned/32bits
48+
R"(<BitParameterBlock Name="nominal" Size="16"><BitParameter Pos="1" Size="2" Name="twobits"/><BitParameter Pos="3" Size="3" Max="6" Name="treebits"/></BitParameterBlock>)"};
49+
50+
const auto &invalidBitParameterParameters =
51+
Tests<string>{{"Too much bits", "<BitParameterBlock Name='toomuchbits' Size='8'><BitParameter "
52+
"Pos='1' Size='2' Name='twobits'/><BitParameter Pos='3' "
53+
"Size='7' Name='toobits'/></BitParameterBlock>"},
54+
{"Max too high", "<BitParameterBlock Name='maxtoohigh' Size='8'><BitParameter "
55+
"Pos='1' Size='2' Name='twobits'/><BitParameter Pos='3' "
56+
"Size='2' Max='5' Name='toohigh'/></BitParameterBlock>"}};
57+
58+
struct BitParameterPF : public ParameterFramework
59+
{
60+
BitParameterPF() : ParameterFramework{std::move(validBitParameterInstances)} {}
61+
};
62+
63+
SCENARIO_METHOD(LazyPF, "Invalid BitParameter types XML structure", "[BitParameter types]")
64+
{
65+
for (auto &vec : invalidBitParameterParameters) {
66+
GIVEN ("intentional error: " + vec.title) {
67+
create(Config{&Config::instances, vec.payload});
68+
THEN ("Start should fail") {
69+
CHECK_THROWS_AS(mPf->start(), Exception);
70+
}
71+
}
72+
}
73+
}
74+
75+
SCENARIO_METHOD(BitParameterPF, "BitParameter types", "[BitParameter types]")
76+
{
77+
GIVEN ("A valid XML structure file") {
78+
THEN ("Start should succeed") {
79+
CHECK_NOTHROW(start());
80+
REQUIRE_NOTHROW(setTuningMode(true));
81+
string path = "/test/test/nominal/treebits";
82+
83+
AND_THEN ("Set/Get a BitParameter type parameter in real value space") {
84+
85+
for (auto &vec : Tests<string>{
86+
{"(too high)", "7"}, {"(too low)", "-1"},
87+
}) {
88+
GIVEN ("Invalid value " + vec.title) {
89+
CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
90+
}
91+
}
92+
for (auto &vec : Tests<string>{
93+
{"(upper limit)", "6"}, {"(lower limit)", "0"},
94+
}) {
95+
GIVEN ("A valid value " + vec.title) {
96+
CHECK_NOTHROW(setParameter(path, vec.payload));
97+
string getValueBack;
98+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
99+
CHECK(getValueBack == vec.payload);
100+
}
101+
}
102+
}
103+
104+
AND_THEN ("Set/Get a BitParameter type parameter in real value space") {
105+
ElementHandle handle{*this, path};
106+
REQUIRE_NOTHROW(setRawValueSpace(true));
107+
REQUIRE_NOTHROW(setHexOutputFormat(true));
108+
109+
for (auto &vec : Tests<string>{
110+
{"(too high)", "0x7"},
111+
}) {
112+
GIVEN ("Invalid value " + vec.title) {
113+
CHECK_THROWS_AS(setParameter(path, vec.payload), Exception);
114+
}
115+
}
116+
for (auto &vec : Tests<string>{
117+
{"(upper limit)", "0x6"}, {"(lower limit)", "0x0"},
118+
}) {
119+
GIVEN ("A valid value " + vec.title) {
120+
CHECK_NOTHROW(setParameter(path, vec.payload));
121+
string getValueBack;
122+
REQUIRE_NOTHROW(getParameter(path, getValueBack));
123+
CHECK(getValueBack == vec.payload);
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}

test/functional-tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if(BUILD_TESTING)
3636
add_executable(parameterFunctionalTest
3737
Basic.cpp
3838
Boolean.cpp
39+
BitParameter.cpp
3940
FloatingPoint.cpp
4041
FixedPoint.cpp
4142
Integer.cpp

0 commit comments

Comments
 (0)