[alsa-devel] [PATCH 2/2] hda-emu: Initial draft of test framework implementation
David Henningsson
david.henningsson at canonical.com
Wed Aug 8 11:54:30 CEST 2012
Still work in progress, but it is starting to prove useful.
Signed-off-by: David Henningsson <david.henningsson at 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 at 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 at 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
More information about the Alsa-devel
mailing list