def run_test(): accept_stoppable = Waldo.tcp_accept(Modifier, MODIFIER_HOST, MODIFIER_PORT, connected_callback=modifier_connected) data_reader = Waldo.tcp_connect(DataReader, MODIFIER_HOST, MODIFIER_PORT) modifier = modifier_wait_queue.get() # check peered value is initialized properly if modifier.read_peered_num() != 22: print "\nErr: incorrect modifier initial val of peered num" return False if data_reader.read_peered_num() != 22: print "\nErr: incorrect data reader initial val of peered num" return False # check modifier can increment if modifier.increment_peered_num() != 23: print "\nErr: incorrect modifier return from peered num increment" return False # check modifier sees increment if modifier.read_peered_num() != 23: print "\nErr: incorrect modifier return from peered num read" return False # check data reader sees increment if data_reader.read_peered_num() != 23: print "\nErr: incorrect data reader return from peered num read" return False accept_stoppable.stop() return True
def run_chatter_a(): # runs in accept mode name = raw_input('Input name: ') #print name Waldo.tcp_accept( ChatterA, HOSTNAME, PORT, display_msg, name, connected_callback = listen_for_other_side) while True: pass
def run_test(): single_side = Waldo.no_partner_create(SingleSide, min_func, max_func, mod_func) # to mod between mod_tuples_list = [(6, 2), (5, 3), (100, 3), (38, 7)] for mod_tuple in mod_tuples_list: if single_side.test_mod(*mod_tuple) != mod_func(None, *mod_tuple): print "\nErr with mod call" return False # to max max_min_list_list = [list(range(205, 150, -1)), [-1, 52, 1, 0], [73, 13.25, 100, 239]] for max_min_list in max_min_list_list: if single_side.test_max(max_min_list) != max_func(None, max_min_list): print "\nErr with max call" return False # to min for max_min_list in max_min_list_list: if single_side.test_min(max_min_list) != min_func(None, max_min_list): print "\nErr with min call" return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) num_to_assign = 30 single_side.assign_num_to_number_struct(num_to_assign) if single_side.read_num_from_number_struct() != num_to_assign: print '\nErr: could not write user struct number' return False # tests nesting user structs outer_nested_num = 52 inner_nested_num = 31 single_side.assign_num_to_nested_struct( outer_nested_num,inner_nested_num) if single_side.get_outer_and_inner_nested_nums() != (outer_nested_num,inner_nested_num): print '\nErr with nested user structs' return False # tests passing struct through argument to method new_num = 1 if single_side.get_endpoint_nested_struct_num(new_num) != new_num: print '\nError passing structs through as method args' return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) if not test_ext_num(single_side): return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) if not test_maps(single_side): return False if not test_lists(single_side): return False return True
def run_test(): # for single side tests, these values do not really matter. host_uuid = 10 single_side = Waldo.no_partner_create( SingleSide, text_identity,text_len,list_sum,no_return, sum_three_args,return_three_args) test_strings_list = ['hello','wow','my','good','this is it'] # test identity text call for string in test_strings_list: if not single_side.execute_identity_endpoint_func (string): print '\nErr in identity func call' return False # test len text call for string in test_strings_list: if not single_side.execute_len_endpoint_func (string): print '\nErr in len func call' return False test_nums_list = [ list(range(0,13)), list(range(50,500,2)), [1.2,3.9,-1.3]] # test sum list call for num_list in test_nums_list: if not single_side.execute_sum_list_endpoint_func (num_list): print '\nErr in sum list func call' return False # execute no return single_side.execute_no_return_endpoint_func() # test multiple arguments mult_args_array = [ (1,3,5), (38,10,1000), (-1.4,-50,10) ] for arg_tuple in mult_args_array: if not single_side.execute_sum_three_args_endpoint_func(*arg_tuple): print '\nErr: with multiple arguments to functions' return False # test multiple return arguments for arg_tuple in mult_args_array: if single_side.execute_return_three_args_endpoint_func(*arg_tuple) != arg_tuple: print '\nErr could not return tuple' return False return True
def run_test(): modifier,data_reader = Waldo.same_host_create(Modifier).same_host_create(DataReader) # check peered value is initialized properly if modifier.read_peered_num() != 22: print '\nErr: incorrect modifier initial val of peered num' return False if data_reader.read_peered_num() != 22: print '\nErr: incorrect data reader initial val of peered num' return False # check modifier can increment if modifier.increment_peered_num() != 23: print '\nErr: incorrect modifier return from peered num increment' return False # check modifier sees increment if modifier.read_peered_num() != 23: print '\nErr: incorrect modifier return from peered num read' return False # check data reader sees increment if data_reader.read_peered_num() != 23: print '\nErr: incorrect data reader return from peered num read' return False # check modifier can increment if modifier.increment_peered_num() != 24: print '\nErr: incorrect second modifier return from peered num increment' return False if modifier.increment_peered_num() != 25: print '\nErr: incorrect second modifier return from peered num increment' return False # check work on peered map to_add_list = [ ('r',{ 'a': True, 'b': False}), ('dl',{ 'a': False, 'b': False}), ('m',{ 'a': False, 'b': True}), ('dl',{ 'a': True, 'b': False})] first_time = True for index,inner_map_to_add in to_add_list: modifier.add_inner_map(index,inner_map_to_add) if data_reader.read_inner_map(index) != inner_map_to_add: print '\nErr: problem with updating peered nested map' return False return True
def run(): # listen on <INCREMENTER_HOST:INCREMENTER_PORT> for TCP # connections. For each new connection, create an Incrementer. # Non-blocking. Waldo.tcp_accept( Incrementer, INCREMENTER_HOST, INCREMENTER_PORT, # the argument to Incrementer's onCreate 55, # a callback that executes whenever a new incrementer is # created connected_callback=incrementer_connected ) # connect to <INCREMENTER_HOST:INCREMENTER_PORT> and create a # requester object. Blocks until connection is created. requester = Waldo.tcp_connect( Requester,INCREMENTER_HOST,INCREMENTER_PORT) num_incremented = requester.increment(5) print '\nFinal value of number: %s\n' % str(num_incremented)
def run(): # listen on <INCREMENTER_HOST:INCREMENTER_PORT> for TCP # connections. For each new connection, create an Incrementer. # Non-blocking. Waldo.tcp_accept( Incrementer, INCREMENTER_HOST, INCREMENTER_PORT, # the argument to Incrementer's onCreate 55, # a callback that executes whenever a new incrementer is # created connected_callback=incrementer_connected) # connect to <INCREMENTER_HOST:INCREMENTER_PORT> and create a # requester object. Blocks until connection is created. requester = Waldo.tcp_connect(Requester, INCREMENTER_HOST, INCREMENTER_PORT) num_incremented = requester.increment(5) print '\nFinal value of number: %s\n' % str(num_incremented)
def run_test(): original_sidea_num = 13 original_sideb_num = 135.1 accept_stoppable = Waldo.tcp_accept( SideA, SIDEA_HOST, SIDEA_PORT,original_sidea_num, connected_callback=sidea_connected) sideb = Waldo.tcp_connect( SideB,SIDEA_HOST,SIDEA_PORT,original_sideb_num) sidea = sidea_wait_queue.get() # check if each initialized correctly if sidea.get_other_val() != original_sideb_num: print '\nErr: symmetric did not initialize correctly' return False if sideb.get_other_val() != original_sidea_num: print '\nErr: symmetric did not initialize correctly' return False sidea_num = 39 sideb_num = 41 # write endpoint number to each side sidea.set_other_val(sideb_num) sideb.set_other_val(sidea_num) if sidea.get_other_val() != sideb_num: print '\nErr: symmetric did not set other side correctly' return False if sideb.get_other_val() != sidea_num: print '\nErr: symmetric did not set other side correctly' return False accept_stoppable.stop() return True
def run_test(): sideA, sideB = ( Waldo.same_host_create(SideA).same_host_create(SideB)) sideX, sideY=( Waldo.same_host_create(SideA).same_host_create(SideB)) in_val = 320 if sideA.get_struct_from_other_side(sideX,in_val) != in_val: print '\nErr: getting struct from endpoint call' return False if sideA.get_partner_struct(in_val) != in_val: print '\nErr: getting struct from partner' return False # test changes to input struct across sequences inc1 = 39 inc2 = 5 if sideA.input_struct_sequence(inc1,inc2) != (inc1 + inc2): print '\nErr: input struct sequence did not increment correctly' return False # test that can insert a struct into a map and access its fields # from within map expected_num = 390 if sideA.test_struct_map('hello',expected_num) != expected_num: print '\nErr: structs in maps is broken' return False # test that can serialize maps of structs sideA.test_sequence_struct_map() return True
def run_test(): sideA, sideB = ( Waldo.same_host_create( SideA,print_debug).same_host_create(SideB,print_debug)) texta, textb = ('a','b') received_texta, received_textb = sideA.test_two_sequences(texta,textb) if (received_texta != texta) or (received_textb != textb): err_msg = '\nError: did not get correct values back when ' err_msg += 'initiating a 2-sequence test' print err_msg return False return True
def run_test(): math_endpoint = Waldo.math_endpoint_lib() single_side = Waldo.no_partner_create(SingleSide, math_endpoint) # to mod between mod_tuples_list = [ (6,2), (5,3), (100,3), (38, 7)] for mod_tuple in mod_tuples_list: lhs = mod_tuple[0] rhs = mod_tuple[1] if single_side.test_mod(lhs,rhs) != (lhs % rhs): print '\nErr with mod call' return False # to max max_min_list_list = [ list(range(205,150, -1)), [-1, 52,1,0], [73, 13.25,100,239]] for max_min_list in max_min_list_list: if single_side.test_max(max_min_list) != max(max_min_list): print '\nErr with max call' return False # to min for max_min_list in max_min_list_list: if single_side.test_min(max_min_list) != min(max_min_list): print '\nErr with min call' return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) if not test_range(single_side): return False if not test_while(single_side): return False if not test_for(single_side): return False if not test_break_continue(single_side): return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) if not test_to_text(single_side): return False if not test_misc_list(single_side): return False if not test_nested_map(single_side): return False if not test_user_struct_returns(single_side): return False return True
def run_test(): a_num = 3902 a_index = 133 b_num = 302 b_index = 33 side_a, side_b = ( Waldo.same_host_create(SideA,a_num,a_index).same_host_create(SideB,b_num)) list_of_endpoints, map_of_endpoints = side_a.get_self_holders() # load sideb into external list and map side_b.append_self_to_list(list_of_endpoints) side_b.append_self_to_map(b_index,map_of_endpoints) # make endpoint calls on all endpoints in the list (ie, sideA and # sideB) and test that their values are what should be expected # for sidea's and sideb's internal numbers endpoint_num_list = side_a.get_numbers_from_list() if len(endpoint_num_list) != 2: print '\nErr: incorrect number of numbers returned in endpoint list' return False if (endpoint_num_list[0] != a_num) or (endpoint_num_list[1] != b_num): print '\nErr: incorrect numbers returned in endpoint list' return False # make endpoint calls on all endpoints in the list (ie, sideA and # sideB) and test that their values are what should be expected # for sidea's and sideb's internal numbers endpoint_num_map = side_a.get_numbers_from_map() if len(endpoint_num_map) != 2: print '\nErr: incorrect number of numbers returned in endpoint map' return False if (a_index not in endpoint_num_map) or (b_index not in endpoint_num_map): print '\nErr: missing indices in endpoint number map' return False if (endpoint_num_map[a_index] != a_num) or (endpoint_num_map[b_index] != b_num): print '\nErr: incorrect values returned in endpoint map' return False return True
def run_test(): # for single side tests, these values do not really matter. single_side = Waldo.no_partner_create(SingleSide) if not test_comparisons(single_side): return False if not test_math(single_side): return False if not test_other_plusses(single_side): return False if not test_in(single_side): return False return True
def run_test(): # for single side tests, these values do not really matter. host_uuid = 10 wlist = Waldo._waldo_classes['WaldoListVariable']('some list',host_uuid) single_side = Waldo.no_partner_create(SingleSide, wlist) internal_list = wlist.get_val(None) raw_internal_list = internal_list.val if len(raw_internal_list) != 1: print '\nErr: did not append self to list' return False if raw_internal_list[0] != single_side: print '\nErr: incorrect endpoint value appended to list' return False return True
def run_test(): new_peered_num = 30 new_end_text = "hoi" sideA, sideB = Waldo.same_host_create(SideA, new_peered_num).same_host_create(SideB, new_end_text) if sideB.read_peered_num() != new_peered_num: print "\nErr: B has incorrect peered number" return False if sideA.read_peered_num() != new_peered_num: print "\nErr: A has incorrect peered number" return False if sideA.read_b_text() != new_end_text: print "\nErr: A read incorrect text from B" return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) expected_txt = 'a' expected_num = 30 expected_tf = False expected_list = [2,4,6] expected_map = { True: 100, False: 93 } expected_other_num = 30 expected_other_list = [2,4,6] if (single_side.return_local_vars() != (expected_txt, expected_num, expected_tf, expected_list, expected_map, expected_other_num, expected_other_list)): print '\nErr getting locally initialized' return False if (single_side.return_global_vars() != (expected_txt, expected_num, expected_tf, expected_list, expected_map, expected_other_num, expected_other_list)): print '\nErr getting globally initialized' return False return True
def run_test(): sideA, sideB = Waldo.same_host_create(SideA).same_host_create(SideB) # assign endpoint into a sideA.assign_endpoint(sideB) # check to ensure that one side can make an endpoint call to the # other side and receive a result. base_num = 20 increment_num = 30 if sideA.test_assigned_number(base_num,increment_num) != (base_num+increment_num): print '\nErr: with basic endpoint call' return False if sideA.check_value_type_argument(base_num,increment_num) != (base_num,base_num+increment_num): print '\nErr: incorrectly modified value type data' return False # Test to ensure that passing an external variable through an # endpoint call can change its value. original_num = 32 ext_num = Waldo._waldo_classes['WaldoExtNumVariable']( 'garbage',sideA._host_uuid,False,original_num) sideA.assign_external_number(ext_num) new_num = 50 if sideA.test_updated_val(new_num) != new_num: print '\nErr: external should have global change' return False # test that lists and maps are copied across endpoint calls original_list = ['eiof','ff','efeio'] if sideA.hide_list(original_list) != len(original_list): print '\nErr: list passed by reference across endpoint call' return False return True
def run_test(): # for single side tests, these values do not really matter. internal_num = 35 index_num = 31 single_side = Waldo.no_partner_create( SingleSide,internal_num,index_num) if single_side.get_external_vals(index_num) != (internal_num,internal_num): print '\nErr: got an incorrect external val' return False internal_num = 22 single_side.change_external_num(internal_num) if single_side.get_external_vals(index_num) != (internal_num,internal_num): print '\nErr: got an incorrect external val after changing' return False return True
def run_test(): # for single side tests, these values do not really matter. init_num = 50 init_text = 'hello' init_list = [ [True,False], [False]] init_map = { 2: 'wow', 6: 'this'} host_uuid = 10 single_side = Waldo.no_partner_create( SingleSide, init_num,init_text,init_list,init_map) if (single_side.get_endpoint_values() != (init_num,init_text,init_list,init_map)): print '\nErr when initializing' return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) if single_side.get_num() != 0: print '\nGot incorrect initial value for number' return False if single_side.get_txt() != '': print '\nGot incorrect initial value for text' return False for counter in range(0,100): if single_side.increment_num() != counter + 1: print '\nGot incorrect number when incrementing' return False # just want to append a single a each time. Note: probably # more efficient to just keep track of a shadow text val # myself and append an 'a' to it each time. But I wanted to # play with reduce a bit. expected_str = reduce( lambda x,y: x + y, (['a']*(counter+1)), '') if single_side.increment_txt('a') != expected_str: print '\nGot incorrect string back' return False internal_list = single_side.increment_list(counter) expected_internal_list = list(range(0,counter+1)) if internal_list != expected_internal_list: print '\nNot appending to internal list correctly' return False return True
def run_test(): single_side = Waldo.no_partner_create(SingleSide) if (1,2,3) != single_side.return_static_nums(): print '\nErr getting static numbers' return False if (1,2,3) != single_side.return_func_call_nums(): print '\nErr getting func call numbers' return False if ('a','b') != single_side.return_variable_texts(): print '\nErr getting variable texts' return False if ('a','b') != single_side.return_func_call_variable_texts(): print '\nErr getting func call variable texts' return False if ('a','b','c') != single_side.return_extended_texts(): print '\nErr getting extended texts' return False for i in range(1,15): if (i,i) != single_side.return_tuple_endpoint_global(): print '\nErr: incorrect tuple value of mutated state' return False for j in range(i+1,i+15): if (j,j,0) != single_side.wrapped_tuple(): print '\nErr: incorrect tuple value of wrapped mutated state' return False return True
def run_test(): sideA, sideB = ( Waldo.same_host_create(SideA,num_func).same_host_create(SideB,num_func)) for i in range(0,20): sideA.run_signal(i) sideA.service_signal() time.sleep(.1) sideB.service_signal() time.sleep(.1) try: for j in range(0,2): read_num = num_queue.get_nowait() if (read_num != i) and (read_num != (i+1)): print '\nUnexpected num read from queue\n' return False except Queue.Empty: print '\nNever received signal to execute\n' return False return True
def run(test_filename, init_val): waldo_file = WaldoFS.WaldoExtFileVariable(test_filename, init_val) single = Waldo.no_partner_create(Single, waldo_file) time.sleep(10) single.write_into_file('ooo bla') time.sleep(10)
def run(test_filename,init_val): waldo_file = WaldoFS.WaldoExtFileVariable(test_filename,init_val) single = Waldo.no_partner_create(Single,waldo_file) time.sleep(10) single.write_into_file('ooo bla') time.sleep(10)
import sys sys.path.append("C:/Users/perceptual/Waldo") from lib import Waldo from emitted import Ping import time import subprocess ping = Waldo.tcp_connect(Ping, 'localhost', 6767) ping.changeText("ping: "+subprocess.check_output("pwd")) print (str(ping.ping_seq('')))
import sys sys.path.append("C:/Users/perceptual/Waldo") from lib import Waldo from emitted import Pong import time import subprocess def pong_connected(endpoint): print '\nPong endpoint is connected!\n' endpoint.changeText("pong: " + subprocess.check_output("pwd")) Waldo.tcp_accept( Pong, 'localhost',6767, connected_callback=pong_connected) for i in range(1,10): print i time.sleep(1)
def run_test(): single_side = Waldo.no_partner_create(SingleSide) # basic if test if single_side.test_if(True,1,2) != 1: print '\nErr: error of conditional of if 1' return False if single_side.test_if(False,1,2) != 2: print '\nErr: error of conditional of if 2' return False # basic if, else, elseIf tests if single_side.test_else_if( True,1, True,-1, True,-1, True,-1, True,-1, True,-1, True,-1, -1,-1) != 1: print '\nErr of if condition of test else if' return False if single_side.test_else_if( False,-1, True,1, True,-1, True,-1, True,-1, True,-1, True,-1, -1,-1) != 1: print '\nErr of elseIf1 condition of test else if' return False if single_side.test_else_if( False,-1, False,-1, True,1, True,-1, True,-1, True,-1, True,-1, -1,-1) != 1: print '\nErr of elseIf2 condition of test else if' return False if single_side.test_else_if( False,-1, False,-1, False,-1, True,1, True,-1, True,-1, True,-1, -1,-1) != 1: print '\nErr of elseIf3 condition of test else if' return False if single_side.test_else_if( False,-1, False,-1, False,-1, False,-1, True,1, True,-1, True,-1, -1,-1) != 1: print '\nErr of elseIf4 condition of test else if' return False if single_side.test_else_if( False,-1, False,-1, False,-1, False,-1, False,-1, True,1, True,-1, -1,-1) != 1: print '\nErr of elseIf5 condition of test else if' return False if single_side.test_else_if( False,-1, False,-1, False,-1, False,-1, False,-1, False,-1, True,1, -1,-1) != 1: print '\nErr of elseIf6 condition of test else if' return False if single_side.test_else_if( False,-1, False,-1, False,-1, False,-1, False,-1, False,-1, False,-1, 1,-1) != 1: print '\nErr of elseIf7 condition of test else if' return False # test if else if single_side.test_if_else(True,1,-1,-1) != 1: print '\nErr of ifElse 1' return False if single_side.test_if_else(False,-1,1,-1) != 1: print '\nErr of ifElse 2' return False # test boolean logic # Public Function test_boolean_logic( # TrueFalse a_or1, TrueFalse a_or2,TrueFalse b_and1, # TrueFalse b_and2, Number return_if, Number return_else) returns Number # { # if ((a_or1 or a_or2) and (b_and1 and b_and2)) # { # return return_if; # } # return return_else; # } if single_side.test_boolean_logic( False, False, True, True, -1, 1) != 1: print '\nErr on test_boolean_logic1' return False if single_side.test_boolean_logic( False, True, True, True, 1, -1) != 1: print '\nErr on test_boolean_logic2' return False if single_side.test_boolean_logic( True, True, True, False, -1, 1) != 1: print '\nErr on test_boolean_logic3' return False # Test many statements if_else_if_else if single_side.many_statements_in_if_else_if_else( True,True,1,-1,-1,-1) != 21: print '\n\n' print single_side.many_statements_in_if_else_if_else( True,True,1,-1,-1,-1) print '\n\n' print '\nErr on many if 1' return False if single_side.many_statements_in_if_else_if_else( False,True,-1,1,-1,-1) != 21: print '\nErr on many if 2' return False if single_side.many_statements_in_if_else_if_else( False,False,-1,-1,1,-1) != 21: print '\nErr on many if 3' return False # Test empty bodies single_side.test_empty_if_body() single_side.test_empty_else_if_body() single_side.test_empty_else_body() return True