args= ['py','-u','ChatServer.py','6001']
server_errors= open( 'server-errors.txt', 'w' )
server= subprocess.Popen( args, stderr= server_errors )

time.sleep( 1 ) 

shell_command= 'py input-writer.py 0 2 client1-msg.txt | py -u ChatClient.py 6001 >client1-recvd.txt 2>client1-errors.txt &'
os.system( shell_command )

shell_command= 'py input-writer.py 1 2 client2-msg.txt | py -u ChatClient.py 6001 >client2-recvd.txt 2>client2-errors.txt'
os.system( shell_command )

print( 'execution completed; grading...' )

found= withinFile.searchText( 'client1-recvd-single-ref.txt', 'client1-recvd.txt' )
if found:
	points+= 1

found= withinFile.searchText( 'client2-recvd-single-ref.txt', 'client2-recvd.txt' )
if found:
	points+= 1

server.kill()
try:
	server_errors.close()
except Exception:
	pass

print( 'Executing 2 clients with multiple messages...' )
Beispiel #2
0
args = ['java', 'ChatServer', '6001']
server_errors = open('server-errors.txt', 'w')
server = subprocess.Popen(args, stderr=server_errors)

time.sleep(1)

shell_command = 'py input-writer.py 0 2 client1-msg.txt | java ChatClient 6001 >client1-recvd.txt 2>client1-errors.txt &'
os.system(shell_command)

shell_command = 'py input-writer.py 1 2 client2-msg.txt | java ChatClient 6001 >client2-recvd.txt 2>client2-errors.txt'
os.system(shell_command)

print('execution completed; grading...')

found = withinFile.searchText('client1-recvd-single-ref.txt',
                              'client1-recvd.txt')
if found:
    points += 1
else:
    print('client1 did not receive message')

found = withinFile.searchText('client2-recvd-single-ref.txt',
                              'client2-recvd.txt')
if found:
    points += 1
else:
    print('client2 did not receive message')

print('Points so far: ' + str(points) + '/2')

server.kill()
shell_command= 'cd client; rm Ameca_splendens.jpg'
os.system( shell_command )

print( 'Executing server and client with a single message...' )

shell_command= 'cd server; py ../input-writer.py 2 2 server-msg.txt 2>errors.txt | py -u ../messenger_with_files.py -l 6001 >server-recvd.txt &'
os.system( shell_command )

time.sleep( 1 ) 

shell_command= 'cd client; py ../input-writer.py 0 2 client-msg.txt 2>errors.txt | py -u ../messenger_with_files.py -l 6002 -p 6001 >client-recvd.txt'
os.system( shell_command )

print( 'execution completed; grading...' )

found= withinFile.searchText( 'client/client-recvd-single-ref.txt', 'client/client-recvd.txt' )
if found:
	points+= 1
	
found= withinFile.searchText( 'server/server-recvd-single-ref.txt', 'server/server-recvd.txt' )
if found:
	points+= 1

print( 'Executing server and client with multiple messages...' )

shell_command= 'cd server; py ../input-writer.py 2 2 server-msgs.txt 2>>errors.txt | py -u ../messenger_with_files.py -l 6001 >server-recvd.txt &'
os.system( shell_command )

time.sleep( 1 ) 

shell_command= 'cd client; py ../input-writer.py 0 2 client-msgs.txt 2>>errors.txt | py -u ../messenger_with_files.py -l 6002 -p 6001 >client-recvd.txt'
    sys.exit()

# create the input for the pipe
args = ['py', '-u', 'input-writer.py', '2', '1', 'input1.txt']
input_writer = subprocess.Popen(args, stdout=subprocess.PIPE)

# start the program
args = ['java', program_name]
output_text = open('output.txt', 'w')
input_program = subprocess.Popen(args,
                                 stdin=input_writer.stdout,
                                 stdout=output_text)

# check whether output was written immediately
time.sleep(3)
found = withinFile.searchText('input1.txt', 'output.txt')
if not found:
    print('output must be written immediately; your program must be revised')
    sys.exit()

# wait until the input pipe closes; then, check whether the process terminated
try:
    input_program.wait(2)
    if input_program.returncode != 0:
        print(program_name + ' returned: ' + str(input_program.returncode) +
              '; your program must be revised')
        sys.exit()
