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

Revision 2023, 4.4 kB (checked in by adi, 12 years ago)

ffado-diag: helper functions for juju device permissions and group membership

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