[alsa-devel] [PATCH 0/5] hda-emu: Test all codecs, not just the first one

I've improved my test suite to test all the codecs of an alsa-info file, instead of just testing the first one.
However, this means that some errors started to show up in my test suite again, so it also means more work to do...but hopefully it's all leading better quality HDA driver in the end!
David Henningsson (5): hda-emu: Deal with two cards with one codec each hda-emu: Quit early if requested codec index is above limit hda-emu: Improve error message for modem codecs hda-emu/tester: Add codec index parameter to hda-emu-tester hda-emu/tester: Test all codecs, not just one
hda-parse.c | 29 +++++++++++++++------- tester/hda-emu-tester.py | 2 ++ tester/runner.py | 14 +++++++++-- tester/summary.py | 62 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 83 insertions(+), 24 deletions(-)

When using the -i switch to specify an index, we need to deal with two common cases: 1) All codecs belong to one card 2) There are as many cards as there are codecs
This patch makes sure we pick the correct pci ID and SSID for the second case, too.
Signed-off-by: David Henningsson david.henningsson@canonical.com --- hda-parse.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/hda-parse.c b/hda-parse.c index 8d9a3c7..d9fc311 100644 --- a/hda-parse.c +++ b/hda-parse.c @@ -481,21 +481,21 @@ static int parse_codec_recursive(const char *buffer) } /* check the extra information from alsa-info output */ -static void check_alsa_info(char *line) +static int check_alsa_info(char *line, int override) { int dummy, classid, vendor, id, rev;
if (sscanf(line, "%02x:%02x.%1d %04x: %04x:%04x (rev %02x)", &dummy, &dummy, &dummy, &classid, &vendor, &id, &rev) == 7) { - if (classid == 0x0403 && !codec->pci_vendor) { + if (classid == 0x0403 && (override || !codec->pci_vendor)) { codec->pci_vendor = vendor; codec->pci_device = id; codec->pci_revision = rev; } - return; + return 0; } if (sscanf(line, " Subsystem: %04x:%04x", &vendor, &id) == 2) { - if (!codec->pci_subvendor) { + if (override || !codec->pci_subvendor) { codec->pci_subvendor = vendor; codec->pci_subdevice = id; hda_log(HDA_LOG_INFO, "Getting PCI ID %04x:%04x (%04x:%04x) rev %02x\n", @@ -503,8 +503,9 @@ static void check_alsa_info(char *line) codec->pci_subvendor, codec->pci_subdevice, codec->pci_revision); } - return; + return 1; } + return 0; }
static int add_sysfs_list(struct xhda_codec *codec, int *vals) @@ -612,7 +613,7 @@ static void clear_codec(struct xhda_codec *codec) int parse_codec_proc(FILE *fp, struct xhda_codec *codecp, int codec_index) { char buffer[256], *p; - int curidx = -1; + int curidx = -1, pciidx = 0; int err = 0;
codec = codecp; @@ -625,7 +626,8 @@ int parse_codec_proc(FILE *fp, struct xhda_codec *codecp, int codec_index) again: if (parse_mode == PARSE_START) { if (!strmatch(buffer, "Codec: ")) { - check_alsa_info(buffer); + if (check_alsa_info(buffer, pciidx == codec_index)) + pciidx++; continue; } curidx++;

Signed-off-by: David Henningsson david.henningsson@canonical.com --- hda-parse.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/hda-parse.c b/hda-parse.c index d9fc311..57e9ee3 100644 --- a/hda-parse.c +++ b/hda-parse.c @@ -687,6 +687,11 @@ int parse_codec_proc(FILE *fp, struct xhda_codec *codecp, int codec_index) } }
+ if (curidx < codec_index) { + hda_log(HDA_LOG_ERR, "Codec index %d requested, but found only %d codecs\n", codec_index, curidx+1); + return -ENODEV; + } + add_codec_extensions(codec);
return 0;

In some cases (when codec index parameter was specified), selecting a modem codec resulted in "ERROR -77", which was confusing.
Signed-off-by: David Henningsson david.henningsson@canonical.com --- hda-parse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/hda-parse.c b/hda-parse.c index 57e9ee3..b5abd5e 100644 --- a/hda-parse.c +++ b/hda-parse.c @@ -675,13 +675,17 @@ int parse_codec_proc(FILE *fp, struct xhda_codec *codecp, int codec_index) parse_mode = PARSE_ROOT; } err = parse_codec_recursive(buffer); - if (err < 0) { - if (err == -EBADFD && codec_index < 0) { + if (err == -EBADFD) { + if (codec_index < 0) { hda_log(HDA_LOG_INFO, "Codec %d is a modem codec, skipping\n", curidx); parse_mode = PARSE_START; clear_codec(codec); continue; } + hda_log(HDA_LOG_ERR, "Codec %d is a modem codec, aborting\n", curidx); + return err; + } + else if (err < 0) { hda_log(HDA_LOG_ERR, "ERROR %d\n", err); return err; }

Also improve runner's error handling a little.
Signed-off-by: David Henningsson david.henningsson@canonical.com --- tester/hda-emu-tester.py | 2 ++ tester/runner.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/tester/hda-emu-tester.py b/tester/hda-emu-tester.py index 4782a97..3b994ab 100755 --- a/tester/hda-emu-tester.py +++ b/tester/hda-emu-tester.py @@ -22,6 +22,7 @@ def handle_argv(): import argparse parser = argparse.ArgumentParser(description='Hda-emu automated test wrapper.') parser.add_argument('--file', dest='file', required=True, help='alsa-info filename') + parser.add_argument('--codec-index', dest='codecindex', default=0, help='what codec to test') parser.add_argument('--print-errors', dest='print_errors', action="store_true", default=False, help='print errors, and the command that caused it') parser.add_argument('--comm-log', dest='comm_log', action="store_true", @@ -34,6 +35,7 @@ def run_test(argv): result.set_print_errors(argv.print_errors) result.set_comm_log_enabled(argv.comm_log) result.set_alsa_info_file(argv.file) + result.set_codec_index(argv.codecindex) result.run_standard() return result
diff --git a/tester/runner.py b/tester/runner.py index 1e7ecf9..964da1a 100644 --- a/tester/runner.py +++ b/tester/runner.py @@ -20,6 +20,9 @@ import subprocess import os import re
+class HdaEmuFatalError(Exception): + pass + class ControlInfo(): def __init__(self, runner, list_info): self.runner = runner @@ -48,15 +51,20 @@ class HdaEmuRunner(): def __init__(self): import os.path hda_emu_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../hda-emu") - self.child_args = '"' + hda_emu_path + '" -M -F' + self.child_args = '"' + hda_emu_path + '" -M -F -i' self.alsa_info = "/proc/asound/card0/codec#0" self.errors = 0 self.warnings = 0 self.fatals = 0 + self.codec_index = 0 self.print_errors = False + self.error_list = [] self.comm_log_enabled = False self.last_command = None
+ def set_codec_index(self, codec_index): + self.codec_index = codec_index + def set_alsa_info_file(self, filename): self.alsa_info = filename
@@ -71,6 +79,7 @@ class HdaEmuRunner(): from subprocess import PIPE, STDOUT
args = shlex.split(self.child_args) + args.append(str(self.codec_index)) args.append(self.alsa_info) self.child = subprocess.Popen(args, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE)
@@ -82,6 +91,7 @@ class HdaEmuRunner(): self.child = None
def add_error(self, message, severity): + self.error_list.append(message) if severity == "Warning": self.warnings += 1 else: @@ -97,7 +107,7 @@ class HdaEmuRunner(): self.last_command_printed = True print " ", message if self.fatals > 0: - raise Exception(message) + raise HdaEmuFatalError(message)
def check_stdout(self): s = os.read(self.child.stdout.fileno(), 65536)

This way we get a more complete test over the codecs.
Signed-off-by: David Henningsson david.henningsson@canonical.com --- tester/summary.py | 62 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 13 deletions(-)
diff --git a/tester/summary.py b/tester/summary.py index 0f9fbf3..640d1c1 100755 --- a/tester/summary.py +++ b/tester/summary.py @@ -18,15 +18,33 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see http://www.gnu.org/licenses/.
+import runner + + def defaultpath(s): import os.path q = os.path.dirname(os.path.realpath(__file__)) return os.path.join(q, s)
+def count_codecs(filename): + r = runner.HdaEmuRunner() + r.set_alsa_info_file(filename) + r.set_codec_index(99999) + r.start_process() + try: + r.run_command() + except runner.HdaEmuFatalError: + import re + m = re.compile("Codec index (\d+) requested, but found only (\d+) codecs") + for line in r.error_list: + match = m.search(line) + if match: + return int(match.group(2)) + return -1 + def main(): import os import os.path - import runner
import argparse parser = argparse.ArgumentParser(description='Hda-emu automated test wrapper.') @@ -53,19 +71,37 @@ def main(): index += 1 if verbose > 2: print '[{0}/{1}]: Testing {2}'.format(index, len(files), f) + try: - r = runner.HdaEmuRunner() - r.set_alsa_info_file(os.path.join(directory, f)) - r.set_print_errors(verbose > 1) - r.run_standard() - if r.errors > 0 or r.warnings > 0: - fails += 1 - errors += r.errors - warnings += r.warnings - if verbose > 0: - print '{0} errors, {1} warnings. ({2})'.format(r.errors, r.warnings, f) - else: - successes += 1 + codecs = count_codecs(os.path.join(directory, f)) + + fail_this = False + skip_this = codecs < 0 + for codec_index in range(codecs): + r = runner.HdaEmuRunner() + r.set_alsa_info_file(os.path.join(directory, f)) + r.set_codec_index(codec_index) + r.set_print_errors(verbose > 1) + + try: + r.run_standard() + except runner.HdaEmuFatalError: + for line in r.error_list: + if line.find("is a modem codec, aborting"): + skip_this = True + + if (not skip_this) and (r.errors > 0 or r.warnings > 0): + fail_this = True + errors += r.errors + warnings += r.warnings + if verbose > 0: + print '{0} errors, {1} warnings for {2}, codec {3}/{4}.'.format(r.errors, r.warnings, f, codec_index+1, codecs) + + if not skip_this: + if fail_this: + fails += 1 + else: + successes += 1 except KeyboardInterrupt: import sys sys.exit(1)

At Thu, 4 Sep 2014 14:21:02 +0200, David Henningsson wrote:
I've improved my test suite to test all the codecs of an alsa-info file, instead of just testing the first one.
However, this means that some errors started to show up in my test suite again, so it also means more work to do...but hopefully it's all leading better quality HDA driver in the end!
David Henningsson (5): hda-emu: Deal with two cards with one codec each hda-emu: Quit early if requested codec index is above limit hda-emu: Improve error message for modem codecs hda-emu/tester: Add codec index parameter to hda-emu-tester hda-emu/tester: Test all codecs, not just one
Thanks, applied all patches.
Takashi
hda-parse.c | 29 +++++++++++++++------- tester/hda-emu-tester.py | 2 ++ tester/runner.py | 14 +++++++++-- tester/summary.py | 62 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 83 insertions(+), 24 deletions(-)
-- 1.9.1
participants (2)
-
David Henningsson
-
Takashi Iwai