def runTest(self): # TODO: create a get devices function? devs = [] for device in self.config.devices: devs.append(getattr(self.config, device)) devs.append(board.get_pp_dev()) results = [] for d1 in devs: for d2 in devs: if d1 is d2: continue board.touch() print("comparing " + d1.name + " to " + d2.name) try: ip1 = d1.get_interface_ipaddr(d1.iface_dut) ip2 = d2.get_interface_ipaddr(d2.iface_dut) def parse_ping_times(string): r = [ float(i) for i in re.findall('time=([^\s]*) ms', string) ] return sum(r) / len(r) d1.sendline("ping -c20 %s" % ip2) d1.expect_exact("ping -c20 %s" % ip2) d1.expect(d1.prompt) result = parse_ping_times(d1.before) if result is not float('nan'): results.append('latency from %s to %s = %s ms' % (d1.name, d2.name, str(result))) d2.sendline("ping -c20 %s" % ip1) d2.expect_exact("ping -c20 %s" % ip1) d2.expect(d2.prompt) result = parse_ping_times(d2.before) if result is not float('nan'): results.append('latency from %s to %s = %s ms' % (d2.name, d1.name, str(result))) except: print("failed to ping " + d1.name + " to " + d2.name) continue print("Results:") for line in results: print(line)
def runTest(self): self.dir = 'jmeter_%s' % self.shortname install_jmeter(lan) lan.sendline('rm -rf $HOME/%s' % self.dir) lan.expect(prompt) lan.sendline('mkdir -p $HOME/%s/wd' % self.dir) lan.expect(prompt) lan.sendline('mkdir -p $HOME/%s/results' % self.dir) lan.expect(prompt) if self.jmx.startswith('http'): lan.sendline('curl %s > $HOME/%s/test.jmx' % (self.jmx, self.dir)) lan.expect(prompt) else: print("Copying %s to lan device" % self.jmx) lan.sendline('echo $HOME') lan.expect_exact('echo $HOME') lan.expect(prompt) lan.copy_file_to_server(self.jmx, dst=lan.before.strip() + '/%s/test.jmx' % self.dir) board.collect_stats(stats=['mpstat']) lan.sendline('cd $HOME/%s/wd' % self.dir) lan.expect(prompt) lan.sendline( 'JVM_ARGS="-Xms4096m -Xmx8192m" jmeter -n -t ../test.jmx -l foo.log -e -o $HOME/%s/results' % self.dir) lan.expect_exact('$HOME/%s/results' % self.dir) for i in range(self.default_time): if 0 != lan.expect([pexpect.TIMEOUT] + prompt, timeout=5): break conns = board.get_nf_conntrack_conn_count() board.get_proc_vmstat() board.touch() if i > 100 and conns < 20: raise Exception("jmeter is dead/stuck/broke, aborting the run") if i == 599: raise Exception("jmeter did not have enough time to complete") lan.sendline('cd -') lan.expect(prompt) lan.sendline('rm test.jmx') lan.expect(prompt) self.recover()
def runTest(self): lan.sendline('nmap -sS -A -v -p 1-10000 %s' % board.get_interface_ipaddr(board.lan_iface)) lan.expect('Starting Nmap') for i in range(12): if 0 == lan.expect(['Nmap scan report', pexpect.TIMEOUT], timeout=100): break board.touch() lan.expect(prompt, timeout=60) open_ports = re.findall("(\d+)/tcp\s+open", lan.before) msg = "Found %s open TCP ports on LAN interface: %s." % \ (len(open_ports), ", ".join(open_ports)) self.result_message = msg
def runTest(self): installers.apt_install(lan, "wget") urls = [ 'www.amazon.com', 'www.apple.com', 'www.baidu.com', 'www.bing.com', 'www.cnn.com', 'www.ebay.com', 'www.facebook.com', 'www.google.com', 'www.imdb.com', 'www.imgur.com', 'www.instagram.com', 'www.linkedin.com', 'www.microsoft.com', 'www.nbcnews.com', 'www.netflix.com', 'www.pinterest.com', 'www.reddit.com', 'www.twitter.com', 'www.wikipedia.org', 'www.yahoo.com', ] #urls = 2 * urls # browse more random.shuffle(urls) user = '******' cmd = "wget -Hp http://%(url)s " + \ "-e robots=off " + \ "-P /tmp/webbrowse-test " + \ "-T 10 " + \ "--header='Accept: text/html' " + \ "-U '%(user)s' " + \ "2>&1 | tail -1" for url in urls: lan.sendline("mkdir -p /tmp/webbrowse-test") print("\n%s" % url) tmp = cmd % {'url': url, 'user': user} lan.sendline(tmp) try: lan.expect('Downloaded:', timeout=20) except Exception: lan.sendcontrol('c') lan.expect(prompt) lan.sendline("rm -rf /tmp/webbrowse-test") lan.expect(prompt) board.touch()
def runTest(self): wan_ip = wan.get_interface_ipaddr(wan.iface_dut) wan.sendline('iperf -s -l 1M -w 1M') wan.expect('Server listening on ') board.collect_stats(stats=['mpstat']) time = 10 cmd = "iperf -R -c %s -P %s -t 10 -N -w 1M -l 1M | grep SUM" # prime the pipes... lan.sendline(cmd % (wan_ip, 4)) lan.expect(prompt) prev_con = 0 prev_failed = 0 for con_conn in range(32, 513, 16): try: tstart = datetime.now() lan.sendline(cmd % (wan_ip, con_conn)) failed_cons = 0 while (datetime.now() - tstart).seconds < (time * 2): timeout = (time * 2) - (datetime.now() - tstart).seconds if 0 == lan.expect( ['write failed: Connection reset by peer'] + prompt, timeout=timeout): failed_cons += 1 else: break print_bold("For iperf with %s connections, %s failed...." % (con_conn, failed_cons)) lan.expect('.*') wan.expect('.*') board.touch() prev_conn = con_conn prev_failed = failed_cons if con_conn == 512: self.result_message = "iPerf Concurrent passed 512 connections (failed conns = %s)" % failed_cons except: self.result_message = "iPerf Concurrent Connections failed entirely at %s (failed conns = %s)" % ( prev_conn, prev_failed) break print(self.result_message) self.recover()
def runTest(self): install_hping3(lan) wan_ip = wan.get_interface_ipaddr(wan.iface_dut) wan.sendline('nc -lvu %s 565' % wan_ip) wan.expect_exact('nc -lvu %s 565' % wan_ip) board.collect_stats(stats=['mpstat']) # dest ip and port are fixed, random src port, fixed src ip, 100 us between lan.sendline('hping3 -2 -c %s -d 120 -S -w 64 -p 445 -i %s %s' % (self.conns, self.conn_rate, wan_ip)) lan.expect('HPING') self.max_conns = 0 for not_used in range(10): self.max_conns = max(self.max_conns, board.get_nf_conntrack_conn_count()) board.get_proc_vmstat() lan.expect(pexpect.TIMEOUT, timeout=3) board.expect(pexpect.TIMEOUT, timeout=3) board.touch() self.recover()
def runTest(self): random.seed(99) for d in [wan, lan]: d.sendline( 'apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat pv' ) d.expect(prompt) max_time = 0 single_max = 45 board.collect_stats(stats=['mpstat']) # TODO: query interfaces but this is OK for now for i in range(self.conns): board.get_nf_conntrack_conn_count() board.touch() print("Starting connection %s" % i) sz, rate, ip, port = self.startSingleFlow(maxtime=single_max) print("started flow to %s:%s sz = %s, rate = %sk" % (ip, port, sz, rate)) max_time = max(max_time, sz / (rate * 1024)) self.check_and_clean_ips() print("waiting max time of %ss" % max_time) start = time.time() while time.time() - start < max_time + 5: lan.sendline('wait') lan.expect_exact('wait') lan.expect([pexpect.TIMEOUT] + prompt, timeout=5) lan.sendcontrol('c') lan.expect(prompt) self.check_and_clean_ips() board.get_nf_conntrack_conn_count() board.touch() self.recover()
def runTest(self): wan_ip_addr = board.get_interface_ipaddr(board.wan_iface) wan.sendline('\nnmap -sS -A -v %s' % wan_ip_addr) wan.expect('Starting Nmap', timeout=5) wan.expect(pexpect.TIMEOUT, timeout=60) board.touch() wan.expect(pexpect.TIMEOUT, timeout=60) board.touch() wan.expect(pexpect.TIMEOUT, timeout=60) board.touch() wan.expect('Nmap scan report', timeout=60) wan.expect(prompt, timeout=60) open_ports = re.findall("(\d+)/tcp\s+open", wan.before) msg = "Found %s open TCP ports on WAN interface." % len(open_ports) self.result_message = msg print("open ports = %s" % open_ports) if hasattr(board, 'wan_open_ports'): print("allowing open ports %s" % board.wan_open_ports) open_ports = set(map(int, open_ports)) - set(board.wan_open_ports) assert len(open_ports) == 0
def recover(self): board.touch() lan.sendcontrol('c') lan.expect(prompt) board.touch() print("Copying files from lan to dir = %s" % self.config.output_dir) lan.sendline('readlink -f $HOME/%s/' % self.dir) lan.expect_exact('$HOME/%s/' % self.dir) board.touch() lan.expect(prompt) board.touch() fname = lan.before.replace('\n', '').replace('\r', '') board.touch() rm_r(os.path.join(self.config.output_dir, self.dir)) scp_from(fname, lan.ipaddr, lan.username, lan.password, lan.port, self.config.output_dir) # let board settle down board.expect(pexpect.TIMEOUT, timeout=30) board.touch() board.parse_stats(dict_to_log=self.logged) board.touch() self.result_message = 'JMeter: DONE, name = %s cpu usage = %s' % ( self.shortname, self.logged['mpstat'])
def testWrapper(self): self.start_time = time.time() for d in self.config.devices: dev = getattr(self.config, d) dev.test_to_log = self dev.test_prefix = d.encode("utf8") for c in board.consoles: c.test_to_log = self c.test_prefix = 'console-%s' % str(board.consoles.index(c) + 1) if not c.isalive(): self.result_grade = "SKIP" print( "\n\n=========== Test skipped! Board is not alive... =============" ) self.skipTest("Board is not alive") raise try: if wan and hasattr(self, 'wan_setup'): self.wan_setup() if lan and hasattr(self, 'lan_setup'): self.lan_setup() if wlan and hasattr(self, 'wlan_setup'): self.wlan_setup() if self.config.retry and not self.dont_retry: retry = self.config.retry else: retry = 0 while retry >= 0: try: self.runTest() board.touch() retry = -1 except Exception as e: retry = retry - 1 if (retry > 0): if hasattr(e, 'get_trace'): print(e.get_trace()) else: print("Exception has no trace, type = %s" % type(e)) print( "\n\n----------- Test failed! Retrying in 5 seconds... -------------" ) time.sleep(5) else: raise if wan and hasattr(self, 'wan_cleanup'): self.wan_cleanup() if lan and hasattr(self, 'lan_cleanup'): self.lan_cleanup() if wlan and hasattr(self, 'wlan_cleanup'): self.wlan_cleanup() if hasattr(self, 'expected_failure') and self.expected_failure: self.result_grade = "Unexp OK" else: self.result_grade = "OK" self.stop_time = time.time() self.logged['test_time'] = float(self.stop_time - self.start_time) except unittest2.case.SkipTest: self.stop_time = time.time() self.logged['test_time'] = float(self.stop_time - self.start_time) self.result_grade = "SKIP" print("\n\n=========== Test skipped! Moving on... =============") raise except Exception as e: self.stop_time = time.time() self.logged['test_time'] = float(self.stop_time - self.start_time) if hasattr(self, 'expected_failure') and self.expected_failure: self.result_grade = "Exp FAIL" else: self.result_grade = "FAIL" print( "\n\n=========== Test failed! Running recovery Time: %s ===========" % now_short(self._format)) if e.__class__.__name__ == "TIMEOUT": print(e.get_trace()) else: print(e) traceback.print_exc(file=sys.stdout) import os if 'BFT_DEBUG' in os.environ: print(self) for device in self.config.devices: d = getattr(self.config, device) print(d) self.recover() raise