After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777258 - libsoup 2.52 / 2.54 test suite: /header-parsing/qvalue fails due to unspecified behaviour
libsoup 2.52 / 2.54 test suite: /header-parsing/qvalue fails due to unspecifi...
Status: RESOLVED FIXED
Product: libsoup
Classification: Core
Component: Misc
2.54.x
Other Linux
: Normal normal
: ---
Assigned To: libsoup-maint@gnome.bugs
libsoup-maint@gnome.bugs
Depends on:
Blocks:
 
 
Reported: 2017-01-15 02:12 UTC by A. Wilcox (awilfox)
Modified: 2017-05-01 17:59 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description A. Wilcox (awilfox) 2017-01-15 02:12:52 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