1 |
#!/usr/bin/python |
---|
2 |
# |
---|
3 |
|
---|
4 |
# |
---|
5 |
# Copyright (C) 2008 Pieter Palmers |
---|
6 |
# |
---|
7 |
# This program is free software: you can redistribute it and/or modify |
---|
8 |
# it under the terms of the GNU General Public License as published by |
---|
9 |
# the Free Software Foundation, version 3 of the License. |
---|
10 |
# |
---|
11 |
# This program is distributed in the hope that it will be useful, |
---|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 |
# GNU General Public License for more details. |
---|
15 |
# |
---|
16 |
# You should have received a copy of the GNU General Public License |
---|
17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 |
# |
---|
19 |
|
---|
20 |
# |
---|
21 |
# Test for common FFADO problems |
---|
22 |
# |
---|
23 |
|
---|
24 |
import os |
---|
25 |
import sys |
---|
26 |
import commands |
---|
27 |
import re |
---|
28 |
import logging |
---|
29 |
|
---|
30 |
from listirqinfo import IRQ,SoftIRQ,IRQInfo |
---|
31 |
from helpstrings import HelpStrings |
---|
32 |
|
---|
33 |
## message strings |
---|
34 |
FFADODIAG_VERSION = "0.1" |
---|
35 |
|
---|
36 |
welcome_msg = """ |
---|
37 |
|
---|
38 |
FFADO diagnostic utility """ + FFADODIAG_VERSION + """ |
---|
39 |
============================ |
---|
40 |
(C) 2008 Pieter Palmers |
---|
41 |
|
---|
42 |
""" |
---|
43 |
|
---|
44 |
help_msg = """ |
---|
45 |
Usage: ffado-diag [verboselevel] |
---|
46 |
|
---|
47 |
verboselevel : verbosity level. (optional) |
---|
48 |
|
---|
49 |
""" |
---|
50 |
|
---|
51 |
## logging setup |
---|
52 |
logging.basicConfig() |
---|
53 |
log = logging.getLogger('diag') |
---|
54 |
|
---|
55 |
## helper routines |
---|
56 |
|
---|
57 |
# kernel |
---|
58 |
def get_kernel_version(): |
---|
59 |
(exitstatus, outtext) = commands.getstatusoutput('uname -r') |
---|
60 |
log.debug("uname -r outputs: %s" % outtext) |
---|
61 |
return outtext |
---|
62 |
|
---|
63 |
def get_kernel_rt_patched(): |
---|
64 |
print "FIXME: implement test for RT kernel" |
---|
65 |
return False |
---|
66 |
|
---|
67 |
# modules |
---|
68 |
def check_for_module_loaded(modulename): |
---|
69 |
log.info("Checking if module '%s' is loaded... " % modulename) |
---|
70 |
f = open('/proc/modules') |
---|
71 |
lines = f.readlines() |
---|
72 |
f.close() |
---|
73 |
for l in lines: |
---|
74 |
mod = l.split()[0] |
---|
75 |
if mod == modulename: |
---|
76 |
log.info(" found") |
---|
77 |
return True |
---|
78 |
log.info(" not found") |
---|
79 |
return False |
---|
80 |
|
---|
81 |
def check_for_module_present(modulename): |
---|
82 |
log.info("Checking if module '%s' is present... " % modulename) |
---|
83 |
kver = get_kernel_version() |
---|
84 |
(exitstatus, outtext) = commands.getstatusoutput("find \"/lib/modules/%s/\" -name '%s.ko' | grep '%s'" % \ |
---|
85 |
(kver, modulename, modulename) ) |
---|
86 |
log.debug("find outputs: %s" % outtext) |
---|
87 |
if outtext == "": |
---|
88 |
log.info(" not found") |
---|
89 |
return False |
---|
90 |
else: |
---|
91 |
log.info(" found") |
---|
92 |
return True |
---|
93 |
|
---|
94 |
def check_1394oldstack_loaded(): |
---|
95 |
retval = True |
---|
96 |
if not check_for_module_loaded('ieee1394'): |
---|
97 |
retval = False |
---|
98 |
if not check_for_module_loaded('ohci1394'): |
---|
99 |
retval = False |
---|
100 |
if not check_for_module_loaded('raw1394'): |
---|
101 |
retval = False |
---|
102 |
return retval |
---|
103 |
|
---|
104 |
def check_1394oldstack_present(): |
---|
105 |
retval = True |
---|
106 |
if not check_for_module_present('ieee1394'): |
---|
107 |
retval = False |
---|
108 |
if not check_for_module_present('ohci1394'): |
---|
109 |
retval = False |
---|
110 |
if not check_for_module_present('raw1394'): |
---|
111 |
retval = False |
---|
112 |
return retval |
---|
113 |
|
---|
114 |
def check_1394newstack_loaded(): |
---|
115 |
retval = True |
---|
116 |
if not check_for_module_loaded('fw-core'): |
---|
117 |
retval = False |
---|
118 |
if not check_for_module_loaded('fw-ohci'): |
---|
119 |
retval = False |
---|
120 |
return retval |
---|
121 |
|
---|
122 |
def check_1394newstack_present(): |
---|
123 |
retval = True |
---|
124 |
if not check_for_module_present('fw-core'): |
---|
125 |
retval = False |
---|
126 |
if not check_for_module_present('fw-ohci'): |
---|
127 |
retval = False |
---|
128 |
return retval |
---|
129 |
|
---|
130 |
def check_1394oldstack_devnode_present(): |
---|
131 |
return os.path.exists('/dev/raw1394') |
---|
132 |
|
---|
133 |
def check_1394oldstack_devnode_permissions(): |
---|
134 |
f = open('/dev/raw1394','w') |
---|
135 |
if f: |
---|
136 |
f.close() |
---|
137 |
return True |
---|
138 |
else: |
---|
139 |
return False |
---|
140 |
|
---|
141 |
def run_command(cmd): |
---|
142 |
(exitstatus, outtext) = commands.getstatusoutput(cmd) |
---|
143 |
log.debug("%s outputs: %s" % (cmd, outtext)) |
---|
144 |
return outtext |
---|
145 |
|
---|
146 |
# package versions |
---|
147 |
def get_package_version(name): |
---|
148 |
cmd = "pkg-config --modversion %s" % name |
---|
149 |
return run_command(cmd) |
---|
150 |
|
---|
151 |
def get_package_flags(name): |
---|
152 |
cmd = "pkg-config --cflags --libs %s" % name |
---|
153 |
return run_command(cmd) |
---|
154 |
|
---|
155 |
def get_command_path(name): |
---|
156 |
cmd = "which %s" % name |
---|
157 |
return run_command(cmd) |
---|
158 |
|
---|
159 |
def get_version_first_line(cmd): |
---|
160 |
ver = run_command(cmd).split("\n") |
---|
161 |
if len(ver) == 0: |
---|
162 |
ver = ["None"] |
---|
163 |
return ver[0] |
---|
164 |
|
---|
165 |
|
---|
166 |
def list_host_controllers(): |
---|
167 |
cmd = "lspci | grep 1394" |
---|
168 |
controllers = run_command(cmd).split("\n") |
---|
169 |
log.debug("lspci | grep 1394: %s" % controllers) |
---|
170 |
for c in controllers: |
---|
171 |
tmp = c.split() |
---|
172 |
if len(tmp) > 0: |
---|
173 |
tmp |
---|
174 |
cmd = "lspci -vv -nn -s %s" % tmp[0] |
---|
175 |
print run_command(cmd) |
---|
176 |
|
---|
177 |
## main program |
---|
178 |
if __name__== '__main__': |
---|
179 |
|
---|
180 |
print welcome_msg |
---|
181 |
|
---|
182 |
num_args = len(sys.argv) |
---|
183 |
if num_args not in [1,2]: |
---|
184 |
print help |
---|
185 |
sys.exit(0) |
---|
186 |
|
---|
187 |
if num_args == 2: |
---|
188 |
loglevel = eval(sys.argv[1]) |
---|
189 |
if loglevel == 1: |
---|
190 |
logging.getLogger('diag').setLevel(logging.INFO) |
---|
191 |
elif loglevel == 2: |
---|
192 |
logging.getLogger('diag').setLevel(logging.DEBUG) |
---|
193 |
|
---|
194 |
print "=== CHECK ===" |
---|
195 |
print " Base system..." |
---|
196 |
|
---|
197 |
# check kernel |
---|
198 |
kernel_version = get_kernel_version() |
---|
199 |
print " kernel version............ " + str(kernel_version) |
---|
200 |
kernel_is_rt_patched = get_kernel_rt_patched() |
---|
201 |
print " RT patched............... " + str(kernel_is_rt_patched) |
---|
202 |
|
---|
203 |
# check modules |
---|
204 |
oldstack_present = check_1394oldstack_present() |
---|
205 |
oldstack_loaded = check_1394oldstack_loaded() |
---|
206 |
newstack_present = check_1394newstack_present() |
---|
207 |
newstack_loaded = check_1394newstack_loaded() |
---|
208 |
|
---|
209 |
print " old 1394 stack present.... " + str(oldstack_present) |
---|
210 |
print " old 1394 stack loaded..... " + str(oldstack_loaded) |
---|
211 |
print " new 1394 stack present.... " + str(newstack_present) |
---|
212 |
print " new 1394 stack loaded..... " + str(newstack_loaded) |
---|
213 |
|
---|
214 |
# check /dev/raw1394 node presence |
---|
215 |
devnode_present = check_1394oldstack_devnode_present() |
---|
216 |
print " /dev/raw1394 node present. " + str(devnode_present) |
---|
217 |
if devnode_present: |
---|
218 |
# check /dev/raw1394 access permissions |
---|
219 |
devnode_permissions = check_1394oldstack_devnode_permissions() |
---|
220 |
print " /dev/raw1394 permissions.. " + str(devnode_permissions) |
---|
221 |
else: |
---|
222 |
devnode_permissions = None |
---|
223 |
|
---|
224 |
# check libraries |
---|
225 |
print " Prerequisites..." |
---|
226 |
print " gcc................ %s" % get_version_first_line('gcc --version') |
---|
227 |
print " g++................ %s" % get_version_first_line('g++ --version') |
---|
228 |
print " PyQt............... %s" % get_version_first_line('pyuic -version') |
---|
229 |
print " jackd.............. %s" % get_version_first_line('jackd --version') |
---|
230 |
print " path............. %s" % get_command_path('jackd') |
---|
231 |
print " flags............ %s" % get_package_flags("jack") |
---|
232 |
print " libraw1394......... %s" % get_package_version("libraw1394") |
---|
233 |
print " flags............ %s" % get_package_flags("libraw1394") |
---|
234 |
print " libavc1394......... %s" % get_package_version("libavc1394") |
---|
235 |
print " flags............ %s" % get_package_flags("libavc1394") |
---|
236 |
print " libiec61883........ %s" % get_package_version("libiec61883") |
---|
237 |
print " flags............ %s" % get_package_flags("libiec61883") |
---|
238 |
print " libxml++-2.6....... %s" % get_package_version("libxml++-2.6") |
---|
239 |
print " flags............ %s" % get_package_flags("libxml++-2.6") |
---|
240 |
print " dbus-1............. %s" % get_package_version("dbus-1") |
---|
241 |
print " flags............ %s" % get_package_flags("dbus-1") |
---|
242 |
|
---|
243 |
# libraw |
---|
244 |
|
---|
245 |
print " Hardware..." |
---|
246 |
# check host controller |
---|
247 |
print " Host controllers:" |
---|
248 |
list_host_controllers() |
---|
249 |
print " CPU info:" |
---|
250 |
print run_command("cat /proc/cpuinfo") |
---|
251 |
|
---|
252 |
print " Configuration..." |
---|
253 |
# check RT settings |
---|
254 |
|
---|
255 |
# check IRQ settings |
---|
256 |
print " IRQ information" |
---|
257 |
info = IRQInfo() |
---|
258 |
|
---|
259 |
info.load() |
---|
260 |
print str(info) |
---|
261 |
|
---|
262 |
print "" |
---|
263 |
print "=== REPORT ===" |
---|
264 |
|
---|
265 |
help = HelpStrings() |
---|
266 |
|
---|
267 |
# do the interpretation of the tests |
---|
268 |
print "FireWire kernel drivers:" |
---|
269 |
## FIXME: what about in-kernel firewire? (i.e. no modules) |
---|
270 |
if not oldstack_present: |
---|
271 |
help.show('MODULES_OLD_STACK_NOT_INSTALLED') |
---|
272 |
sys.exit(-1) |
---|
273 |
else: |
---|
274 |
if newstack_loaded and oldstack_loaded: |
---|
275 |
help.show('MODULES_BOTH_STACKS_LOADED') |
---|
276 |
sys.exit(-1) |
---|
277 |
elif newstack_loaded: |
---|
278 |
help.show('MODULES_NEW_STACK_LOADED') |
---|
279 |
sys.exit(-1) |
---|
280 |
elif not oldstack_loaded: |
---|
281 |
help.show('MODULES_OLD_STACK_NOT_LOADED') |
---|
282 |
sys.exit(-1) |
---|
283 |
else: |
---|
284 |
print "[PASS] Kernel modules present and correctly loaded." |
---|
285 |
|
---|
286 |
if not devnode_present: |
---|
287 |
help.show('DEVNODE_OLD_STACK_NOT_PRESENT') |
---|
288 |
sys.exit(-1) |
---|
289 |
else: |
---|
290 |
if not devnode_permissions: |
---|
291 |
help.show('DEVNODE_OLD_STACK_NO_PERMISSION') |
---|
292 |
sys.exit(-1) |
---|
293 |
else: |
---|
294 |
print "[PASS] /dev/raw1394 node present and accessible." |
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|