How to use _get_name method in lisa

Best Python code snippet using lisa_python

federation_sys.py

Source:federation_sys.py Github

copy

Full Screen

...87 b.destroy(self.qmf)88 TestBase010.tearDown(self)89 self.qmf.close()90 #--- General test utility functions91 def _get_name(self):92 """93 Return the name of method which called this method stripped of "test_" prefix. Used for naming94 queues and exchanges on a per-test basis.95 """96 return stack()[1][3][5:]97 def _get_broker_port(self, key):98 """99 Get the port of a broker defined in the environment using -D<key>=portno100 """101 return int(self.defines[key])102 def _get_send_address(self, exch_name, queue_name):103 """104 Get an address to which to send messages based on the exchange name and queue name, but taking into account105 that the exchange name may be "" (the default exchange), in whcih case the format changes slightly.106 """107 if len(exch_name) == 0: # Default exchange108 return queue_name109 return "%s/%s" % (exch_name, queue_name)110 def _get_broker(self, broker_port_key):111 """112 Read the port numbers for pre-started brokers from the environment using keys, then find or create and return113 the Qmf broker proxy for the appropriate broker114 """115 port = self._get_broker_port(broker_port_key)116 return self._find_create_broker("localhost:%s" % port)117 ################118 def _get_msg_subject(self, topic_key):119 """120 Return an appropriate subject for sending a message to a known topic. Return None if there is no topic.121 """122 if len(topic_key) == 0: return None123 if "*" in topic_key: return topic_key.replace("*", "test")124 if "#" in topic_key: return topic_key.replace("#", "multipart.test")125 return topic_key126 def _send_msgs(self, session_name, broker, addr, msg_count, msg_content = "Message_%03d", topic_key = "",127 msg_durable_flag = False, enq_txn_size = 0):128 """129 Send messages to a broker using address addr130 """131 send_session = broker.session(session_name, transactional_flag = enq_txn_size > 0)132 sender = send_session.sender(addr)133 txn_cnt = 0134 for i in range(0, msg_count):135 sender.send(Message(msg_content % (i + 1), subject = self._get_msg_subject(topic_key), durable = msg_durable_flag))136 if enq_txn_size > 0:137 txn_cnt += 1138 if txn_cnt >= enq_txn_size:139 send_session.commit()140 txn_cnt = 0141 if enq_txn_size > 0 and txn_cnt > 0:142 send_session.commit()143 sender.close()144 send_session.close()145 def _receive_msgs(self, session_name, broker, addr, msg_count, msg_content = "Message_%03d", deq_txn_size = 0,146 timeout = 0):147 """148 Receive messages from a broker149 """150 receive_session = broker.session(session_name, transactional_flag = deq_txn_size > 0)151 receiver = receive_session.receiver(addr)152 txn_cnt = 0153 for i in range(0, msg_count):154 try:155 msg = receiver.fetch(timeout = timeout)156 if deq_txn_size > 0:157 txn_cnt += 1158 if txn_cnt >= deq_txn_size:159 receive_session.commit()160 txn_cnt = 0161 receive_session.acknowledge()162 except Empty:163 if deq_txn_size > 0: receive_session.rollback()164 receiver.close()165 receive_session.close()166 if i == 0:167 self.fail("Broker %s queue \"%s\" is empty" % (broker.qmf_broker.getBroker().getUrl(), addr))168 else:169 self.fail("Unable to receive message %d from broker %s queue \"%s\"" % (i, broker.qmf_broker.getBroker().getUrl(), addr))170 if msg.content != msg_content % (i + 1):171 receiver.close()172 receive_session.close()173 self.fail("Unexpected message \"%s\", was expecting \"%s\"." % (msg.content, msg_content % (i + 1)))174 try:175 msg = receiver.fetch(timeout = 0)176 if deq_txn_size > 0: receive_session.rollback()177 receiver.close()178 receive_session.close()179 self.fail("Extra message \"%s\" found on broker %s address \"%s\"" % (msg.content, broker.qmf_broker.getBroker().getUrl(), addr))180 except Empty:181 pass182 if deq_txn_size > 0 and txn_cnt > 0:183 receive_session.commit()184 receiver.close()185 receive_session.close()186 #--- QMF-specific utility functions187 def _get_qmf_property(self, props, key):188 """189 Get the value of a named property key kj from a property list [(k0, v0), (k1, v1), ... (kn, vn)].190 """191 for k,v in props:192 if k.name == key:193 return v194 return None195 def _check_qmf_return(self, method_result):196 """197 Check the result of a Qmf-defined method call198 """199 self.assertTrue(method_result.status == 0, method_result.text)200 def _check_optional_qmf_property(self, qmf_broker, type, qmf_object, key, expected_val, obj_ref_flag):201 """202 Optional Qmf properties don't show up in the properties list when they are not specified. Checks for203 these property types involve searching the properties list and making sure it is present or not as204 expected.205 """206 val = self._get_qmf_property(qmf_object.getProperties(), key)207 if val is None:208 if len(expected_val) > 0:209 self.fail("%s %s exists, but has does not have %s property. Expected value: \"%s\"" %210 (type, qmf_object.name, key, expected_val))211 else:212 if len(expected_val) > 0:213 if obj_ref_flag:214 obj = self.qmf.getObjects(_objectId = val, _broker = qmf_broker.getBroker())215 self.assertEqual(len(obj), 1, "More than one object with the same objectId: %s" % obj)216 val = obj[0].name217 self.assertEqual(val, expected_val, "%s %s exists, but has incorrect %s property. Found \"%s\", expected \"%s\"" %218 (type, qmf_object.name, key, val, expected_val))219 else:220 self.fail("%s %s exists, but has an unexpected %s property \"%s\" set." % (type, qmf_object.name, key, val))221 #--- Find/create Qmf broker objects222 def _find_qmf_broker(self, url):223 """224 Find the Qmf broker object for the given broker URL. The broker must have been previously added to Qmf through225 addBroker()226 """227 for b in self.qmf.getObjects(_class="broker"):228 if b.getBroker().getUrl() == url:229 return b230 return None231 def _find_create_broker(self, url):232 """233 Find a running broker through Qmf. If it does not exist, add it (assuming the broker is already running).234 """235 broker = self._Broker(url)236 self._brokers.append(broker)237 if self.qmf is not None:238 qmf_broker = self._find_qmf_broker(broker.url)239 if qmf_broker is None:240 self.qmf.addBroker(broker.url)241 broker.qmf_broker = self._find_qmf_broker(broker.url)242 else:243 broker.qmf_broker = qmf_broker244 return broker245 #--- Find/create/delete exchanges246 def _find_qmf_exchange(self, qmf_broker, name, type, alternate, durable, auto_delete):247 """248 Find Qmf exchange object249 """250 for e in self.qmf.getObjects(_class="exchange", _broker = qmf_broker.getBroker()):251 if e.name == name:252 if len(name) == 0 or (len(name) >= 4 and name[:4] == "amq."): return e # skip checks for special exchanges253 self.assertEqual(e.type, type,254 "Exchange \"%s\" exists, but is of unexpected type %s; expected type %s." %255 (name, e.type, type))256 self._check_optional_qmf_property(qmf_broker, "Exchange", e, "altExchange", alternate, True)257 self.assertEqual(e.durable, durable,258 "Exchange \"%s\" exists, but has incorrect durability. Found durable=%s, expected durable=%s" %259 (name, e.durable, durable))260 self.assertEqual(e.autoDelete, auto_delete,261 "Exchange \"%s\" exists, but has incorrect auto-delete property. Found %s, expected %s" %262 (name, e.autoDelete, auto_delete))263 return e264 return None265 def _find_create_qmf_exchange(self, qmf_broker, name, type, alternate, durable, auto_delete, args):266 """267 Find Qmf exchange object if exchange exists, create exchange and return its Qmf object if not268 """269 e = self._find_qmf_exchange(qmf_broker, name, type, alternate, durable, auto_delete)270 if e is not None: return e271 # Does not exist, so create it272 props = dict({"exchange-type": type, "type": type, "durable": durable, "auto-delete": auto_delete, "alternate-exchange": alternate}, **args)273 self._check_qmf_return(qmf_broker.create(type="exchange", name=name, properties=props, strict=True))274 e = self._find_qmf_exchange(qmf_broker, name, type, alternate, durable, auto_delete)275 self.assertNotEqual(e, None, "Creation of exchange %s on broker %s failed" % (name, qmf_broker.getBroker().getUrl()))276 return e277 def _find_delete_qmf_exchange(self, qmf_broker, name, type, alternate, durable, auto_delete):278 """279 Find and delete Qmf exchange object if it exists280 """281 e = self._find_qmf_exchange(qmf_broker, name, type, alternate, durable, auto_delete)282 if e is not None and not auto_delete:283 self._check_qmf_return(qmf_broker.delete(type="exchange", name=name, options={}))284 #--- Find/create/delete queues285 def _find_qmf_queue(self, qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete):286 """287 Find a Qmf queue object288 """289 for q in self.qmf.getObjects(_class="queue", _broker = qmf_broker.getBroker()):290 if q.name == name:291 self._check_optional_qmf_property(qmf_broker, "Queue", q, "altExchange", alternate_exchange, True)292 self.assertEqual(q.durable, durable,293 "Queue \"%s\" exists, but has incorrect durable property. Found %s, expected %s" %294 (name, q.durable, durable))295 self.assertEqual(q.exclusive, exclusive,296 "Queue \"%s\" exists, but has incorrect exclusive property. Found %s, expected %s" %297 (name, q.exclusive, exclusive))298 self.assertEqual(q.autoDelete, auto_delete,299 "Queue \"%s\" exists, but has incorrect auto-delete property. Found %s, expected %s" %300 (name, q.autoDelete, auto_delete))301 return q302 return None303 def _find_create_qmf_queue(self, qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete, args):304 """305 Find Qmf queue object if queue exists, create queue and return its Qmf object if not306 """307 q = self._find_qmf_queue(qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete)308 if q is not None: return q309 # Queue does not exist, so create it310 props = dict({"durable": durable, "auto-delete": auto_delete, "exclusive": exclusive, "alternate-exchange": alternate_exchange}, **args)311 self._check_qmf_return(qmf_broker.create(type="queue", name=name, properties=props, strict=True))312 q = self._find_qmf_queue(qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete)313 self.assertNotEqual(q, None, "Creation of queue %s on broker %s failed" % (name, qmf_broker.getBroker().getUrl()))314 return q315 def _find_delete_qmf_queue(self, qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete, args):316 """317 Find and delete Qmf queue object if it exists318 """319 q = self._find_qmf_queue(qmf_broker, name, alternate_exchange, durable, exclusive, auto_delete)320 if q is not None and not auto_delete:321 self._check_qmf_return(qmf_broker.delete(type="queue", name=name, options={}))322 #--- Find/create/delete bindings (between an exchange and a queue)323 def _find_qmf_binding(self, qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args):324 """325 Find a Qmf binding object326 """327 for b in self.qmf.getObjects(_class="binding", _broker = qmf_broker.getBroker()):328 if b.exchangeRef == qmf_exchange.getObjectId() and b.queueRef == qmf_queue.getObjectId():329 if qmf_exchange.type != "fanout": # Fanout ignores the binding key, and always returns "" as the key330 self.assertEqual(b.bindingKey, binding_key,331 "Binding between exchange %s and queue %s exists, but has mismatching binding key: Found %s, expected %s." %332 (qmf_exchange.name, qmf_queue.name, b.bindingKey, binding_key))333 self.assertEqual(b.arguments, binding_args,334 "Binding between exchange %s and queue %s exists, but has mismatching arguments: Found %s, expected %s" %335 (qmf_exchange.name, qmf_queue.name, b.arguments, binding_args))336 return b337 return None338 def _find_create_qmf_binding(self, qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args):339 """340 Find Qmf binding object if it exists, create binding and return its Qmf object if not341 """342 b = self._find_qmf_binding(qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args)343 if b is not None: return b344 # Does not exist, so create it345 self._check_qmf_return(qmf_broker.create(type="binding", name="%s/%s/%s" % (qmf_exchange.name, qmf_queue.name, binding_key), properties=binding_args, strict=True))346 b = self._find_qmf_binding(qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args)347 self.assertNotEqual(b, None, "Creation of binding between exchange %s and queue %s with key %s failed" %348 (qmf_exchange.name, qmf_queue.name, binding_key))349 return b350 def _find_delete_qmf_binding(self, qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args):351 """352 Find and delete Qmf binding object if it exists353 """354 b = self._find_qmf_binding(qmf_broker, qmf_exchange, qmf_queue, binding_key, binding_args)355 if b is not None:356 if len(qmf_exchange.name) > 0: # not default exchange357 self._check_qmf_return(qmf_broker.delete(type="binding", name="%s/%s/%s" % (qmf_exchange.name, qmf_queue.name, binding_key), options={}))358 #--- Find/create a link359 def _find_qmf_link(self, qmf_from_broker_proxy, host, port):360 """361 Find a Qmf link object362 """363 for l in self.qmf.getObjects(_class="link", _broker=qmf_from_broker_proxy):364 if l.host == host and l.port == port:365 return l366 return None367 def _find_create_qmf_link(self, qmf_from_broker, qmf_to_broker_proxy, link_durable_flag, auth_mechanism, user_id,368 password, transport, pause_interval, link_ready_timeout):369 """370 Find a Qmf link object if it exists, create it and return its Qmf link object if not371 """372 to_broker_host = qmf_to_broker_proxy.host373 to_broker_port = qmf_to_broker_proxy.port374 l = self._find_qmf_link(qmf_from_broker.getBroker(), to_broker_host, to_broker_port)375 if l is not None: return l376 # Does not exist, so create it377 self._check_qmf_return(qmf_from_broker.connect(to_broker_host, to_broker_port, link_durable_flag, auth_mechanism, user_id, password, transport))378 l = self._find_qmf_link(qmf_from_broker.getBroker(), to_broker_host, to_broker_port)379 self.assertNotEqual(l, None, "Creation of link from broker %s to broker %s failed" %380 (qmf_from_broker.getBroker().getUrl(), qmf_to_broker_proxy.getUrl()))381 self._wait_for_link(l, pause_interval, link_ready_timeout)382 return l383 def _wait_for_link(self, link, pause_interval, link_ready_timeout):384 """385 Wait for link to become active (state=Operational)386 """387 tot_time = 0388 link.update()389 while link.state != "Operational" and tot_time < link_ready_timeout:390 sleep(pause_interval)391 tot_time += pause_interval392 link.update()393 self.assertEqual(link.state, "Operational", "Timeout: Link not operational, state=%s" % link.state)394 #--- Find/create a bridge395 def _find_qmf_bridge(self, qmf_broker_proxy, qmf_link, source, destination, key):396 """397 Find a Qmf link object398 """399 for b in self.qmf.getObjects(_class="bridge", _broker=qmf_broker_proxy):400 if b.linkRef == qmf_link.getObjectId() and b.src == source and b.dest == destination and b.key == key:401 return b402 return None403 def _find_create_qmf_bridge(self, qmf_broker_proxy, qmf_link, queue_name, exch_name, topic_key,404 queue_route_type_flag, bridge_durable_flag):405 """406 Find a Qmf bridge object if it exists, create it and return its Qmf object if not407 """408 if queue_route_type_flag:409 src = queue_name410 dest = exch_name411 key = ""412 else:413 src = exch_name414 dest = exch_name415 if len(topic_key) > 0:416 key = topic_key417 else:418 key = queue_name419 b = self._find_qmf_bridge(qmf_broker_proxy, qmf_link, src, dest, key)420 if b is not None:421 return b422 # Does not exist, so create it423 self._check_qmf_return(qmf_link.bridge(bridge_durable_flag, src, dest, key, "", "", queue_route_type_flag, False, False, 1))424 b = self._find_qmf_bridge(qmf_broker_proxy, qmf_link, src, dest, key)425 self.assertNotEqual(b, None, "Bridge creation failed: src=%s dest=%s key=%s" % (src, dest, key))426 return b427 def _wait_for_bridge(self, bridge, src_broker, dest_broker, exch_name, queue_name, topic_key, pause_interval,428 bridge_ready_timeout):429 """430 Wait for bridge to become active by sending messages over the bridge at 1 sec intervals until they are431 observed at the destination.432 """433 tot_time = 0434 active = False435 send_session = src_broker.session("tx")436 sender = send_session.sender(self._get_send_address(exch_name, queue_name))437 src_receive_session = src_broker.session("src_rx")438 src_receiver = src_receive_session.receiver(queue_name)439 dest_receive_session = dest_broker.session("dest_rx")440 dest_receiver = dest_receive_session.receiver(queue_name)441 while not active and tot_time < bridge_ready_timeout:442 sender.send(Message("xyz123", subject = self._get_msg_subject(topic_key)))443 try:444 src_receiver.fetch(timeout = 0)445 src_receive_session.acknowledge()446 # Keep receiving msgs, as several may have accumulated447 while True:448 dest_receiver.fetch(timeout = 0)449 dest_receive_session.acknowledge()450 sleep(1)451 active = True452 except Empty:453 sleep(pause_interval)454 tot_time += pause_interval455 dest_receiver.close()456 dest_receive_session.close()457 src_receiver.close()458 src_receive_session.close()459 sender.close()460 send_session.close()461 self.assertTrue(active, "Bridge failed to become active after %ds: %s" % (bridge_ready_timeout, bridge))462 #--- Find/create/delete utility functions463 def _create_and_bind(self, qmf_broker, exchange_args, queue_args, binding_args):464 """465 Create a binding between a named exchange and queue on a broker466 """467 e = self._find_create_qmf_exchange(qmf_broker, **exchange_args)468 q = self._find_create_qmf_queue(qmf_broker, **queue_args)469 return self._find_create_qmf_binding(qmf_broker, e, q, **binding_args)470 def _check_alt_exchange(self, qmf_broker, alt_exch_name, alt_exch_type, alt_exch_op):471 """472 Check for existence of alternate exchange. Return the Qmf exchange proxy object for the alternate exchange473 """474 if len(alt_exch_name) == 0: return None475 if alt_exch_op == _alt_exch_ops.create:476 return self._find_create_qmf_exchange(qmf_broker=qmf_broker, name=alt_exch_name, type=alt_exch_type,477 alternate="", durable=False, auto_delete=False, args={})478 if alt_exch_op == _alt_exch_ops.delete:479 return self._find_delete_qmf_exchange(qmf_broker=qmf_broker, name=alt_exch_name, type=alt_exch_type,480 alternate="", durable=False, auto_delete=False)481 return self._find_qmf_exchange(qmf_broker=qmf_broker, name=alt_exchange_name, type=alt_exchange_type,482 alternate="", durable=False, auto_delete=False)483 def _delete_queue_binding(self, qmf_broker, exchange_args, queue_args, binding_args):484 """485 Delete a queue and the binding between it and the exchange486 """487 e = self._find_qmf_exchange(qmf_broker, exchange_args["name"], exchange_args["type"], exchange_args["alternate"], exchange_args["durable"], exchange_args["auto_delete"])488 q = self._find_qmf_queue(qmf_broker, queue_args["name"], queue_args["alternate_exchange"], queue_args["durable"], queue_args["exclusive"], queue_args["auto_delete"])489 self._find_delete_qmf_binding(qmf_broker, e, q, **binding_args)490 self._find_delete_qmf_queue(qmf_broker, **queue_args)491 def _create_route(self, queue_route_type_flag, src_broker, dest_broker, exch_name, queue_name, topic_key,492 link_durable_flag, bridge_durable_flag, auth_mechanism, user_id, password, transport,493 pause_interval = 1, link_ready_timeout = 20, bridge_ready_timeout = 20):494 """495 Create a route from a source broker to a destination broker496 """497 l = self._find_create_qmf_link(dest_broker.qmf_broker, src_broker.qmf_broker.getBroker(), link_durable_flag,498 auth_mechanism, user_id, password, transport, pause_interval, link_ready_timeout)499 self._links.append(l)500 b = self._find_create_qmf_bridge(dest_broker.qmf_broker.getBroker(), l, queue_name, exch_name, topic_key,501 queue_route_type_flag, bridge_durable_flag)502 self._bridges.append(b)503 self._wait_for_bridge(b, src_broker, dest_broker, exch_name, queue_name, topic_key, pause_interval, bridge_ready_timeout)504 # Parameterized test - entry point for tests505 def _do_test(self,506 test_name, # Name of test507 exch_name = "amq.direct", # Remote exchange name508 exch_type = "direct", # Remote exchange type509 exch_alt_exch = "", # Remote exchange alternate exchange510 exch_alt_exch_type = "direct", # Remote exchange alternate exchange type511 exch_durable_flag = False, # Remote exchange durability512 exch_auto_delete_flag = False, # Remote exchange auto-delete property513 exch_x_args = {}, # Remote exchange args514 queue_alt_exch = "", # Remote queue alternate exchange515 queue_alt_exch_type = "direct", # Remote queue alternate exchange type516 queue_durable_flag = False, # Remote queue durability517 queue_exclusive_flag = False, # Remote queue exclusive property518 queue_auto_delete_flag = False, # Remote queue auto-delete property519 queue_x_args = {}, # Remote queue args520 binding_durable_flag = False, # Remote binding durability521 binding_x_args = {}, # Remote binding args522 topic_key = "", # Binding key For remote topic exchanges only523 msg_count = 10, # Number of messages to send524 msg_durable_flag = False, # Message durability525 link_durable_flag = False, # Route link durability526 bridge_durable_flag = False, # Route bridge durability527 queue_route_type_flag = False, # Route type: false = bridge route, true = queue route528 enq_txn_size = 0, # Enqueue transaction size, 0 = no transactions529 deq_txn_size = 0, # Dequeue transaction size, 0 = no transactions530 alt_exch_op = _alt_exch_ops.create,# Op on alt exch [create (ensure present), delete (ensure not present), none (neither create nor delete)]531 auth_mechanism = "", # Authorization mechanism for linked broker532 user_id = "", # User ID for authorization on linked broker533 password = "", # Password for authorization on linked broker534 transport = "tcp" # Transport for route to linked broker535 ):536 """537 Parameterized federation test. Sets up a federated link between a source broker and a destination broker and538 checks that messages correctly pass over the link to the destination. Where appropriate (non-queue-routes), also539 checks for the presence of messages on the source broker.540 In these tests, the concept is to create a LOCAL broker, then create a link to a REMOTE broker using federation.541 In other words, the messages sent to the LOCAL broker will be replicated on the REMOTE broker, and tests are542 performed on the REMOTE broker to check that the required messages are present. In the case of regular routes,543 the LOCAL broker will also retain the messages, and a similar test is performed on this broker.544 TODO: There are several items to improve here:545 1. _do_test() is rather general. Rather create a version for each exchange type and test the exchange/queue546 interaction in more detail based on the exchange type547 2. Add a headers and an xml exchange type548 3. Restructure the tests to start and stop brokers directly rather than relying on previously549 started brokers. Then persistence can be checked by stopping and restarting the brokers. In particular,550 test the persistence of links and bridges, both of which take a persistence flag.551 4. Test the behavior of the alternate exchanges when messages are sourced through a link. Also check behavior552 when the alternate exchange is not present or is deleted after the reference is made.553 5. Test special queue types (eg LVQ)554 """555 local_broker = self._get_broker("local-port")556 remote_broker = self._get_broker("remote-port")557 # Check alternate exchanges exist (and create them if not) on both local and remote brokers558 self._check_alt_exchange(local_broker.qmf_broker, exch_alt_exch, exch_alt_exch_type, alt_exch_op)559 self._check_alt_exchange(local_broker.qmf_broker, queue_alt_exch, queue_alt_exch_type, alt_exch_op)560 self._check_alt_exchange(remote_broker.qmf_broker, exch_alt_exch, exch_alt_exch_type, alt_exch_op)561 self._check_alt_exchange(remote_broker.qmf_broker, queue_alt_exch, queue_alt_exch_type, alt_exch_op)562 queue_name = "queue_%s" % test_name563 exchange_args = {"name": exch_name, "type": exch_type, "alternate": exch_alt_exch,564 "durable": exch_durable_flag, "auto_delete": exch_auto_delete_flag, "args": exch_x_args}565 queue_args = {"name": queue_name, "alternate_exchange": queue_alt_exch, "durable": queue_durable_flag,566 "exclusive": queue_exclusive_flag, "auto_delete": queue_auto_delete_flag, "args": queue_x_args}567 binding_args = {"binding_args": binding_x_args}568 if exch_type == "topic":569 self.assertTrue(len(topic_key) > 0, "Topic exchange selected, but no topic key was set.")570 binding_args["binding_key"] = topic_key571 elif exch_type == "direct":572 binding_args["binding_key"] = queue_name573 else:574 binding_args["binding_key"] = ""575 self._create_and_bind(qmf_broker=local_broker.qmf_broker, exchange_args=exchange_args, queue_args=queue_args, binding_args=binding_args)576 self._create_and_bind(qmf_broker=remote_broker.qmf_broker, exchange_args=exchange_args, queue_args=queue_args, binding_args=binding_args)577 self._create_route(queue_route_type_flag, local_broker, remote_broker, exch_name, queue_name, topic_key,578 link_durable_flag, bridge_durable_flag, auth_mechanism, user_id, password, transport)579 self._send_msgs("send_session", local_broker, addr = self._get_send_address(exch_name, queue_name),580 msg_count = msg_count, topic_key = topic_key, msg_durable_flag = msg_durable_flag, enq_txn_size = enq_txn_size)581 if not queue_route_type_flag:582 self._receive_msgs("local_receive_session", local_broker, addr = queue_name, msg_count = msg_count, deq_txn_size = deq_txn_size)583 self._receive_msgs("remote_receive_session", remote_broker, addr = queue_name, msg_count = msg_count, deq_txn_size = deq_txn_size, timeout = 5)584 # Clean up585 self._delete_queue_binding(qmf_broker=local_broker.qmf_broker, exchange_args=exchange_args, queue_args=queue_args, binding_args=binding_args)586 self._delete_queue_binding(qmf_broker=remote_broker.qmf_broker, exchange_args=exchange_args, queue_args=queue_args, binding_args=binding_args)587class A_ShortTests(QmfTestBase010):588 def test_route_defaultExch(self):589 self._do_test(self._get_name())590 def test_queueRoute_defaultExch(self):591 self._do_test(self._get_name(), queue_route_type_flag=True)592class A_LongTests(QmfTestBase010):593 def test_route_amqDirectExch(self):594 self._do_test(self._get_name(), exch_name="amq.direct")595 def test_queueRoute_amqDirectExch(self):596 self._do_test(self._get_name(), exch_name="amq.direct", queue_route_type_flag=True)597 def test_route_directExch(self):598 self._do_test(self._get_name(), exch_name="testDirectExchange")599 def test_queueRoute_directExch(self):600 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True)601 def test_route_fanoutExch(self):602 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout")603 def test_queueRoute_fanoutExch(self):604 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True)605 def test_route_topicExch(self):606 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#")607 def test_queueRoute_topicExch(self):608 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True)609class B_ShortTransactionTests(QmfTestBase010):610 def test_txEnq01_route_defaultExch(self):611 self._do_test(self._get_name(), enq_txn_size=1)612 def test_txEnq01_queueRoute_defaultExch(self):613 self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1)614 def test_txEnq01_txDeq01_route_defaultExch(self):615 self._do_test(self._get_name(), enq_txn_size=1, deq_txn_size=1)616 def test_txEnq01_txDeq01_queueRoute_defaultExch(self):617 self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)618class B_LongTransactionTests(QmfTestBase010):619 def test_txEnq10_route_defaultExch(self):620 self._do_test(self._get_name(), enq_txn_size=10, msg_count = 103)621 def test_txEnq10_queueRoute_defaultExch(self):622 self._do_test(self._get_name(), queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)623 def test_txEnq01_route_directExch(self):624 self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1)625 def test_txEnq01_queueRoute_directExch(self):626 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1)627 def test_txEnq10_route_directExch(self):628 self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=10, msg_count = 103)629 def test_txEnq10_queueRoute_directExch(self):630 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)631 def test_txEnq01_txDeq01_route_directExch(self):632 self._do_test(self._get_name(), exch_name="testDirectExchange", enq_txn_size=1, deq_txn_size=1)633 def test_txEnq01_txDeq01_queueRoute_directExch(self):634 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)635 def test_txEnq01_route_fanoutExch(self):636 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1)637 def test_txEnq01_queueRoute_fanoutExch(self):638 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1)639 def test_txEnq10_route_fanoutExch(self):640 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=10, msg_count = 103)641 def test_txEnq10_queueRoute_fanoutExch(self):642 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)643 def test_txEnq01_txDeq01_route_fanoutExch(self):644 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", enq_txn_size=1, deq_txn_size=1)645 def test_txEnq01_txDeq01_queueRoute_fanoutExch(self):646 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)647 def test_txEnq01_route_topicExch(self):648 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1)649 def test_txEnq01_queueRoute_topicExch(self):650 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1)651 def test_txEnq10_route_topicExch(self):652 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=10, msg_count = 103)653 def test_txEnq10_queueRoute_topicExch(self):654 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)655 def test_txEnq01_txDeq01_route_topicExch(self):656 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", enq_txn_size=1, deq_txn_size=1)657 def test_txEnq01_txDeq01_queueRoute_topicExch(self):658 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)659class E_ShortPersistenceTests(QmfTestBase010):660 def test_route_durQueue_defaultExch(self):661 self._do_test(self._get_name(), queue_durable_flag=True)662 def test_route_durMsg_durQueue_defaultExch(self):663 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True)664 def test_queueRoute_durQueue_defaultExch(self):665 self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True)666 def test_queueRoute_durMsg_durQueue_defaultExch(self):667 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)668class E_LongPersistenceTests(QmfTestBase010):669 def test_route_durQueue_directExch(self):670 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True)671 def test_route_durMsg_durQueue_directExch(self):672 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True)673 def test_queueRoute_durQueue_directExch(self):674 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True)675 def test_queueRoute_durMsg_durQueue_directExch(self):676 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)677 def test_route_durQueue_fanoutExch(self):678 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True)679 def test_route_durMsg_durQueue_fanoutExch(self):680 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True)681 def test_queueRoute_durQueue_fanoutExch(self):682 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True)683 def test_queueRoute_durMsg_durQueue_fanoutExch(self):684 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)685 def test_route_durQueue_topicExch(self):686 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True)687 def test_route_durMsg_durQueue_topicExch(self):688 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True)689 def test_queueRoute_durQueue_topicExch(self):690 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True)691 def test_queueRoute_durMsg_durQueue_topicExch(self):692 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True)693class F_ShortPersistenceTransactionTests(QmfTestBase010):694 def test_txEnq01_route_durQueue_defaultExch(self):695 self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1)696 def test_txEnq01_route_durMsg_durQueue_defaultExch(self):697 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)698 def test_txEnq01_queueRoute_durQueue_defaultExch(self):699 self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)700 def test_txEnq01_queueRoute_durMsg_durQueue_defaultExch(self):701 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)702 def test_txEnq01_txDeq01_route_durQueue_defaultExch(self):703 self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)704 def test_txEnq01_txDeq01_route_durMsg_durQueue_defaultExch(self):705 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)706 def test_txEnq01_txDeq01_queueRoute_durQueue_defaultExch(self):707 self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)708 def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_defaultExch(self):709 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)710class F_LongPersistenceTransactionTests(QmfTestBase010):711 def test_txEnq10_route_durQueue_defaultExch(self):712 self._do_test(self._get_name(), queue_durable_flag=True, enq_txn_size=10, msg_count = 103)713 def test_txEnq10_route_durMsg_durQueue_defaultExch(self):714 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)715 def test_txEnq10_queueRoute_durQueue_defaultExch(self):716 self._do_test(self._get_name(), queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)717 def test_txEnq10_queueRoute_durMsg_durQueue_defaultExch(self):718 self._do_test(self._get_name(), msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)719 def test_txEnq01_route_durQueue_directExch(self):720 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1)721 def test_txEnq01_route_durMsg_durQueue_directExch(self):722 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)723 def test_txEnq01_queueRoute_durQueue_directExch(self):724 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)725 def test_txEnq01_queueRoute_durMsg_durQueue_directExch(self):726 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)727 def test_txEnq10_route_durQueue_directExch(self):728 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=10, msg_count = 103)729 def test_txEnq10_route_durMsg_durQueue_directExch(self):730 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)731 def test_txEnq10_queueRoute_durQueue_directExch(self):732 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)733 def test_txEnq10_queueRoute_durMsg_durQueue_directExch(self):734 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)735 def test_txEnq01_txDeq01_route_durQueue_directExch(self):736 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)737 def test_txEnq01_txDeq01_route_durMsg_durQueue_directExch(self):738 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)739 def test_txEnq01_txDeq01_queueRoute_durQueue_directExch(self):740 self._do_test(self._get_name(), exch_name="testDirectExchange", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)741 def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_directExch(self):742 self._do_test(self._get_name(), exch_name="testDirectExchange", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)743 def test_txEnq01_route_durQueue_fanoutExch(self):744 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1)745 def test_txEnq01_route_durMsg_durQueue_fanoutExch(self):746 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)747 def test_txEnq01_queueRoute_durQueue_fanoutExch(self):748 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)749 def test_txEnq01_queueRoute_durMsg_durQueue_fanoutExch(self):750 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)751 def test_txEnq10_route_durQueue_fanoutExch(self):752 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=10, msg_count = 103)753 def test_txEnq10_route_durMsg_durQueue_fanoutExch(self):754 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)755 def test_txEnq10_queueRoute_durQueue_fanoutExch(self):756 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)757 def test_txEnq10_queueRoute_durMsg_durQueue_fanoutExch(self):758 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)759 def test_txEnq01_txDeq01_route_durQueue_fanoutExch(self):760 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)761 def test_txEnq01_txDeq01_route_durMsg_durQueue_fanoutExch(self):762 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)763 def test_txEnq01_txDeq01_queueRoute_durQueue_fanoutExch(self):764 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)765 def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_fanoutExch(self):766 self._do_test(self._get_name(), exch_name="testFanoutExchange", exch_type="fanout", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)767 def test_txEnq01_route_durQueue_topicExch(self):768 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1)769 def test_txEnq01_route_durMsg_durQueue_topicExch(self):770 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1)771 def test_txEnq01_queueRoute_durQueue_topicExch(self):772 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)773 def test_txEnq01_queueRoute_durMsg_durQueue_topicExch(self):774 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1)775 def test_txEnq10_route_durQueue_topicExch(self):776 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=10, msg_count = 103)777 def test_txEnq10_route_durMsg_durQueue_topicExch(self):778 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=10, msg_count = 103)779 def test_txEnq10_queueRoute_durQueue_topicExch(self):780 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)781 def test_txEnq10_queueRoute_durMsg_durQueue_topicExch(self):782 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=10, msg_count = 103)783 def test_txEnq01_txDeq01_route_durQueue_topicExch(self):784 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)785 def test_txEnq01_txDeq01_route_durMsg_durQueue_topicExch(self):786 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", msg_durable_flag=True, queue_durable_flag=True, enq_txn_size=1, deq_txn_size=1)787 def test_txEnq01_txDeq01_queueRoute_durQueue_topicExch(self):788 self._do_test(self._get_name(), exch_name="testTopicExchange", exch_type="topic", topic_key=self._get_name()+".#", queue_durable_flag=True, queue_route_type_flag=True, enq_txn_size=1, deq_txn_size=1)789 def test_txEnq01_txDeq01_queueRoute_durMsg_durQueue_topicExch(self):...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...30 split_name = name.split("_")31 ds = split_name[0]32 if split_name[-1].startswith("again") or split_name[-1].endswith("AUC"):33 del split_name[-1]34 def _get_name(st, it):35 return next(s for s in it if s.upper() == st.upper())36 ###########37 # #38 # dataset #39 # #40 ###########41 if ds == "dr":42 ds = next(dataset for dataset in dr_spoc_datasets if line.startswith(dataset))43 for idx, word in enumerate(split_name, 2):44 prev_prev_word = split_name[idx - 2] if len(split_name) > idx - 2 else ""45 previous_word = split_name[idx - 1] if len(split_name) > idx - 1 else ""46 prev_prev_word_upper = prev_prev_word.upper()47 previous_word_upper = previous_word.upper()48 upper3 = (prev_prev_word + previous_word + word).upper()49 upper2 = (prev_prev_word + previous_word).upper()50 upper1 = (previous_word + word).upper()51 upper0 = word.upper()52 extra_loss = lambda: "".join(53 split_name[54 (55 split_name.index(transfer)56 if "transfer" in locals() and transfer in split_name57 else 058 )59 + 1 : -260 ]61 ).upper()62 ##########63 # #64 # epochs #65 # #66 ##########67 if prev_prev_word == "epochs":68 epochs = int(previous_word)69 ############70 # #71 # transfer #72 # #73 ############74 elif upper0 in valid_models_upper:75 transfer = word76 elif upper1 in valid_models_upper:77 transfer = _get_name(upper1, valid_models)78 elif upper2 in valid_models_upper:79 transfer = _get_name(upper2, valid_models)80 elif upper3 in valid_models_upper:81 transfer = _get_name(upper3, valid_models)82 elif previous_word_upper in valid_models_upper:83 transfer = _get_name(previous_word_upper, valid_models)84 elif prev_prev_word_upper in valid_models_upper:85 transfer = _get_name(prev_prev_word_upper, valid_models)86 ########87 # #88 # loss #89 # #90 ########91 elif upper0 in valid_losses_upper:92 loss = word93 elif upper1 in valid_losses_upper:94 loss = _get_name(upper1, valid_losses)95 elif upper2 in valid_losses_upper:96 loss = _get_name(upper2, valid_losses)97 elif upper3 in valid_losses_upper:98 loss = _get_name(upper3, valid_losses)99 elif previous_word_upper in valid_losses_upper:100 loss = _get_name(previous_word_upper, valid_losses)101 elif prev_prev_word_upper in valid_losses_upper:102 loss = _get_name(prev_prev_word_upper, valid_losses)103 elif extra_loss() in valid_losses_upper:104 loss = _get_name(extra_loss(), valid_losses)105 #############106 # #107 # optimizer #108 # #109 #############110 elif upper0 in valid_optimizers_upper:111 optimizer = _get_name(word, valid_optimizers)112 elif upper1 in valid_optimizers_upper:113 optimizer = _get_name(upper1, valid_optimizers)114 elif upper2 in valid_optimizers_upper:115 optimizer = _get_name(upper2, valid_optimizers)116 elif upper3 in valid_optimizers_upper:117 optimizer = _get_name(upper3, valid_optimizers)118 elif previous_word_upper in valid_optimizers_upper:119 optimizer = _get_name(previous_word_upper, valid_optimizers)120 elif prev_prev_word_upper in valid_optimizers_upper:121 optimizer = _get_name(prev_prev_word_upper, valid_optimizers)122 ####################123 # #124 # optimizer params #125 # #126 ####################127 elif previous_word in frozenset(("lr", "alpha")) and len(split_name) != idx:128 optimizer_params[previous_word] = float(split_name[idx])129 ########130 # #131 # base #132 # #133 ########134 elif upper0 in valid_bases_upper:135 base = word136 elif upper1 in valid_bases_upper:137 base = _get_name(upper1, valid_bases)138 elif previous_word_upper in valid_bases_upper:139 base = _get_name(previous_word_upper, valid_bases)140 ########141 # #142 # else #143 # #144 ########145 """146 else:147 print('------------------------------')148 print('prev_prev_word:'.ljust(14), prev_prev_word,149 '\nprevious_word:'.ljust(16), previous_word,150 '\nword:'.ljust(16), word,151 '\nsplit_name:'.ljust(16), split_name,152 '\nidx:'.ljust(16), idx,153 '\nlen(split_name):'.ljust(16), len(split_name),...

