5
from hwtest.question import Question, QuestionPlugin
6
from hwtest.constants import HWTEST_DIR
9
TEST_DOMAIN = "canonical.com"
12
class QuestionInfo(QuestionPlugin):
15
super(QuestionInfo, self).__init__(self)
16
self.questions = [Question(**kwargs) for kwargs in [
18
"cats": ["laptop", "desktop"],
19
"command": self.command_audio,
21
Testing detected soundcard:
25
Did you hear a sound?"""},
26
{"name": "resolution",
27
"cats": ["laptop", "desktop"],
28
"command": self.command_resolution,
30
Testing detected resolution:
34
Is your video display hardware working properly?"""},
36
"cats": ["laptop", "desktop"],
38
Moving the mouse should move the cursor on the screen.
40
Is your mouse working properly?"""},
42
"command": self.command_network,
44
Detecting your network controller(s):
50
"command": self.command_internet,
52
Testing your internet connection:
56
Is your internet connection working properly?"""},
59
Typing keys on your keyboard should display the corresponding
60
characters in a text area.
62
Is your keyboard working properly?"""}]]
64
def command_audio(self):
65
gnome.sound_init("localhost")
66
sound_file = os.path.join(HWTEST_DIR, "data", "sound.wav")
67
gnome.sound_play(sound_file)
70
fd = file('/proc/asound/card0/id')
71
device = fd.readline().strip()
77
def command_resolution(self, test_output=None):
80
for item in os.popen('lsmod | grep fglrx'):
81
ati_brain_damage.append(item)
83
if len(ati_brain_damage):
84
retval = "impossible with fglrx"
87
res, freq = None, None
88
contents = test_output or os.popen(command).read()
89
for line in contents.splitlines():
91
if line.endswith("*"):
93
fields = line.replace("*", "").split()
97
res, freq = fields[0], "N/A"
99
elif line.startswith("*"):
101
fields = line.replace("*", "").split(' ')
102
res = fields[1].replace(" ", "")
110
retval = "%s @ %d Hz" % (res, float(freq))
114
def command_network(self):
115
from hwtest.pci import get_pci_devices
116
from hwtest.pci_ids import get_class, get_device
118
devices = get_pci_devices()
119
network_devices = filter(
120
lambda x: get_class(x["class_name"]) == "Network controller",
122
network_strings = map(
123
lambda x: get_device(x["vendor"], x["device"]),
125
return "\n".join(network_strings)
127
def command_internet(self):
128
command = "ping -q -w4 -c2 %s" % TEST_DOMAIN
129
reg = re.compile(r"(\d) received")
130
ping = os.popen(command)
133
line = ping.readline()
135
received = re.findall(reg, line)
137
num_packets = int(received[0])
140
return "No internet connection"
141
elif num_packets == 2:
142
return "Internet connection fully established"
144
return "Connection established by problematic"
147
factory = QuestionInfo