GNOME Bugzilla – Bug 777258
libsoup 2.52 / 2.54 test suite: /header-parsing/qvalue fails due to unspecified behaviour
Last modified: 2017-05-01 17:59:53 UTC
While building libsoup-2.52.2 for our new distribution, Adélie Linux, I ran in to a test failure reproducable on all tested arches (x86_64, i486, and PowerPC): PASS: header-parsing 1 /header-parsing/request PASS: header-parsing 2 /header-parsing/response FAIL: header-parsing 3 /header-parsing/qvalue PASS: header-parsing 4 /header-parsing/content-disposition PASS: header-parsing 5 /header-parsing/content-type PASS: header-parsing 6 /header-parsing/append-param PASS: header-parsing 7 /header-parsing/bad ERROR: header-parsing - exited with status 1 Reviewing the header-parsing.log file showed: ** ERROR:/usr/src/net-libs/libsoup-2.52.2/work/libsoup-2.52.2/tests/header-parsing.c:905:do_qvalue_tests: assertion failed (iter->data == qvaluetests[i].acceptable[j]): ("text/x-c" == "text/html") ** ERROR:/usr/src/net-libs/libsoup-2.52.2/work/libsoup-2.52.2/tests/header-parsing.c:905:do_qvalue_tests: assertion failed (iter->data == qvaluetests[i].acceptable[j]): ("text/html" == "text/x-c") # random seed: R02Sc6fc600bf1e5dc05d586e88d94821cb4 Reviewing the test code, I noticed the the Accept: header it was testing with was "text/plain; q=0.5, text/html,\t text/x-dvi; q=0.8, text/x-c" and it was expecting a list returned from soup_header_parse_quality_list that matched: { "text/html", "text/x-c", "text/x-dvi", "text/plain", NULL } This is all well and good, except when I looked at soup_header_parse_quality_list I noticed that it is actually using qsort: libsoup/soup-headers.c:595: qsort (array, n, sizeof (QualityItem), sort_by_qval); Both the C99 standard and the POSIX standard[1] clearly specify for qsort(3): If two members compare as equal, their order in the sorted array is unspecified. The test is therefore failing due to relying on an implementation detail of whichever qsort implementation was in use on the developer's computer when the test was written. A quick fix would be to add ;q=0.9 to text/x-c in the header. A more proper fix might be to sort by alphabetical name and then split the quality number off, so that results are always guaranteed in alphabetical order. If neither of these options are acceptable, then the test is broken and should be removed. [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/qsort.html