Full Screen

Full Screen

memory.py

Source:memory.py Github

copy

Full Screen

...12from migen.fhdl.specials import *13def memory_emit_verilog(name, memory, namespace, add_data_file):14 # Helpers.15 # --------16 def _get_name(e):17 if isinstance(e, Memory):18 return namespace.get_name(e)19 else:20 return verilog_printexpr(namespace, e)[0]21 # Parameters.22 # -----------23 r = ""24 adr_regs = {}25 data_regs = {}26 # Ports Transformations.27 # ----------------------28 # Set Port Mode to Read-First when several Ports with different Clocks.29 # FIXME: Verify behaviour with the different FPGA toolchains, try to avoid it.30 clocks = [port.clock for port in memory.ports]31 if clocks.count(clocks[0]) != len(clocks):32 for port in memory.ports:33 port.mode = READ_FIRST34 # Set Port Granularity when 0.35 for port in memory.ports:36 if port.we_granularity == 0:37 port.we_granularity = memory.width38 # Memory Description.39 # -------------------40 r += "//" + "-"*78 + "\n"41 r += f"// Memory {_get_name(memory)}: {memory.depth}-words x {memory.width}-bit\n"42 r += "//" + "-"*78 + "\n"43 for n, port in enumerate(memory.ports):44 r += f"// Port {n} | "45 if port.async_read:46 r += "Read: Async | "47 else:48 r += "Read: Sync | "49 if port.we is None:50 r += "Write: ---- | "51 else:52 r += "Write: Sync | "53 r += "Mode: "54 if port.mode == WRITE_FIRST:55 r += "Write-First | "56 elif port.mode == READ_FIRST:57 r += "Read-First | "58 elif port.mode == NO_CHANGE:59 r += "No-Change | "60 r += f"Write-Granularity: {port.we_granularity} "61 r += "\n"62 # Memory Logic Declaration/Initialization.63 # ----------------------------------------64 r += f"reg [{memory.width-1}:0] {_get_name(memory)}[0:{memory.depth-1}];\n"65 if memory.init is not None:66 content = ""67 formatter = f"{{:0{int(memory.width/4)}x}}\n"68 for d in memory.init:69 content += formatter.format(d)70 memory_filename = add_data_file(f"{name}_{_get_name(memory)}.init", content)71 r += "initial begin\n"72 r += f"\t$readmemh(\"{memory_filename}\", {_get_name(memory)});\n"73 r += "end\n"74 # Port Intermediate Signals.75 # --------------------------76 for n, port in enumerate(memory.ports):77 # No Intermediate Signal for Async Read.78 if port.async_read:79 continue80 # Create Address Register in Write-First mode.81 if port.mode in [WRITE_FIRST]:82 adr_regs[n] = Signal(name_override=f"{_get_name(memory)}_adr{n}")83 r += f"reg [{bits_for(memory.depth-1)-1}:0] {_get_name(adr_regs[n])};\n"84 # Create Data Register in Read-First/No Change mode.85 if port.mode in [READ_FIRST, NO_CHANGE]:86 data_regs[n] = Signal(name_override=f"{_get_name(memory)}_dat{n}")87 r += f"reg [{memory.width-1}:0] {_get_name(data_regs[n])};\n"88 # Ports Write/Read Logic.89 # -----------------------90 for n, port in enumerate(memory.ports):91 r += f"always @(posedge {_get_name(port.clock)}) begin\n"92 # Write Logic.93 if port.we is not None:94 # Split Write Logic.95 for i in range(memory.width//port.we_granularity):96 wbit = f"[{i}]" if memory.width != port.we_granularity else ""97 r += f"\tif ({_get_name(port.we)}{wbit})\n"98 lbit = i*port.we_granularity99 hbit = (i+1)*port.we_granularity-1100 dslc = f"[{hbit}:{lbit}]" if (memory.width != port.we_granularity) else ""101 r += f"\t\t{_get_name(memory)}[{_get_name(port.adr)}]{dslc} <= {_get_name(port.dat_w)}{dslc};\n"102 # Read Logic.103 if not port.async_read:104 # In Write-First mode, Read from Address Register.105 if port.mode in [WRITE_FIRST]:106 rd = f"\t{_get_name(adr_regs[n])} <= {_get_name(port.adr)};\n"107 # In Read-First/No Change mode:108 if port.mode in [READ_FIRST, NO_CHANGE]:109 rd = ""110 # Only Read in No-Change mode when no Write.111 if port.mode == NO_CHANGE:112 rd += f"\tif (!{_get_name(port.we)})\n\t"113 # Read-First/No-Change Read logic.114 rd += f"\t{_get_name(data_regs[n])} <= {_get_name(memory)}[{_get_name(port.adr)}];\n"115 # Add Read-Enable Logic.116 if port.re is None:117 r += rd118 else:119 r += f"\tif ({_get_name(port.re)})\n"120 r += "\t" + rd.replace("\n\t", "\n\t\t")121 r += "end\n"122 # Ports Read Mapping.123 # -------------------124 for n, port in enumerate(memory.ports):125 # Direct (Asynchronous) Read on Async-Read mode.126 if port.async_read:127 r += f"assign {_get_name(port.dat_r)} = {_get_name(memory)}[{_get_name(port.adr)}];\n"128 continue129 # Write-First mode: Do Read through Address Register.130 if port.mode in [WRITE_FIRST]:131 r += f"assign {_get_name(port.dat_r)} = {_get_name(memory)}[{_get_name(adr_regs[n])}];\n"132 # Read-First/No-Change mode: Data already Read on Data Register.133 if port.mode in [READ_FIRST, NO_CHANGE]:134 r += f"assign {_get_name(port.dat_r)} = {_get_name(data_regs[n])};\n"135 r += "\n\n"...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful