alsa_conformance_test.py: parameter for avail-delay option

The use of snd_pcm_avail_delay() in alsa_conformance_tool is made to be
optional and it is only enabled when --avail-delay parameter is passed.

While the use of snd_pcm_avail_delay() on systems where the driver does not
report delay is equal to the use of snd_pcm_avail(), make this optional
also via the python wrapper.

The use of snd_pcm_avail_delay() is required on systems where DSP offload
is used with large buffer to account for the delay caused by it.

BUG=b:404643973
TEST=alsa_conformance_test.py -P hw:0,31 --allow-rates 48000 --avail-delay

Change-Id: I1559f2a064cbb9c528352c4406530aa20a40eed6
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: Naveen Manohar <naveen.m@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/audiotest/+/6565788
Commit-Queue: ChromeOS Auto Retry <chromeos-auto-retry@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Terry Cheong <htcheong@chromium.org>
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Tested-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
diff --git a/script/alsa_conformance_test.py b/script/alsa_conformance_test.py
index 946c32b..3c261d1 100755
--- a/script/alsa_conformance_test.py
+++ b/script/alsa_conformance_test.py
@@ -596,7 +596,7 @@
     """Object which can set params and run alsa_conformance_test."""
 
     def __init__(
-        self, name, stream, criteria, threshold, allow_rates, allow_formats
+        self, name, stream, criteria, threshold, allow_rates, allow_formats, avail_delay
     ):
         """Initializes an AlsaConformanceTester.
 
@@ -606,6 +606,7 @@
           criteria: A Criteria object for pass criteria.
           allow_rates: Restrict the sample rates to be tested if specified.
           allow_formats: Restrict the formats to be tested if specified.
+          avail_delay: use snd_pcm_avail_delay().
         """
         self.name = name
         self.stream = stream
@@ -615,6 +616,7 @@
         self.period_size = None
         self.merge_thld_size = threshold
         self.criteria = criteria
+        self.avail_delay = avail_delay
 
         output = self.run(["--dev_info_only"])
         if output.rc != 0:
@@ -704,6 +706,8 @@
             cmd += ["-p", str(self.period_size)]
         if self.merge_thld_size is not None:
             cmd += ["--merge_threshold_sz", str(self.merge_thld_size)]
+        if self.avail_delay is True:
+            cmd += ["--avail-delay"]
 
         logging.info("Execute command: %s", " ".join(cmd))
         # Replace stdout/stderr with capture_output=True when Python 3.7 is
@@ -1164,6 +1168,12 @@
         "only be used for temporary workarounds, e.g. b/244418775; otherwise "
         "all available formats obtained from device info should be respected.",
     )
+    parser.add_argument(
+        "--avail-delay",
+        action='store_true',
+        help="Use snd_pcm_avail_delay() instead of snd_pcm_avail() to take the"
+        "driver reported delay value into account.",
+    )
 
     args = parser.parse_args()
 
@@ -1190,6 +1200,7 @@
             args.merge_thld_size,
             args.allow_rates,
             args.allow_formats,
+            args.avail_delay,
         )
 
     if args.output_device:
@@ -1200,6 +1211,7 @@
             args.merge_thld_size,
             args.allow_rates,
             args.allow_formats,
+            args.avail_delay,
         )
 
     tester.test(args.test_suites, args.json, args.json_file)