54 | | |
---|
55 | | ## logging setup |
---|
56 | | logging.basicConfig() |
---|
57 | | log = logging.getLogger('diag') |
---|
58 | | |
---|
59 | | ## helper routines |
---|
60 | | |
---|
61 | | # kernel |
---|
62 | | def get_kernel_version(): |
---|
63 | | (exitstatus, outtext) = commands.getstatusoutput('uname -r') |
---|
64 | | log.debug("uname -r outputs: %s" % outtext) |
---|
65 | | return outtext |
---|
66 | | |
---|
67 | | def get_kernel_rt_patched(): |
---|
68 | | print "FIXME: implement test for RT kernel" |
---|
69 | | return False |
---|
70 | | |
---|
71 | | # modules |
---|
72 | | def check_for_module_loaded(modulename): |
---|
73 | | log.info("Checking if module '%s' is loaded... " % modulename) |
---|
74 | | f = open('/proc/modules') |
---|
75 | | lines = f.readlines() |
---|
76 | | f.close() |
---|
77 | | for l in lines: |
---|
78 | | mod = l.split()[0] |
---|
79 | | if mod == modulename: |
---|
80 | | log.info(" found") |
---|
81 | | return True |
---|
82 | | log.info(" not found") |
---|
83 | | return False |
---|
84 | | |
---|
85 | | def check_for_module_present(modulename): |
---|
86 | | log.info("Checking if module '%s' is present... " % modulename) |
---|
87 | | kver = get_kernel_version() |
---|
88 | | (exitstatus, outtext) = commands.getstatusoutput("find \"/lib/modules/%s/\" -name '%s.ko' | grep '%s'" % \ |
---|
89 | | (kver, modulename, modulename) ) |
---|
90 | | log.debug("find outputs: %s" % outtext) |
---|
91 | | if outtext == "": |
---|
92 | | log.info(" not found") |
---|
93 | | return False |
---|
94 | | else: |
---|
95 | | log.info(" found") |
---|
96 | | return True |
---|
97 | | |
---|
98 | | def check_1394oldstack_loaded(): |
---|
99 | | retval = True |
---|
100 | | if not check_for_module_loaded('ieee1394'): |
---|
101 | | retval = False |
---|
102 | | if not check_for_module_loaded('ohci1394'): |
---|
103 | | retval = False |
---|
104 | | if not check_for_module_loaded('raw1394'): |
---|
105 | | retval = False |
---|
106 | | return retval |
---|
107 | | |
---|
108 | | def check_1394oldstack_present(): |
---|
109 | | retval = True |
---|
110 | | if not check_for_module_present('ieee1394'): |
---|
111 | | retval = False |
---|
112 | | if not check_for_module_present('ohci1394'): |
---|
113 | | retval = False |
---|
114 | | if not check_for_module_present('raw1394'): |
---|
115 | | retval = False |
---|
116 | | return retval |
---|
117 | | |
---|
118 | | def check_1394newstack_loaded(): |
---|
119 | | retval = True |
---|
120 | | if not check_for_module_loaded('fw-core'): |
---|
121 | | retval = False |
---|
122 | | if not check_for_module_loaded('fw-ohci'): |
---|
123 | | retval = False |
---|
124 | | return retval |
---|
125 | | |
---|
126 | | def check_1394newstack_present(): |
---|
127 | | retval = True |
---|
128 | | if not check_for_module_present('fw-core'): |
---|
129 | | retval = False |
---|
130 | | if not check_for_module_present('fw-ohci'): |
---|
131 | | retval = False |
---|
132 | | return retval |
---|
133 | | |
---|
134 | | def check_1394oldstack_devnode_present(): |
---|
135 | | return os.path.exists('/dev/raw1394') |
---|
136 | | |
---|
137 | | def check_1394oldstack_devnode_permissions(): |
---|
138 | | f = open('/dev/raw1394','w') |
---|
139 | | if f: |
---|
140 | | f.close() |
---|
141 | | return True |
---|
142 | | else: |
---|
143 | | return False |
---|
144 | | |
---|
145 | | def run_command(cmd): |
---|
146 | | (exitstatus, outtext) = commands.getstatusoutput(cmd) |
---|
147 | | log.debug("%s outputs: %s" % (cmd, outtext)) |
---|
148 | | return outtext |
---|
149 | | |
---|
150 | | # package versions |
---|
151 | | def get_package_version(name): |
---|
152 | | cmd = "pkg-config --modversion %s" % name |
---|
153 | | return run_command(cmd) |
---|
154 | | |
---|
155 | | def get_package_flags(name): |
---|
156 | | cmd = "pkg-config --cflags --libs %s" % name |
---|
157 | | return run_command(cmd) |
---|
158 | | |
---|
159 | | def get_command_path(name): |
---|
160 | | cmd = "which %s" % name |
---|
161 | | return run_command(cmd) |
---|
162 | | |
---|
163 | | def get_version_first_line(cmd): |
---|
164 | | ver = run_command(cmd).split("\n") |
---|
165 | | if len(ver) == 0: |
---|
166 | | ver = ["None"] |
---|
167 | | return ver[0] |
---|
168 | | |
---|
169 | | |
---|
170 | | def list_host_controllers(): |
---|
171 | | cmd = "lspci | grep 1394" |
---|
172 | | controllers = run_command(cmd).split("\n") |
---|
173 | | log.debug("lspci | grep 1394: %s" % controllers) |
---|
174 | | for c in controllers: |
---|
175 | | tmp = c.split() |
---|
176 | | if len(tmp) > 0: |
---|
177 | | tmp |
---|
178 | | cmd = "lspci -vv -nn -s %s" % tmp[0] |
---|
179 | | print run_command(cmd) |
---|