| #!/usr/bin/python2.7 |
| """Tests for report.""" |
| |
| import ifstats |
| import report |
| from wvtest import wvtest |
| |
| |
| @wvtest.wvtest |
| def LoadExternalData(): |
| print |
| report.LoadNRates() |
| wvtest.WVPASS(report.nrates) |
| |
| idx = (0, 20, 800) |
| print 'Testing MCS rate in file', idx |
| wvtest.WVPASSEQ(report.nrates[idx], 6.5) |
| |
| idx = (25, 40, 400) |
| print 'Testing computed MCS rate', idx |
| wvtest.WVPASSEQ(report.nrates[idx], 120) |
| |
| print |
| report.LoadChannels() |
| wvtest.WVPASS(report.channels) |
| |
| ch = 5 |
| print 'Testing 2.4GHz channel', ch |
| wvtest.WVPASSEQ(report.channels[ch], 2432) |
| |
| ch = 149 |
| print 'Testing 5GHz channel', ch |
| wvtest.WVPASSEQ(report.channels[ch], 5745) |
| |
| |
| @wvtest.wvtest |
| def TVBoxReport(): |
| rpt = 'testdata/wifi-1424739295.41-0010' |
| |
| print 'Restoring report' |
| system, cache = ifstats.Restore(rpt) |
| wvtest.WVPASSEQ(len(system), 1) |
| wvtest.WVPASS('Linux' in system) |
| |
| print 'Checking IP address' |
| addrmap = ifstats.fabric.ParseIpAddr(cache['ipaddr']) |
| wvtest.WVPASSEQ(addrmap.get('lo'), '127.0.0.1/32') |
| wvtest.WVPASSEQ(addrmap.get('wcli0'), '192.168.1.222/24') |
| |
| print 'Checking for link information' |
| data = ifstats.fabric.ParseIwLink(cache['iwlink']) |
| wvtest.WVPASSEQ(data.get('SSID'), 'GSAFNS1441P0208_TestWifi') |
| wvtest.WVPASSEQ(data.get('BSSID'), 'f4:f5:e8:80:f3:d0') |
| |
| got = report.ReportLine(rpt) |
| want = { |
| 'Steps': 10, |
| 'Channel': 5745, |
| 'Width': 80, |
| 'RSSI': -39, |
| 'TCP BW up': 92.1, |
| 'TCP BW up units': 'Mbits/sec', |
| 'UDP BW up': 91.2, |
| 'UDP BW up units': 'Mbits/sec', |
| } |
| |
| print 'Checking report.' |
| for key, value in want.items(): |
| print key |
| wvtest.WVPASSEQ(got[key], value) |
| del got[key] |
| |
| print |
| print 'Not checked:', got |
| |
| |
| @wvtest.wvtest |
| def MacbookReport(): |
| rpt = 'testdata/wifi-1424744066.47-0010' |
| got = report.ReportLine(rpt) |
| want = { |
| 'Steps': 10, |
| 'Channel': 5755, |
| 'Width': 40, |
| 'RSSI': -29, |
| 'Noise': -90, |
| 'Shared': 17, |
| 'Interfering': 10, |
| 'MCS': 21, |
| 'TCP BW up': 196.0, |
| 'TCP BW up units': 'Mbits/sec', |
| 'UDP BW up': 260.0, |
| 'UDP BW up units': 'Mbits/sec', |
| } |
| |
| print 'Checking report.' |
| for key, value in want.items(): |
| print key |
| wvtest.WVPASSEQ(got[key], value) |
| del got[key] |
| |
| print 'PHY rate' |
| wvtest.WVPASS(abs(got['PHY'] - 340.9) < 0.1) |
| del got['PHY'] |
| |
| print |
| print 'Not checked:', got |
| |
| |
| @wvtest.wvtest |
| def SkidReport(): |
| rpt = 'testdata/wifi-1431102603.48-0103' |
| |
| print 'Checking subset of skid report.' |
| line = report.ReportLine(rpt) |
| wvtest.WVPASSEQ(line['isostream'], |
| '50.638s 14Mbps offset=0.003s disconn=0/0.000s ' |
| 'drops=2/0.009s/-0.049s') |
| |
| |
| @wvtest.wvtest |
| def ReportWithHyphensInPath(): |
| rpt = 'testdata/this-failed-before/wifi-1425669615.33-0010' |
| try: |
| _ = report.ReportLine(rpt) |
| except ValueError: |
| wvtest.WVFAIL('Failed to read report directory with hyphens in path.') |
| return |
| |
| wvtest.WVPASS('Report with hyphens in path read successfully.') |
| |
| |
| @wvtest.wvtest |
| def ReportWithoutIperfFiles(): |
| try: |
| rl = report.ReportLine('testdata/wifi-1426545351.85-0085') |
| for key, value in rl.items(): |
| if key.startswith('TCP BW') or key.startswith('UDP BW'): |
| wvtest.WVFAIL("Report included unexpected field: report['{}'] = {}" |
| .format(key, value)) |
| except IOError: |
| wvtest.WVFAIL('Failed to read report without iperf output files.') |
| |
| wvtest.WVPASS('Report without iperf files succeeded.') |
| |
| |
| if __name__ == '__main__': |
| wvtest.wvtest_main() |