lib/igt_audio: make audio_signal_detect take const data
PATCH v2 1/1 lib/igt_audio: make audio_signal_detect take const data
audio_signal_detect uses gsl_fft_real_radix2_transform which mutates the data array. This can be surprising when calling audio_signal_detect and then read again the data (e.g. for another check).
Instead of mutating the array, make audio_signal_detect less error-prone by taking a const parameter. Do an internal copy before calling the gsl function.
--- lib/igt_audio.c | 18 +++++++++++++++--- lib/igt_audio.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-)
lib/igt_audio.c +15 -3
@@ -251,11 +251,14 @@ void audio_signal_fill(struct audio_signal *signal, int16_t *buffer,* Checks that frequencies specified in signal, and only those, are included * in the input data. * -* sampling_rate is given in Hz. data_len is the number of elements in data. +* sampling_rate is given in Hz. samples_len is the number of elements in +* samples. */ bool audio_signal_detect (struct audio_signal *signal,int sampling_rate, -int channel,double *data,size_t data_len) +int channel,const double *samples,size_t samples_len) { +double *data; +size_t data_len = samples_len;size_t bin_power_len = data_len /2 +1 ;double bin_power[bin_power_len];bool detected[FREQS_MAX ];
@@ -264,12 +267,19 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,size_t i, j;bool above, success; +/* gsl will mutate the array in-place, so make a copy */ + data =malloc (samples_len *sizeof (double )); +memcpy (data, samples, samples_len *sizeof (double )); +/* Allowed error in Hz due to FFT step */ freq_accuracy = sampling_rate / data_len;igt_debug ("Allowed freq. error: %d Hz\n" , freq_accuracy); ret =gsl_fft_real_radix2_transform (data,1 , data_len); -igt_assert (ret ==0 ); +if (ret !=0 ) { +free (data); +igt_assert (0 ); + }/* Compute the power received by every bin of the FFT, and record the * maximum power received as a way to normalize all the others.
@@ -372,6 +382,8 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, } } +free (data); +return success; }
lib/igt_audio.h +1 -1
@@ -43,7 +43,7 @@ void audio_signal_reset(struct audio_signal *signal);void audio_signal_fill (struct audio_signal *signal,int16_t *buffer,size_t buffer_len);bool audio_signal_detect (struct audio_signal *signal,int sampling_rate, -int channel,double *data,size_t data_len); +int channel,const double *samples,size_t samples_len);size_t audio_extract_channel_s32_le (double *dst,size_t dst_cap,int32_t *src,size_t src_len,int n_channels,int channel);
--
2.21.0
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Quoted 35 lines · Simon Ser
audio_signal_detectusesgsl_fft_real_radix2_transformwhich mutates the data array. This can be surprising when callingaudio_signal_detectand then read again the data (e.g. for another check).Instead of mutating the array, make
audio_signal_detectless error-prone by taking a const parameter. Do an internal copy before calling the gsl function.Signed-off-by Simon Ser <[email protected]>--- lib/igt_audio.c | 18 +++++++++++++++--- lib/igt_audio.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-)lib/igt_audio.c +5
-2@@ -251,11 +251,14 @@ void audio_signal_fill(struct audio_signal *signal, int16_t *buffer,* Checks that frequencies specified in signal, and only those, are included * in the input data. * -* sampling_rate is given in Hz. data_len is the number of elements in data. +* sampling_rate is given in Hz. samples_len is the number of elements in +* samples. */ bool audio_signal_detect (struct audio_signal *signal,int sampling_rate, -int channel,double *data,size_t data_len) +int channel,const double *samples,size_t samples_len) { +double *data; +size_t data_len = samples_len;size_t bin_power_len = data_len /2 +1 ;double bin_power[bin_power_len];bool detected[FREQS_MAX ];
lib/igt_audio.c bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, · line 272
Quoted 6 lines
lib/igt_audio.c +3
-0@@ -264,12 +267,19 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,size_t i, j;bool above, success; +/* gsl will mutate the array in-place, so make a copy */ + data =malloc (samples_len *sizeof (double )); +memcpy (data, samples, samples_len *sizeof (double ));
Maybe some kind of memdup() might be useful. Not sure how many instances of this pattern we have in igt.
lib/igt_audio.c bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, · line 282
Quoted 11 lines
lib/igt_audio.c +5
-1+/* Allowed error in Hz due to FFT step */ freq_accuracy = sampling_rate / data_len;igt_debug ("Allowed freq. error: %d Hz\n" , freq_accuracy); ret =gsl_fft_real_radix2_transform (data,1 , data_len); -igt_assert (ret ==0 ); +if (ret !=0 ) { +free (data); +igt_assert (0 ); + }
It's an assert. Do we really care about cleanup?
Patch is
Quoted 32 lines
lib/igt_audio.c +2
-0/* Compute the power received by every bin of the FFT, and record the * maximum power received as a way to normalize all the others. @@ -372,6 +382,8 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, } } +free (data); +return success; }lib/igt_audio.h +1
-2@@ -43,7 +43,7 @@ void audio_signal_reset(struct audio_signal *signal);void audio_signal_fill (struct audio_signal *signal,int16_t *buffer,size_t buffer_len);bool audio_signal_detect (struct audio_signal *signal,int sampling_rate, -int channel,double *data,size_t data_len); +int channel,const double *samples,size_t samples_len);size_t audio_extract_channel_s32_le (double *dst,size_t dst_cap,int32_t *src,size_t src_len,int n_channels,int channel); --2.21.0
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Signature · 6 lines
Ville Syrjälä Intel _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
Quoted 51 lines · Ville Syrjälä
Quoted 35 lines · Simon Ser
audio_signal_detectusesgsl_fft_real_radix2_transformwhich mutates the data array. This can be surprising when callingaudio_signal_detectand then read again the data (e.g. for another check).Instead of mutating the array, make
audio_signal_detectless error-prone by taking a const parameter. Do an internal copy before calling the gsl function.Signed-off-by Simon Ser <[email protected]>--- lib/igt_audio.c | 18 +++++++++++++++--- lib/igt_audio.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-)lib/igt_audio.c +5
-2@@ -251,11 +251,14 @@ void audio_signal_fill(struct audio_signal *signal, int16_t *buffer,* Checks that frequencies specified in signal, and only those, are included * in the input data. * -* sampling_rate is given in Hz. data_len is the number of elements in data. +* sampling_rate is given in Hz. samples_len is the number of elements in +* samples. */ bool audio_signal_detect (struct audio_signal *signal,int sampling_rate, -int channel,double *data,size_t data_len) +int channel,const double *samples,size_t samples_len) { +double *data; +size_t data_len = samples_len;size_t bin_power_len = data_len /2 +1 ;double bin_power[bin_power_len];bool detected[FREQS_MAX ];lib/igt_audio.c bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, · line 272
Quoted 6 lines
lib/igt_audio.c +3
-0@@ -264,12 +267,19 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate,size_t i, j;bool above, success; +/* gsl will mutate the array in-place, so make a copy */ + data =malloc (samples_len *sizeof (double )); +memcpy (data, samples, samples_len *sizeof (double ));Maybe some kind of
memdup()might be useful. Not sure how many instances of this pattern we have in igt.Quoted 5 lines
lib/igt_audio.c +1
-0+/* Allowed error in Hz due to FFT step */ freq_accuracy = sampling_rate / data_len;igt_debug ("Allowed freq. error: %d Hz\n" , freq_accuracy);
Quoted 8 lines
lib/igt_audio.c bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, · line 282
Quoted 6 lines
lib/igt_audio.c +4
-1ret =gsl_fft_real_radix2_transform (data,1 , data_len); -igt_assert (ret ==0 ); +if (ret !=0 ) { +free (data); +igt_assert (0 ); + }It's an assert. Do we really care about cleanup?
igt_assert, so basically we jump out of test and continue executing.
we wouldn't leak much and matters a little when running a whole binary but it makes some code analysis tools less angry
Quoted 29 lines
Patch is
Reviewed-by Ville Syrjälä <[email protected]>Quoted 27 lines
lib/igt_audio.c +2
-0/* Compute the power received by every bin of the FFT, and record the * maximum power received as a way to normalize all the others. @@ -372,6 +382,8 @@ bool audio_signal_detect(struct audio_signal *signal, int sampling_rate, } } +free (data); +return success; }lib/igt_audio.h +1
-2@@ -43,7 +43,7 @@ void audio_signal_reset(struct audio_signal *signal);void audio_signal_fill (struct audio_signal *signal,int16_t *buffer,size_t buffer_len);bool audio_signal_detect (struct audio_signal *signal,int sampling_rate, -int channel,double *data,size_t data_len); +int channel,const double *samples,size_t samples_len);size_t audio_extract_channel_s32_le (double *dst,size_t dst_cap,int32_t *src,size_t src_len,int n_channels,int channel); --2.21.0
Quoted 12 lines
Quoted 4 lines
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-devSignature · 6 lines
Ville Syrjälä Intel _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.BAT: success for lib/igt_audio: make audio_signal_detect take const data (rev2)
In reply to Simon Ser== Series Details ==
== Series Details ==
Series: lib/igt_audio: make audio_signal_detect take const data (rev2)
URL : https://patchwork.freedesktop.org/series/60585/
State : success
== Summary ==
CI Bug Log - changes from IGT_4988 -> IGTPW_2982
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/60585/revisions/2/mbox/
Known issues
------------
Here are the changes found in IGTPW_2982 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@i915_selftest@live_contexts:
- fi-bdw-gvtdvm: [PASS][1] -> [DMESG-FAIL][2] ([fdo#110235])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/fi-bdw-gvtdvm/igt@i915_selftest@live_contexts.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/fi-bdw-gvtdvm/igt@i915_selftest@live_contexts.html
#### Possible fixes ####
* igt@i915_selftest@live_hangcheck:
- fi-kbl-8809g: [DMESG-FAIL][3] -> [PASS][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/fi-kbl-8809g/igt@i915_selftest@live_hangcheck.html
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/fi-kbl-8809g/igt@i915_selftest@live_hangcheck.html
[fdo#110235]: https://bugs.freedesktop.org/show_bug.cgi?id=110235
Participating hosts (51 -> 46)
------------------------------
Additional (2): fi-icl-u2 fi-pnv-d510
Missing (7): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-byt-clapper fi-bdw-samus
Build changes
-------------
* IGT: IGT_4988 -> IGTPW_2982
CI_DRM_6080: 6c6b621677cc0d3616de3dab025d967aa2c43877 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2982: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/
IGT_4988: 2f6303d13e09b2457762540383c7f36cecd02bbf @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.IGT: success for lib/igt_audio: make audio_signal_detect take const data (rev2)
In reply to Simon Ser== Series Details ==
== Series Details ==
Series: lib/igt_audio: make audio_signal_detect take const data (rev2)
URL : https://patchwork.freedesktop.org/series/60585/
State : success
== Summary ==
CI Bug Log - changes from IGT_4988_full -> IGTPW_2982_full
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/60585/revisions/2/mbox/
Known issues
------------
Here are the changes found in IGTPW_2982_full that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@i915_pm_rpm@i2c:
- shard-iclb: [PASS][1] -> [DMESG-WARN][2] ([fdo#109982])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb8/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb2/igt@[email protected]
* igt@kms_flip@2x-flip-vs-suspend-interruptible:
- shard-hsw: [PASS][3] -> [INCOMPLETE][4] ([fdo#103540])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-hsw6/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-hsw2/igt@[email protected]
* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-render:
- shard-iclb: [PASS][5] -> [FAIL][6] ([fdo#103167]) +2 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb2/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-render.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb2/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-render.html
* igt@kms_psr@psr2_cursor_plane_onoff:
- shard-iclb: [PASS][7] -> [SKIP][8] ([fdo#109441]) +4 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb2/igt@kms_psr@psr2_cursor_plane_onoff.html
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb7/igt@kms_psr@psr2_cursor_plane_onoff.html
* igt@kms_vblank@pipe-c-ts-continuation-suspend:
- shard-apl: [PASS][9] -> [DMESG-WARN][10] ([fdo#108566]) +2 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-apl1/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-apl3/igt@[email protected]
#### Possible fixes ####
* igt@gem_wait@basic-wait-all:
- shard-iclb: [INCOMPLETE][11] ([fdo#107713]) -> [PASS][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb8/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb2/igt@[email protected]
* igt@gem_workarounds@suspend-resume:
- shard-apl: [DMESG-WARN][13] ([fdo#108566]) -> [PASS][14] +3 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-apl8/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-apl4/igt@[email protected]
* igt@kms_color@pipe-b-ctm-negative:
- shard-iclb: [DMESG-WARN][15] -> [PASS][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb2/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb7/igt@[email protected]
* igt@kms_dp_dsc@basic-dsc-enable-edp:
- shard-iclb: [SKIP][17] ([fdo#109349]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb5/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb2/igt@[email protected]
* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-shrfb-plflip-blt:
- shard-iclb: [FAIL][19] ([fdo#103167]) -> [PASS][20] +4 similar issues
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-shrfb-plflip-blt.html
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb1/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-shrfb-plflip-blt.html
* igt@kms_frontbuffer_tracking@psr-rgb101010-draw-blt:
- shard-iclb: [FAIL][21] ([fdo#109247]) -> [PASS][22] +1 similar issue
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb2/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb2/igt@[email protected]
* igt@kms_plane_lowres@pipe-a-tiling-x:
- shard-iclb: [FAIL][23] ([fdo#103166]) -> [PASS][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb1/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb8/igt@[email protected]
* igt@kms_psr@primary_mmap_gtt:
- shard-iclb: [FAIL][25] ([fdo#107383] / [fdo#110215]) -> [PASS][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb2/igt@kms_psr@primary_mmap_gtt.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb7/igt@kms_psr@primary_mmap_gtt.html
* igt@kms_setmode@basic:
- shard-apl: [FAIL][27] ([fdo#99912]) -> [PASS][28]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-apl2/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-apl4/igt@[email protected]
- shard-kbl: [FAIL][29] ([fdo#99912]) -> [PASS][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-kbl6/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-kbl4/igt@[email protected]
* igt@kms_universal_plane@universal-plane-pipe-b-functional:
- shard-apl: [FAIL][31] ([fdo#110037]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-apl7/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-apl3/igt@[email protected]
- shard-kbl: [FAIL][33] ([fdo#110037]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-kbl4/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-kbl2/igt@[email protected]
#### Warnings ####
* igt@gem_mmap_gtt@forked-big-copy-odd:
- shard-iclb: [TIMEOUT][35] ([fdo#109673]) -> [INCOMPLETE][36] ([fdo#107713] / [fdo#109100])
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4988/shard-iclb8/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/shard-iclb5/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#103166]: https://bugs.freedesktop.org/show_bug.cgi?id=103166
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103540]: https://bugs.freedesktop.org/show_bug.cgi?id=103540
[fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
[fdo#107383]: https://bugs.freedesktop.org/show_bug.cgi?id=107383
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#109100]: https://bugs.freedesktop.org/show_bug.cgi?id=109100
[fdo#109247]: https://bugs.freedesktop.org/show_bug.cgi?id=109247
[fdo#109349]: https://bugs.freedesktop.org/show_bug.cgi?id=109349
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109673]: https://bugs.freedesktop.org/show_bug.cgi?id=109673
[fdo#109982]: https://bugs.freedesktop.org/show_bug.cgi?id=109982
[fdo#110037]: https://bugs.freedesktop.org/show_bug.cgi?id=110037
[fdo#110215]: https://bugs.freedesktop.org/show_bug.cgi?id=110215
[fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912
Participating hosts (7 -> 6)
------------------------------
Missing (1): shard-skl
Build changes
-------------
* IGT: IGT_4988 -> IGTPW_2982
CI_DRM_6080: 6c6b621677cc0d3616de3dab025d967aa2c43877 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2982: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/
IGT_4988: 2f6303d13e09b2457762540383c7f36cecd02bbf @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2982/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev