Skip to content
Snippets Groups Projects
Commit c9549815 authored by Felix Gerking's avatar Felix Gerking Committed by Jonas Höppner
Browse files

EMV Testsuite: Tool to check if the network interfaces work

* Merge from jethro, refs #30619
* Detects the existing network interfaces
* Verifies the shell commands used in the BIT-Test
* Provides a guided test that prints out the instructions for each step

Change-Id: Ic7c4d49779202e82f226509c5cacbffa371a2ce6
Reviewed-on: http://gfweb/gerrit/297
parent 7a70c14d
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
# EMV-Network-Pretest
# This test validates the commands, which are execute in the BIT-Test
# It is necessary to configure the network interfaces as described in the Testcase
# If any problems occure check the log file /opt/ltp/results/network_test.log
import subprocess
import time
import curses
# Window dimensions
x_max = 70
y_max = 20
unplugged_tabstop = 15
plugged_tabstop = 37
current_line = 0
#---------------------------------------------------------------------------#
# Curses Window
#---------------------------------------------------------------------------#
def initialize_window(stdscr):
curses.start_color()
curses.noecho()
stdscr.keypad(1)
# Init color pairs
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_YELLOW) # Action messages
curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED) # Test failed
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_GREEN) # Test passed
# Draw frame
stdscr.addstr(1, 27, "EMV-Network-Test", curses.color_pair(4))
stdscr.addstr(3, unplugged_tabstop, "Unplugged")
stdscr.addstr(3, plugged_tabstop, "Plugged")
for x in range(0,x_max+1):
stdscr.move(0,x)
stdscr.addstr("-")
for x in range(0,x_max+1):
stdscr.move(y_max,x)
stdscr.addstr("-")
for y in range(1,y_max):
stdscr.move(y,0)
stdscr.addstr("|")
for y in range(1,y_max):
stdscr.move(y,x_max)
stdscr.addstr("|")
stdscr.refresh()
#def destroy_window():
# curses.nocbreak(); stdscr.keypad(0); curses.echo()
# curses.endwin()
#---------------------------------------------------------------------------#
# Instruction messages
#---------------------------------------------------------------------------#
def msg_write(action,keys,stdscr):
stdscr.move(18,2)
stdscr.addstr(action, curses.color_pair(1))
stdscr.move(19,2)
stdscr.addstr(keys, curses.color_pair(1))
stdscr.refresh()
stdscr.move(y_max+2,0)
def msg_clear(stdscr):
for x in range(1,70):
stdscr.move(18,x)
stdscr.addstr(" ")
for x in range(1,70):
stdscr.move(19,x)
stdscr.addstr(" ")
stdscr.refresh()
stdscr.move(y_max+2,0)
#---------------------------------------------------------------------------#
# Evaluate test output
#---------------------------------------------------------------------------#
def ev_output(out,plug,line,stdscr):
# Passed if the output = 0 and the network is up
if plug == 1:
if out == 0:
stdscr.addstr(line,plugged_tabstop," Test passed ",curses.color_pair(3))
else:
stdscr.addstr(line,plugged_tabstop," Test failed ",curses.color_pair(2))
else:
# Passed if the output != 0 and the network is down
if out != 0:
stdscr.addstr(line,unplugged_tabstop," Test passed ",curses.color_pair(3))
else:
stdscr.addstr(line,unplugged_tabstop," Test failed ",curses.color_pair(2))
stdscr.refresh()
#---------------------------------------------------------------------------#
# Get user events
#---------------------------------------------------------------------------#
def user_input(stdscr):
action = ord('q')
while action != ord('c'):
action = stdscr.getch()
if action == ord('q'):
curses.nocbreak(); stdscr.keypad(0); curses.echo()
curses.endwin()
exit()
#---------------------------------------------------------------------------#
# Execute bash commands and obtain return values
#---------------------------------------------------------------------------#
def bash_cmd(inputStr):
callStr = inputStr + " &>>/opt/ltp/results/network_test.log"
value = subprocess.call(callStr, shell=True)
return value
#---------------------------------------------------------------------------#
# Network Ethernet 0
#---------------------------------------------------------------------------#
def eth0(stdscr):
current_line = 5
stdscr.addstr(current_line,2,"Ethernet 0:")
# Unplugged test
msg_write("Remove the cable from ethernet port 0","Press 'c' to continue, 'q' to quit",stdscr)
user_input(stdscr)
msg_clear(stdscr)
out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.1.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True)
ev_output(out,0,current_line,stdscr)
# Plugged test
msg_write ("Reconnect the cable","Press 'c' to continue, 'q' to quit",stdscr)
user_input(stdscr)
msg_clear(stdscr)
msg_write("Wait for the network to come up","",stdscr)
time.sleep(8)
msg_clear(stdscr)
out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.1.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True)
ev_output(out,1,current_line,stdscr)
#---------------------------------------------------------------------------#
# Network Ethernet 1
#---------------------------------------------------------------------------#
def eth1(stdscr):
current_line = 7
stdscr.addstr(current_line,2,"Ethernet 1:")
# Unplugged test
msg_write("Remove the cable from ethernet port 1","Press 'c' to continue, 'q' to quit",stdscr)
user_input(stdscr)
msg_clear(stdscr)
out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.2.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True)
ev_output(out,0,current_line,stdscr)
# Plugged test
msg_write ("Reconnect the cable","Press 'c' to continue, 'q' to quit",stdscr)
user_input(stdscr)
msg_clear(stdscr)
msg_write("Wait for the network to come up","",stdscr)
time.sleep(8)
msg_clear(stdscr)
out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.2.100 -n 1 -w 50 &>>/opt/ltp/results/network_test.log", shell=True)
ev_output(out,1,current_line,stdscr)
#---------------------------------------------------------------------------#
# WLAN
#---------------------------------------------------------------------------#
def wlan(stdscr):
current_line = 9
stdscr.addstr(current_line,2,"WLAN:")
# Unplugged test
msg_write("Remove ethernet cable from the router","Press 'c' to continue, 'q' to quit",stdscr)
user_input(stdscr)
msg_clear(stdscr)
out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.3.100 -n 1 -w 1000 &>>/opt/ltp/results/network_test.log", shell=True)
ev_output(out,0,current_line,stdscr)
# Plugged test
msg_write ("Reconnect the cable","Press 'c' to continue, 'q' to quit",stdscr)
user_input(stdscr)
msg_clear(stdscr)
msg_write("Wait for the network to come up","",stdscr)
time.sleep(10)
msg_clear(stdscr)
out = subprocess.call("/opt/ltp/testcases/bin/iptest -q -g 192.168.3.100 -n 1 -w 1000 &>>/opt/ltp/results/network_test.log", shell=True)
ev_output(out,1,current_line,stdscr)
#---------------------------------------------------------------------------#
# Main
#---------------------------------------------------------------------------#
def main(stdscr):
initialize_window(stdscr)
msg_write("Ensure the network interfaces are configured correctly. For this","you can use the emv_network_config.sh file. Press 'c' to continue",stdscr)
user_input(stdscr)
msg_clear(stdscr)
# Resest log
subprocess.call("date &>/opt/ltp/results/network_test.log", shell=True)
# Ethernet 0 test
eth0(stdscr)
# Check if a second ethernet interface exists
if(subprocess.call("ifconfig -a | grep eth1 &> /dev/null", shell=True)== 0):
eth1(stdscr)
# Check if a wlan interface exists
if(subprocess.call("ifconfig -a | grep wlan0 &> /dev/null", shell=True)== 0):
wlan(stdscr)
curses.wrapper(main)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment