libabigail/tests/runtestfedabipkgdiff.py.in
Chenxiong Qi 1a00cad493 Make fedabipkgdiff consistent with Libabigail's other tests
In the libabigail project, almost all the tests for the tools follow a
similar pattern.  The test contains a set of input files to compare.
The result of the comparison is thus compared to a set of reference
comparison result.

This approach is already documented in the CONTRIBUTING file.

There are several interesting properties with this scheme.  First, it
capture the behaviour of the tools, including what is shown to the
user.

Second, it eases the job of a hacker who wants to add a new test for a
new behaviour of a given tool.  The user just has to provide:

  1/ A new reference output of the new use case of the tool (that is easily
     constructed by using the tool itself and saving its output) and add an
     entry to array of entries that describe what to compare

  2/ A new set of inputs to the tool

And voila.

Unfortunately, fedabipkgdiff tests don't follow this scheme.  That
make them surprising to hackers who read the source code of the
existing tests, at very least.  Also, the fedabipkgdiff tests were
only unit tests.  They were not testing the tool as used by users in
general.

This patch makes the fedabipkgdiff tests follow the general approach
of the tests of the other Libabigail tools.

The patch first craetes a program names tests/mockfedabipkgdiff.  It's
a wrapper around tools/fedabipkgdiff.  It overloads the Koji client of
fedabipkgdiff with a fake Koji client that gets the Fedora packages
locally, from tests/data/test-fedabipkgdiff/packages.  In other words,
mockfedabipkgdiff is fedabipkgdiff without going to the network.

I believe that in the future, tests/mockfedabipkgdiff should be killed
when fedabipkgdiff is able to cache a local description of a local
partial view of a Koji repository, along with the build packages that
were already downloaded.

That way, calling fedabipkgdiff twice with the same set of option
should make the tool perform correctly without going to the netword on
the second invocation.  We should be able to save the local partial
view of the Koji repository under e.g,
tests/data/test-fedabipkgdiff/local-koji and tell fedabipkgdiff to use
that, instead of using the network.  But we are not there yet.  So for
now, I am using mockfedabipkgdiff.

Then, tests/runtestfedabipkdiff.py.in has been re-written to use
tests/mockfedabipkgdiff and to look like what is described in
CONTRIBUTING as far as how Libabigail tools' tests are organized:
mockfedabipkgdiff is called to perform a comparison.  The result of
the comparison is then compared (using GNU diff) to a reference
comparison result file.

Please note that tests/runtestfedabipkdiff.py is relatively fast for
the moment.  But when it contains much more tests and start becoming
slow, then we'll need to change the code to run several comparisons in
parallel, just like we do today in tests/test-diff-filter.cc.  At that
point, I believe I'll just re-write this in C++, just like
tests/test-diff-filter.cc because that will allow us to have true
concurrent code based on the abigail:workers API.  For now, I am
keeping this in Python also because I think that keeps Chenxiong happy
;-)

To be sure that fedabipkgdiff (and its underlying abipkgdiff) are
really comparing all the packages they are supposed to compare and
also all the binaries in those packages, I have added a new
--show-identical-binaries to abipkgdiff and fedabipkgdiff.  That
option shows the name of the binaries (and packages) that are
compared, *even if* the ABI of those binaries are identical.  Because
otherwise, today, if two binaries (or packages) have the same ABI,
nothing is displayed.

For instance, here is the result of comparing a package against
itself, using this new --show-identical-binaries options:

    dodji@adjoa:patches$ ./tools/fedabipkgdiff --abipkgdiff ./build/tools/abipkgdiff --show-identical-binaries  dbus-glib-0.80-3.fc12.x86_64.rpm dbus-glib-0.80-3.fc12.x86_64.rpm
    Comparing the ABI of binaries between dbus-glib-0.80-3.fc12.x86_64.rpm and dbus-glib-0.80-3.fc12.x86_64.rpm:

    ================ changes of 'dbus-binding-tool'===============
    No ABI change detected
    ================ end of changes of 'dbus-binding-tool'===============

    ================ changes of 'libdbus-glib-1.so.2.1.0'===============
    No ABI change detected
    ================ end of changes of 'libdbus-glib-1.so.2.1.0'===============
    dodji@adjoa:patches$

And here is what this command before that patch would do:

    dodji@adjoa:patches$ ./tools/fedabipkgdiff --abipkgdiff ../master/build/tools/abipkgdiff dbus-glib-0.80-3.fc12.x86_64.rpm dbus-glib-0.80-3.fc12.x86_64.rpm
    Comparing the ABI of binaries between dbus-glib-0.80-3.fc12.x86_64.rpm and dbus-glib-0.80-3.fc12.x86_64.rpm:
    dodji@adjoa:patches$

The rest of the patch is mostly new test inputs material and the
necessary adjustments following all the changes above.

	* configure.ac: Do not require Python dependencies itertools,
	unittest and StringIO anymore as they are not used anymore.
	Require new module tempfile now.  Generate new executable script
	tests/mockfedabipkgdiff from tests/mockfedabipkgdiff.in.
	* doc/manuals/abipkgdiff.rst: Add doc for new option
	--show-identical-binaries to abipkgdiff
	* doc/manuals/fedabipkgdiff.rst: Add doc for new options
	--show-identical-binaries to fedabipkgdiff.
	* tools/abipkgdiff.cc (options::show_identical_binaries): New data
	member.
	(options::options): Initialize new data member.
	(display_usage): Add a new help string for the new
	--show-identical-binaries option.
	(parse_command_line): Parse the newq --show-identical-binaries
	command line switch.
	(pthread_routine_compare): When the comparison of two binaries is
	empty, if --show-identical-binaries was provided, then emit some
	output saying the comparison did yield the empty set.
	* tools/fedabipkgdiff (DEFAULT_ABIPKGDIFF): Store the default path
	to abipkgdiff in this new global variable.  Naming this default
	path is useful because it can then be cleanly overloaded when
	using mock.patch.
	(build_path_to_abipkgdiff): Return the new DEFAULT_ABIPKGDIFF
	global variable.
	(cmd): Parse the new --show-identical-binaries command line
	switch.
	* tests/data/test-diff-pkg/test-dbus-glib-0.80-3.fc12.x86_64-report-0.txt:
	New reference output.
	* tests/data/test-fedabipkgdiff/test0-from-fc20-to-fc23-dbus-glib-report-0.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/test1-from-fc20-to-dbus-glib-0.106-1.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/test2-dbus-glib-0.100.2-2.fc20--dbus-glib-0.106-1.fc23-report-0.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i686-report-0.txt:
	Likewise.
	* tests/mockfedabipkgdiff.in: New uninstalled script template.
	* tests/runtestfedabipkgdiff.py.in (counter)
	(temp_file_or_dir_prefix, UtilsTest, RPMTest, LocalRPMTest)
	(RunAbipkgdiffTest, GetPackageLatestBuildTest, DownloadRPMTest)
	(BrewListRPMsTest, AssertionHelper, MockGlobalConfig)
	(BUILT_ABIPKGDIFF, CompareABIFromCommandLineTest): Remove these
	classes, global variables and functions.
	(FEDABIPKGDIFF, TEST_SRC_DIR, TEST_BUILD_DIR, INPUT_DIR)
	(OUTPUT_DIR, FEDABIPKGDIFF_TEST_SPECS): New global variables.
	(ensure_output_dir_created, run_fedabipkgdiff_tests, main): New
	functions.
	* tests/test-diff-pkg.cc (in_out_specs): Add
	tests/data/test-diff-pkg/test-dbus-glib-0.80-3.fc12.x86_64-report-0.txt
	to the set of reference outputs to consider.
	* tests/Makefile.am: Add non-installed script mockfedabipkgdiff to
	source distribution. Also added
	tests/data/test-diff-pkg/test-dbus-glib-0.80-3.fc12.x86_64-report-0.txt,
	tests/data/test-fedabipkgdiff/test0-from-fc20-to-fc23-dbus-glib-report-0.txt,
	tests/data/test-fedabipkgdiff/test1-from-fc20-to-dbus-glib-0.106-1.fc23.x86_64-report-0.txt,
	tests/data/test-fedabipkgdiff/test2-dbus-glib-0.100.2-2.fc20--dbus-glib-0.106-1.fc23-report-0.txt
	and
	tests/data/test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i686-report-0.txt
	to source distribution.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-07-15 19:41:08 +02:00

