abipkgdiff: Avoid uncertainty when sorting worker tasks

Message ID 20201125123521.931F4581C97@localhost
State New
Headers
Series abipkgdiff: Avoid uncertainty when sorting worker tasks |

Commit Message

Dodji Seketeli Nov. 25, 2020, 12:35 p.m. UTC
  Hello,

Worker tasks that have compared the binaries of two packages are sorted
according to the sizes of the binaries they compared.  The tasks that
compared bigger binaries come first.  So the output of these tasks is
always sorted the same.

When two tasks have sorted binaries of the same size, let's sort them by
taking into account the lexicographic order of the binaries names.  This
reduces the sorting uncertainty due to having same size binaries.

	* elf_size_is_greater: Take the name of the binaries into account
	when their size is equal.  Also, assert that all comparison tasks
	have compared binaries.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 tools/abipkgdiff.cc | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
  

Patch

diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc
index 6d3f5e79..2968338a 100644
--- a/tools/abipkgdiff.cc
+++ b/tools/abipkgdiff.cc
@@ -2524,10 +2524,17 @@  elf_size_is_greater(const task_sptr &task1,
   compare_task_sptr t1 = dynamic_pointer_cast<compare_task>(task1);
   compare_task_sptr t2 = dynamic_pointer_cast<compare_task>(task2);
 
-  off_t s1 = t1->args ? t1->args->elf1.size + t1->args->elf2.size : 0;
-  off_t s2 = t2->args ? t2->args->elf1.size + t2->args->elf2.size: 0;
+  ABG_ASSERT(t1->args && t2->args);
+  off_t s1 = t1->args->elf1.size + t1->args->elf2.size;
+  off_t s2 = t2->args->elf1.size + t2->args->elf2.size;
+
+  if (s1 != s2)
+    return s1 > s2;
+
+  // The sizes of the compared binaries are the same.  So sort them
+  // lexicographically.
+  return t1->args->elf1.name < t2->args->elf1.name;
 
-  return s1 > s2;
 }
 
 /// This type is used to notify the calling thread that the comparison