[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Feature] Add --self-compare option in fedabipkgdiff



Hi,

This patch (available in email attachment)  adds --self-compare option
in fedabipkgdiff tool.

fedabipkgdiff tool can communicate with Fedora koji and has capability
to download and perform ABI comparison between specified NVRs.

With addition of --self-compare option, it will be possible to perform
ABI comparison on same package. One of the important usecase of this
option is to run automated ABI checks on packages with known expected
result i.e. no ABI change. This usecase will be useful to ensure that
libabigail functionality doesn't break with new commits made.
This option can be invoked as:
  fedabipkgdiff -a --self-compare -fc24 pacakge_name


Thanks,
Sinny
From d283161bfc91c7a450945ac75a7eeae899733850 Mon Sep 17 00:00:00 2001
From: Sinny Kumari <sinny@redhat.com>
Date: Sun, 21 May 2017 15:10:12 +0530
Subject: [PATCH] Add --self-compare option in fedabipkgdiff

fedabipkgdiff tool can communicate with Fedora koji and has
capability to download and perform ABI comparison between
specified NVRs.

With addition of --self-compare option, it will be possible
to perform ABI comparison on same package. One of the important
usecase of this option is to run automated ABI checks on
packages with known expected result i.e. no ABI change. This usecase
will be useful to ensure that libabigail functionality doesn't
break with new commits made.
This option can be invoked as:
fedabipkgdiff -a --self-compare -fc24 pacakge_name

	* bash-completion/fedabipkgdiff: Add new option --self-compare
	* tests/data/Makefile.am: Add new test file
	* tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt:
	New reference output for testing ABI comparison on same package
	* tests/runtestfedabipkgdiff.py.in (FEDABIPKGDIFF_TEST_SPECS):
	Add test case for --self-compare
	* tools/fedabipkgdiff (build_commandline_args_parser()): Add
	new option --self-compare
	(generate_comparison_halves()): Find second comparision half in same
	package list while doing self-compare
	(self_compare_rpms_from_distro()): New function to perform ABI
	comparision on same pacakge
	(main()): Add if condition when --self-compare option is enabled
---
 bash-completion/fedabipkgdiff                      |  3 +-
 tests/data/Makefile.am                             |  1 +
 ...7-self-compare-from-fc23-dbus-glib-report-0.txt | 12 ++++
 tests/runtestfedabipkgdiff.py.in                   |  4 ++
 tools/fedabipkgdiff                                | 64 ++++++++++++++++++++--
 5 files changed, 77 insertions(+), 7 deletions(-)
 create mode 100644 tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt

diff --git a/bash-completion/fedabipkgdiff b/bash-completion/fedabipkgdiff
index 789d990..d074419 100644
--- a/bash-completion/fedabipkgdiff
+++ b/bash-completion/fedabipkgdiff
@@ -19,7 +19,8 @@ _fedabipkgdiff_module()
                     --abipkgdiff
                     --clean-cache
                     --clean-cache-before
-                    --clean-cache-after"
+                    --clean-cache-after
+                    --self-compare"
 	    COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 	    return 0
 	    ;;
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 47c91a6..3be5ab7 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -1294,6 +1294,7 @@ test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i
 test-fedabipkgdiff/test4-glib-0.100.2-2.fc20.x86_64.rpm-glib-0.106-1.fc23.x86_64.rpm-report-0.txt \
 test-fedabipkgdiff/test5-same-dir-dbus-glib-0.100.2-2.fc20.x86_64--dbus-glib-0.106-1.fc23.x86_64-report-0.txt \
 test-fedabipkgdiff/test6-nss-util-3.12.6-1.fc14.x86_64--nss-util-3.24.0-2.0.fc25.x86_64-report-0.txt \
+test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt \
 test-fedabipkgdiff/packages/dbus-glib/0.100.2/2.fc20/i686/dbus-glib-0.100.2-2.fc20.i686.rpm \
 test-fedabipkgdiff/packages/dbus-glib/0.100.2/2.fc20/i686/dbus-glib-debuginfo-0.100.2-2.fc20.i686.rpm \
 test-fedabipkgdiff/packages/dbus-glib/0.100.2/2.fc20/i686/dbus-glib-devel-0.100.2-2.fc20.i686.rpm \
