def _run_game(self, dst_cls, src_cls): sandbox = ThreadedSandbox([[dst_cls, src_cls]]) game = Game(self.testbed, sandbox, packet_limit=self.PACKET_LIMIT, time_limit=self.TIME_LIMIT) ctl = GameController() return ctl.run(game)[0]
def run(args): logging.basicConfig(level=logging.DEBUG) logging.getLogger('jsonrpc2_zeromq').setLevel(logging.WARNING) testbed = get_testbed(args.testbed, args.testbed_options) sandbox = SubprocessSandbox(args.player_paths) packet_limit = args.packet_limit if args.packet_limit > 0 else None time_limit = args.time_limit if args.time_limit > 0 else None game = Game(testbed, sandbox, packet_limit=packet_limit, time_limit=time_limit) ctl = GameController() log.info("Running game...") results = ctl.run(game) log.info("Done.") game_time = game.end_time - game.start_time print "Results:" for i, result in enumerate(results): if result.src_transmit_packets > 0: packet_loss = 100. * ( result.src_transmit_packets - result.dst_received_packets) / result.src_transmit_packets packet_loss_str = "(%.0f%% packet loss)" % (packet_loss, ) else: packet_loss_str = "" print "Player %d:" % (i + 1, ) print " crashed : %s" % (result.crashed, ) print " transmitted packets : %d" % (result.src_transmit_packets, ) print " received packets : %d" % ( result.dst_received_packets, ), packet_loss_str print " transferred payload : %d bytes (avg %.1f bytes/s)" % ( result.payload_bytes, result.payload_bytes / game_time) print if result.crashed: print " Crash reports:" for desc in result.crash_report: print desc print print "Game time: %.1f seconds" % (game_time, ) if args.log_path: pickle.dump(game.log, open(args.log_path, "wb"))
def _run_game(self, dst_cls, src_cls, packet_limit=PACKET_LIMIT, payload_limit=PAYLOAD_LIMIT, time_limit=TIME_LIMIT): sandbox = ThreadedSandbox([[dst_cls, src_cls]]) game = Game(self.testbed, sandbox, packet_limit=packet_limit, time_limit=time_limit, payload_limit=payload_limit) ctl = GameController() return ctl.run(game)[0]