root/trunk/libffado/support/tools/ffado_diag_helpers.py

Revision 2147, 4.6 kB (checked in by jwoithe, 9 years ago)

ffado-diag: attempt to detect whether the kernel is configured for low latency and/or is RT patched. This relies on 'uname -v'. While /proc/config.gz could be used and may be more reliable, the kernels on many systems don't have this configured (eg: Fedora 16). Let's see how this goes.

  • Property svn:mergeinfo set to
Line 
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 import sys
22
23 import os
24 import commands
25 import re
26 import logging
27
28 ## logging setup
29 logging.basicConfig()
30 log = logging.getLogger('diag')
31
32 ## helper routines
33
34 # kernel
35 def get_kernel_version():
36     return run_command('uname -r')
37
38 def get_kernel_rt_patched():
39     l = run_command('uname -v')
40     if l.find("PREEMPT RT") > -1:
41         return True
42     return False
43
44 def get_kernel_preempt():
45     l = run_command('uname -v')
46     if l.find(" PREEMPT ") > -1 and l.find(" RT ") == -1:
47         return True
48     return False
49
50 # modules
51 def check_for_module_loaded(modulename, procfile):
52     log.info("Checking if module '%s' is present in %s... " % (modulename, procfile))
53     f = open(procfile)
54     lines = f.readlines()
55     f.close()
56     for l in lines:
57         if l.find(modulename) > -1 or l.find(modulename.replace('-', '_')) > -1:
58             log.info(" found")
59             return True
60     log.info(" not found")
61     return False
62
63 def check_for_module_present(modulename):
64     log.info("Checking if module '%s' is present... " % modulename)
65     kver = get_kernel_version()
66     (exitstatus, outtext) = commands.getstatusoutput("find \"/lib/modules/%s/\" -name '%s.ko' | grep '%s'" % \
67                                                      (kver, modulename, modulename) )
68     log.debug("find outputs: %s" % outtext)
69     if outtext == "":
70         log.info(" not found")
71         return False
72     else:
73         log.info(" found")
74         return True
75
76 def check_1394oldstack_active():
77     return check_for_module_loaded('ohci1394', '/proc/interrupts')
78
79 def check_1394oldstack_linked():
80     return os.access('/sys/module/ohci1394', os.F_OK) and \
81            os.access('/sys/module/raw1394',  os.F_OK)
82
83 def check_1394oldstack_loaded():
84     retval = True
85     for modulename in ('ieee1394', 'ohci1394', 'raw1394'):
86         if not check_for_module_loaded(modulename, '/proc/modules'):
87             retval = False
88     return retval
89
90 def check_1394oldstack_present():
91     retval = True
92     for modulename in ('ieee1394', 'ohci1394', 'raw1394'):
93         if not check_for_module_present(modulename):
94             retval = False
95     return retval
96
97 def check_1394newstack_active():
98     return check_for_module_loaded('firewire_ohci', '/proc/interrupts')
99
100 def check_1394newstack_linked():
101     return os.access('/sys/module/firewire_ohci', os.F_OK)
102
103 def check_1394newstack_loaded():
104     retval = True
105     for modulename in ('firewire_core', 'firewire_ohci'):
106         if not check_for_module_loaded(modulename, '/proc/modules'):
107             retval = False
108     return retval
109
110 def check_1394newstack_present():
111     retval = True
112     for modulename in ('firewire-core', 'firewire-ohci'):
113         if not check_for_module_present(modulename):
114             retval = False
115     return retval
116
117 def check_1394oldstack_devnode_present():
118     return os.path.exists('/dev/raw1394')
119
120 def check_1394oldstack_devnode_permissions():
121     f = open('/dev/raw1394','w')
122     if f:
123         f.close()
124         return True
125     else:
126         return False
127
128 def run_command(cmd):
129     (exitstatus, outtext) = commands.getstatusoutput(cmd)
130     log.debug("%s outputs: %s" % (cmd, outtext))
131     return outtext
132
133 # package versions
134 def get_package_version(name):
135     cmd = "pkg-config --modversion %s" % name
136     return run_command(cmd)
137
138 def get_package_flags(name):
139     cmd = "pkg-config --cflags --libs %s" % name
140     return run_command(cmd)
141
142 def get_command_path(name):
143     cmd = "which %s" % name
144     return run_command(cmd)
145
146 def get_version_first_line(cmd):
147     ver = run_command(cmd).split("\n")
148     if len(ver) == 0:
149         ver = ["None"]
150     return ver[0]
151
152
153 def list_host_controllers():
154     cmd = "lspci | grep 1394"
155     controllers = run_command(cmd).split("\n")
156     log.debug("lspci | grep 1394: %s" % controllers)
157     for c in controllers:
158         tmp = c.split()
159         if len(tmp) > 0:
160             tmp
161             cmd = "lspci -vv -nn -s %s" % tmp[0]
162             print run_command(cmd)
163
164 def get_juju_permissions():
165     return run_command('ls -lh /dev/fw*')
166
167 def get_user_ids():
168     return run_command('id');
Note: See TracBrowser for help on using the browser.