diff --git a/tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt b/tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt
new file mode 100644
index 0000000..63a6dca
--- /dev/null
+++ b/tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt
@@ -0,0 +1,12 @@
+Comparing the ABI of binaries between dbus-glib-0.106-1.fc23.i686.rpm and dbus-glib-0.106-1.fc23.i686.rpm:
+
+
+Comparing the ABI of binaries between dbus-glib-devel-0.106-1.fc23.i686.rpm and dbus-glib-devel-0.106-1.fc23.i686.rpm:
+
+
+Comparing the ABI of binaries between dbus-glib-0.106-1.fc23.x86_64.rpm and dbus-glib-0.106-1.fc23.x86_64.rpm:
+
+
+Comparing the ABI of binaries between dbus-glib-devel-0.106-1.fc23.x86_64.rpm and dbus-glib-devel-0.106-1.fc23.x86_64.rpm:
+
+
diff --git a/tests/runtestfedabipkgdiff.py.in b/tests/runtestfedabipkgdiff.py.in
index 0ac054a..78898f3 100755
--- a/tests/runtestfedabipkgdiff.py.in
+++ b/tests/runtestfedabipkgdiff.py.in
@@ -91,6 +91,10 @@ FEDABIPKGDIFF_TEST_SPECS = [
       os.path.join(INPUT_DIR, 'nss-util/nss-util-3.24.0-2.0.fc25.x86_64.rpm')],
      'data/test-fedabipkgdiff/test6-nss-util-3.12.6-1.fc14.x86_64--nss-util-3.24.0-2.0.fc25.x86_64-report-0.txt',
      'output/test-fedabipkgdiff/test6-nss-util-3.12.6-1.fc14.x86_64--nss-util-3.24.0-2.0.fc25.x86_64-report-0.txt'),
+
+    (['--self-compare', '-a', '--from', 'fc23', 'dbus-glib'],
+     'data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt',
+     'output/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt'),
 ]
 
 
diff --git a/tools/fedabipkgdiff b/tools/fedabipkgdiff
index 15145d3..a8329d4 100755
--- a/tools/fedabipkgdiff
+++ b/tools/fedabipkgdiff
@@ -528,16 +528,23 @@ def generate_comparison_halves(rpm_col1, rpm_col2):
         if _rpm.is_devel and not global_config.check_all_subpackages:
             continue
 
-        rpm2 = rpm_col2.get_peer_rpm(_rpm)
-        if rpm2 is None:
-            logger.warning('Peer RPM of {0} is not found.'.format(_rpm.filename))
-            continue
+        if global_config.self_compare:
+            rpm2 = _rpm
+        else:
+            rpm2 = rpm_col2.get_peer_rpm(_rpm)
+            if rpm2 is None:
+                logger.warning('Peer RPM of {0} is not found.'.format(_rpm.filename))
+                continue
 
         debuginfo1 = rpm_col1.get_sibling_debuginfo(_rpm)
         devel1 = rpm_col1.get_sibling_devel(_rpm)
 
-        debuginfo2 = rpm_col2.get_sibling_debuginfo(rpm2)
-        devel2 = rpm_col2.get_sibling_devel(rpm2)
+        if global_config.self_compare:
+            debuginfo2 = debuginfo1
+            devel2 = devel1
+        else:
+            debuginfo2 = rpm_col2.get_sibling_debuginfo(rpm2)
+            devel2 = rpm_col2.get_sibling_devel(rpm2)
 
         yield (ComparisonHalf(subject=_rpm,
                               ancillary_debug=debuginfo1,
@@ -1206,6 +1213,40 @@ def diff_two_nvras_from_koji():
 
 
 @log_call
+def self_compare_rpms_from_distro():
+    """Compare ABI between same package from a distro
+
+    Doing ABI comparison on self package should return no
+    ABI change and hence return code should be 0. This is useful
+    to ensure that functionality of libabigail itself
+    didn't break. This utility can be invoked like this:
+
+    fedabipkgdiff --self-compare -a --from fc25 foo
+    """
+
+    from_distro = global_config.from_distro
+
+    if not is_distro_valid(from_distro):
+        raise InvalidDistroError('Invalid distro {0}'.format(from_distro))
+
+    package_name = global_config.NVR[0]
+
+    rpm_col1 = session.get_latest_built_rpms(package_name,
+                                             distro=global_config.from_distro)
+
+    if global_config.clean_cache_before:
+        delete_download_cache()
+
+    download_rpms(rpm_col1.rpms_iter())
+    result = run_abipkgdiff(rpm_col1, rpm_col1)
+
+    if global_config.clean_cache_after:
+        delete_download_cache()
+
+    return result
+
+
+@log_call
 def diff_from_two_rpm_files(from_rpm_file, to_rpm_file):
     """Diff two RPM files"""
     rpm_col1 = RPMCollection.gather_from_dir(from_rpm_file)
@@ -1345,6 +1386,13 @@ def build_commandline_args_parser():
         dest='clean_cache_after',
         default=None,
         help='Clean cache after ABI comparison')
+    parser.add_argument(
+        '--self-compare',
+        required=False,
+        action='store_true',
+        dest='self_compare',
+        default=None,
+        help='ABI comparison on same package')
     return parser
 
 
@@ -1367,6 +1415,10 @@ def main():
 
     logger.debug(args)
 
+    if global_config.from_distro and global_config.self_compare and \
+            global_config.NVR:
+        return self_compare_rpms_from_distro()
+
     if global_config.from_distro and global_config.to_distro is None and \
             global_config.NVR:
         return diff_local_rpm_with_latest_rpm_from_koji()
-- 
2.9.4