From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v2 8/9] tests/kms_chamelium: add pulse audio test
Date: Fri, 24 May 2019 18:03:33 +0300 [thread overview]
Message-ID: <20190524150334.15833-9-simon.ser@intel.com> (raw)
In-Reply-To: <20190524150334.15833-1-simon.ser@intel.com>
This commit adds a pulse test alongside the existing frequencies test.
The test sends an infinite pulse and checks that the amplitude is correct. A
window is used to check that each sample is within acceptable bounds. The test
is stopped as soon as 3 audio pages pass the test.
Signed-off-by: Simon Ser <simon.ser@intel.com>
---
tests/kms_chamelium.c | 100 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index 14262831c3ff..073feff0d32d 100644
--- a/tests/kms_chamelium.c
+++ b/tests/kms_chamelium.c
@@ -772,6 +772,9 @@ test_display_frame_dump(data_t *data, struct chamelium_port *port)
/* A streak of 3 gives confidence that the signal is good. */
#define MIN_STREAK 3
+#define PULSE_AMPLITUDE 0.9 /* normalized, ie. in [0, 1] */
+#define PULSE_ACCURACY 0.001 /* ± 0.1 % of the full amplitude */
+
/* TODO: enable >48KHz rates, these are not reliable */
static int test_sampling_rates[] = {
32000,
@@ -1136,6 +1139,102 @@ static bool test_audio_frequencies(struct audio_state *state)
return success;
}
+static int audio_output_pulse_callback(void *data, void *buffer, int samples)
+{
+ struct audio_state *state = data;
+ double *tmp;
+ size_t len, i;
+
+ len = samples * state->playback.channels;
+ tmp = malloc(len * sizeof(double));
+ for (i = 0; i < len; i++)
+ tmp[i] = PULSE_AMPLITUDE;
+ audio_convert_to(buffer, tmp, len, state->playback.format);
+ free(tmp);
+
+ return state->run ? 0 : -1;
+}
+
+static bool detect_pulse_amplitude(double *buf, size_t buf_len)
+{
+ double min, max;
+ size_t i;
+ bool ok;
+
+ min = max = NAN;
+ for (i = 0; i < buf_len; i++) {
+ if (isnan(min) || buf[i] < min)
+ min = buf[i];
+ if (isnan(max) || buf[i] > max)
+ max = buf[i];
+ }
+
+ ok = (min >= PULSE_AMPLITUDE - PULSE_ACCURACY &&
+ max <= PULSE_AMPLITUDE + PULSE_ACCURACY);
+ if (ok)
+ igt_debug("Pulse detected\n");
+ else
+ igt_debug("Pulse not detected (min=%f, max=%f)\n",
+ min, max);
+ return ok;
+}
+
+static bool test_audio_pulse(struct audio_state *state)
+{
+ bool success;
+ int32_t *recv;
+ size_t recv_len, i, channel_len;
+ int streak, capture_chan;
+ double *channel;
+
+ alsa_register_output_callback(state->alsa,
+ audio_output_pulse_callback, state,
+ PLAYBACK_SAMPLES);
+
+ audio_state_start(state, "pulse");
+
+ recv = NULL;
+ recv_len = 0;
+ success = false;
+ while (!success && state->msec < AUDIO_TIMEOUT) {
+ audio_state_receive(state, &recv, &recv_len);
+
+ igt_debug("Detecting audio signal, t=%d msec\n", state->msec);
+
+ for (i = 0; i < state->playback.channels; i++) {
+ capture_chan = state->channel_mapping[i];
+ igt_assert(capture_chan >= 0);
+ igt_debug("Processing channel %zu (captured as "
+ "channel %d)\n", i, capture_chan);
+
+ channel_len = audio_extract_channel_s32_le(NULL, 0,
+ recv, recv_len,
+ state->capture.channels,
+ capture_chan);
+ channel = malloc(channel_len * sizeof(double));
+ audio_extract_channel_s32_le(channel, channel_len,
+ recv, recv_len,
+ state->capture.channels,
+ capture_chan);
+
+ if (detect_pulse_amplitude(channel, channel_len))
+ streak++;
+ else
+ streak = 0;
+
+ free(channel);
+ }
+
+ success = streak == MIN_STREAK * state->playback.channels;
+ }
+
+ audio_state_stop(state, success);
+
+ free(recv);
+
+ return success;
+}
+
static bool check_audio_configuration(struct alsa *alsa, snd_pcm_format_t format,
int channels, int sampling_rate)
{
@@ -1233,6 +1332,7 @@ test_display_audio(data_t *data, struct chamelium_port *port,
audio_state_init(&state, data, alsa, port,
format, channels, sampling_rate);
success &= test_audio_frequencies(&state);
+ success &= test_audio_pulse(&state);
audio_state_fini(&state);
alsa_close_output(alsa);
--
2.21.0
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-05-24 15:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 15:03 [igt-dev] [PATCH i-g-t v2 0/9] tests/kms_chamelium: add pulse test Simon Ser
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 1/9] tests/kms_chamelium: refactor audio test Simon Ser
2019-05-27 10:20 ` Martin Peres
2019-05-27 12:17 ` Ser, Simon
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 2/9] tests/kms_chamelium: introduce audio_state_receive Simon Ser
2019-05-27 12:24 ` Martin Peres
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 3/9] tests/kms_chamelium: rename do_test_display_audio and test_audio_configuration Simon Ser
2019-05-27 12:25 ` Martin Peres
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 4/9] tests/kms_chamelium: explain why 8-channel tests aren't performed Simon Ser
2019-05-27 12:25 ` Martin Peres
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 5/9] lib/igt_audio: introduce audio_convert_to Simon Ser
2019-05-27 12:27 ` Martin Peres
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 6/9] tests/kms_chamelium: add name parameter to audio_state_start Simon Ser
2019-05-27 12:29 ` Martin Peres
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 7/9] lib/igt_audio: make audio_extract_channel_s32_le support a NULL dst Simon Ser
2019-05-27 12:30 ` Martin Peres
2019-05-24 15:03 ` Simon Ser [this message]
2019-05-27 12:46 ` [igt-dev] [PATCH i-g-t v2 8/9] tests/kms_chamelium: add pulse audio test Martin Peres
2019-05-24 15:03 ` [igt-dev] [PATCH i-g-t v2 9/9] tests/kms_chamelium: add audio channel alignment test Simon Ser
2019-05-27 13:34 ` Martin Peres
2019-05-26 9:58 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_chamelium: add pulse test Patchwork
2019-05-26 13:09 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2019-05-27 6:31 ` Ser, Simon
2019-05-27 13:41 ` Martin Peres
2019-05-27 7:01 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/kms_chamelium: add pulse test (rev2) Patchwork
2019-05-27 15:00 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190524150334.15833-9-simon.ser@intel.com \
--to=simon.ser@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.