1 |
# |
---|
2 |
# Copyright (C) 2008 Pieter Palmers |
---|
3 |
# |
---|
4 |
# This program is free software: you can redistribute it and/or modify |
---|
5 |
# it under the terms of the GNU General Public License as published by |
---|
6 |
# the Free Software Foundation, version 3 of the License. |
---|
7 |
# |
---|
8 |
# This program is distributed in the hope that it will be useful, |
---|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 |
# GNU General Public License for more details. |
---|
12 |
# |
---|
13 |
# You should have received a copy of the GNU General Public License |
---|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
15 |
# |
---|
16 |
|
---|
17 |
# |
---|
18 |
# Test for common FFADO problems |
---|
19 |
# |
---|
20 |
|
---|
21 |
from __future__ import print_function |
---|
22 |
import glob |
---|
23 |
import sys |
---|
24 |
import os |
---|
25 |
import errno |
---|
26 |
import logging |
---|
27 |
import subprocess |
---|
28 |
|
---|
29 |
## logging setup |
---|
30 |
logging.basicConfig() |
---|
31 |
log = logging.getLogger('diag') |
---|
32 |
|
---|
33 |
## helper routines |
---|
34 |
|
---|
35 |
# kernel |
---|
36 |
def get_kernel_version(): |
---|
37 |
return run_command (('uname', '-r')).rstrip () |
---|
38 |
|
---|
39 |
def get_kernel_rt_patched(): |
---|
40 |
l = run_command (('uname', '-v')) |
---|
41 |
return "PREEMPT RT" in l |
---|
42 |
|
---|
43 |
def get_kernel_preempt(): |
---|
44 |
l = run_command (('uname', '-v')) |
---|
45 |
return (" PREEMPT " in l) and (not " RT " in l) |
---|
46 |
|
---|
47 |
# modules |
---|
48 |
def check_for_module_loaded(modulename, procfile): |
---|
49 |
log.info("Checking if module '%s' is present in %s... " % (modulename, procfile)) |
---|
50 |
with open (procfile) as f: |
---|
51 |
for l in f: |
---|
52 |
if modulename in l or modulename.replace('-', '_') in l: |
---|
53 |
log.info(" found") |
---|
54 |
return True |
---|
55 |
log.info(" not found") |
---|
56 |
return False |
---|
57 |
|
---|
58 |
def check_for_module_present(modulename): |
---|
59 |
log.info("Checking if module '%s' is present... " % modulename) |
---|
60 |
kver = get_kernel_version() |
---|
61 |
outtext = run_command (('find', '/lib/modules/' + kver, '-name', modulename + '.ko')) |
---|
62 |
if not modulename in outtext: |
---|
63 |
log.info(" not found") |
---|
64 |
return False |
---|
65 |
else: |
---|
66 |
log.info(" found") |
---|
67 |
return True |
---|
68 |
|
---|
69 |
def check_1394oldstack_active(): |
---|
70 |
return check_for_module_loaded('ohci1394', '/proc/interrupts') |
---|
71 |
|
---|
72 |
def check_1394oldstack_linked(): |
---|
73 |
return os.access('/sys/module/ohci1394', os.F_OK) and \ |
---|
74 |
os.access('/sys/module/raw1394', os.F_OK) |
---|
75 |
|
---|
76 |
def check_1394oldstack_loaded(): |
---|
77 |
for modulename in ('ieee1394', 'ohci1394', 'raw1394'): |
---|
78 |
if not check_for_module_loaded(modulename, '/proc/modules'): |
---|
79 |
return False |
---|
80 |
return True |
---|
81 |
|
---|
82 |
def check_1394oldstack_present(): |
---|
83 |
for modulename in ('ieee1394', 'ohci1394', 'raw1394'): |
---|
84 |
if not check_for_module_present(modulename): |
---|
85 |
return False |
---|
86 |
return True |
---|
87 |
|
---|
88 |
def check_1394newstack_active(): |
---|
89 |
return check_for_module_loaded('firewire_ohci', '/proc/interrupts') |
---|
90 |
|
---|
91 |
def check_1394newstack_linked(): |
---|
92 |
return os.access('/sys/module/firewire_ohci', os.F_OK) |
---|
93 |
|
---|
94 |
def check_1394newstack_loaded(): |
---|
95 |
for modulename in ('firewire_core', 'firewire_ohci'): |
---|
96 |
if not check_for_module_loaded(modulename, '/proc/modules'): |
---|
97 |
return False |
---|
98 |
return True |
---|
99 |
|
---|
100 |
def check_1394newstack_present(): |
---|
101 |
for modulename in ('firewire-core', 'firewire-ohci'): |
---|
102 |
if not check_for_module_present(modulename): |
---|
103 |
return False |
---|
104 |
return True |
---|
105 |
|
---|
106 |
def check_1394oldstack_devnode_present(): |
---|
107 |
return os.path.exists('/dev/raw1394') |
---|
108 |
|
---|
109 |
def check_1394oldstack_devnode_permissions(): |
---|
110 |
try: |
---|
111 |
with open('/dev/raw1394', 'w'): |
---|
112 |
return True |
---|
113 |
except: |
---|
114 |
return False |
---|
115 |
|
---|
116 |
# Raise an exception for any problem. |
---|
117 |
def run_command (cmd): |
---|
118 |
outtext = subprocess.check_output (cmd) |
---|
119 |
outtext = outtext.decode ('utf8') |
---|
120 |
log.debug("%s outputs: %s" % (str (cmd), outtext)) |
---|
121 |
return outtext |
---|
122 |
|
---|
123 |
# Wrapper intercepting common exceptions and returning a string nevertheless. |
---|
124 |
def run_command_string (cmd): |
---|
125 |
try: |
---|
126 |
return run_command (cmd) |
---|
127 |
except OSError, ( errorcode, emsg ): |
---|
128 |
if (errorcode == errno.ENOENT): |
---|
129 |
msg = "Not found" |
---|
130 |
else: |
---|
131 |
msg = "Failed to execute %s" % str (cmd) |
---|
132 |
log.warning (msg) |
---|
133 |
return msg |
---|
134 |
# Other errors are raised. |
---|
135 |
except subprocess.CalledProcessError: |
---|
136 |
msg = "Command %s returned a non-zero exit status" % str (cmd) |
---|
137 |
log.warning (msg) |
---|
138 |
return msg |
---|
139 |
|
---|
140 |
# package versions |
---|
141 |
def get_package_version(name): |
---|
142 |
return run_command_string (('pkg-config', '--modversion', name)) |
---|
143 |
|
---|
144 |
def get_package_flags(name): |
---|
145 |
return run_command_string (('pkg-config', '--cflags', '--libs', name)) |
---|
146 |
|
---|
147 |
def get_version_first_line(cmd): |
---|
148 |
outtext = run_command_string (cmd) |
---|
149 |
i = outtext.find ("\n") |
---|
150 |
if i == -1: |
---|
151 |
return outtext |
---|
152 |
else: |
---|
153 |
return outtext [:i] |
---|
154 |
|
---|
155 |
def list_host_controllers(): |
---|
156 |
try: |
---|
157 |
lspci_cmd = run_command (('which', 'lspci')).rstrip () |
---|
158 |
except subprocess.CalledProcessError: |
---|
159 |
lspci_cmd = "/sbin/lspci" |
---|
160 |
outtext = run_command ((lspci_cmd,)) |
---|
161 |
for c in outtext.split("\n"): |
---|
162 |
if '1394' in c: |
---|
163 |
tmp = c.split() |
---|
164 |
if len(tmp) > 0: |
---|
165 |
cmd = (lspci_cmd, '-vv', '-nn', '-s', tmp[0]) |
---|
166 |
print( run_command(cmd) ) |
---|
167 |
|
---|
168 |
def get_juju_permissions(): |
---|
169 |
return run_command_string (['ls', '-lh'] + glob.glob ('/dev/fw*')) |
---|
170 |
|
---|
171 |
def get_user_ids(): |
---|
172 |
return run_command_string (('id',)); |
---|
173 |
|
---|
174 |
def usage (): |
---|
175 |
print ("") |
---|
176 |
print ("Usage: %s [verboselevel]" % sys.argv [0]) |
---|
177 |
print (" verboselevel : verbosity level.") |
---|
178 |
print ("") |
---|
179 |
sys.exit (0) |
---|
180 |
|
---|
181 |
def parse_command_line (): |
---|
182 |
num_args = len(sys.argv) |
---|
183 |
if num_args > 2: |
---|
184 |
usage () |
---|
185 |
elif num_args == 2: |
---|
186 |
loglevel = int (sys.argv [1]) |
---|
187 |
if loglevel == 1: |
---|
188 |
log.setLevel(logging.INFO) |
---|
189 |
elif loglevel == 2: |
---|
190 |
log.setLevel(logging.DEBUG) |
---|
191 |
|
---|
192 |
def check_libraries (): |
---|
193 |
print(" gcc ............... %s" % get_version_first_line(('gcc', '--version'))) |
---|
194 |
print(" g++ ............... %s" % get_version_first_line(('g++', '--version'))) |
---|
195 |
print(" PyQt4 (by pyuic4) . %s" % get_version_first_line(('pyuic4', '--version'))) |
---|
196 |
print(" PyQt5 (by pyuic5) . %s" % get_version_first_line(('pyuic5', '--version'))) |
---|
197 |
print(" jackd ............. %s" % get_version_first_line(('jackd', '--version'))) |
---|
198 |
print(" path ............ %s" % run_command_string (('which', 'jackd')), end='') |
---|
199 |
print(" flags ........... %s" % get_package_flags("jack")) |
---|
200 |
print(" libraw1394 ........ %s" % get_package_version("libraw1394")) |
---|
201 |
print(" flags ........... %s" % get_package_flags("libraw1394")) |
---|
202 |
print(" libavc1394 ........ %s" % get_package_version("libavc1394")) |
---|
203 |
print(" flags ........... %s" % get_package_flags("libavc1394")) |
---|
204 |
print(" libiec61883 ....... %s" % get_package_version("libiec61883")) |
---|
205 |
print(" flags ........... %s" % get_package_flags("libiec61883")) |
---|
206 |
print(" libxml++-2.6 ...... %s" % get_package_version("libxml++-2.6")) |
---|
207 |
print(" flags ........... %s" % get_package_flags("libxml++-2.6")) |
---|
208 |
print(" dbus-1 ............ %s" % get_package_version("dbus-1")) |
---|
209 |
print(" flags ........... %s" % get_package_flags("dbus-1")) |
---|