def __init__(self, universe, uid, sub_device, pid_file): """Create a new InteractiveModeController. Args: universe: uid: sub_device: pid_file: """ cmd.Cmd.__init__(self) self._universe = universe self._uid = uid self._sub_device = sub_device self.pid_store = PidStore.GetStore(pid_file) self.wrapper = ClientWrapper() self.client = self.wrapper.Client() self.rdm_api = RDMAPI(self.client, self.pid_store) self._uids = [] self._response_printer = ResponsePrinter() # tuple of (sub_device, command_class, pid) self._outstanding_request = None self.prompt = '> '
def main(): pid_store = PidStore.GetStore() pids = [] manufacturers = [] for pid in pid_store.Pids(): pid_dict = BuildPid(pid) pids.append(pid_dict) for id, name in pid_store._manufacturer_id_to_name.iteritems(): manufacturer = { 'id': id, 'name': name, 'pids': [] } for pid in pid_store._manufacturer_pids[id].values(): pid_dict = BuildPid(pid) manufacturer['pids'].append(pid_dict) manufacturers.append(manufacturer) # pprint.pprint(manufacturers) pprint.pprint(pids)
def __init__(self): self.pid_store = PidStore.GetStore() # we can provide custom printers for PIDs below self._handlers = { 'SUPPORTED_PARAMETERS': self.SupportedParameters, 'PROXIED_DEVICES': self.ProxiedDevices, }
def main(): options = parse_options() settings.update(options.__dict__) pid_store = PidStore.GetStore(options.pid_store, ('pids.proto')) logging.basicConfig(level=logging.INFO, format='%(message)s') SetupLogDirectory(options) #Check olad status logging.info('Checking olad status') try: ola_client = OlaClient() except OLADNotRunningException: logging.error('Error creating connection with olad. Is it running?') sys.exit(127) ola_thread = OLAThread(ola_client) ola_thread.start() test_thread = RDMTestThread(pid_store, settings['log_directory']) test_thread.start() app = BuildApplication(ola_thread, test_thread) httpd = make_server('', settings['PORT'], app.HandleRequest) logging.info('Running RDM Tests Server on %s:%s' % ('127.0.0.1', httpd.server_port)) try: httpd.serve_forever() except KeyboardInterrupt: pass ola_thread.Stop() test_thread.Stop() ola_thread.join() test_thread.join()
def testDirectoryAndSingleton(self): store = PidStore.GetStore(os.path.join(path, "pids")) self.assertIs(store, PidStore.GetStore(os.path.join(path, "pids"))) self.assertEqual(len(store.Pids()), 6) self.assertEqual(len(store.ManufacturerPids(OPEN_LIGHTING_ESTA_CODE)), 1) # in pids1 self.assertIsNotNone(store.GetPid(16)) self.assertIsNotNone(store.GetPid(17)) self.assertIsNotNone(store.GetName("DEVICE_INFO")) self.assertIsNotNone(store.GetName("PROXIED_DEVICES", OPEN_LIGHTING_ESTA_CODE)) self.assertEqual(store.NameToValue("DEVICE_INFO"), 96) # in pids2 self.assertIsNotNone(store.GetPid(80)) self.assertIsNotNone(store.GetName("COMMS_STATUS")) self.assertEqual(store.GetName("PROXIED_DEVICES"), store.GetPid(16, OPEN_LIGHTING_ESTA_CODE)) self.assertIsNotNone(store.GetPid(32768, 161)) # check override file self.assertIsNone(store.GetName("SERIAL_NUMBER", OPEN_LIGHTING_ESTA_CODE)) self.assertIsNone(store.GetName("DEVICE_MODE", OPEN_LIGHTING_ESTA_CODE)) pid = store.GetName("FOO_BAR", OPEN_LIGHTING_ESTA_CODE) self.assertEqual(pid.value, 32768) self.assertEqual(pid, store.GetPid(32768, OPEN_LIGHTING_ESTA_CODE)) self.assertEqual(pid.name, "FOO_BAR") self.assertIsNotNone(pid.GetRequest(PidStore.RDM_GET)) self.assertIsNotNone(pid.GetResponse(PidStore.RDM_GET)) self.assertIsNone(pid.GetRequest(PidStore.RDM_SET)) self.assertIsNone(pid.GetResponse(PidStore.RDM_SET)) self.assertEqual(store.NameToValue("FOO_BAR", OPEN_LIGHTING_ESTA_CODE), 32768) self.assertIsNone(store.NameToValue("FOO_BAR", OPEN_LIGHTING_ESTA_CODE + 1)) self.assertEqual(pid.GetResponse(PidStore.RDM_GET).GetDescription(), ("<baz>", " baz: <[0, 4294967295]>"))
def __init__(self, universe, uid, rdm_api, wrapper, limit=25): self._universe = universe self._uid = uid self._api = rdm_api self._wrapper = wrapper # implement some basic endless loop checking self._limit = limit self._counter = 0 self._outstanding_ack_timers = 0 store = PidStore.GetStore() self._queued_message_pid = store.GetName('QUEUED_MESSAGE') self._status_messages_pid = store.GetName('STATUS_MESSAGES')
def testSort(self): store = PidStore.PidStore() store.Load([os.path.join(path, "test_pids.proto")]) self.assertEqual(len(store.Pids()), 70) pids = [p.value for p in sorted(store.Pids())] self.assertEqual(pids, [16, 17, 21, 32, 48, 49, 50, 51, 80, 81, 96, 112, 128, 129, 130, 144, 160, 176, 192, 193, 194, 224, 225, 240, 288, 289, 290, 512, 513, 514, 1024, 1025, 1026, 1027, 1028, 1029, 1280, 1281, 1536, 1537, 1538, 1539, 4096, 4097, 4112, 4128, 4129, 4144, 4145, 32688, 32689, 32690, 32691, 32692, 32752, 32753, 32754, 32755, 32756, 32757, 32758, 32759, 32760, 32761, 32762, 32763, 32764, 32765, 32766, 32767]) allNotEqual(self, store.Pids()) allHashNotEqual(self, store.Pids())
def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'dhp:u:', [ 'debug', 'help', 'skip-queued-messages', 'pid-location=', 'universe=' ]) except getopt.GetoptError as e: print(str(e)) Usage() sys.exit(2) universe = None pid_location = None level = logging.INFO skip_queued_messages = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('--skip-queued-messages'): skip_queued_messages = True elif o in ( '-p', '--pid-location', ): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() logging.basicConfig(level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_location) controller = ModelCollector(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) pprint.pprint(data)
def testPackUnpack(self): store = PidStore.PidStore() store.Load([os.path.join(path, "test_pids.proto")]) pid = store.GetName("DMX_PERSONALITY_DESCRIPTION") # Pid.Pack only packs requests and Pid.Unpack only unpacks responses # so test in two halves args = ["42"] blob = pid.Pack(args, PidStore.RDM_GET) self.assertEqual(blob, binascii.unhexlify("2a")) decoded = pid._requests.get(PidStore.RDM_GET).Unpack(blob)[0] self.assertEqual(decoded['personality'], 42) args = ["42", "7", "UnpackTest"] blob = pid._responses.get(PidStore.RDM_GET).Pack(args)[0] self.assertEqual(blob, binascii.unhexlify("2a0007556e7061636b54657374")) decoded = pid.Unpack(blob, PidStore.RDM_GET) self.assertEqual(decoded['personality'], 42) self.assertEqual(decoded['slots_required'], 7) self.assertEqual(decoded['name'], "UnpackTest")
def testBasic(self): store = PidStore.PidStore() store.Load([os.path.join(path, "test_pids.proto")]) pid = store.GetPid(17) self.assertEqual(pid.name, "PROXIED_DEVICE_COUNT") self.assertEqual(pid.value, 17) self.assertEqual(len(store.Pids()), 70) pid = store.GetName("DEVICE_INFO") self.assertEqual(pid.value, 96) self.assertIsNotNone(pid.GetRequest(PidStore.RDM_GET)) self.assertIsNotNone(pid.GetResponse(PidStore.RDM_GET)) self.assertIsNone(pid.GetRequest(PidStore.RDM_SET)) self.assertIsNone(pid.GetResponse(PidStore.RDM_SET)) expected = ( "<protocol_major> <protocol_minor> <device_model> " "<product_category> <software_version> <dmx_footprint> " "<current_personality> <personality_count> <dmx_start_address> " "<sub_device_count> <sensor_count>", " protocol_major: <[0, 255]>\n protocol_minor: <[0, 255]>\n " "device_model: <[0, 65535]>\n product_category: <[0, 65535]>\n " "software_version: <[0, 4294967295]>\n dmx_footprint: <[0, 65535]>\n " "current_personality: <[0, 255]>\n personality_count: <[0, 255]>\n " "dmx_start_address: <[0, 65535]>\n sub_device_count: <[0, 65535]>\n " "sensor_count: <[0, 255]>") self.assertEqual(pid.GetResponse(PidStore.RDM_GET).GetDescription(), expected) pid = store.GetName("CAPTURE_PRESET") expected = ("<scene> <fade_up_time> <fade_down_time> <wait_time>", " scene: <[1, 65534]>\n" " fade_up_time: <[0.0, 6553.5]>, increment 0.1\n" " fade_down_time: <[0.0, 6553.5]>, increment 0.1\n" " wait_time: <[0.0, 6553.5]>, increment 0.1") self.assertEqual(pid.GetRequest(PidStore.RDM_SET).GetDescription(), expected) self.assertEqual(1, pid._GroupCmp(pid._requests, pid._responses))
skip_queued_messages = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('--skip_queued_messages'): skip_queued_messages = True elif o in ('--pid_file',): pid_file = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() logging.basicConfig( level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_file) controller = ModelCollector(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) pprint.pprint(data) if __name__ == '__main__': main()
def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'dhi:o:p:u:', [ 'debug', 'help', 'input=', 'skip-queued-messages', 'output=', 'pid-location=', 'universe=' ]) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) universe = None output_file = None input_file = None pid_location = None level = logging.INFO skip_queued_messages = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-i', '--input'): input_file = a elif o in ('--skip-queued-messages'): skip_queued_messages = True elif o in ('-o', '--output'): output_file = a elif o in ( '-p', '--pid-location', ): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() if input_file and output_file: print('Only one of --input and --output can be provided.') sys.exit() logging.basicConfig(level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_location) if input_file: configuration = ReadFile(input_file) if configuration: writer = ConfigWriter(client_wrapper, pid_store) writer.Run(universe, configuration) else: controller = ConfigReader(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) if output_file: WriteToFile(output_file, data) else: pprint.pprint(data)
def testSetParamsWithNack(self): """uses client to send an RDM set with mocked olad. Regression test that confirms sent message is correct and sends fixed response message.""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) pid_store = PidStore.GetStore(pid_store_path) client = wrapper.Client() rdm_api = RDMAPI(client, pid_store) class results: got_request = False got_response = False def DataCallback(self): # request and response for # ola_rdm_set.py -u 1 --uid 7a70:ffffff00 DMX_PERSONALITY 10 # against olad dummy plugin # enable logging in rpc/StreamRpcChannel.py data = sockets[1].recv(4096) expected = binascii.unhexlify( "2b000010080110001a0a52444d436f6d6d616e6422190801120908f0f401150" "0ffffff180020e0012a010a30013800") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.got_request = True response = binascii.unhexlify( "2f0000100802100022290800100218002202000628e001300138004a0908f0f" "4011500ffffff520908f0f40115ac107de05831") sent_bytes = sockets[1].send(response) self.assertEqual(sent_bytes, len(response)) def ResponseCallback(self, response, data, unpack_exception): results.got_response = True self.assertEqual(response.response_type, client.RDM_NACK_REASON) self.assertEqual(response.pid, 0xe0) self.assertEqual(response.nack_reason, RDMNack.NR_DATA_OUT_OF_RANGE) wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) uid = UID.FromString("7a70:ffffff00") pid = pid_store.GetName("DMX_PERSONALITY") rdm_api.Set(1, uid, 0, pid, lambda x, y, z: ResponseCallback(self, x, y, z), args=["10"]) wrapper.Run() sockets[0].close() sockets[1].close() self.assertTrue(results.got_request) self.assertTrue(results.got_response)
def main(): readline.set_completer_delims(' \t') try: opts, args = getopt.getopt(sys.argv[1:], 'd:hilp:u:', ['sub-device=', 'help', 'interactive', 'list-pids', 'pid-location=', 'uid=', 'universe=']) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) universe = None uid = None sub_device = 0 list_pids = False pid_location = None interactive_mode = False for o, a in opts: if o in ('-d', '--sub-device'): sub_device = int(a) elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-i', '--interactive'): interactive_mode = True elif o in ('-l', '--list-pids'): list_pids = True elif o in ('--uid',): uid = UID.FromString(a) elif o in ('-p', '--pid-location',): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None and not list_pids: Usage() sys.exit() if not uid and not list_pids and not interactive_mode: Usage() sys.exit() # try to load the PID store so we fail early if we're missing PIDs try: PidStore.GetStore(pid_location) except PidStore.MissingPLASAPIDs as e: print(e) sys.exit() controller = InteractiveModeController(universe, uid, sub_device, pid_location) if interactive_mode: sys.stdout.write('Available Uids:\n') controller.onecmd('uids') controller.cmdloop() sys.exit() if list_pids: controller.onecmd('list') sys.exit() if len(args) == 0: Usage() sys.exit() request_type = 'get' if os.path.basename(sys.argv[0]) == 'ola_rdm_set.py': request_type = 'set' controller.onecmd('%s %s' % (request_type, ' '.join(args)))
if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('--skip-queued-messages'): skip_queued_messages = True elif o in ( '-p', '--pid-location', ): pid_location = a elif o in ('-u', '--universe'): universe = int(a) if universe is None: Usage() sys.exit() logging.basicConfig(level=level, format='%(message)s') client_wrapper = ClientWrapper() pid_store = PidStore.GetStore(pid_location) controller = ModelCollector(client_wrapper, pid_store) data = controller.Run(universe, skip_queued_messages) pprint.pprint(data) if __name__ == '__main__': main()
names = True elif o in ('--include-draft'): include_draft = True elif o in ( '-p', '--pid-location', ): pid_location = a logging.basicConfig(level=level, format='%(message)s') pid_files = ['pids.proto'] if include_draft: pid_files.append('draft_pids.proto') pid_store = PidStore.GetStore(pid_location, pid_files) for pid in pid_store.Pids(): pid_test_base_name = pid.name.lower().title().replace('_', '') get_size = 0 if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())): get_size = pid.GetRequest(PidStore.RDM_GET).GetAtoms()[0].size # print('# Get requires %d bytes' % (get_size)) AllSubDevicesGet(names, pid, pid_test_base_name, get_size) Get(names, pid, pid_test_base_name) if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())):
def testInconsistentData(self): store = PidStore.PidStore() with self.assertRaises(PidStore.PidStructureException): store.Load([os.path.join(path, "inconsistent_pid.proto")])
def testLoadMissing(self): store = PidStore.PidStore() with self.assertRaises(IOError): store.Load([os.path.join(path, "missing_file_pids.proto")])
def testGetParamsWithResponse(self): """uses client to send an RDM get with mocked olad. Regression test that confirms sent message is correct and sends fixed response message.""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) pid_store = PidStore.GetStore(pid_store_path) client = wrapper.Client() rdm_api = RDMAPI(client, pid_store) class results: got_request = False got_response = False def DataCallback(self): # request and response for # ola_rdm_get.py -u 1 --uid 7a70:ffffff00 DMX_PERSONALITY_DESCRIPTION 2 # against olad dummy plugin # enable logging in rpc/StreamRpcChannel.py data = sockets[1].recv(4096) expected = binascii.unhexlify( "2b000010080110001a0a52444d436f6d6d616e6422190801120908f0f4011500" "ffffff180020e1012a010230003800") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.got_request = True response = binascii.unhexlify( "3d0000100802100022370800100018002210020005506572736f6e616c697479" "203228e101300038004a0908f0f4011500ffffff520908f0f40115ac107de058" "29") sent_bytes = sockets[1].send(response) self.assertEqual(sent_bytes, len(response)) def ResponseCallback(self, response, data, unpack_exception): results.got_response = True self.assertEqual(response.response_type, client.RDM_ACK) self.assertEqual(response.pid, 0xe1) self.assertEqual(data['personality'], 2) self.assertEqual(data['slots_required'], 5) self.assertEqual(data['name'], "Personality 2") wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) uid = UID.FromString("7a70:ffffff00") pid = pid_store.GetName("DMX_PERSONALITY_DESCRIPTION") rdm_api.Get(1, uid, 0, pid, lambda x, y, z: ResponseCallback(self, x, y, z), args=["2"]) wrapper.Run() sockets[0].close() sockets[1].close() self.assertTrue(results.got_request) self.assertTrue(results.got_response)
def testLoadDuplicateManufacturer(self): store = PidStore.PidStore() with self.assertRaises(PidStore.InvalidPidFormat): store.Load([os.path.join(path, "duplicate_manufacturer.proto")])
def testCmp(self): p1 = PidStore.Pid("base", 42) p1a = PidStore.Pid("notbase", 42) g1getreq = PidStore.Group("grg", [PidStore.UInt16("ui16"), PidStore.Int32("i32")]) g1setreq = PidStore.Group("srg", [PidStore.MACAtom("mac"), PidStore.Int8("i32")]) p1b = PidStore.Pid("base", 42, None, None, g1getreq, g1setreq) p2 = PidStore.Pid("base", 43, None, None, g1getreq, g1setreq) p3 = PidStore.Pid("notbase", 43) self.assertEqual(p1, p1a) self.assertEqual(p1, p1b) self.assertEqual(p1a, p1b) self.assertEqual(p2, p3) self.assertNotEqual(p1, p2) self.assertNotEqual(p1a, p2) self.assertNotEqual(p1b, p2) self.assertNotEqual(p1a, p3) self.assertEqual(hash(p1), hash(p1a)) self.assertEqual(hash(p1), hash(p1b)) self.assertEqual(hash(p1a), hash(p1b)) self.assertEqual(hash(p2), hash(p3)) self.assertNotEqual(hash(p1), hash(p2)) self.assertNotEqual(hash(p1a), hash(p2)) self.assertNotEqual(hash(p1b), hash(p2)) self.assertNotEqual(hash(p1a), hash(p3))
def testLoadDuplicateName(self): store = PidStore.PidStore() with self.assertRaises(PidStore.InvalidPidFormat): store.Load([os.path.join(path, "duplicate_pid_name.proto")])
def testLoad(self): store = PidStore.GetStore(os.environ['PIDDATA']) self.assertIsNotNone(store) pids = store.Pids() self.assertNotEqual(0, len(pids))
def testGetWithResponse(self): """uses client to send an RDM get with mocked olad. Regression test that confirms sent message is correct and sends fixed response message.""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) pid_store = PidStore.GetStore(pid_store_path) client = wrapper.Client() rdm_api = RDMAPI(client, pid_store) class results: got_request = False got_response = False def DataCallback(self): # request and response for # ola_rdm_get.py -u 1 --uid 7a70:ffffff00 device_info # against olad dummy plugin # enable logging in rpc/StreamRpcChannel.py data = sockets[1].recv(4096) expected = binascii.unhexlify( "29000010080110001a0a52444d436f6d6d616e6422170801120908f0f4011500" "ffffff180020602a0030003800") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.got_request = True response = binascii.unhexlify( "3f0000100802100022390800100018002213010000017fff0000000300050204" "00010000032860300038004a0908f0f4011500ffffff520908f0f40115ac1100" "02580a") sent_bytes = sockets[1].send(response) self.assertEqual(sent_bytes, len(response)) def ResponseCallback(self, response, data, unpack_exception): results.got_response = True self.assertEqual(response.response_type, client.RDM_ACK) self.assertEqual(response.pid, 0x60) self.assertEqual(data["dmx_footprint"], 5) self.assertEqual(data["software_version"], 3) self.assertEqual(data["personality_count"], 4) self.assertEqual(data["device_model"], 1) self.assertEqual(data["current_personality"], 2) self.assertEqual(data["protocol_major"], 1) self.assertEqual(data["protocol_minor"], 0) self.assertEqual(data["product_category"], 32767) self.assertEqual(data["dmx_start_address"], 1) self.assertEqual(data["sub_device_count"], 0) self.assertEqual(data["sensor_count"], 3) wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) uid = UID.FromString("7a70:ffffff00") pid = pid_store.GetName("DEVICE_INFO") rdm_api.Get(1, uid, 0, pid, lambda x, y, z: ResponseCallback(self, x, y, z)) wrapper.Run() sockets[0].close() sockets[1].close() self.assertTrue(results.got_request) self.assertTrue(results.got_response)
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', 'manufacturer_names.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, pid_store)
def testLoadInvalidEstaPid(self): store = PidStore.PidStore() with self.assertRaises(PidStore.InvalidPidFormat): store.Load([os.path.join(path, "invalid_esta_pid.proto")])
def main(): try: opts, args = getopt.getopt( sys.argv[1:], 'dhnp:', ['debug', 'help', 'names', 'pid-location=', 'include-draft']) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) pid_location = None level = logging.INFO names = False include_draft = False for o, a in opts: if o in ('-d', '--debug'): level = logging.DEBUG elif o in ('-h', '--help'): Usage() sys.exit() elif o in ('-n', '--names'): names = True elif o in ('--include-draft'): include_draft = True elif o in ( '-p', '--pid-location', ): pid_location = a logging.basicConfig(level=level, format='%(message)s') pid_files = ['pids.proto'] if include_draft: pid_files.append('draft_pids.proto') pid_store = PidStore.GetStore(pid_location, pid_files) for pid in pid_store.Pids(): pid_test_base_name = pid.name.lower().title().replace('_', '') get_size = 0 if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())): get_size = pid.GetRequest(PidStore.RDM_GET).GetAtoms()[0].size # print('# Get requires %d bytes' % (get_size)) AllSubDevicesGet(names, pid, pid_test_base_name, get_size) Get(names, pid, pid_test_base_name) if ((pid.RequestSupported(PidStore.RDM_GET)) and (pid.GetRequest(PidStore.RDM_GET).HasAtoms())): first_atom = pid.GetRequest(PidStore.RDM_GET).GetAtoms()[0] if (first_atom.HasRanges() and (not first_atom.ValidateRawValueInRange(0) and first_atom.ValidateRawValueInRange(1))): GetZero(names, pid, pid_test_base_name, first_atom) GetWithNoData(names, pid, pid_test_base_name) GetWithExtraData(names, pid, pid_test_base_name, get_size) else: GetWithData(names, pid, pid_test_base_name) Set(names, pid, pid_test_base_name) set_size = 0 if ((pid.RequestSupported(PidStore.RDM_SET)) and (pid.GetRequest(PidStore.RDM_SET).HasAtoms())): for atom in pid.GetRequest(PidStore.RDM_SET).GetAtoms(): set_size += atom.size # print('# Set requires %d bytes' % (set_size)) first_atom = pid.GetRequest(PidStore.RDM_SET).GetAtoms()[0] if (first_atom.HasRanges() and (not first_atom.ValidateRawValueInRange(0) and first_atom.ValidateRawValueInRange(1))): SetZero(names, pid, pid_test_base_name, first_atom) SetWithNoData(names, pid, pid_test_base_name) SetWithExtraData(names, pid, pid_test_base_name, set_size) else: SetWithData(names, pid, pid_test_base_name) sys.exit(0)
def testPackRanges(self): store = PidStore.PidStore() store.Load([os.path.join(path, "test_pids.proto")]) pid = store.GetName("REAL_TIME_CLOCK") # first check encoding of valid RTC data args = ["2020", "6", "20", "21", "22", "23"] blob = pid.Pack(args, PidStore.RDM_SET) self.assertEqual(blob, binascii.unhexlify("07e40614151617")) decoded = pid._requests.get(PidStore.RDM_SET).Unpack(blob)[0] self.assertEqual(decoded, {'year': 2020, 'month': 6, 'day': 20, 'hour': 21, 'minute': 22, 'second': 23}) # next check that ranges are being enforced properly # invalid year (2002 < 2003) with self.assertRaises(PidStore.ArgsValidationError): args = ["2002", "6", "20", "20", "20", "20"] blob = pid.Pack(args, PidStore.RDM_SET) # invalid month < 1 with self.assertRaises(PidStore.ArgsValidationError): args = ["2020", "0", "20", "20", "20", "20"] blob = pid.Pack(args, PidStore.RDM_SET) # invalid month > 12 with self.assertRaises(PidStore.ArgsValidationError): args = ["2020", "13", "20", "20", "20", "20"] blob = pid.Pack(args, PidStore.RDM_SET) # invalid month > 255 with self.assertRaises(PidStore.ArgsValidationError): args = ["2020", "256", "20", "20", "20", "20"] blob = pid.Pack(args, PidStore.RDM_SET) # invalid negative month with self.assertRaises(PidStore.ArgsValidationError): args = ["2020", "-1", "20", "20", "20", "20"] blob = pid.Pack(args, PidStore.RDM_SET) # tests for string with min=max=2 pid = store.GetName("LANGUAGE_CAPABILITIES") args = ["en"] blob = pid._responses.get(PidStore.RDM_GET).Pack(args)[0] self.assertEqual(blob, binascii.unhexlify("656e")) decoded = pid.Unpack(blob, PidStore.RDM_GET) self.assertEqual(decoded, {'languages': [{'language': 'en'}]}) with self.assertRaises(PidStore.ArgsValidationError): args = ["e"] blob = pid._responses.get(PidStore.RDM_GET).Pack(args)[0] with self.assertRaises(PidStore.ArgsValidationError): args = ["enx"] blob = pid._responses.get(PidStore.RDM_GET).Pack(args)[0] # valid empty string pid = store.GetName("STATUS_ID_DESCRIPTION") args = [""] blob = pid._responses.get(PidStore.RDM_GET).Pack(args)[0] self.assertEqual(len(blob), 0) decoded = pid.Unpack(blob, PidStore.RDM_GET) self.assertEqual(decoded['label'], "") # string too long with self.assertRaises(PidStore.ArgsValidationError): args = ["123456789012345678901234567890123"] blob = pid._responses.get(PidStore.RDM_GET).Pack(args)[0]