Merge lp:~brendan-donegan/checkbox/bug916859_record_playback into lp:checkbox

Proposed by Brendan Donegan
Status: Merged
Merged at revision: 1200
Proposed branch: lp:~brendan-donegan/checkbox/bug916859_record_playback
Merge into: lp:checkbox
Diff against target: 201 lines (+119/-12)
4 files modified
debian/changelog (+3/-1)
debian/control (+1/-1)
jobs/audio.txt.in (+7/-10)
scripts/audio_settings (+108/-0)
To merge this branch: bzr merge lp:~brendan-donegan/checkbox/bug916859_record_playback
Reviewer Review Type Date Requested Status
Marc Tardif (community) Approve
Brendan Donegan (community) Needs Resubmitting
Review via email: mp+89899@code.launchpad.net

Description of the change

This branch introduces a script (written in Perl! Shock horror!) which manipulates the PulseAudio command line (pacmd) to ensure that when an audio test is run, the system is using the correct input and output, so that the test will be successful as long as the audio is working. I was careful to add functions to store and restore the users settings, so that these tests can still be used in Ubuntu Friendly.

Probably the nicest thing about this test is that all of the instructions in the usb_record_playback test are now superfluous, so I've removed them :)

Since the script is quite complex and the number of scenarios it can be used in numerous, I'd appreciate some independent testing of the script and the modified tests.

To post a comment you must log in.
1180. By Brendan Donegan

Remove Sound Settings instructions from usb_record_playback

Revision history for this message
Marc Tardif (cr3) wrote :

Any particular reason why the script is written in Perl? This makes it very difficult for most of the team to maintain, so I could volunteer to rewrite it in Python if you'd like.

review: Needs Information
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

I think for what it is, which is a script to basically glue together calls to the 'pacmd' tool, it's perfectly understandable. It basically does 3 things 'store', 'set' and 'restore'. Each of these functions constitutes only a handful of lines of code. Personally I think when you're heavily dependent on calling external commands like this, bash or perl is the way to go.

review: Needs Resubmitting
Revision history for this message
Marc Tardif (cr3) wrote :

In that case, since this seems to be the one and only Perl script in checkbox, we should at least add the corresponding package name to the Recommends line in the debian/control file. It doesn't strictly need to be in the Depends line because only a script depends on that package. By the way, I'm not sure whether the package should be expressed as just "perl" or something more esoteric like "${perl:Depends}".

review: Needs Fixing
1181. By Brendan Donegan

Made audio_settings a bit more understandable and added a dependency on perl

1182. By Brendan Donegan

Updated debian changelog with entry for bug fix.

1183. By Brendan Donegan

Merged from trunk.

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

I added 'perl' to the list of dependencies. It seems {perl:Depends} would be replaced with whatever perl is a synonym for (like python is synonymous with python2.7 depending on the release). perl doesn't use this convention, so it seems just 'perl' will do.

review: Needs Resubmitting
Revision history for this message
Marc Tardif (cr3) wrote :

I've noticed some packages like slony1-bin uses the convention ${perl:Depends} whereas postgresql-8.4 just uses perl, so I'm easy either way. However, I would prefer that the dependency was added to Recommends rather than Depends because, as stated in my previous message, only the script has the dependency as opposed to the core.

review: Needs Fixing
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Ok, hopefully should be better now. Sorry about that.

review: Needs Resubmitting
1184. By Brendan Donegan

Put perl as a recommends instead of a depends

Revision history for this message
Marc Tardif (cr3) wrote :

