<s> import string <EOL> import random <EOL> import time <EOL> from threading import Event <EOL> import roslib ; roslib . load_manifest ( '<STR_LIT>' ) <EOL> import rospy <EOL> from std_msgs . msg import String <EOL> from Test . srv import StringEcho <EOL> SIZES = [ <NUM_LIT:3> , <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> class TestCenter ( object ) : <EOL> _TIMEOUT = <NUM_LIT:15> <EOL> def __init__ ( self ) : <EOL> self . _times = [ ] <EOL> self . _counter = <NUM_LIT:0> <EOL> self . _event = None <EOL> self . _pub = None <EOL> self . _str = None <EOL> self . _time = None <EOL> rospy . Subscriber ( '<STR_LIT>' , String , self . _resp ) <EOL> def _runService ( self ) : <EOL> try : <EOL> rospy . wait_for_service ( '<STR_LIT>' , timeout = <NUM_LIT:5> ) <EOL> except rospy . ROSException : <EOL> return [ - <NUM_LIT:1.0> ] * len ( SIZES ) <EOL> times = [ ] <EOL> serviceFunc = rospy . ServiceProxy ( '<STR_LIT>' , StringEcho ) <EOL> for size in SIZES : <EOL> if size > <NUM_LIT:10> : <EOL> sample = '<STR_LIT>' . join ( random . choice ( string . lowercase ) <EOL> for _ in xrange ( <NUM_LIT:10> ) ) <EOL> s = sample * int ( size / <NUM_LIT:10> ) + '<STR_LIT:A>' * ( size % <NUM_LIT:10> ) <EOL> else : <EOL> s = '<STR_LIT>' . join ( random . choice ( string . lowercase ) <EOL> for _ in xrange ( size ) ) <EOL> start = time . time ( ) <EOL> response = serviceFunc ( s ) <EOL> end = time . time ( ) <EOL> if response . data != s : <EOL> times . append ( - <NUM_LIT:1.0> ) <EOL> else : <EOL> times . append ( ( end - start ) * <NUM_LIT:1000> ) <EOL> return times <EOL> def _req ( self ) : <EOL> if self . _counter >= len ( SIZES ) : <EOL> self . _event . set ( ) <EOL> else : <EOL> if SIZES [ self . _counter ] > <NUM_LIT:10> : <EOL> sample = '<STR_LIT>' . join ( random . choice ( string . lowercase ) <EOL> for _ in xrange ( <NUM_LIT:10> ) ) <EOL> rep = int ( SIZES [ self . _counter ] / <NUM_LIT:10> ) <EOL> tail = '<STR_LIT:A>' * ( SIZES [ self . _counter ] % <NUM_LIT:10> ) <EOL> self . _str = sample * rep + tail <EOL> else : <EOL> self . _str = '<STR_LIT>' . join ( random . choice ( string . lowercase ) <EOL> for _ in xrange ( SIZES [ self . _counter ] ) ) <EOL> self . _time = time . time ( ) <EOL> self . _pub . publish ( self . _str ) <EOL> def _resp ( self , msg ) : <EOL> stop = time . time ( ) <EOL> if not self . _pub : <EOL> return <EOL> if len ( self . _str ) == len ( msg . data ) and self . _str [ : <NUM_LIT:10> ] == msg . data [ : <NUM_LIT:10> ] : <EOL> self . _times . append ( ( stop - self . _time ) * <NUM_LIT:1000> ) <EOL> self . _time = None <EOL> self . _counter += <NUM_LIT:1> <EOL> self . _req ( ) <EOL> def _runTopic ( self ) : <EOL> self . _counter = <NUM_LIT:0> <EOL> self . _times = [ ] <EOL> self . _event = Event ( ) <EOL> self . _pub = rospy . Publisher ( '<STR_LIT>' , String , latch = True ) <EOL> self . _req ( ) <EOL> if ( not self . _event . wait ( self . _TIMEOUT ) or <EOL> len ( self . _times ) != len ( SIZES ) ) : <EOL> times = [ - <NUM_LIT:1.0> ] * len ( SIZES ) <EOL> else : <EOL> times = self . _times <EOL> self . _pub = None <EOL> return times <EOL> def runTest ( self , test ) : <EOL> if test == '<STR_LIT>' : <EOL> times = self . _runService ( ) <EOL> elif test == '<STR_LIT>' : <EOL> times = self . _runTopic ( ) <EOL> else : <EOL> print ( '<STR_LIT>' . format ( test ) ) <EOL> times = [ - <NUM_LIT:1.0> ] <EOL> return times </s>
