This file is indexed.

/usr/bin/rdm_responder_test.py is in ola-rdm-tests 0.10.3.nojsmin-2+deb9u1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#! /usr/bin/python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# rdm_responder_test.py
# Copyright (C) 2010 Simon Newton

from ola.testing.rdm import TestDefinitions, TestRunner
from ola.testing.rdm.DMXSender import DMXSender
from ola.testing.rdm.TestState import TestState
import datetime
import logging
import re
import sys
import textwrap
import time
from TimingStats import TimingStats
from ola import PidStore
from ola import Version
from ola.ClientWrapper import ClientWrapper
from ola.UID import UID
from optparse import OptionParser

'''Automated testing for RDM responders.'''

__author__ = 'nomis52@gmail.com (Simon Newton)'


def ParseOptions():
  usage = 'Usage: %prog [options] <uid>'
  description = textwrap.dedent("""\
    Run a series of tests on a RDM responder to check the behaviour.
    This requires the OLA server to be running, and the RDM device to have been
    detected. You can confirm this by running ola_rdm_discover -u
    UNIVERSE.  This will send SET commands to the broadcast UIDs which means
    the start address, device label etc. will be changed for all devices
    connected to the responder. Think twice about running this on your
    production lighting rig.
  """)
  parser = OptionParser(usage, description=description)
  parser.add_option('-c', '--slot-count', default=10,
                    help='Number of slots to send when sending DMX.')
  parser.add_option('-d', '--debug', action='store_true',
                    help='Print debug information to assist in diagnosing '
                         'failures.')
  parser.add_option('-f', '--dmx-frame-rate', default=0,
                    type='int',
                    help='Send DMX frames at this rate in the background.')
  parser.add_option('-l', '--log', metavar='FILE',
                    help='Also log to the file named FILE.uid.timestamp.')
  parser.add_option('--list-tests', action='store_true',
                    help='Display a list of all tests')
  parser.add_option('-p', '--pid-location', metavar='DIR',
                    help='The location of the PID definitions.')
  parser.add_option('-s', '--skip-check', action='store_true',
                    help='Skip the check for multiple devices.')
  parser.add_option('-t', '--tests', metavar='TEST1,TEST2',
                    help='A comma separated list of tests to run.')
  parser.add_option('--timestamp', action='store_true',
                    help='Add timestamps to each test.')
  parser.add_option('--timing', action='store_true',
                    help='Display summary timing information')
  parser.add_option('--no-factory-defaults', action='store_true',
                    help="Don't run the SET factory defaults tests")
  parser.add_option('-w', '--broadcast-write-delay', default=0,
                    type='int',
                    help='The time in ms to wait after sending broadcast set '
                         'commands.')
  parser.add_option('-u', '--universe', default=0,
                    type='int',
                    help='The universe number to use, default is universe 0.')
  parser.add_option('--inter-test-delay', default=0,
                    type='int',
                    help='The delay in ms to wait between tests, defaults to '
                         '0.')

  options, args = parser.parse_args()

  if options.list_tests:
    return options

  if not args:
    parser.print_help()
    sys.exit(2)

  uid = UID.FromString(args[0])
  if uid is None:
    parser.print_usage()
    print 'Invalid UID: %s' % args[0]
    sys.exit(2)

  options.uid = uid
  return options


class MyFilter(object):
  """Filter out the ascii coloring."""
  def filter(self, record):
    msg = record.msg
    record.msg = re.sub('\x1b\[\d*m', '', str(msg))
    return True


def SetupLogging(options):
  """Setup the logging for test results."""
  level = logging.INFO

  if options.debug:
    level = logging.DEBUG

  logging.basicConfig(
      level=level,
      format='%(message)s')

  if options.log:
    file_name = '%s.%s.%d' % (options.log, options.uid, time.time())
    file_handler = logging.FileHandler(file_name, 'w')
    file_handler.addFilter(MyFilter())
    if options.debug:
      file_handler.setLevel(logging.DEBUG)
    logging.getLogger('').addHandler(file_handler)


def LogTimingParam(parameter, data):
  # if non-0 print the stats
  if data['max']:
    data['param'] = parameter
    logging.info('  %s:' % parameter)
    logging.info('    Mean: %(mean).1f, StdDev %(std).1f, Median %(median).1f'
                 % data)
    logging.info('    Min: %(min).1f, Max %(max).1f, 99%%: %(99).1f' % data)


def LogAllTimingParams(response_type, stats):
  if not stats.Count():
    return

  logging.info('%s [%d frames]' % (response_type, stats.Count()))
  LogTimingParam('Response Time', stats.ResponseTime())
  LogTimingParam('Break', stats.Break())
  LogTimingParam('Mark', stats.Mark())
  LogTimingParam('Data', stats.Data())


