2 Contains various helper functions and information for benchmarking RTEMS CAN GW implementation.
13 load_types = ("cpu", "eth", "none")
14 traffic_modes = ("oneatatime", "50", "flood")
17 """Wrapper class for "globals"
18 Used to keep track of current test settings for other functions.
21 targetname = "rtems4.10-midam"
26 def set_hostname(name):
27 settings.hostname = name
29 def set_targetname(name):
30 settings.targetname = name
32 def set_traffic(traffic):
33 settings.traffic = traffic
38 def set_testname(name):
39 settings.testname = name
41 def set_testenv(hostname = None, targetname = None, traffic = None, load = None, testname = None):
42 set_hostname(hostname)
43 set_targetname(targetname)
46 set_testname(testname)
48 gateway_IP_addr = "192.168.2.3"
49 ping_flood_cmd = "ping -f -s 60000 -q {}".format(gateway_IP_addr)
51 #Prepares 755 flag for setting privileges
52 file_flag = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
54 base_plot_string = ('#!/bin/bash\n'
56 'export hostkvers={1}\n'
57 'export traffic={2}\n'
59 'cd $(dirname $0)/../../../../../..\n'
60 'exec ./{4}.sh --plot "$@"\n')
62 tftpboot_path = "/var/lib/tftpboot/ryu/"
63 load_image_path = tftpboot_path + "rtems4.10_{}_FULL_LOAD"
64 no_load_image_path = tftpboot_path + "rtems4.10_{}_NO_LOAD"
65 boot_image_path = tftpboot_path + "uImage"
69 """Starts eth load by ping_flood_cmd"""
71 eth_process = subprocess.Popen(ping_flood_cmd.split())
74 """Stops eth load if active"""
76 if eth_process is not None:
77 eth_process.terminate()
79 print("Eth load stopped")
81 print("Couldn't stop eth load -- was not active")
84 """Physically restarts the board"""
85 result = subprocess.call("../scripts/restart")
86 print("Waiting on restart for 15s.")
87 time.sleep(15) # 15 seconds should be enough to boot up fully even when it runs slowly
89 def start_cpu_load(test_name):
90 """Actually flashes different image, because I don't have working way of communicating commands to the board."""
91 shutil.copy(load_image_path.format(settings.testname), boot_image_path)
94 def stop_cpu_load(test_name):
95 """Actually flashes different image, because I don't have working way of communicating commands to the board."""
96 shutil.copy(no_load_image_path.format(settings.testname), boot_image_path)
99 def run_in_dir(directory, test):
100 """Runs given test in given directory and after it is finished, changes it back."""
107 """Prepares proper directory for test and then runs it in the directory."""
108 target_dir = os.path.join("results", settings.hostname, settings.targetname, settings.traffic, settings.load, test.name)
109 prepare_directory(target_dir)
110 run_in_dir(target_dir, test)
112 def prepare_directory(path):
113 """Creates given path if it does not already exist."""
114 if not os.path.exists(path):
118 def create_plot_script():
119 """Creates plot.sh with correct format to be graphed."""
120 with open("plot.sh", "w+") as file:
121 file.write(base_plot_string.format(settings.targetname, settings.hostname, settings.traffic, settings.load, settings.testname))
122 os.chmod("plot.sh", file_flag)
124 def get_latester_arg(msg_len):
125 """Returns first part of the latester arguments."""
126 if settings.traffic == "oneatatime":
128 elif settings.traffic == "flood":
130 elif settings.traffic == "50":
131 return "-p " + str(2 * (44 + 8 * msg_len))
133 raise InvalidModeException("invalid argument for get_latester_arg")
135 def call_latester(args):
136 """Calls latester with the supplied arguments"""
137 cmd = "latester " + args
138 subprocess.call(cmd.split())
140 def symlink_results(orig_name):
141 """Symlinks all .txt files in path given by ../{orig_name}/ into current directory under their original names."""
142 files = glob.iglob("../{}/*.txt".format(orig_name))
143 for txt_file in files:
144 link_file = txt_file.split(os.path.sep)[-1]
145 if os.path.islink(link_file) or os.path.exists(link_file):
147 os.symlink(txt_file, link_file)
150 """Reads uname from host kernel."""
151 k_call = subprocess.Popen("uname -r".split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
152 output, error = k_call.communicate()
153 #we have to convert output from bytearray to string and strip trailing newline from output
154 return "host-" + output.decode(sys.stdout.encoding).rstrip()
157 def original_name_from_histogram_name(hist_name):
158 """Retuns name of the original test from the name of its histogram."""
159 return "-".join(hist_name.split("-")[:-1])
161 def set_txqueuelen(length):
162 """Sets txqueuelen on can0 interface to given length"""
163 subprocess.call("ifconfig can0 txqueuelen {}".format(length).split())