From patchwork Wed Jun 6 00:46:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925690 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="G0gTBQtE"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r371JGZz9s02 for ; Wed, 6 Jun 2018 11:01:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D921EC21EDC; Wed, 6 Jun 2018 00:53:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8A1E6C21FAD; Wed, 6 Jun 2018 00:49:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C6AFCC21FED; Wed, 6 Jun 2018 00:47:57 +0000 (UTC) Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by lists.denx.de (Postfix) with ESMTPS id C01B2C21F6E for ; Wed, 6 Jun 2018 00:47:52 +0000 (UTC) Received: by mail-it0-f65.google.com with SMTP id k17-v6so15988164ita.0 for ; Tue, 05 Jun 2018 17:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=kqTyuuLY61c+HrWdYFF2vRe0ma6Us+nEz6KeuDrc6RM=; b=G0gTBQtEYfyO3aN8bOa7gObeKESJoUsMEAtZhkeAGqzjp3qrOHl2wLypPKK5CZlNa3 ZJdwh3lvuF6qpvMUCoSWbZUDYXetBv+NKtCTJOfJcU1pUUIXUALpcSSKhAWp/wDaE0/1 UG0S5P+GmBhkqw/jwzaj0kT4IUX7vZSXeIk3jv+t9E9KMUHgYvBCUPW8Jm9xjRAqrD0Y THHcgIEM/rbu9rp+0Pv/FNZfCz0ETJT98nblDzCpXgN/DAUHY/SWsnwEr8i+XxGEq8rc yjqhulWqqPhXuT9Grt1vAUPrv/JelyCS4wE6M7OaT3xGcVZ7LMPGQmFaC/wLkj3DjuIS mktQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=kqTyuuLY61c+HrWdYFF2vRe0ma6Us+nEz6KeuDrc6RM=; b=Wii7IikmftX4L1xD5MOFy5dqr1WAez5k2dWKn4dmXpaa+9VP9GA/wrwEFnBs9aw+s4 f9EG0y0HrT83sH85N+2+55dWCDi2akemGQ+Qz2vAZMYwx5YzLRnlZeDfHLpeTZRgvNTT 7dJhhQ8Rt6MUzaQxeuvxA97LB8hqVu4H0s3NhWTC2ASWpktAy19FI5kYzMZFeFK01Qmt hWkpWMQpC0pK2skZW6yw/yB1d+m89D6aqiIAdOgb0/hDf8IS/o0a34g6H3PV/D1PtvxB 5ZCdCEBnfCfYjwPzDahWqrzFv73lDKPQcUkpp1w8AuCugctko2Um4eytWCpnJssCwxb8 0dDg== X-Gm-Message-State: APt69E0MdoLjQYhM9ZwJzTV2TxjTwgcRaPyD3UGWX2htAYLZGPFKJtGO NqeSMq6y5zcV7A9/a5LPncXttA== X-Google-Smtp-Source: ADUXVKKMsCET+qrNQiBJNWY1kwYZmYW65j8rs6raLEXL33lKNCKqY06hQMfB0nIuBDFWGM+vjb9j9w== X-Received: by 2002:a24:552:: with SMTP id 79-v6mr487211itl.109.1528246071229; Tue, 05 Jun 2018 17:47:51 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id d202-v6sm1517436itc.30.2018.06.05.17.47.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:50 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id D37E7140700; Tue, 5 Jun 2018 18:47:49 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:48 -0600 Message-Id: <20180606004705.79641-13-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 12/29] dtoc: Update tests to write failures to /tmp X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When a test fails due to an output mismatch (e.g. due to a new property being adding to a test file) it is currently hard to update the test to the new output. In particular the tabs in the file are written as \t in the Python tests. To make this easier, write both the expected and actual results to /tmp to allow use of meld, and copying into the test. Signed-off-by: Simon Glass --- tools/dtoc/test_dtoc.py | 56 ++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index e475a7eb14e..ce6d2585a40 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -68,6 +68,34 @@ class TestDtoc(unittest.TestCase): 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')) @@ -138,7 +166,7 @@ class TestDtoc(unittest.TestCase): 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 { @@ -162,7 +190,7 @@ struct dtd_sandbox_spl_test_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_sandbox_spl_test dtv_spl_test = { \t.bytearray\t\t= {0x6, 0x0, 0x0}, \t.byteval\t\t= 0x5, @@ -240,7 +268,7 @@ U_BOOT_DEVICE(pmic_at_9) = { 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]; }; @@ -252,7 +280,7 @@ struct dtd_target { 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, }; @@ -302,7 +330,7 @@ U_BOOT_DEVICE(phandle_source) = { 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; }; @@ -313,7 +341,7 @@ struct dtd_compat1 { 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, }; @@ -332,7 +360,7 @@ U_BOOT_DEVICE(spl_test) = { 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]; }; @@ -347,7 +375,7 @@ struct dtd_test3 { 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}, }; @@ -384,7 +412,7 @@ U_BOOT_DEVICE(test3) = { 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]; }; @@ -396,7 +424,7 @@ struct dtd_test2 { 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}, }; @@ -424,7 +452,7 @@ U_BOOT_DEVICE(test2) = { 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]; }; @@ -439,7 +467,7 @@ struct dtd_test3 { 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}, }; @@ -476,7 +504,7 @@ U_BOOT_DEVICE(test3) = { 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]; }; @@ -491,7 +519,7 @@ struct dtd_test3 { 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}, };