~kelemeng/checkbox/bug868571

« back to all changes in this revision

Viewing changes to plugins/question_info.py

  • Committer: Marc Tardif
  • Date: 2007-10-04 23:12:10 UTC
  • Revision ID: marc.tardif@canonical.com-20071004231210-unxckndkgndxfdp6
Refactored questions to use templates and scripts which fixes bug #149195.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os
2
 
import re
3
 
import gnome
4
 
 
5
 
from hwtest.question import Question, QuestionPlugin
6
 
from hwtest.constants import HWTEST_DIR
7
 
 
8
 
 
9
 
TEST_DOMAIN = "canonical.com"
10
 
 
11
 
 
12
 
class QuestionInfo(QuestionPlugin):
13
 
 
14
 
    def __init__(self):
15
 
        super(QuestionInfo, self).__init__(self)
16
 
        self.questions = [Question(**kwargs) for kwargs in [
17
 
            {"name": "audio",
18
 
             "cats": ["laptop", "desktop"],
19
 
             "command": self.command_audio,
20
 
             "desc": """\
21
 
Testing detected soundcard:
22
 
 
23
 
$result
24
 
 
25
 
Did you hear a sound?"""},
26
 
            {"name": "resolution",
27
 
             "cats": ["laptop", "desktop"],
28
 
             "command": self.command_resolution,
29
 
             "desc": """\
30
 
Testing detected resolution:
31
 
 
32
 
$result
33
 
 
34
 
Is your video display hardware working properly?"""},
35
 
            {"name": "mouse",
36
 
             "cats": ["laptop", "desktop"],
37
 
             "desc": """\
38
 
Moving the mouse should move the cursor on the screen.
39
 
 
40
 
Is your mouse working properly?"""},
41
 
            {"name": "network",
42
 
             "command": self.command_network,
43
 
             "desc": """\
44
 
Detecting your network controller(s):
45
 
 
46
 
$result
47
 
 
48
 
Is this correct?"""},
49
 
            {"name": "internet",
50
 
             "command": self.command_internet,
51
 
             "desc": """\
52
 
Testing your internet connection:
53
 
 
54
 
$result
55
 
 
56
 
Is your internet connection working properly?"""},
57
 
            {"name": "keyboard",
58
 
             "desc": """\
59
 
Typing keys on your keyboard should display the corresponding
60
 
characters in a text area.
61
 
 
62
 
Is your keyboard working properly?"""}]]
63
 
 
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)
68
 
 
69
 
        try:
70
 
            fd = file('/proc/asound/card0/id')
71
 
            device = fd.readline().strip()
72
 
        except IOError:
73
 
            device = 'None'
74
 
 
75
 
        return device
76
 
 
77
 
    def command_resolution(self, test_output=None):
78
 
        ati_brain_damage = []
79
 
        command = 'xrandr -q'
80
 
        for item in os.popen('lsmod | grep fglrx'):
81
 
            ati_brain_damage.append(item)
82
 
 
83
 
        if len(ati_brain_damage):
84
 
            retval = "impossible with fglrx"
85
 
        else:
86
 
            retval = None
87
 
            res, freq = None, None
88
 
            contents = test_output or os.popen(command).read()
89
 
            for line in contents.splitlines():
90
 
                line = line.strip()
91
 
                if line.endswith("*"):
92
 
                    # gutsy
93
 
                    fields = line.replace("*", "").split()
94
 
                    if len(fields) == 2:
95
 
                        res, freq = fields
96
 
                    else:
97
 
                        res, freq = fields[0], "N/A"
98
 
                    break
99
 
                elif line.startswith("*"):
100
 
                    # dapper
101
 
                    fields = line.replace("*", "").split('  ')
102
 
                    res = fields[1].replace(" ", "")
103
 
                    if len(fields) < 4:
104
 
                        freq = "N/A"
105
 
                    else:
106
 
                        freq = fields[4]
107
 
                    break
108
 
 
109
 
            if res:
110
 
                retval = "%s @ %d Hz" % (res, float(freq))
111
 
 
112
 
        return retval
113
 
 
114
 
    def command_network(self):
115
 
        from hwtest.pci import get_pci_devices
116
 
        from hwtest.pci_ids import get_class, get_device
117
 
 
118
 
        devices = get_pci_devices()
119
 
        network_devices = filter(
120
 
            lambda x: get_class(x["class_name"]) == "Network controller",
121
 
            devices)
122
 
        network_strings = map(
123
 
            lambda x: get_device(x["vendor"], x["device"]),
124
 
            network_devices)
125
 
        return "\n".join(network_strings)
126
 
 
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)
131
 
        num_packets = 0
132
 
        while 1:
133
 
            line = ping.readline()
134
 
            if not line: break
135
 
            received = re.findall(reg, line)
136
 
            if received:
137
 
                num_packets = int(received[0])
138
 
 
139
 
        if num_packets == 0:
140
 
            return "No internet connection"
141
 
        elif num_packets == 2:
142
 
            return "Internet connection fully established"
143
 
        else:
144
 
            return "Connection established by problematic"
145
 
 
146
 
 
147
 
factory = QuestionInfo