def test_constructor(self): with self.assertRaises(TypeError): Profile() with self.assertRaises(TypeError): Profile('myid', 'myname', ProfileExecutor, float) with self.assertRaises(TypeError): Profile('myid', 'myname', float, ProfileExecutor) Profile('myid', 'myname', ProfileExecutor, ProfileExecutor)
def test_properties(self): d = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) self.assertEqual(d.id, 'myid') self.assertEqual(d.name, 'myname') self.assertEqual(d.send_executor_class, ProfileExecutorA) self.assertEqual(d.receive_executor_class, ProfileExecutorB) self.assertIsNotNone(d.supported_options) self.assertIsNotNone(d.supported_results) self.assertIsNone(d.description) d = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB, description='mydesc') self.assertEqual(d.description, 'mydesc')
def test_constructor(self): p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) dir = ExecutionDirection('s') with self.assertRaises(TypeError): ProfileExecution() with self.assertRaises(TypeError): ProfileExecution(p) with self.assertRaises(TypeError): ProfileExecution(p, dir) with self.assertRaises(TypeError): ProfileExecution(p, dir, Options(p.supported_options)) c = NullNSTSConnection() with self.assertRaises(TypeError): ProfileExecution(p, dir, Options(p.supported_options), float) with self.assertRaises(TypeError): ProfileExecution(p, dir, float, c) with self.assertRaises(TypeError): ProfileExecution(p, float, Options(p.supported_options), c) with self.assertRaises(TypeError): ProfileExecution(float, dir, Options(p.supported_options), c) ctx = ProfileExecution(p, dir, Options(p.supported_options), c)
def __cmd_dispatcher(self, connection): ''' Read messages from client and dispatch to different commands ''' while(True): msg = connection.wait_msg() if msg.type == "CHECKPROFILE": # Check a profile self.__serve_cmd_checkprofile( connection, msg.params["profile_id"]) elif msg.type == "INSTANTIATEPROFILE": # Run a profile profile = Profile.get_all_profiles()[msg.params['profile_id']] direction = ExecutionDirection(msg.params["direction"]) execution_id = msg.params['execution_id'] options = msg.params['options'] execution = ProfileExecution( profile, direction, options, connection, execution_id) self.__serve_cmd_run_profile(execution)
def test_options(self): p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) self.assertEqual(len(p.supported_options), 0) p.supported_options.add_option('myid', 'myhelp', float) self.assertEqual(p.supported_options['myid'].help, 'myhelp') # No need check as it is of type OptionsDescriptor self.assertIsInstance(p.supported_options, OptionsDescriptor)
def test_name(self): c = NullNSTSConnection() p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) dir = ExecutionDirection('s') opt = Options(p.supported_options) ctx = ProfileExecution(p, dir, opt, c) self.assertIsInstance(ctx.name, basestring) self.assertTrue(p.name in ctx.name)
def test_finished(self): c = NullNSTSConnection() p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) opt = Options(p.supported_options) ctx = ProfileExecution(p, ExecutionDirection('s'), opt, c) time.sleep(0.8) ctx.mark_finished() passed = ctx.execution_time() self.assertTrue(abs(passed.raw_value - 0.8) < 0.1)
def test_properties(self): c = NullNSTSConnection() p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) dir = ExecutionDirection('s') opt = Options(p.supported_options) ctx = ProfileExecution(p, dir, opt, c) self.assertEqual(ctx.profile, p) self.assertEqual(ctx.connection, c) self.assertEqual(ctx.direction, dir) self.assertEqual(ctx.options, opt)
def test_executor(self): c = NullNSTSConnection() p = Profile('myid', 'myname', ProfileExecutorA, ProfileExecutorB) opt = Options(p.supported_options) ctx = ProfileExecution(p, ExecutionDirection('s'), opt, c) x = ctx.executor self.assertIsInstance(x, ProfileExecutorA) self.assertEqual(x.profile, p) ctx = ProfileExecution(p, ExecutionDirection('r'), opt, c) x = ctx.executor self.assertIsInstance(x, ProfileExecutorB) self.assertEqual(x.profile, p)
def __serve_cmd_checkprofile(self, connection, test_id): ''' Serve client command of checking profile status ''' installed = test_id in Profile.get_all_profiles() supported = False if installed: supported = True connection.send_msg( "PROFILEINFO", { "profile_id": test_id, "installed": installed, "supported": supported, "error": "unknown" })
def test_msg(self): p = Profile('profid', 'profname', ProfileExecutorA, ProfileExecutorB) c = NullNSTSConnection() ctxa = ProfileExecution(p, ExecutionDirection('s'), Options(p.supported_options), c) a = ctxa.executor ctxb = ProfileExecution(p, ExecutionDirection('r'), Options(p.supported_options), c) b = ctxb.executor a.send_msg('LALA') msg = b.wait_msg_type('LALA') self.assertEqual(msg.type, '__profid_LALA') self.assertEqual(msg.params, {}) a.send_msg('LALA2') with self.assertRaises(ProtocolError): msg = b.wait_msg_type('LALA')
def load_file(suite_filename): ''' Parse a suite filename and return the SpeedTestSuite object ''' suite = SpeedTestSuite() config = ConfigParser.ConfigParser() config.read(suite_filename) # Read global options if 'global' in config.sections(): for opt in config.options('global'): suite.options[opt] = config.get('global', opt) config.remove_section('global') for test_id in config.sections(): if 'profile' not in config.options(test_id): raise ParseError("'profile' entry is mandatory for every test") if 'direction' in config.options(test_id): direction = [ExecutionDirection(config.get(test_id, 'direction'))] config.remove_option(test_id, 'direction') else: direction = [ExecutionDirection('s'), ExecutionDirection('r')] prof_id = config.get(test_id, 'profile') profile = Profile.get_all_profiles()[prof_id] config.remove_option(test_id, 'profile') # Load options only for profiles profile_options = {} for opt in config.options(test_id): if opt[:len(prof_id)] == prof_id: profile_options[opt[len(prof_id) + 1:]] \ = config.get(test_id, opt) config.remove_option(test_id, opt) # The rest are for test itself for direct in direction: test = SpeedTest(profile, direct, profile_options) for opt in config.options(test_id): test.options[opt] = config.get(test_id, opt) suite.add_test(test) return suite
def __cmd_dispatcher(self, connection): ''' Read messages from client and dispatch to different commands ''' while (True): msg = connection.wait_msg() if msg.type == "CHECKPROFILE": # Check a profile self.__serve_cmd_checkprofile(connection, msg.params["profile_id"]) elif msg.type == "INSTANTIATEPROFILE": # Run a profile profile = Profile.get_all_profiles()[msg.params['profile_id']] direction = ExecutionDirection(msg.params["direction"]) execution_id = msg.params['execution_id'] options = msg.params['options'] execution = ProfileExecution(profile, direction, options, connection, execution_id) self.__serve_cmd_run_profile(execution)
def parse_command_line(tests): ''' Parse SpeedTestSuite from brief command line ''' suite = SpeedTestSuite() parsed_profiles = [] for test in tests.split(","): if "-" not in test: parsed_profiles.append([test, ExecutionDirection("send")]) parsed_profiles.append([test, ExecutionDirection("receive")]) else: parts = test.split("-") profile_id = parts[0] direction = ExecutionDirection(parts[1]) parsed_profiles.append([profile_id, direction]) for p in parsed_profiles: profile = Profile.get_all_profiles()[p[0]] suite.add_test(SpeedTest(profile, p[1])) return suite
def test_propage_results(self): p = Profile('profid', 'profname', ProfileExecutorA, ProfileExecutorB) p.add_result('testdt', 'name', units.Time) p.add_result('testbit', 'name', units.BitRate) c = NullNSTSConnection() ctxa = ProfileExecution(p, ExecutionDirection('s'), Options(p.supported_options), c) a = ctxa.executor ctxb = ProfileExecution(p, ExecutionDirection('r'), Options(p.supported_options), c) b = ctxb.executor a.store_result('testdt', '10 sec') a.store_result('testbit', '32 bps') a.propagate_results() b.collect_results() self.assertEqual(b.results['testdt'], units.Time('10 sec')) self.assertEqual(b.results['testbit'], units.BitRate('32 bps'))
def dummy_ctx(self): p = Profile('profid', 'profame', ProfileExecutor, ProfileExecutor) c = NullNSTSConnection() ctx = ProfileExecution(p, ExecutionDirection('s'), Options(p.supported_options), c) return ctx
"-t", str(self.context.options['time'].raw_value), "-b", str(self.context.options['rate'].raw_value)]) def parse_and_store_output(self): output = self.get_subprocess_output().split("\n") received = output[1].split(',') self.store_result('transfer_rate', units.BitRate(received[8])) self.store_result('jitter', units.Time(received[9] + "ms")) self.store_result('lost_packets', units.Packet(received[10])) self.store_result('total_packets', units.Packet(received[11])) self.store_result('percentage_lost', units.Percentage(received[12])) # TCP Profile p = Profile( "iperf_tcp", "TCP (iperf)", IperfExecutorSender, IperfExecutorReceiver, 'Wrapper for "iperf" benchmark tool, to measure raw TCP throughput.') p.add_result("transfer_rate", "Transfer Rate", units.BitRate) p.supported_options.add_option( 'time', 'time to transmit for', units.Time, default=10) # Jitter profile p = Profile( "iperf_jitter", "Jitter (iperf)", IperfJitterExecutorSender, IperfExecutorReceiver, description='Wrapper for "iperf" benchmark tool, to ' + 'measure latency jittering on UDP transmissions') p.add_result("transfer_rate", "Trans. Rate", units.BitRate) p.add_result("jitter", "Jitter", units.Time) p.add_result("lost_packets", "Lost Pck", units.Packet) p.add_result("total_packets", "Total Pck", units.Packet)
]) def parse_and_store_output(self): output = self.get_subprocess_output().split("\n") received = output[1].split(',') self.store_result('transfer_rate', units.BitRate(received[8])) self.store_result('jitter', units.Time(received[9] + "ms")) self.store_result('lost_packets', units.Packet(received[10])) self.store_result('total_packets', units.Packet(received[11])) self.store_result('percentage_lost', units.Percentage(received[12])) # TCP Profile p = Profile( "iperf_tcp", "TCP (iperf)", IperfExecutorSender, IperfExecutorReceiver, 'Wrapper for "iperf" benchmark tool, to measure raw TCP throughput.') p.add_result("transfer_rate", "Transfer Rate", units.BitRate) p.supported_options.add_option('time', 'time to transmit for', units.Time, default=10) # Jitter profile p = Profile("iperf_jitter", "Jitter (iperf)", IperfJitterExecutorSender, IperfExecutorReceiver, description='Wrapper for "iperf" benchmark tool, to ' + 'measure latency jittering on UDP transmissions') p.add_result("transfer_rate", "Trans. Rate", units.BitRate)
if self.context.connection.is_ipv6(): host = "[{0}]".format(self.context.connection.remote_addr) else: host = self.context.connection.remote_addr self.url_base = "http://{remote}:{port}/".format( remote=host, port=self.context.options['port']) def is_supported(self): return SubProcessExecutorBase.is_supported(self) def cleanup(self): SubProcessExecutorBase.cleanup(self) p = Profile( "apache", "HTTP (apache)", ApacheExecutorServer, WgetExecutorClient, "Measure the performance of HTTP, by setting up a " "sandboxed apache server and download arbitrary binary files.") p.add_result("transfer_rate", "TransferRate", units.ByteRate) p.supported_options.add_option("port", "Apache listen port", unit_type=int, default=58338) p.supported_options.add_option('mode', '"size" to download a specific filesize,' ' "time" to download for a specified period', unit_type=str, default='size') p.supported_options.add_option("filesize", "The size of file to download (size mode), " "or the initial filesize to try.(time mode)", unit_type=units.Byte,
self.logger.debug("ping stopped running.") # Parse output self.parse_and_store_output() self.propagate_results() class PingExecutorReceiver(ProfileExecutor): def __init__(self, owner): super(PingExecutorReceiver, self).__init__(owner) def run(self): self.collect_results() def prepare(self): return True def is_supported(self): return True def cleanup(self): return True p = Profile( "ping", "Ping", PingExecutorSender, PingExecutorReceiver, description='A wrapper for "ping" system tool to" +\ " measure round trip latency') p.add_result("rtt", "RTT", units.Time)