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

Commit 7bb05e1

Browse files
committed
Merge pull request #331 from krocard/add-complex-edd-test
- Advance testing of XML generation from EDD. - XML generation from EDD test was not detecting failures. - XML generation from EDD had a bug that made impossible to use the sequence aware domain feature. - Fix various error message typos.
2 parents 49c3d81 + 719ae7c commit 7bb05e1

File tree

8 files changed

+115
-26
lines changed

8 files changed

+115
-26
lines changed

parameter/ParameterMgr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string &strDomain,
24012401
const string &strConfigurableElementPath,
24022402
string &strError)
24032403
{
2404-
LOG_CONTEXT("Adding configurable element '" + strConfigurableElementPath + "to domain '" +
2404+
LOG_CONTEXT("Adding configurable element '" + strConfigurableElementPath + "' to domain '" +
24052405
strDomain + "'");
24062406
// Check tuning mode
24072407
if (!checkTuningModeOn(strError)) {
@@ -2649,7 +2649,7 @@ bool CParameterMgr::exportDomainsXml(string &xmlDest, bool withSettings, bool to
26492649
string &errorMsg) const
26502650
{
26512651
LOG_CONTEXT("Exporting domains to " +
2652-
(toFile ? ('"' + xmlDest + '"') : " a user-provided buffer"));
2652+
(toFile ? ('"' + xmlDest + '"') : "a user-provided buffer"));
26532653

26542654
const CConfigurableDomains *configurableDomains = getConstConfigurableDomains();
26552655

@@ -2660,7 +2660,7 @@ bool CParameterMgr::exportSingleDomainXml(string &xmlDest, const string &domainN
26602660
bool withSettings, bool toFile, string &errorMsg) const
26612661
{
26622662
LOG_CONTEXT("Exporting single domain '" + domainName + "' to " +
2663-
(toFile ? ('"' + xmlDest + '"') : " a user-provided buffer"));
2663+
(toFile ? ('"' + xmlDest + '"') : "a user-provided buffer"));
26642664

26652665
// Element to be serialized
26662666
const CConfigurableDomain *requestedDomain =

test/xml-generator/PFConfig/structure.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ParameterBlock Name="block" ArrayLength="5">
1515
<FixedPointParameter Name="q2.5" Size="8" Integral="2" Fractional="5"/>
1616
<IntegerParameter Name="uint8" Signed="false" Size="8"/>
17-
<StringParameter Name="string" MaxLength="20"/>
17+
<StringParameter Name="string" MaxLength="50"/>
1818
</ParameterBlock>
1919

2020
</InstanceDefinition>

test/xml-generator/test.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,16 @@ def check(self, reference=None, expectedErrors=0):
7373

7474
if not reference:
7575
# The caller only wants to check the number of errors
76-
return True
76+
return
7777

7878
# The generation has succeeded as expected - let's compare with the reference.
79-
unified = difflib.unified_diff(reference,
80-
actual,
81-
fromfile="reference.xml",
82-
tofile="-",
83-
lineterm="")
84-
diffs = list(unified)
85-
if diffs:
86-
for d in diffs:
87-
print(d)
88-
return AssertionError("The result and the reference don't match.")
89-
return True
79+
if reference != actual:
80+
unified = difflib.unified_diff(reference,
81+
actual,
82+
fromfile="reference.xml",
83+
tofile="-",
84+
lineterm="")
85+
raise AssertionError("The result and the reference don't match:" + "\n".join(unified))
9086

9187

9288
basedir = os.path.dirname(sys.argv[0])
@@ -100,20 +96,21 @@ class TestCase(unittest.TestCase):
10096
os.path.join(basedir, "../../schemas"))
10197
nominal_vector = TestVector(os.path.join(vector_dir, "initialSettings.xml"),
10298
[os.path.join(vector_dir, "first.pfw"),
103-
os.path.join(vector_dir, "second.pfw")],
99+
os.path.join(vector_dir, "second.pfw"),
100+
os.path.join(vector_dir, "complex.pfw")],
104101
[os.path.join(vector_dir, "third.xml"),
105102
os.path.join(vector_dir, "fourth.xml")])
106103

107104
def test_nominal(self):
108105
tester = Tester(self.nominal_pfconfig, self.nominal_vector)
109-
self.assertTrue(tester.check(self.nominal_reference))
106+
tester.check(self.nominal_reference)
110107

111108
def test_nonfatalError(self):
112109
vector = copy.copy(self.nominal_vector)
113110
vector.edds.append(os.path.join(vector_dir, "duplicate.pfw"))
114111

115112
tester = Tester(self.nominal_pfconfig, vector)
116-
self.assertTrue(tester.check(self.nominal_reference, expectedErrors=1))
113+
tester.check(self.nominal_reference, expectedErrors=1)
117114

118115
if __name__ == "__main__":
119116
unittest.main()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
domain: sequenceAware sequenceAware
2+
3+
domainGroup: Red sequenceAware
4+
Colors Includes Red
5+
confType: On
6+
ANY
7+
Switch Is On
8+
# Expecting a empty tree of all (except for the last `Switch Is On` rule)
9+
ALL
10+
ALL
11+
ALL
12+
ALL
13+
ANY
14+
Switch Is On
15+
confType: On
16+
Switch Is On
17+
18+
domain: Black
19+
Colors Includes Green
20+
confGroup: green.confGroup
21+
# Should add a `.` in the conf name
22+
# Ie an empty confGroup in a legal name
23+
confGroup:
24+
25+
confType: On
26+
Switch Is On
27+
28+
# confGroups with the same name should not overwrite one another
29+
confGroup: On
30+
Colors Includes Green
31+
32+
conf: Blue.dot
33+
Colors Includes Blue
34+
35+
component: /Test/test
36+
component: block/3
37+
q2.5 = 1.18750
38+
string = 12 ab @ <![CDATA[ < > \n \0 ✔ "'\
39+
component: included
40+
bool = 1

test/xml-generator/testVector/reference.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,54 @@
168168
</Configuration>
169169
</Settings>
170170
</ConfigurableDomain>
171+
<ConfigurableDomain Name="sequenceAware" SequenceAware="true">
172+
<Configurations/>
173+
<ConfigurableElements/>
174+
<Settings/>
175+
</ConfigurableDomain>
176+
<ConfigurableDomain Name="Red.Black" SequenceAware="true">
177+
<Configurations>
178+
<Configuration Name="green.confGroup..On.Blue.dot">
179+
<CompoundRule Type="All">
180+
<SelectionCriterionRule SelectionCriterion="Colors" MatchesWhen="Includes" Value="Red"/>
181+
<SelectionCriterionRule SelectionCriterion="Colors" MatchesWhen="Includes" Value="Green"/>
182+
<CompoundRule Type="Any">
183+
<SelectionCriterionRule SelectionCriterion="Switch" MatchesWhen="Is" Value="On"/>
184+
<CompoundRule Type="All">
185+
<CompoundRule Type="All">
186+
<CompoundRule Type="All"/>
187+
</CompoundRule>
188+
<CompoundRule Type="All">
189+
<CompoundRule Type="Any">
190+
<SelectionCriterionRule SelectionCriterion="Switch" MatchesWhen="Is" Value="On"/>
191+
</CompoundRule>
192+
</CompoundRule>
193+
</CompoundRule>
194+
</CompoundRule>
195+
<SelectionCriterionRule SelectionCriterion="Switch" MatchesWhen="Is" Value="On"/>
196+
<SelectionCriterionRule SelectionCriterion="Switch" MatchesWhen="Is" Value="On"/>
197+
<SelectionCriterionRule SelectionCriterion="Colors" MatchesWhen="Includes" Value="Green"/>
198+
<SelectionCriterionRule SelectionCriterion="Colors" MatchesWhen="Includes" Value="Blue"/>
199+
</CompoundRule>
200+
</Configuration>
201+
</Configurations>
202+
<ConfigurableElements>
203+
<ConfigurableElement Path="/Test/test/block/3/q2.5"/>
204+
<ConfigurableElement Path="/Test/test/block/3/string"/>
205+
<ConfigurableElement Path="/Test/test/included/bool"/>
206+
</ConfigurableElements>
207+
<Settings>
208+
<Configuration Name="green.confGroup..On.Blue.dot">
209+
<ConfigurableElement Path="/Test/test/block/3/q2.5">
210+
<FixedPointParameter Name="q2.5">1.18750</FixedPointParameter>
211+
</ConfigurableElement>
212+
<ConfigurableElement Path="/Test/test/block/3/string">
213+
<StringParameter Name="string">12 ab @ &lt;![CDATA[ &lt; &gt; \n \0 ✔ "'\</StringParameter>
214+
</ConfigurableElement>
215+
<ConfigurableElement Path="/Test/test/included/bool">
216+
<BooleanParameter Name="bool">1</BooleanParameter>
217+
</ConfigurableElement>
218+
</Configuration>
219+
</Settings>
220+
</ConfigurableDomain>
171221
</ConfigurableDomains>

tools/xmlGenerator/PFWScriptGenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _doCreateConfiguration(self, name):
6060
self._appendCommand("createConfiguration", self._ctx_domain, name)
6161

6262
def _doSetElementSequence(self, paths):
63-
self._appendCommand("setElementSequence", self._ctx_domain, self._ctx_configuration, " ".join(paths))
63+
self._appendCommand("setElementSequence", self._ctx_domain, self._ctx_configuration, *paths)
6464

6565
def _doSetRule(self, rule):
6666
self._appendCommand("setRule", self._ctx_domain, self._ctx_configuration, rule)

tools/xmlGenerator/domainGenerator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ def parseCriteria(criteriaFile):
127127

128128
return all_criteria
129129

130-
def parseEdd(EDDFiles, verbose):
130+
def parseEdd(EDDFiles):
131131
parsed_edds = []
132132

133133
for edd_file in EDDFiles:
134134
try:
135-
root = EddParser.Parser().parse(edd_file, verbose)
135+
root = EddParser.Parser().parse(edd_file)
136136
except EddParser.MySyntaxError as ex:
137137
logging.critical(str(ex))
138138
logging.info("EXIT ON FAILURE")
@@ -184,7 +184,7 @@ def main():
184184
#
185185
# EDD files (aka ".pfw" files)
186186
#
187-
parsed_edds = parseEdd(args.edd_files, args.verbose)
187+
parsed_edds = parseEdd(args.edd_files)
188188

189189
# We need to modify the toplevel configuration file to account for differences
190190
# between development setup and target (installation) setup, in particular, the

tools/xmlGenerator/domainGeneratorConnector.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <memory>
3838
#include <string>
3939
#include <limits>
40+
#include <numeric>
4041
#include <algorithm>
4142
#include <stdexcept>
4243

@@ -169,9 +170,10 @@ size_t XmlGenerator::parse(std::istream &input)
169170
string output;
170171
if (not mCommandHandler->process(command, tokens, output)) {
171172
errorNb++;
172-
std::cerr << "Failed to executing command: "
173-
<< utility::join<string>(begin(tokens), end(tokens),
174-
[](string l, string r) { return l + ' ' + r; })
173+
174+
std::cerr << accumulate(begin(tokens), end(tokens),
175+
"Failed to executing command: `" + command + "'",
176+
[](string l, string r) { return l + " `" + r + "'"; })
175177
<< std::endl
176178
<< output << std::endl;
177179
}

0 commit comments

Comments
 (0)