146 lines
5.3 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
# -*- Mode: Python
#
# This file is part of the GNU Application Binary Interface Generic
# Analysis and Instrumentation Library (libabigail). This library 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, or (at your option) any
# later version.
#
# This library 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 this program; see the file COPYING-GPLV3. If
# not, see <http:#www.gnu.org/licenses/>.
#
# Author: Chenxiong Qi
'''Runs tests for the fedabipkgdiff program
This program runs the fedabipkgdiff tool (via the mockfedabipkgdiff
tool) repeatedly and compares its output against a set of reference
output files.
'''
import sys
import os
import subprocess
FEDABIPKGDIFF = '@abs_top_builddir@/tests/mockfedabipkgdiff'
TEST_SRC_DIR = '@abs_top_srcdir@/tests'
TEST_BUILD_DIR = '@abs_top_builddir@/tests'
INPUT_DIR = '@abs_top_srcdir@/tests/data/test-fedabipkgdiff'
OUTPUT_DIR = '@abs_top_builddir@/tests/output/test-fedabipkgdiff'
# This variable is a list of 3-uples. Here is the meaning of
# the elements of each 3-uples:
#
# (arguments to pass to fedabipkgdiff,
# reference output file,
# where to store the result of the comparison)
#
# Note that after fedabipkgdiff is run (using the arguments that are
# the first element of the tuple) the result of the comparison is
# going to be compared against the reference output file, and both
# must be equal.
#
# If a user wants to add a new test, she must add a new tuple to the
# variable below, and also add a new reference output to the source
# distribution.
#
FEDABIPKGDIFF_TEST_SPECS = [
(['--from', 'fc20', '--to', 'fc23', 'dbus-glib'],
'data/test-fedabipkgdiff/test0-from-fc20-to-fc23-dbus-glib-report-0.txt',
'output/test-fedabipkgdiff/test0-type-suppr-report-0.txt'),
(['--from', 'fc20', os.path.join(INPUT_DIR,
'packages/dbus-glib/0.106/1.fc23/x86_64/'
'dbus-glib-0.106-1.fc23.x86_64.rpm')],
'data/test-fedabipkgdiff/test1-from-fc20-to-dbus-glib-0.106-1.fc23.x86_64-report-0.txt',
'output/test-fedabipkgdiff/test1-from-fc20-to-dbus-glib-0.106-1.fc23.x86_64-report-0.txt'),
(['dbus-glib-0.100.2-2.fc20', 'dbus-glib-0.106-1.fc23'],
'data/test-fedabipkgdiff/test2-dbus-glib-0.100.2-2.fc20--dbus-glib-0.106-1.fc23-report-0.txt',
'output/test-fedabipkgdiff/test2-dbus-glib-0.100.2-2.fc20--dbus-glib-0.106-1.fc23-report-0.txt'),
(['dbus-glib-0.100.2-2.fc20.i686', 'dbus-glib-0.106-1.fc23.i686'],
'data/test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i686-report-0.txt',
'output/test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i686-report-0.txt'),
]
def ensure_output_dir_created():
'''Create output dir if it's not already created.'''
try:
os.makedirs(OUTPUT_DIR)
except:
pass
if not os.path.exists(OUTPUT_DIR):
sys.exit(1);
def run_fedabipkgdiff_tests():
"""Run the fedabipkgdiff tests
Loop through the test inputs in the FEDABIPKGDIFF_TEST_SPECS global
variable and for each of the test input, launch a comparison using
mockfedabipkgdiff, which calls fedabipkgdiff by making sure it
doesn't use the network.
The result of the comparison is stored in an output file, and that
output file is compared (using GNU diff) against the reference
output file specified in the FEDABIPKGDIFF_TEST_SPECS global
variable.
This function returns True iff all comparison specified by
FEDABIPKGDIFF_TEST_SPECS succeed.
"""
result = True;
for args, reference_report_path, output_path in FEDABIPKGDIFF_TEST_SPECS:
reference_report_path = os.path.join(TEST_SRC_DIR, reference_report_path)
output_path = os.path.join(TEST_BUILD_DIR, output_path)
cmd = [FEDABIPKGDIFF,
'--no-default-suppression',
'--show-identical-binaries'] + args
with open(output_path, 'w') as out_file:
subprocess.call(cmd, stdout=out_file)
if not os.path.exists(reference_report_path):
sys.stderr.write('file not found: ' + reference_report_path)
return_code = -1
else:
diffcmd = ['diff', '-u', reference_report_path, output_path]
return_code = subprocess.call(diffcmd)
if return_code:
sys.stderr.write('fedabipkgdiff test failed for ' +
reference_report_path + '\n')
result &= not return_code
return result;
def main():
"""The main entry point of this program.
This creates the output directory and launches the tests for the
fedabipkgdiff program.
"""
ensure_output_dir_created()
result = 0;
result = run_fedabipkgdiff_tests()
if not result:
return result;
if __name__ == '__main__':
exit_code = main()
sys.exit(exit_code)