Skip to contentSkip to conversation

hda-emu: Test all codecs, not just the first one

PATCH Applied David Henningsson 2 participants 7 messages Sep 4, 2014

lore
Share & tools
lore
#0 lore raw

cover 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(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/5 hda-emu: Deal with two cards with one codec each

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.

---
 hda-parse.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
hda-parse.c +9 -7
index 8d9a3c7..d9fc311 100644
@@ -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++;
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/5 hda-emu: Quit early if requested codec index is above limit

In reply to David Henningsson
---
 hda-parse.c | 5 +++++
 1 file changed, 5 insertions(+)
hda-parse.c +5 -0
index d9fc311..57e9ee3 100644
@@ -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;
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/5 hda-emu: Improve error message for modem codecs

In reply to David Henningsson

In some cases (when codec index parameter was specified), selecting a modem codec resulted in "ERROR -77", which was confusing.

---
 hda-parse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hda-parse.c +6 -2
index 57e9ee3..b5abd5e 100644
@@ -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;
 		}
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/5 hda-emu/tester: Add codec index parameter to hda-emu-tester

In reply to David Henningsson

Also improve runner's error handling a little.

---
 tester/hda-emu-tester.py |  2 ++
 tester/runner.py         | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
tester/hda-emu-tester.py +2 -0
index 4782a97..3b994ab 100755
@@ -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
 
tester/runner.py +12 -2
index 1e7ecf9..964da1a 100644
@@ -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)
Signature · 1 line
1.9.1
#5 lore raw

PATCH 5/5 hda-emu/tester: Test all codecs, not just one

In reply to David Henningsson

This way we get a more complete test over the codecs.

---
 tester/summary.py | 62 +++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 13 deletions(-)
tester/summary.py +49 -13
index 0f9fbf3..640d1c1 100755
@@ -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)
Signature · 1 line
1.9.1
Applied
#6 lore raw
In reply to David Henningsson

At Thu, 4 Sep 2014 14:21:02 +0200,

Quoted 8 lines · David Henningsson

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!

Quoted 6 lines

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

Quoted 10 lines
 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(-)
Signature · 1 line
1.9.1