From 78d43c516db58a89c23ee41a1eb23e47bf2109c8 Mon Sep 17 00:00:00 2001
From: Vagrant Cascadian <vagrant@debian.org>
Date: Mon, 24 Apr 2017 10:35:52 -0700
Subject: [PATCH 2/2] Add tests for .dtb files.

---
 debian/control                      |   1 +
 debian/copyright                    |  12 ++++++
 tests/comparators/test_dtb.py       |  57 +++++++++++++++++++++++++++++
 tests/data/devicetree1.dtb          | Bin 0 -> 68260 bytes
 tests/data/devicetree2.dtb          | Bin 0 -> 68323 bytes
 tests/data/devicetree_expected_diff |  71 ++++++++++++++++++++++++++++++++++++
 6 files changed, 141 insertions(+)
 create mode 100644 tests/comparators/test_dtb.py
 create mode 100644 tests/data/devicetree1.dtb
 create mode 100644 tests/data/devicetree2.dtb
 create mode 100644 tests/data/devicetree_expected_diff

diff --git a/debian/control b/debian/control
index d0eef28..e3cbc55 100644
--- a/debian/control
+++ b/debian/control
@@ -19,6 +19,7 @@ Build-Depends:
  dh-python (>= 2.20160818~),
  docx2txt <!nocheck>,
  dpkg-dev (>= 1.17.14),
+ device-tree-compiler <!nocheck>,
  enjarify <!nocheck>,
  fontforge-extras <!nocheck>,
  fp-utils <!nocheck>,
diff --git a/debian/copyright b/debian/copyright
index ac52ac0..8c0e230 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -93,6 +93,18 @@ Copyright: 2007-2014 OpenWrt.org
            2010 Vertical Communications
 License: GPL-2
 
