9 load_types = ("cpu", "eth", "none")
10 traffic_modes = ("oneatatime", "50", "flood")
13 """Wrapper class for "globals"
14 Used to keep track of current test settings for other functions.
17 targetname = "rtems4.10-midam"
22 def set_hostname(name):
23 settings.hostname = name
25 def set_targetname(name):
26 settings.targetname = name
28 def set_traffic(traffic):
29 settings.traffic = traffic
34 def set_testname(name):
35 settings.testname = name
37 def set_testenv(hostname = None, targetname = None, traffic = None, load = None, testname = None):
38 set_hostname(hostname)
39 set_targetname(targetname)
42 set_testname(testname)
44 gateway_IP_addr = "192.168.2.3"
45 ping_flood_cmd = "ping -f -s 60000 -q {}".format(gateway_IP_addr)
47 #Prepares 755 flag for setting privileges
48 file_flag = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
50 base_plot_string = ('#!/bin/bash\n'
52 'export hostkvers={1}\n'
53 'export traffic={2}\n'
55 'cd $(dirname $0)/../../../../../..\n'
56 'exec ./{4}.sh --plot "$@"\n')
58 tftpboot_path = "/var/lib/tftpboot/ryu/"
59 load_image_path = tftpboot_path + "rtems4.10_{}_FULL_LOAD"
60 no_load_image_path = tftpboot_path + "rtems4.10_{}_NO_LOAD"
61 boot_image_path = tftpboot_path + "uImage"
65 """Starts eth load by ping_flood_cmd"""
67 eth_process = subprocess.Popen(ping_flood_cmd.split())
70 """Stops eth load if active"""
72 if eth_process is not None:
73 eth_process.terminate()
75 print("Eth load stopped")
77 print("Couldn't stop eth load -- was not active")
80 """Physically restarts the board"""
81 result = subprocess.call("../scripts/restart")
82 print("Waiting on restart for 15s.")
83 time.sleep(15) # 15 seconds should be enough to boot up fully even when it runs slowly
85 def start_cpu_load(test_name):
86 """Actually flashes different image, because I don't have working way of communicating commands to the board."""
87 shutil.copy(load_image_path.format(settings.testname), boot_image_path)
90 def stop_cpu_load(test_name):
91 """Actually flashes different image, because I don't have working way of communicating commands to the board."""
92 shutil.copy(no_load_image_path.format(settings.testname), boot_image_path)
95 def run_in_dir(directory, test):
96 """Runs given test in given directory and after it is finished, changes it back."""
103 """Prepares proper directory for test and then runs it in the directory."""
104 target_dir = os.path.join("results", settings.hostname, settings.targetname, settings.traffic, settings.load, test.name)
105 prepare_directory(target_dir)
106 run_in_dir(target_dir, test)
108 def prepare_directory(path):
109 """Creates given path if it does not already exist."""
110 if not os.path.exists(path):
114 def create_plot_script():
115 """Creates plot.sh with correct format to be graphed."""
116 with open("plot.sh", "w+") as file:
117 file.write(base_plot_string.format(settings.targetname, settings.hostname, settings.traffic, settings.load, settings.testname))
118 os.chmod("plot.sh", file_flag)
120 def get_latester_arg(msg_len):
121 """Returns first part of the latester arguments."""
122 if settings.traffic == "oneatatime":
124 elif settings.traffic == "flood":
126 elif settings.traffic == "50":
127 return "-p " + str(2 * (44 + 8 * msg_len))
129 raise InvalidModeException("invalid argument for get_latester_arg")
131 def call_latester(args):
132 """Calls latester with the supplied arguments"""
133 cmd = "latester " + args
134 subprocess.call(cmd.split())
136 def symlink_results(orig_name):
137 """Symlinks all .txt files in path given by ../{orig_name}/ into current directory under their original names."""
138 files = glob.iglob("../{}/*.txt".format(orig_name))
139 for txt_file in files:
140 link_file = txt_file.split(os.path.sep)[-1]
141 if os.path.islink(link_file) or os.path.exists(link_file):
143 os.symlink(txt_file, link_file)
146 """Reads uname from host kernel."""
147 k_call = subprocess.Popen("uname -r".split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
148 output, error = k_call.communicate()
149 #we have to convert output from bytearray to string and strip trailing newline from output
150 return "host-" + output.decode(sys.stdout.encoding).rstrip()
153 def original_name_from_histogram_name(hist_name):
154 """Retuns name of the original test from the name of its histogram."""
155 return "-".join(hist_name.split("-")[:-1])