Looks good and thanks for keeping the Recommends in alphabetical order! Merging...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-01-25 15:03:00 +0000
3+++ debian/changelog 2012-01-25 17:31:47 +0000
4@@ -20,7 +20,9 @@
5 output tests.
6 * Added removable_storage_watcher script to replace watch_command to make
7 testing USB, FireWire and MMC devices easier and more cohesive.
8- * Added memory_compare script to automate the memory/info job
9+ * Added memory_compare script to automate the memory/info job
10+ * Switch audio settings to correct device before running audio tests
11+ (LP: #916859)
12
13 [Gabor Kelemen]
14 * Fixed last two remaining strings with backslashes (LP: #868571)
15
16=== modified file 'debian/control'
17--- debian/control 2011-12-07 04:34:49 +0000
18+++ debian/control 2012-01-25 17:31:47 +0000
19@@ -14,7 +14,7 @@
20 Replaces: hwtest (<< 0.1-0ubuntu12)
21 Provides: hwtest
22 Depends: ${misc:Depends}, ${python:Depends}, debconf, python-libxml2, udev
23-Recommends: dpkg (>= 1.13), lsb-release, pm-utils, python-apport, python-apt, python-dateutil, python-gst0.10
24+Recommends: dpkg (>= 1.13), lsb-release, perl, pm-utils, python-apport, python-apt, python-dateutil, python-gst0.10
25 Suggests: checkbox-cli | checkbox-gtk, bonnie++, bootchart, bzr, cvs, ethtool, flex, fwts, git-core, hdparm, lshw, make, nmap, obexd-client, python-pexpect, smartmontools, sox, stress, wodim
26 Conflicts: hwtest (<< 0.1-0ubuntu12)
27 Description: System testing application
28
29=== modified file 'jobs/audio.txt.in'
30--- jobs/audio.txt.in 2011-11-25 18:07:15 +0000
31+++ jobs/audio.txt.in 2012-01-25 17:31:47 +0000
32@@ -12,7 +12,7 @@
33 requires:
34 device.category == 'AUDIO'
35 package.name == 'alsa-base' and package.name == 'python-gst0.10'
36-command: gst_pipeline_test -t 2 'audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! gconfaudiosink'
37+command: audio_settings store $CHECKBOX_SHARE/pulseaudio_settings; audio_settings set --device=pci --volume=50; gst_pipeline_test -t 2 'audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! gconfaudiosink'; audio_settings restore --file=$CHECKBOX_SHARE/pulseaudio_settings
38 _description:
39 PURPOSE:
40 This test will check that internal speakers work correctly
41@@ -29,7 +29,7 @@
42 requires:
43 device.category == 'AUDIO'
44 package.name == 'alsa-base' and package.name == 'python-gst0.10'
45-command: gst_pipeline_test -t 2 'audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! gconfaudiosink'
46+command: audio_settings store $CHECKBOX_SHARE/pulseaudio_settings; audio_settings set --device=pci --volume=50; gst_pipeline_test -t 2 'audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! gconfaudiosink'; audio_settings restore --file=$CHECKBOX_SHARE/pulseaudio_settings
47 _description:
48 PURPOSE:
49 This test will check that headphones connector works correctly
50@@ -45,7 +45,7 @@
51 requires:
52 device.category == 'AUDIO'
53 package.name == 'alsa-base'
54-command: alsa_record_playback
55+command: audio_settings store $CHECKBOX_SHARE/pulseaudio_settings; audio_settings set --device=pci --volume=50; alsa_record_playback; audio_settings restore --file=$CHECKBOX_SHARE/pulseaudio_settings
56 _description:
57 PURPOSE:
58 This test will check that recording sound using the onboard microphone works correctly
59@@ -62,7 +62,7 @@
60 requires:
61 device.category == 'AUDIO'
62 package.name == 'alsa-base'
63-command: alsa_record_playback
64+command: audio_settings store $CHECKBOX_SHARE/pulseaudio_settings; audio_settings set --device=pci --volume=50; alsa_record_playback; audio_settings restore --file=$CHECKBOX_SHARE/pulseaudio_settings
65 _description:
66 PURPOSE:
67 This test will check that recording sound using an external microphone works correctly
68@@ -78,17 +78,14 @@
69 requires:
70 device.category == 'AUDIO'
71 package.name == 'alsa-base'
72-command: alsa_record_playback
73+command: audio_settings store > $CHECKBOX_SHARE/pulseaudio_settings; audio_settings set --device=usb --volume=50; alsa_record_playback; audio_settings restore --file=$CHECKBOX_SHARE/pulseaudio_settings
74 _description:
75 PURPOSE:
76 This test will check that a USB audio device works correctly
77 STEPS:
78 1. Connect a USB audio device to your system
79- 2. Open the volume control application by left-clicking on the speaker icon in the panel and selecting "Sound Settings"
80- 3. Select the "Input" tab and choose your USB device
81- 4. Select the "Output" tab and choose your USB device
82- 5. Click "Test", then speak into the microphone
83- 6. After a few seconds, your speech will be played back to you
84+ 2. Click "Test", then speak into the microphone
85+ 3. After a few seconds, your speech will be played back to you
86 VERIFICATION:
87 Did you hear your speech played back through the USB headphones?
88
89
90=== added file 'scripts/audio_settings'
91--- scripts/audio_settings 1970-01-01 00:00:00 +0000
92+++ scripts/audio_settings 2012-01-25 17:31:47 +0000
93@@ -0,0 +1,108 @@
94+#!/usr/bin/perl
95+
96+use strict;
97+use warnings;
98+
99+use Getopt::Long;
100+
101+my $action = shift @ARGV;
102+my @types = ('sink','source');
103+
104+if ($action eq "store") {
105+ # Find the current sink and and its mute/volume settings
106+ foreach my $type (@types) {
107+ my $index = `pacmd list-${type}s | grep '* index' | awk -F': ' '{print \$2}'`;
108+ chomp $index;
109+ print "${type}_index: ${index}\n";
110+
111+ my $muted = `pacmd list-${type}s | grep -A15 '* index' | grep 'muted:' | awk -F': ' '{print \$2}'`;
112+ chomp $muted;
113+ print "${type}_muted: ${muted}\n";
114+
115+ my $volume = `pacmd list-${type}s | grep -A10 '* index' | grep 'volume: 0:' | awk '{print \$3}'`;
116+ chomp $volume; chop $volume; # Strip off the trailing %
117+ print "${type}_volume: ${volume}\n";
118+ }
119+}
120+elsif ($action eq "set") {
121+ print "Updating audio settings\n";
122+
123+ my ($device, $mute, $volume);
124+ $mute = 0;
125+ $volume = 100;
126+ GetOptions( 'device=s' => \$device,
127+ 'mute' => \$mute,
128+ 'volume=s' => \$volume);
129+
130+ if ($device) {
131+ foreach my $type (@types) {
132+ my $direction = ($type eq 'sink') ? 'out' : 'in';
133+ my $index = `pacmd list-${type}s | grep -B4 alsa_${direction}put[.]$device | grep index | awk -F': ' '{print \$2}'`;
134+ chomp $index;
135+ system("pacmd set-default-$type $index");
136+
137+ if ($type eq 'sink') {
138+ foreach my $input (`pacmd list-sink-inputs | grep index | awk -F': ' '{print \$2}'`) {
139+ chomp($input);
140+ system("pacmd move-sink-input $input $index");
141+ }
142+ }
143+
144+ system("pacmd set-${type}-mute $index $mute");
145+
146+ # Set the volume as requested
147+ my $base_volume = `pacmd list-${type}s | grep -A15 alsa_${direction}put[.]$device | grep 'volume steps:' | awk -F': ' '{print \$2}'`;
148+ chomp $base_volume;
149+ my $new_volume = int($base_volume / 100 * $volume);
150+ system("pacmd set-${type}-volume $index $new_volume");
151+ }
152+ }
153+ else {
154+ print "No device specified\n";
155+ }
156+}
157+elsif ($action eq "restore") {
158+
159+ my $file;
160+ GetOptions( 'file=s' => \$file);
161+
162+ open PACMD_FILE, $file;
163+
164+ my $index;
165+ foreach (<PACMD_FILE>) {
166+ chomp;
167+
168+ foreach my $type (@types) {
169+ if (/($type)_index/) {
170+ $index = (split(/: /, $_))[-1];
171+
172+ system("pacmd set-default-$type $index");
173+
174+ if ($type eq 'sink') {
175+ foreach my $input (`pacmd list-sink-inputs | grep index | awk -F': ' '{print \$2}'`) {
176+ chomp($input);
177+ system("pacmd move-sink-input $input $index");
178+ }
179+ }
180+ }
181+ elsif (/($type)_muted/) {
182+ my $muted = (split(/: /, $_))[-1];
183+
184+ system("pacmd set-${type}-mute $index $muted");
185+ }
186+ elsif(/($type)_volume/) {
187+ my $volume = (split(/: /, $_))[-1];
188+
189+ # Calculate volume from base volume
190+ my $base_volume = `pacmd list-${type}s | grep -A15 'index: ${index}' | grep 'volume steps:' | awk -F': ' '{print \$2}'`;
191+ chomp $base_volume;
192+
193+ my $new_volume = int($base_volume / 100 * $volume);
194+ system("pacmd set-${type}-volume $index $new_volume");
195+ }
196+ }
197+ }
198+}
199+else {
200+ print "Invalid action!\n";
201+}

Subscribers

People subscribed via source and target branches