def DisplayTiming(timing_stats):
  """Print timing information."""
  logging.info('--------------- Response Timing ----------------')

  stats = timing_stats.GetStatsForType(TimingStats.GET)
  LogAllTimingParams('GET_RESPONSE', stats)
  stats = timing_stats.GetStatsForType(TimingStats.SET)
  LogAllTimingParams('SET_RESPONSE', stats)
  stats = timing_stats.GetStatsForType(TimingStats.DISCOVERY)
  LogAllTimingParams('DISCOVERY_RESPONSE', stats)
  stats = timing_stats.GetStatsForType(TimingStats.DUB)
  LogAllTimingParams('DISCOVERY_UNIQUE_BRANCH', stats)


def DisplaySummary(options, runner, tests, device):
  """Log a summary of the tests."""
  by_category = {}
  warnings = []
  advisories = []
  count_by_state = {}
  for test in tests:
    state = test.state
    count_by_state[state] = count_by_state.get(state, 0) + 1
    warnings.extend(test.warnings)
    advisories.extend(test.advisories)

    by_category.setdefault(test.category, {})
    by_category[test.category][state] = (
        1 + by_category[test.category].get(state, 0))

  total = sum(count_by_state.values())

  logging.info('------------------- Summary --------------------')
  now = datetime.datetime.now()
  logging.info('Test Run: %s' % now.strftime('%F %r %z'))
  logging.info('UID: %s' % options.uid)

  manufacturer_label = getattr(device, 'manufacturer_label', None)
  if manufacturer_label:
    logging.info('Manufacturer: %s' %
                 manufacturer_label.encode('string-escape'))

  model_description = getattr(device, 'model_description', None)
  if model_description:
    logging.info('Model Description: %s' %
                 model_description.encode('string-escape'))

  software_version = getattr(device, 'software_version', None)
  if software_version:
    logging.info('Software Version: %s' % software_version)

  if options.timing:
    timing_stats = runner.TimingStats()
    DisplayTiming(timing_stats)

  logging.info('------------------- Warnings --------------------')
  for warning in sorted(warnings):
    logging.info(warning)

  logging.info('------------------ Advisories -------------------')
  for advisory in sorted(advisories):
    logging.info(advisory)

  logging.info('------------------ By Category ------------------')

  for category, counts in by_category.iteritems():
    passed = counts.get(TestState.PASSED, 0)
    total_run = (passed + counts.get(TestState.FAILED, 0))
    if total_run == 0:
      continue
    percent = 1.0 * passed / total_run
    logging.info(' %26s:   %3d / %3d     %.0f%%' %
                 (category, passed, total_run, percent * 100))

  logging.info('-------------------------------------------------')
  logging.info('%d / %d tests run, %d passed, %d failed, %d broken' % (
      total - count_by_state.get(TestState.NOT_RUN, 0),
      total,
      count_by_state.get(TestState.PASSED, 0),
      count_by_state.get(TestState.FAILED, 0),
      count_by_state.get(TestState.BROKEN, 0)))


def main():
  options = ParseOptions()

  test_classes = TestRunner.GetTestClasses(TestDefinitions)
  if options.list_tests:
    for test_name in sorted(c.__name__ for c in test_classes):
      print test_name
    sys.exit(0)

  SetupLogging(options)
  logging.info('OLA Responder Tests Version %s' % Version.version)
  pid_store = PidStore.GetStore(options.pid_location,
                                ('pids.proto', 'draft_pids.proto'))
  wrapper = ClientWrapper()

  global uid_ok
  uid_ok = False

  def UIDList(state, uids):
    wrapper.Stop()
    global uid_ok
    if not state.Succeeded():
      logging.error('Fetch failed: %s' % state.message)
      return

    for uid in uids:
      if uid == options.uid:
        logging.debug('Found UID %s' % options.uid)
        uid_ok = True

    if not uid_ok:
      logging.error('UID %s not found in universe %d' %
                    (options.uid, options.universe))
      return

    if len(uids) > 1:
      logging.info(
          'The following devices were detected and will be reconfigured')
      for uid in uids:
        logging.info(' %s' % uid)

      if not options.skip_check:
        logging.info('Continue ? [Y/n]')
        response = raw_input().strip().lower()
        uid_ok = response == 'y' or response == ''

  logging.debug('Fetching UID list from server')
  wrapper.Client().FetchUIDList(options.universe, UIDList)
  wrapper.Run()
  wrapper.Reset()

  if not uid_ok:
    sys.exit()

  test_filter = None
  if options.tests is not None:
    logging.info('Restricting tests to %s' % options.tests)
    test_filter = set(options.tests.split(','))

  logging.info(
      'Starting tests, universe %d, UID %s, broadcast write delay %dms, '
      'inter-test delay %dms' %
      (options.universe, options.uid, options.broadcast_write_delay,
       options.inter_test_delay))

  runner = TestRunner.TestRunner(options.universe,
                                 options.uid,
                                 options.broadcast_write_delay,
                                 options.inter_test_delay,
                                 pid_store,
                                 wrapper,
                                 options.timestamp)

  for test_class in test_classes:
    runner.RegisterTest(test_class)

  DMXSender(wrapper,
            options.universe,
            options.dmx_frame_rate,
            options.slot_count)

  tests, device = runner.RunTests(test_filter, options.no_factory_defaults)

  DisplaySummary(options, runner, tests, device)


if __name__ == '__main__':
  main()