alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: David Henningsson <david.henningsson@canonical.com>
To: tiwai@suse.de, alsa-devel@alsa-project.org
Cc: David Henningsson <david.henningsson@canonical.com>
Subject: [PATCH 2/2] hda-emu: Initial draft of test framework implementation
Date: Wed,  8 Aug 2012 11:54:30 +0200	[thread overview]
Message-ID: <1344419670-8946-2-git-send-email-david.henningsson@canonical.com> (raw)
In-Reply-To: <1344419670-8946-1-git-send-email-david.henningsson@canonical.com>

Still work in progress, but it is starting to prove useful.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
---
 tester/hda-emu-tester.py |   61 ++++++++++++++++++++++++++
 tester/runall.sh         |    3 ++
 tester/runner.py         |  109 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+)
 create mode 100755 tester/hda-emu-tester.py
 create mode 100755 tester/runall.sh
 create mode 100644 tester/runner.py

diff --git a/tester/hda-emu-tester.py b/tester/hda-emu-tester.py
new file mode 100755
index 0000000..a931651
--- /dev/null
+++ b/tester/hda-emu-tester.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+# hda-emu-tester - a test framework around hda-emu
+#
+# Written by David Henningsson <david.henningsson@canonical.com>
+#
+#    Copyright 2012 Canonical Ltd.
+#
+#    This program is free software: you can redistribute it and/or modify it 
+#    under the terms of the GNU General Public License version 3, as published 
+#    by the Free Software Foundation.
+#
+#    This program is distributed in the hope that it will be useful, but 
+#    WITHOUT ANY WARRANTY; without even the implied warranties of 
+#    MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
+#    PURPOSE.  See the GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License along 
+#    with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+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')
+    return parser.parse_args()
+
+def run_test(argv):
+    import runner
+    result = runner.HdaEmuRunner()
+    result.set_alsa_info_file(argv.file)
+    result.run_standard()
+    return result
+
+def get_exit_code(result):
+    if result.errors > 9:
+        return 29
+    if result.errors > 0:
+        return 20 + result.errors
+    if result.warnings > 9:
+        return 19
+    if result.warnings > 0:
+        return 10 + result.warnings
+    return 0
+
+def main():
+    import sys
+    try:
+        argv_dict = handle_argv()
+        result = run_test(argv_dict)
+        exitcode = get_exit_code(result)
+        if result.errors > 0 or result.warnings > 0:
+            print '{0} errors, {1} warnings. ({2})'.format(result.errors, result.warnings, argv_dict.file)
+    except:
+        import traceback
+        traceback.print_exc()
+        sys.exit(99)
+
+    sys.exit(exitcode)
+
+if __name__ == "__main__":
+    main()
diff --git a/tester/runall.sh b/tester/runall.sh
new file mode 100755
index 0000000..d078f35
--- /dev/null
+++ b/tester/runall.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+find ../codecs/canonical/ -type f | sort | xargs -n1 ./hda-emu-tester.py --file
+
diff --git a/tester/runner.py b/tester/runner.py
new file mode 100644
index 0000000..28953be
--- /dev/null
+++ b/tester/runner.py
@@ -0,0 +1,109 @@
+# hda-emu-tester - a test framework around hda-emu
+#
+# Written by David Henningsson <david.henningsson@canonical.com>
+#
+#    Copyright 2012 Canonical Ltd.
+#
+#    This program is free software: you can redistribute it and/or modify it 
+#    under the terms of the GNU General Public License version 3, as published 
+#    by the Free Software Foundation.
+#
+#    This program is distributed in the hope that it will be useful, but 
+#    WITHOUT ANY WARRANTY; without even the implied warranties of 
+#    MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
+#    PURPOSE.  See the GNU General Public License for more details.
+#
+#    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 subprocess
+import os
+
+class HdaEmuRunner():
+
+    def __init__(self):
+        self.child_args = "../hda-emu -M -F"
+        self.alsa_info = "/proc/asound/card0/codec#0"
+        self.errors = 0
+        self.warnings = 0
+
+    def set_alsa_info_file(self, filename):
+        self.alsa_info = filename
+
+    def start_process(self):
+        import shlex
+        from subprocess import PIPE, STDOUT
+
+        args = shlex.split(self.child_args)
+        args.append(self.alsa_info)
+        self.child = subprocess.Popen(args, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+
+    def stop_process(self):
+        if self.child is None:
+            return
+        self.child.terminate()
+        self.child.wait()
+        self.child = None
+
+
+    def check_stdout(self):
+        s = os.read(self.child.stdout.fileno(), 65536)
+        # print "Stdout received (", len(s), ")"
+        if s == "":
+            print "Unexpected EOF of stdout (hda-emu crashed?)"
+            self.errors += 1
+            return
+        self.stdout_total += s
+
+        q, _, self.stdout_total = self.stdout_total.rpartition('\n')
+        for s in q.splitlines():
+            if s.startswith("Error:"):
+                self.errors += 1
+                # print s
+            if s.startswith("Warning:"):
+                self.warnings += 1
+                # print s
+
+    def check_stderr(self):
+        s = os.read(self.child.stderr.fileno(), 65536)
+        # print "Stderr received (", len(s), ")"
+        if s == "":
+            print "Unexpected EOF of stderr (hda-emu crashed?)"
+            self.errors += 1
+            return False
+        if s == "> ":
+            return True
+        print "Unexpected stderr output: '" + prompt + "'"
+        self.errors += 1
+        return False
+
+    def run_command(self, command=None):
+        if command:
+            self.child.stdin.write(command + '\n')
+            self.child.stdin.flush()
+
+        import select
+        self.stdout_total = ""
+        pipelist = [self.child.stdout, self.child.stderr]
+        while True:
+            readable, _, broken = select.select(pipelist, [], pipelist, 3)
+            for q in broken:
+                print "Broken pipe (hda-emu crashed?)"
+                self.errors += 1
+                return
+            if readable == []:
+                print "Timeout waiting for hda-emu"
+                self.errors += 1
+                return
+            if self.child.stdout in readable:
+                self.check_stdout()
+            if self.child.stderr in readable:
+                if self.check_stderr():
+                    return
+
+    def run_standard(self):
+        self.start_process()
+        self.run_command() # Initial parsing
+        self.run_command("pm") # S3 test
+        self.stop_process()
+
-- 
1.7.9.5

  reply	other threads:[~2012-08-08  9:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-08  9:54 [PATCH 1/2] hda-emu: Flush output before prompt David Henningsson
2012-08-08  9:54 ` David Henningsson [this message]
2012-08-08  9:55   ` [PATCH 2/2] hda-emu: Initial draft of test framework implementation David Henningsson
2012-08-08 10:03     ` Takashi Iwai

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=1344419670-8946-2-git-send-email-david.henningsson@canonical.com \
    --to=david.henningsson@canonical.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).