def runTest(self, client=wan, server=lan): mpstat_present = self.mpstat_ok() # this is running an arbitrary time, we will ctrl-c and get results self.run_iperf_server(server, opts=self.server_opts_reverse(node=server)) if mpstat_present: board.sendline('mpstat -P ALL 10000 1') board.expect('Linux') self.run_iperf(client, opts=opts, target=self.reverse_ip()) rate = self.parse_iperf(client) if mpstat_present: board.sendcontrol('c') board.expect( 'Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) self.logged['avg_cpu'] = float(avg_cpu) else: avg_cpu = "N/A" self.kill_iperf(server) msg = 'iPerf from WAN to LAN (%s Mbps, CPU=%s)' % (rate, avg_cpu) lib.common.test_msg("\n%s" % msg) self.logged['rate'] = float(rate) self.result_message = msg
def runTest(self): board.sendline('\nopkg list | grep qos-scripts') try: board.expect('qos-scripts - ', timeout=4) except: return # pass if not installed assert False # fail if installed
def runTest(self): board.sendcontrol('c') board.expect(board.prompt) board.sendline('logread -f &') board.expect(board.prompt) lan.sendline('rm -rf Fedora*') lan.expect(lan.prompt) # TODO: apt-get install bittornado for i in range(10): lan.sendline( "btdownloadheadless 'https://torrent.fedoraproject.org/torrents/Fedora-Games-Live-x86_64-28_Beta.torrent'" ) lan.expect('saving:') done = False while not done: lan.expect(pexpect.TIMEOUT, timeout=1) # flush buffer if 0 == lan.expect( ['time left: Download Succeeded!', pexpect.TIMEOUT], timeout=10): print("Finished, restarting....") done = True board.expect(pexpect.TIMEOUT, timeout=5) board.sendline() # keepalive lan.sendcontrol('c') lan.sendcontrol('c') lan.sendcontrol('c') lan.expect(lan.prompt) lan.sendline('rm -rf Fedora*') lan.expect(lan.prompt)
def recover(self): if board.has_cmts: from boardfarm.devices import provisioner # TODO: there are more missing ones CDrouter expects provisioner.sendline('ip route del 200.0.0.0/8 via 192.168.3.2') provisioner.expect(prompt) provisioner.sendline('ip route del 3.3.3.3 via 192.168.3.2') provisioner.expect(prompt) provisioner.sendline( 'ip route del 3001:cafe:1::/64 via 2001:dead:beef:1::2') provisioner.expect(prompt) provisioner.sendline( 'ip route del 3001:51a:cafe::1 via 2001:dead:beef:1::2') provisioner.expect(prompt) if hasattr(self, 'results'): r = self.results.get(self.job_id) if r.status == "running": self.results.stop(self.job_id) # TODO: full recovery... for d in [wan, lan]: d.sendline('ifconfig %s up' % d.iface_dut) d.expect(prompt) # make sure board is back in a sane state board.sendcontrol('c') board.sendline() if 0 != board.expect([pexpect.TIMEOUT] + board.uprompt, timeout=5): board.reset() board.wait_for_linux()
def runTest(self): if not wan: msg = 'No WAN Device defined, skipping ping WAN test.' lib.common.test_msg(msg) self.skipTest(msg) board.sendline('\nping -c5 %s' % wan.gw) board.expect('5 (packets )?received', timeout=15) board.expect(prompt)
def runTest(self): board.sendline('\ntop -b -n 1') board.expect(pexpect.TIMEOUT, timeout=2) try: board.expect(prompt, timeout=2) except: # some versions of top do not support '-n' # must CTRL-C to kill top board.sendcontrol('c')
def runTest(self): self.logged.update(board.get_proc_vmstat()) # Display extra info board.sendline('cat /proc/slabinfo /proc/buddyinfo /proc/meminfo') board.expect('cat /proc/') board.expect(prompt) board.sendline('cat /proc/vmallocinfo') board.expect('cat /proc/vmallocinfo') board.expect(prompt)
def recover(self): lan.sendcontrol('c') lan.expect(lan.prompt) lan.sendline('rm -rf Fedora*') lan.expect(lan.prompt) board.sendcontrol('c') board.expect(board.prompt) board.sendline('fg') board.sendcontrol('c') board.expect(board.prompt)
def mpstat_ok(self): board.sendline('mpstat -V') if board.expect(['sysstat version', 'BusyBox', 'not found'], timeout=5) == 0: mpstat_present = True else: mpstat_present = False board.expect(prompt) return mpstat_present
def runTest(self): board.sendline('\nifconfig') board.expect('ifconfig') board.expect(prompt) results = re.findall('([A-Za-z0-9-\.]+)\s+Link.*\n.*addr:([^ ]+)', board.before) tmp = ', '.join(["%s %s" % (x, y) for x, y in results]) board.sendline('route -n') board.expect(prompt) self.result_message = 'ifconfig shows ip addresses: %s' % tmp
def runTest(self): board.sendline('\nopkg list-installed | wc -l') board.expect('opkg list') board.expect(r'(\d+)\r\n') num_pkgs = int(board.match.group(1)) board.expect(prompt) board.sendline('opkg list-installed') board.expect(prompt) self.result_message = '%s OpenWrt packages are installed.' % num_pkgs self.logged['num_installed'] = num_pkgs
def runTest(self): for sz in ["74", "128", "256", "512", "1024", "1280", "1518"]: print("running %s UDP test" % sz) lan.sendline( 'netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -- -m %s' % sz) lan.expect_exact( 'netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -- -m %s' % sz) lan.expect('UDP UNIDIRECTIONAL') lan.expect(prompt, timeout=90) board.sendline() board.expect(prompt)
def runTest(self): board.sendline('\nuci show mcproxy') board.expect_exact('mcproxy.config=mcproxy', timeout=5) board.expect_exact('mcproxy.config.protocol=IGMPv3', timeout=5) board.expect_exact('mcproxy.@pinstance[0]=pinstance', timeout=5) board.expect_exact('mcproxy.@pinstance[0].name=mcproxy1', timeout=5) board.expect(prompt) board.sendline('cat /etc/mcproxy.conf') board.expect('protocol IGMPv3;', timeout=5) board.expect('pinstance mcproxy1: "eth0" ==> "br-lan";') board.expect(prompt)
def runTest(self): ip = "192.168.1.1" board.sendline('\nhead -c 1000000 /dev/urandom > /www/deleteme.txt') board.expect('head ', timeout=5) board.expect(prompt) lan.sendline('\ncurl -m 25 http://%s/deleteme.txt > /dev/null' % ip) lan.expect('Total', timeout=5) lan.expect('100 ', timeout=10) lan.expect(prompt, timeout=10) board.sendline('\nrm -f /www/deleteme.txt') board.expect('deleteme.txt') board.expect(prompt)
def runTest(self): board.sendline('\nuci set firewall.@defaults[0].forward=REJECT') board.expect('uci set firewall') board.expect(prompt) board.sendline('uci set firewall.@zone[0].forward=REJECT') board.expect(prompt) board.sendline('uci set firewall.@zone[1].input=REJECT') board.expect(prompt) board.sendline('uci set firewall.@zone[1].forward=REJECT') board.expect(prompt) board.sendline('uci commit firewall') board.expect(prompt) board.firewall_restart()
def runTest(self): wlan_iface = wifi_interface(board) if wlan_iface is None: self.skipTest("No wifi interfaces detected, skipping..") board.sendline('\nuci show wireless') board.expect('uci show wireless') board.expect(prompt) wifi_interfaces = re.findall('wireless.*=wifi-device', board.before) self.result_message = "UCI shows %s wifi interface(s)." % ( len(wifi_interfaces)) self.logged['num_ifaces'] = len(wifi_interfaces) # Require that at least one wifi interface is present assert len(wifi_interfaces) > 0
def recover(self): if self.__class__.__name__ == "RootFSBootTest": try: if board.linux_booted: board.sendline('ps auxfw || ps w') board.expect(prompt) board.sendline('iptables -S') board.expect(prompt) except: pass board.close() lib.common.test_msg("Unable to boot, skipping remaining tests...") return try: # let user interact with console if test failed try: board.sendline() board.sendline() if not self.config.batch: board.interact() except: pass if self.reboot == True and self.reset_after_fail: self.boot(self.reflash) self.reboot = True except Exception as e: print("Unable to recover, %s" % e) self.assertEqual(1, 0, e)
def runTest(self): board.sendline('\nip link show') board.expect('ip link show') board.expect(prompt) if "ip: not found" not in board.before: up_interfaces = re.findall('\d: ([A-Za-z0-9-\.]+)[:@].*state UP ', board.before) else: board.sendline('ifconfig') board.expect(prompt) up_interfaces = re.findall('([A-Za-z0-9-\.]+)\s+Link', board.before) num_up = len(up_interfaces) if num_up >= 1: msg = "%s interfaces are UP: %s." % (num_up, ", ".join(sorted(up_interfaces))) else: msg = "0 interfaces are UP." self.result_message = msg assert num_up >= 2
def runTest(self): board.sendline('\n/etc/init.d/mcproxy stop') board.expect(prompt) board.sendline('ps | grep mcproxy') board.expect(prompt) assert '/usr/sbin/mcproxy' not in board.before board.sendline('/etc/init.d/mcproxy start') board.sendline('ps | grep mcproxy') board.expect('/usr/sbin/mcproxy -f /etc/mcproxy.conf', timeout=5) board.expect(prompt)
def recover(self, node1=lan, node2=wan): lib.common.test_msg("sending board ctrl-c") board.sendcontrol('c') board.sendcontrol('c') board.expect(prompt) lib.common.test_msg("sending node1 ctrl-c") node1.sendcontrol('c') node1.sendcontrol('c') node1.expect(prompt) lib.common.test_msg("sending node2ctrl-c") node2.sendcontrol('c') node2.sendcontrol('c') node2.expect(prompt) lib.common.test_msg("killing iperf on node1") self.kill_iperf(node1) lib.common.test_msg("killing iperf on node2") self.kill_iperf(node2) board.sendline('cat /proc/net/nf_conntrack | wc -l') board.expect(prompt) try: board.sendline('cat /proc/devices | grep sfe') board.expect('cat /proc/devices | grep sfe') board.expect('([0-9]+) sfe_ipv4') char_dev = board.match.group(1).strip() board.expect(prompt) board.sendline('mknod /dev/sfe c %s 0' % char_dev) board.expect(prompt) board.sendline('cat /dev/sfe') board.expect(prompt) except: pass board.sendline('ifconfig; route') board.expect_exact('ifconfig; route') board.expect(prompt) node1.sendline('ifconfig; route') node1.expect_exact('ifconfig; route') node1.expect(prompt) node2.sendline('ifconfig; route') node2.expect_exact('ifconfig; route') node2.expect(prompt)
def runTest(self): board.sendline('\nsync; echo 3 > /proc/sys/vm/drop_caches') board.expect('echo 3') board.expect(prompt, timeout=5) # There appears to be a tiny, tiny chance that # /proc/meminfo won't exist, so try one more time. for i in range(2): try: board.sendline('cat /proc/meminfo') board.expect(r'MemTotal:\s+(\d+) kB', timeout=5) break except: pass mem_total = int(board.match.group(1)) board.expect(r'MemFree:\s+(\d+) kB') mem_free = int(board.match.group(1)) board.expect(prompt) mem_used = mem_total - mem_free self.result_message = 'Used memory: %s MB. Free memory: %s MB.' % ( mem_used / 1000, mem_free / 1000) self.logged['mem_used'] = mem_used / 1000
def runTest(self): board.sendline('\n') board.expect(prompt) board.sendline('opkg install ca-certificates') board.expect(prompt) checks = [ ('https://expired.badssl.com/', 'certificate has expired'), ('https://wrong.host.badssl.com/', 'no alternative certificate subject name matches target host name' ), ('https://subdomain.preloaded-hsts.badssl.com/', 'no alternative certificate subject name matches target host name' ), ('https://self-signed.badssl.com/', 'unable to get local issuer certificate'), ('https://superfish.badssl.com/', 'unable to get local issuer certificate'), ('https://edellroot.badssl.com/', 'unable to get local issuer certificate'), ('https://dsdtestprovider.badssl.com/', 'unable to get local issuer certificate'), ('https://incomplete-chain.badssl.com/', 'unable to get local issuer certificate'), ] for check in checks: board.sendline('curl ' + check[0]) board.expect(check[1]) board.expect(prompt) print('\n\nCurl refused to download ' + check[0] + ' as expected\n')
def setUp(self): ip = "192.168.1.1" super(WebTest, self).setUp() if not lan: msg = 'No LAN Device defined, skipping web test.' lib.common.test_msg(msg) self.skipTest(msg) # Set password, just to be sure board.sendline("passwd") board.expect("New password:"******"password") board.expect("Retype password:"******"password") board.expect(prompt) # Create a driver self.driver = lib.common.phantom_webproxy_driver('http://' + lan.name + ':8080') self.driver.get("http://%s/cgi-bin/luci" % ip) self.assertIn(ip, self.driver.current_url) self.assertIn('LuCI', self.driver.title) self.driver.find_element_by_name('luci_password').send_keys('password') self.driver.find_element_by_class_name('cbi-button-apply').submit() self.driver.find_element_by_xpath( "//ul/li/a[contains(text(),'Status')]")
def recover(self): if board.has_cmts and wan.wan_cmts_provisioner: # TODO: there are more missing ones (see above) wan.sendline('ip route del 200.0.0.0/8 via 192.168.3.2') wan.expect(prompt) if hasattr(self, 'results'): r = self.results.get(self.job_id) if r.status == "running": self.results.stop(self.job_id) # TODO: full recovery... for d in [wan,lan]: d.sendline('ifconfig %s up' % d.iface_dut) d.expect(prompt) # make sure board is back in a sane state board.sendcontrol('c') board.sendline() if 0 != board.expect([pexpect.TIMEOUT] + board.uprompt, timeout=5): board.reset() board.wait_for_linux()
def runTest(self): # setup port forwarding to lan netperf server lan_priv_ip = lan.get_interface_ipaddr(lan.iface_dut) board.uci_forward_traffic_redirect("tcp", "12865", lan_priv_ip) # setup port for data socket separate from control port board.uci_forward_traffic_redirect("tcp", "12866", lan_priv_ip) wan_ip = board.get_interface_ipaddr(board.wan_iface) # send at router ip, which will forward to lan client wan.sendline('') wan.expect(prompt) board.sendline('mpstat -P ALL 30 1') speed = self.run_netperf(wan, wan_ip, "-c -C -l 30 -t TCP_STREAM -- -P ,12866") board.expect( 'Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) lib.common.test_msg("Average cpu usage was %s" % avg_cpu) self.result_message = "Setup NetperfReverse and Ran Throughput (Speed = %s 10^6bits/sec, CPU = %s)" % ( speed, avg_cpu)
def runTest(self): board.sendline('cat /etc/os-release') # PRETTY_NAME=RDK (A Yocto Project 1.6 based Distro) 2.0 (krogoth) if 0 == board.expect([ "cat: can't open '/etc/os-release': No such file or directory", 'PRETTY_NAME=([^\s]*) \(A Yocto Project (?:[^\s]*?)\s?based Distro\) ([^\s]*) \(([^\)]*)\)' ]): self.skipTest("Skipping, not not an OE based distro") index = 1 bsp_type = board.match.group(index) index += 1 if len(board.match.groups()) == 4: oe_version = board.match.group(index) index += 1 else: oe_version = "Unknown" bsp_version = board.match.group(index) index += 1 oe_version_string = board.match.group(index) index += 1 board.expect(prompt) print("#########################################") print("bsp-type = %s" % bsp_type) print("oe-version = %s" % oe_version) print("bsp-version = %s" % bsp_version) print("oe-version-string = %s" % oe_version_string) print("#########################################") self.result_message="BSP = %s, BSP version = %s, OE version = %s, OE version string = %s" % \ (bsp_type, bsp_version, oe_version, oe_version_string) self.logged['bsp-type'] = bsp_type self.logged['oe-version'] = oe_version self.logged['bsp-version'] = bsp_version self.logged['oe-version-string'] = oe_version_string
def runTest(self): board.sendline('mpstat -P ALL 30 1') opts = "" num_conns = 1 up = down = 0.0 for i in range(0, num_conns): self.run_netperf_cmd(lan, "192.168.0.1 -c -C -l 30 -- %s" % opts) self.run_netperf_cmd( lan, "192.168.0.1 -c -C -l 30 -t TCP_MAERTS -- %s" % opts) for i in range(0, num_conns): up += float(self.run_netperf_parse(lan)) down += float(self.run_netperf_parse(lan)) board.expect( 'Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) msg = "Bidir speed was %s 10^6Mbits/sec with %s average cpu" % ( (up + down), avg_cpu) lib.common.test_msg(msg) self.result_message = msg
def runTest(self, node1=lan, node2=wan, firewall=True): mpstat_present = self.mpstat_ok() if firewall: self.run_iperf_server(node1, opts=self.server_opts_reverse(node1)) else: self.run_iperf_server(node1, opts=self.server_opts_forward()) self.run_iperf_server(node2, opts=self.server_opts_forward()) board.sendline('cat /proc/net/nf_conntrack | wc -l') board.expect(prompt) # this is running an arbitrary time, we will ctrl-c and get results if mpstat_present: board.sendline('mpstat -P ALL 10000 1') board.expect('Linux') self.run_iperf(node2, opts=opts, target=self.reverse_ip()) self.run_iperf(node1, opts=opts) rate = 0.0 rate += float(self.parse_iperf(node1)) rate += float(self.parse_iperf(node2)) if mpstat_present: board.sendcontrol('c') board.expect( 'Average.*idle\r\nAverage:\s+all(\s+[0-9]+.[0-9]+){10}\r\n') idle_cpu = float(board.match.group(1)) avg_cpu = 100 - float(idle_cpu) self.logged['avg_cpu'] = float(avg_cpu) else: avg_cpu = "N/A" self.kill_iperf(node1) self.kill_iperf(node2) msg = 'iPerf bidir WAN to LAN (%s Mbps, CPU=%s)' % (rate, avg_cpu) lib.common.test_msg("\n%s" % msg) self.logged['rate'] = float(rate) self.result_message = msg
def runTest(self): board.sendline('\n date') board.expect('date') board.expect(prompt) board.sendline('sleep 300') board.expect('sleep ') board.expect(prompt, timeout=310) board.sendline('date') board.expect('date') board.expect(prompt)
def runTest(self): board.sendline('\nls -l /etc/config/') board.expect('/etc/config/', timeout=5) board.expect(prompt) board.sendline('ls -l /etc/config/ | wc -l') board.expect(r'(\d+)\r\n') num_files = int(board.match.group(1)) board.expect(prompt) board.sendline('uci show') board.expect(prompt, searchwindowsize=50) self.result_message = 'Dumped all current uci settings from %s files in /etc/config/.' % num_files