abipkgdiff: Avoid uncertainty when sorting worker tasks
Commit Message
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(-)
@@ -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