except subprocess.TimeoutExpired:
    print(
        program_name +
        ' has not exited within the expected timeframe; your program must be revised'
shell_command = 'cd client1; py ../input-writer-cmds-chat.py 0 3 5 client1-msgs.txt 2>errors.txt | py -u ../ChatClient.py -l 6002 -p 6001 >client1-recvd.txt 2>>client1-errors.txt &'
os.system(shell_command)

shell_command = 'cd client2; py ../input-writer-cmds-chat.py 1 3 4 client2-msgs.txt 2>errors.txt | py -u ../ChatClient.py -l 6003 -p 6001 >client2-recvd.txt 2>>client2-errors.txt &'
os.system(shell_command)

shell_command = 'cd client3; py ../input-writer-cmds-chat.py 2 3 3 client3-msgs.txt 2>errors.txt | py -u ../ChatClient.py -l 6004 -p 6001 >client3-recvd.txt 2>>client3-errors.txt'
os.system(shell_command)

print('execution completed; grading...')

subpoints = 0

found = withinFile.searchText(
    'client1/client1-recvd-from-client2-multiple-ref.txt',
    'client1/client1-recvd.txt')
if found:
    subpoints += 1
else:
    print('client1 did not recieve messages from client2')

found = withinFile.searchText(
    'client1/client1-recvd-from-client3-multiple-ref.txt',
    'client1/client1-recvd.txt')
if found:
    subpoints += 1
else:
    print('client1 did not recieve messages from client3')

found = withinFile.searchText(
args= ['py','-u', client_program_name, '6001' ]
client1_output_text= open( 'client1-recvd.txt', 'w' )
client1= subprocess.Popen( args, stdin= client1_input_writer.stdout, stdout=client1_output_text)

# create the input for the pipe to client2
args= ['py','-u','input-writer.py','1', '1', 'client2-msgs-test.txt'] # CHANGE: changed initial delay from 0 to 1
client2_input_writer= subprocess.Popen( args, stdout=subprocess.PIPE)

# start the client program as client2
args= ['py','-u', client_program_name, '6001' ]
client2_output_text= open( 'client2-recvd.txt', 'w' )
client2= subprocess.Popen( args, stdin= client2_input_writer.stdout, stdout=client2_output_text)

# check whether messages were transferred immediately from client2 to client1
time.sleep( 4 ) # CHANGE: changed from 3 to 4
found= withinFile.searchText( 'client1-recvd-multiple-test.txt', 'client1-recvd.txt' )
if not found:
	print( 'messages must be transferred immediately; your program must be revised' )
	client1.kill()
	client2.kill()
	server.kill()
	try:
		server_errors.close()
	except Exception:
		pass
	sys.exit()

# wait until the input pipe for client2 closes; then, check whether the process terminated
try:
	client2.wait( 3 ) # CHANGE: changed from 0 to 3
	if client2.returncode != 0:
Beispiel #7
0
args= ['py','-u', program_name, '-l', '6001' ]
server_output_text= open( 'server-recvd.txt', 'w' )
server_messenger= subprocess.Popen( args, stdin= server_input_writer.stdout, stdout=server_output_text)

# create the input for the pipe to the client
args= ['py','-u','input-writer.py','0', '1', 'client-msgs.txt']
client_input_writer= subprocess.Popen( args, stdout=subprocess.PIPE)

# start the program as a client
args= ['py','-u', program_name, '6001' ]
client_output_text= open( 'client-recvd.txt', 'w' )
client_messenger= subprocess.Popen( args, stdin= client_input_writer.stdout, stdout=client_output_text)

# check whether messages were transferred immediately from client to server
time.sleep( 4 )
found= withinFile.searchText( 'client-msgs.txt', 'server-recvd.txt' )
if not found:
	print( 'messages from client to server must be transferred immediately; your program must be revised' )
	server_messenger.kill()
	client_messenger.kill()
	sys.exit()

# wait until the server input pipe closes; then, check whether the server process terminated
try:
	server_messenger.wait( 2 )
	if server_messenger.returncode != 0:
		print( 'server ' + program_name + ' returned: ' + str(server_messenger.returncode) + '; your program must be revised' )
		client_messenger.kill()
		sys.exit()
except subprocess.TimeoutExpired:
	print( 'non-sending server ' + program_name + ' has not exited within the expected timeframe; your program must be revised' )