[igt-dev] [PATCH i-g-t 2/5] lib/tests/igt_audio: add test with missing frequency

Simon Ser simon.ser at intel.com
Wed May 29 13:32:47 UTC 2019


Make sure detection fails.

Signed-off-by: Simon Ser <simon.ser at intel.com>
---
 lib/tests/igt_audio.c | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/lib/tests/igt_audio.c b/lib/tests/igt_audio.c
index 0ca3a4342ad9..7b068c255973 100644
--- a/lib/tests/igt_audio.c
+++ b/lib/tests/igt_audio.c
@@ -32,6 +32,10 @@
 #define CHANNELS 1
 #define BUFFER_LEN 2048
 
+static const int test_freqs[] = { 300, 700, 5000 };
+
+static const size_t test_freqs_len = sizeof(test_freqs) / sizeof(test_freqs[0]);
+
 static void test_signal_detect_verbatim(struct audio_signal *signal)
 {
 	double buf[BUFFER_LEN];
@@ -66,21 +70,41 @@ static void test_signal_detect_noise(struct audio_signal *signal)
 	igt_assert(!ok);
 }
 
+static void test_signal_detect_missing(struct audio_signal *signal)
+{
+	double buf[BUFFER_LEN];
+	struct audio_signal *missing;
+	bool ok;
+	size_t i;
+
+	/* Miss the first frequency */
+	missing = audio_signal_init(CHANNELS, SAMPLING_RATE);
+	for (i = 1; i < test_freqs_len; i++) {
+		audio_signal_add_frequency(missing, test_freqs[i], 0);
+	}
+	audio_signal_synthesize(missing);
+
+	audio_signal_fill(missing, buf, BUFFER_LEN / CHANNELS);
+	ok = audio_signal_detect(signal, SAMPLING_RATE, 0, buf, BUFFER_LEN);
+	igt_assert(!ok);
+}
+
 igt_main
 {
 	struct audio_signal *signal;
 	int ret;
+	size_t i;
 
 	igt_subtest_group {
 		igt_fixture {
 			signal = audio_signal_init(CHANNELS, SAMPLING_RATE);
 
-			ret = audio_signal_add_frequency(signal, 300, 0);
-			igt_assert(ret == 0);
-			ret = audio_signal_add_frequency(signal, 700, 0);
-			igt_assert(ret == 0);
-			ret = audio_signal_add_frequency(signal, 5000, 0);
-			igt_assert(ret == 0);
+			for (i = 0; i < test_freqs_len; i++) {
+				ret = audio_signal_add_frequency(signal,
+								 test_freqs[i],
+								 0);
+				igt_assert(ret == 0);
+			}
 
 			audio_signal_synthesize(signal);
 		}
@@ -94,6 +118,9 @@ igt_main
 		igt_subtest("signal-detect-noise")
 			test_signal_detect_noise(signal);
 
+		igt_subtest("signal-detect-missing")
+			test_signal_detect_missing(signal);
+
 		igt_fixture {
 			audio_signal_fini(signal);
 		}
-- 
2.21.0



More information about the igt-dev mailing list