pulseaudio/src/tests
Peter Meerwald 293a1739e2 endianmacros: Replace borked PA_FLOAT32_SWAP() with PA_READ_FLOAT32RE() / PA_WRITE_FLOAT32RE()
building PA with -O0 leads to test failure in mix-test on i386

issue reported by Felipe, see
http://lists.freedesktop.org/archives/pulseaudio-discuss/2014-August/021406.html

the problem is the value 0xbeffbd7f: when byte-swapped it becomes 0x7fbdffbe and according
to IEEE-754 represents a signalling NaN (starting with s111 1111 10, see http://en.wikipedia.org/wiki/NaN)

when this value is assigned to a floating point register, it becomes 0x7ffdffbe, representing
a quiet NaN (starting with s111 1111 11) -- a signalling NaN is turned into a quiet NaN!

so PA_FLOAT32_SWAP(PA_FLOAT32_SWAP(x)) != x for certain values, uhuh!

the following test code can be used; due to volatile, it will always demonstrate the issue;
without volatile, it depends on the optimization level (i386, 32-bit, gcc 4.9):

// snip

static inline float PA_FLOAT32_SWAP(float x) {
    union {
        float f;
        uint32_t u;
    } t;

    t.f = x;
    t.u = bswap_32(t.u);
    return t.f;
}

int main() {
  unsigned x = 0xbeffbd7f;
  volatile float f = PA_FLOAT32_SWAP(*(float *)&x);
  printf("%08x %08x %08x %f\n", 0xbeffbd7f, *(unsigned *)&f, bswap_32(*(unsigned *)&f), f);
}
// snip

the problem goes away with optimization when no temporary floating point registers are used

the proposed solution is to avoid passing swapped floating point data in a
float; this is done with new functions PA_READ_FLOAT32RE() and PA_WRITE_FLOAT32RE()
which use uint32_t to dereference a pointer and byte-swap the data, hence no temporary
float variable is used

also delete PA_FLOAT32_TO_LE()/_BE(), not used

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Reported-by: Felipe Sateler <fsateler@debian.org>
2014-09-04 09:58:20 +02:00
..
alsa-mixer-path-test.c Whitespace cleanup: Remove all multiple newlines 2013-06-24 16:56:24 +03:00
alsa-time-test.c tests: Minor alsa-time-test improvments 2013-03-25 09:47:04 +00:00
asyncmsgq-test.c tests: modify asyncmsgq-test to new 'check' framework 2012-08-20 07:05:59 +05:30
asyncq-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
channelmap-test.c tests: modify channelmap-tets to use 'check' framework 2012-08-20 07:05:59 +05:30
close-test.c add a small test program for pa_close_all() 2008-05-18 19:12:59 +00:00
connect-stress.c tests: modify connect-stress to use 'check' framework 2012-08-20 07:05:59 +05:30
cpu-test.c remap: Make resampler's remap structure more self-contained 2014-04-29 00:00:06 +02:00
cpulimit-test.c tests: modify cpulimit-test to use 'check' framework 2012-08-20 07:05:59 +05:30
extended-test.c tests: modify extended-test to use 'check' framework 2012-08-20 07:05:59 +05:30
flist-test.c thread: name all threads so that the names appear in /proc/$PID/task/$TID/comm 2010-05-07 23:58:59 +02:00
format-test.c tests: modify format-test to use 'check' framework 2012-08-20 07:05:58 +05:30
get-binary-name-test.c tests: modify get-binary-name-test to use 'check' framework 2012-08-20 07:05:59 +05:30
gtk-test.c gtk-test: updated to use PA_CONTEXT_NOAUTOSPAWN|PA_CONTEXT_NOFAIL 2009-03-30 21:05:35 +03:00
hook-list-test.c tests: modify hook-list-test to use 'check' framework 2012-08-20 07:05:59 +05:30
interpol-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
ipacl-test.c tests: modify ipacl-test to use 'check' framework 2012-08-20 07:06:00 +05:30
ladspa-dbus.py ladspa: Added a python script for testing. 2012-06-28 15:05:31 +03:00
lo-latency-test.c tests: Make loopback latency test more accurate 2013-06-04 00:38:44 +05:30
lo-test-util.c tests: Factor out loopback setup code 2013-06-04 00:38:44 +05:30
lo-test-util.h tests: Factor out loopback setup code 2013-06-04 00:38:44 +05:30
lock-autospawn-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
mainloop-test.c mainloop-test: Use FALSE instead of false for gboolean 2013-07-04 12:33:47 +03:00
Makefile build-sys: readd stub makefiles to subdirectories to make building with emacs easier 2012-05-15 14:17:58 +02:00
mcalign-test.c misc: Fix format specifiers 2014-08-18 15:31:19 +02:00
memblock-test.c tests: Adapt memblock-test to changed pa_memimport_get() 2014-06-27 14:16:33 +02:00
memblockq-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
mix-special-test.c tests: Extract PA_CPU_TEST* macros to separate header 2013-11-01 15:02:24 +01:00
mix-test.c endianmacros: Replace borked PA_FLOAT32_SWAP() with PA_READ_FLOAT32RE() / PA_WRITE_FLOAT32RE() 2014-09-04 09:58:20 +02:00
mult-s16-test.c tests: Extract PA_CPU_TEST* macros to separate header 2013-11-01 15:02:24 +01:00
once-test.c Make tests compile on FreeBSD 2014-02-25 14:28:36 +02:00
pacat-simple.c Remove unnecessary #includes 2011-06-22 23:12:20 +01:00
parec-simple.c Remove unnecessary #includes 2011-06-22 23:12:20 +01:00
proplist-test.c tests: modify proplist-test to use 'check' framework 2012-08-20 07:05:59 +05:30
queue-test.c tests: modify queue-test to use 'check' framework 2012-08-20 07:05:59 +05:30
remix-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
resampler-test.c endianmacros: Replace borked PA_FLOAT32_SWAP() with PA_READ_FLOAT32RE() / PA_WRITE_FLOAT32RE() 2014-09-04 09:58:20 +02:00
rtpoll-test.c tests: modify rtpoll-test to use 'check' framework 2012-08-20 07:06:00 +05:30
rtstutter.c Make tests compile on FreeBSD 2014-02-25 14:28:36 +02:00
runtime-test-util.h tests: Extract PA_CPU_TEST* macros to separate header 2013-11-01 15:02:24 +01:00
sig2str-test.c tests: modify sig2str-test to use 'check' framework 2012-08-20 07:05:59 +05:30
sigbus-test.c tests: Check expected result of sigbus-test 2014-08-18 15:31:41 +02:00
smoother-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
srbchannel-test.c tests: Add pstream/srbchannel test 2014-06-27 14:30:56 +02:00
stripnul.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
strlist-test.c tests: modify strlist-test to use new 'check' framework 2012-08-04 08:23:34 +02:00
sync-playback.c tests: modify sync-playback to use 'check' framework 2012-08-20 07:05:59 +05:30
test-daemon.sh tests: Indicate failure in test-daemon.sh by returning 1 if any test fails. 2013-02-06 14:15:09 +02:00
thread-mainloop-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
thread-test.c Remove pa_bool_t and replace it with bool. 2013-07-04 12:25:30 +03:00
usergroup-test.c tests: modify usergroup-test to use 'check' test framework 2012-08-20 07:05:58 +05:30
utf8-test.c tests: modify utf8-test to use new 'check' test framework 2012-08-04 08:23:34 +02:00
volume-test.c volume-test: Increase the allowed number of rouding errors 2014-01-03 14:15:31 +02:00
volume-ui.py tests: show dB in volume-ui.py 2009-05-22 01:31:26 +02:00