summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2014-12-15 21:20:29 +1100
committerErik de Castro Lopo <erikd@mega-nerd.com>2014-12-16 13:21:19 +1100
commiteea13650b97611b0ab11904dd661de8bfb393a9c (patch)
treec68650d67b44f32427d78080eac1f0f0c1f61471
parent149f42892b0206dace36d5117d7814648f78ab01 (diff)
tests/ : Fix undefined behaviour warnings.
-rw-r--r--tests/dwvw_test.c6
-rw-r--r--tests/floating_point_test.tpl16
-rw-r--r--tests/pcm_test.def8
-rw-r--r--tests/utils.tpl5
4 files changed, 20 insertions, 15 deletions
diff --git a/tests/dwvw_test.c b/tests/dwvw_test.c
index 2bd11d1..57bdfac 100644
--- a/tests/dwvw_test.c
+++ b/tests/dwvw_test.c
@@ -1,5 +1,5 @@
/*
-** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2002-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@@ -62,7 +62,7 @@ dwvw_test (const char *filename, int format, int bit_width)
srand (123456) ;
/* Only want to grab the top bit_width bits. */
- bit_mask = (-1 << (32 - bit_width)) ;
+ bit_mask = arith_shift_left (-1, 32 - bit_width) ;
print_test_name ("dwvw_test", filename) ;
@@ -77,7 +77,7 @@ dwvw_test (const char *filename, int format, int bit_width)
} ;
for ( ; k < BUFFER_SIZE ; k++)
- write_buf [k] = bit_mask & ((rand () << 11) ^ (rand () >> 11)) ;
+ write_buf [k] = bit_mask & (arith_shift_left (rand (), 11) ^ (rand () >> 11)) ;
sf_write_int (file, write_buf, BUFFER_SIZE) ;
sf_close (file) ;
diff --git a/tests/floating_point_test.tpl b/tests/floating_point_test.tpl
index b3f480a..1ed4dd4 100644
--- a/tests/floating_point_test.tpl
+++ b/tests/floating_point_test.tpl
@@ -85,8 +85,8 @@ main (int argc, char *argv [])
float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
- float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
- float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
+ float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
+ float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
/* PAF files do not use the same encoding method for 24 bit PCM data as other file
@@ -144,8 +144,8 @@ main (int argc, char *argv [])
double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
- double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
- double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
+ double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
+ double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
/* 24 bit PCM PAF files tested here. */
@@ -159,7 +159,7 @@ main (int argc, char *argv [])
double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
- double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -42.0) ;
+ double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
@@ -203,7 +203,7 @@ float_scaled_test (const char *filename, int allow_exit, int replace_float, int
print_test_name ("float_scaled_test", filename) ;
- gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 1.0) ;
+ gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = DFT_DATA_LENGTH ;
@@ -255,7 +255,7 @@ double_scaled_test (const char *filename, int allow_exit, int replace_float, int
print_test_name ("double_scaled_test", filename) ;
- gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.95) ;
+ gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = DFT_DATA_LENGTH ;
@@ -311,7 +311,7 @@ static void
print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
- gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.98) ;
+ gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
diff --git a/tests/pcm_test.def b/tests/pcm_test.def
index b81f059..2cc91b5 100644
--- a/tests/pcm_test.def
+++ b/tests/pcm_test.def
@@ -3,8 +3,8 @@ autogen definitions pcm_test.tpl;
data_type = {
name = "bits_8" ;
item_count = 127 ;
- short_func = "((k * ((k % 2) ? 1 : -1)) << 8)" ;
- int_func = "((k * ((k % 2) ? 1 : -1)) << 24)" ;
+ short_func = "arith_shift_left (k * ((k % 2) ? 1 : -1), 8)" ;
+ int_func = "arith_shift_left (k * ((k % 2) ? 1 : -1), 24)" ;
float_func = "(k * ((k % 2) ? 1 : -1))" ;
} ;
@@ -12,7 +12,7 @@ data_type = {
name = "bits_16" ;
item_count = 1024 ;
short_func = "(k * ((k % 2) ? 3 : -3))" ;
- int_func = "((k * ((k % 2) ? 3 : -3)) << 16)" ;
+ int_func = "arith_shift_left (k * ((k % 2) ? 3 : -3), 16)" ;
float_func = "(k * ((k % 2) ? 3 : -3))" ;
} ;
@@ -20,7 +20,7 @@ data_type = {
name = "bits_24" ;
item_count = 1024 ;
short_func = "(k * ((k % 2) ? 3 : -3))" ;
- int_func = "((k * ((k % 2) ? 3333 : -3333)) << 8)" ;
+ int_func = "arith_shift_left (k * ((k % 2) ? 3333 : -3333), 8)" ;
float_func = "(k * ((k % 2) ? 3333 : -3333))" ;
} ;
diff --git a/tests/utils.tpl b/tests/utils.tpl
index dc55fa4..6743f1e 100644
--- a/tests/utils.tpl
+++ b/tests/utils.tpl
@@ -79,6 +79,11 @@ exit_if_true (int test, const char *format, ...)
} ;
} /* exit_if_true */
+static inline int32_t
+arith_shift_left (int32_t x, int shift)
+{ return (int32_t) (((uint32_t) x) << shift) ;
+} /* arith_shift_left */
+
/*
** Functions for saving two vectors of data in an ascii text file which
** can then be loaded into GNU octave for comparison.