From eea13650b97611b0ab11904dd661de8bfb393a9c Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 15 Dec 2014 21:20:29 +1100 Subject: [PATCH] tests/ : Fix undefined behaviour warnings. --- tests/dwvw_test.c | 6 +++--- tests/floating_point_test.tpl | 16 ++++++++-------- tests/pcm_test.def | 8 ++++---- tests/utils.tpl | 5 +++++ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/dwvw_test.c b/tests/dwvw_test.c index 2bd11d18..57bdfac9 100644 --- a/tests/dwvw_test.c +++ b/tests/dwvw_test.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2002-2011 Erik de Castro Lopo +** Copyright (C) 2002-2014 Erik de Castro Lopo ** ** 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 b3f480a5..1ed4dd44 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 b81f0594..2cc91b5f 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 dc55fa44..6743f1e3 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.