+Files: tests/data/devicetree*.dtb
+Copyright:
+	2015 Nikolaus Schaller <hns@goldelico.com>
+	2012 Texas Instruments Incorporated - http:www.ti.com/
+	2011 Texas Instruments Incorporated - http:www.ti.com/
+	2013 Linaro, Ltd.
+	2015 Sakari Ailus
+	2011 Texas Instruments Incorporated - http:www.ti.com/
+	2017 Texas Instruments Incorporated - http:www.ti.com/
+	2009-2010 Texas Instruments / 2009 Nokia
+License: GPL-2
+
 Files: debian/*
 Copyright: 2014-2015 Jérémy Bobbio <lunar@debian.org>
 License: GPL-3+
diff --git a/tests/comparators/test_dtb.py b/tests/comparators/test_dtb.py
new file mode 100644
index 0000000..8dbc6c3
--- /dev/null
+++ b/tests/comparators/test_dtb.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Emanuel Bronshtein <e3amn2l@gmx.com>
+# Copyright © 2017 Vagrant Cascadian <vagrant@debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+import subprocess
+
+from diffoscope.config import Config
+from diffoscope.comparators.dtb import DeviceTreeFile
+from diffoscope.comparators.missing_file import MissingFile
+
+from utils.data import load_fixture, get_data
+from utils.tools import skip_unless_tools_exist
+
+# Generated by: dtc --in-format=dts --out-format=dtb --out=devicetree1.dtb devicetree1.dts
+dtb1 = load_fixture('devicetree1.dtb')
+# Generated by: dtc --in-format=dts --out-format=dtb --out=devicetree2.dtb devicetree2.dts
+dtb2 = load_fixture('devicetree2.dtb')
+
+def test_identification(dtb1):
+    assert isinstance(dtb1, DeviceTreeFile)
+
+def test_no_differences(dtb1):
+    difference = dtb1.compare(dtb1)
+    assert difference is None
+
+@pytest.fixture
+def differences(dtb1, dtb2):
+    return dtb1.compare(dtb2).details
+
+@skip_unless_tools_exist('fdtdump')
+def test_diff(differences):
+    expected_diff = get_data('devicetree_expected_diff')
+    assert differences[0].unified_diff == expected_diff
+
+@skip_unless_tools_exist('fdtdump')
+def test_compare_non_existing(monkeypatch, dtb1):
+    monkeypatch.setattr(Config(), 'new_file', True)
+    difference = dtb1.compare(MissingFile('/nonexisting', dtb1))
+    assert difference.source2 == '/nonexisting'
+    assert len(difference.details) > 0
diff --git a/tests/data/devicetree1.dtb b/tests/data/devicetree1.dtb
new file mode 100644
index 0000000000000000000000000000000000000000..996dc01710be662f1d73895edbe09e286e341710
GIT binary patch
diff --git a/tests/data/devicetree2.dtb b/tests/data/devicetree2.dtb
new file mode 100644
index 0000000000000000000000000000000000000000..8e4fb0c33e0cd3f894d1549464f566725901b58e
GIT binary patch
diff --git a/tests/data/devicetree_expected_diff b/tests/data/devicetree_expected_diff
new file mode 100644
index 0000000..7e4f5ed
--- /dev/null
+++ b/tests/data/devicetree_expected_diff
@@ -0,0 +1,71 @@
+@@ -1,18 +1,18 @@
+ /dts-v1/;
+ // magic:		0xd00dfeed
+-// totalsize:		0x10aa4 (68260)
++// totalsize:		0x10ae3 (68323)
+ // off_dt_struct:	0x38
+-// off_dt_strings:	0x10234
++// off_dt_strings:	0x10264
+ // off_mem_rsvmap:	0x28
+ // version:		17
+ // last_comp_version:	16
+ // boot_cpuid_phys:	0x0
+-// size_dt_strings:	0x870
+-// size_dt_struct:	0x101fc
++// size_dt_strings:	0x87f
++// size_dt_struct:	0x1022c
+ 
+ / {
+     compatible = "openpandora,omap3-pandora-1ghz", "ti,omap36xx", "ti,omap3";
+     interrupt-parent = <0x00000001>;
+     #address-cells = <0x00000001>;
+     #size-cells = <0x00000001>;
+     model = "Pandora Handheld Console 1GHz";
+@@ -82,14 +82,15 @@
+                 #size-cells = <0x00000001>;
+                 ranges = <0x00000000 0x00002000 0x00002000>;
+                 pinmux@30 {
+                     compatible = "ti,omap3-padconf", "pinctrl-single";
+                     reg = <0x00000030 0x00000238>;
+                     #address-cells = <0x00000001>;
+                     #size-cells = <0x00000000>;
++                    #pinctrl-cells = <0x00000001>;
+                     #interrupt-cells = <0x00000001>;
+                     interrupt-controller;
+                     pinctrl-single,register-width = <0x00000010>;
+                     pinctrl-single,function-mask = <0x0000ff1f>;
+                     linux,phandle = <0x000000e4>;
+                     phandle = <0x000000e4>;
+                     pinmux_mmc1_pins {
+@@ -240,14 +241,15 @@
+                 clockdomains {
+                 };
+                 pinmux@a00 {
+                     compatible = "ti,omap3-padconf", "pinctrl-single";
+                     reg = <0x00000a00 0x0000005c>;
+                     #address-cells = <0x00000001>;
+                     #size-cells = <0x00000000>;
++                    #pinctrl-cells = <0x00000001>;
+                     #interrupt-cells = <0x00000001>;
+                     interrupt-controller;
+                     pinctrl-single,register-width = <0x00000010>;
+                     pinctrl-single,function-mask = <0x0000ff1f>;
+                     pinmux_twl4030_vpins {
+                         pinctrl-single,pins = <0x00000000 0x00000100 0x00000002 0x00000100 0x00000006 0x00000000 0x00000018 0x00000000>;
+                         linux,phandle = <0x000000e7>;
+@@ -3500,14 +3502,15 @@
+             ti,abb_info = <0x000f7314 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00124f80 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x001437c8 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x0014fb18 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000>;
+         };
+         pinmux@480025a0 {
+             compatible = "ti,omap3-padconf", "pinctrl-single";
+             reg = <0x480025a0 0x0000005c>;
+             #address-cells = <0x00000001>;
+             #size-cells = <0x00000000>;
++            #pinctrl-cells = <0x00000001>;
+             #interrupt-cells = <0x00000001>;
+             interrupt-controller;
+             pinctrl-single,register-width = <0x00000010>;
+             pinctrl-single,function-mask = <0x0000ff1f>;
+             pinctrl-names = "default";
+             pinctrl-0 = <0x00000106 0x00000107>;
+             pinmux_hsusb2_2_pins {
-- 
2.11.0

