def tearDownClass(cls):
tools._RemoveOutputDir()
+ def _WritePythonString(self, fname, data):
+ """Write a string with tabs expanded as done in this Python file
+
+ Args:
+ fname: Filename to write to
+ data: Raw string to convert
+ """
+ data = data.replace('\t', '\\t')
+ with open(fname, 'w') as fd:
+ fd.write(data)
+
+ def _CheckStrings(self, expected, actual):
+ """Check that a string matches its expected value
+
+ If the strings do not match, they are written to the /tmp directory in
+ the same Python format as is used here in the test. This allows for
+ easy comparison and update of the tests.
+
+ Args:
+ expected: Expected string
+ actual: Actual string
+ """
+ if expected != actual:
+ self._WritePythonString('/tmp/binman.expected', expected)
+ self._WritePythonString('/tmp/binman.actual', actual)
+ print 'Failures written to /tmp/binman.{expected,actual}'
+ self.assertEquals(expected, actual)
+
def test_name(self):
"""Test conversion of device tree names to C identifiers"""
self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12'))
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_sandbox_i2c_test {
};
struct dtd_sandbox_pmic_test {
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_sandbox_spl_test dtv_spl_test = {
\t.bytearray\t\t= {0x6, 0x0, 0x0},
\t.byteval\t\t= 0x5,
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_source {
\tstruct phandle_2_arg clocks[4];
};
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_target dtv_phandle_target = {
\t.intval\t\t\t= 0x0,
};
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_compat1 {
\tfdt32_t\t\tintval;
};
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_compat1 dtv_spl_test = {
\t.intval\t\t\t= 0x1,
};
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x5678},
};
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_test1 {
\tfdt32_t\t\treg[2];
};
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x5678},
};
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x123400000000, 0x5678},
};
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(HEADER + '''
+ self._CheckStrings(HEADER + '''
struct dtd_test1 {
\tfdt64_t\t\treg[2];
};
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
with open(output) as infile:
data = infile.read()
- self.assertEqual(C_HEADER + '''
+ self._CheckStrings(C_HEADER + '''
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x567800000000},
};