From 5c4e3a231f6a46cef9d9ae9dc87d92b12ad97fb9 Mon Sep 17 00:00:00 2001 From: Leo Huang Date: Fri, 25 Oct 2024 19:56:10 +1100 Subject: [PATCH] benchmarks/iperf: fix JS TypeError when parsing iperf result with an error (#3925) (#3928) Co-authored-by: Leo Huang --- .../mvc/app/views/OPNsense/iperf/index.volt | 90 ++++++++++--------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/benchmarks/iperf/src/opnsense/mvc/app/views/OPNsense/iperf/index.volt b/benchmarks/iperf/src/opnsense/mvc/app/views/OPNsense/iperf/index.volt index 85ca1d448..8cef80501 100644 --- a/benchmarks/iperf/src/opnsense/mvc/app/views/OPNsense/iperf/index.volt +++ b/benchmarks/iperf/src/opnsense/mvc/app/views/OPNsense/iperf/index.volt @@ -51,47 +51,55 @@ function result_to_html(elements) { // only if test did already run if ('result' in element) { - var result = element.result, - start = result.start, - connection = start.connected[0], - intervals = result.intervals, - test_end = result.end, - cpu = test_end.cpu_utilization_percent; - // General - output += "

{{ lang._('General') }}

"; - output += ''; - output += table_tr_kv("{{ lang._('Time') }}", start.timestamp.time); - output += table_tr_kv("{{ lang._('Duration') }}", start.test_start.duration); - output += table_tr_kv("{{ lang._('Block Size') }}", start.test_start.blksize); - output += "
"; - // connection - output += "

{{ lang._('Connection') }}

"; - output += ''; - output += table_tr_kv("{{ lang._('Local Host') }}", connection.local_host); - output += table_tr_kv("{{ lang._('Local Port') }}", connection.local_port); - output += table_tr_kv("{{ lang._('Remote Host') }}", connection.remote_host); - output += table_tr_kv("{{ lang._('Remote Port') }}", connection.remote_port); - output += "
"; - // CPU Usage - output += "

{{ lang._('CPU Usage') }}

"; - output += ''; - output += table_tr_kv("{{ lang._('Host Total') }}", cpu.host_total.toFixed(2)); - output += table_tr_kv("{{ lang._('Host User') }}", cpu.host_user.toFixed(2)); - output += table_tr_kv("{{ lang._('Host System') }}", cpu.host_system.toFixed(2)); - output += table_tr_kv("{{ lang._('Remote Total') }}", cpu.remote_total.toFixed(2)); - output += table_tr_kv("{{ lang._('Remote User') }}", cpu.remote_user.toFixed(2)); - output += table_tr_kv("{{ lang._('Remote System') }}", cpu.remote_system.toFixed(2)); - output += "
"; - // performance data - output += "

{{ lang._('Performance Data') }}

"; - output += ''; - var fields = ['sum_sent', 'sum_received']; - output += table_tr_transpose("{{ lang._('Start') }}","start",fields, test_end); - output += table_tr_transpose("{{ lang._('End') }}","end",fields, test_end); - output += table_tr_transpose("{{ lang._('Seconds') }}","seconds",fields, test_end); - output += table_tr_transpose("{{ lang._('Bytes') }}","bytes",fields, test_end); - output += table_tr_transpose("{{ lang._('Bits Per Second') }}","bits_per_second",fields, test_end); - output += "
"; + var result = element.result; + if ('error' in result) { + // We can't assume that any other fields exist when there's an error + output += "

{{ lang._('Error') }}

"; + output += ''; + output += table_tr_kv("{{ lang._('Error message') }}", result.error); + output += "
"; + } else { + var start = result.start, + connection = start.connected[0], + intervals = result.intervals, + test_end = result.end, + cpu = test_end.cpu_utilization_percent; + // General + output += "

{{ lang._('General') }}

"; + output += ''; + output += table_tr_kv("{{ lang._('Time') }}", start.timestamp.time); + output += table_tr_kv("{{ lang._('Duration') }}", start.test_start.duration); + output += table_tr_kv("{{ lang._('Block Size') }}", start.test_start.blksize); + output += "
"; + // connection + output += "

{{ lang._('Connection') }}

"; + output += ''; + output += table_tr_kv("{{ lang._('Local Host') }}", connection.local_host); + output += table_tr_kv("{{ lang._('Local Port') }}", connection.local_port); + output += table_tr_kv("{{ lang._('Remote Host') }}", connection.remote_host); + output += table_tr_kv("{{ lang._('Remote Port') }}", connection.remote_port); + output += "
"; + // CPU Usage + output += "

{{ lang._('CPU Usage') }}

"; + output += ''; + output += table_tr_kv("{{ lang._('Host Total') }}", cpu.host_total.toFixed(2)); + output += table_tr_kv("{{ lang._('Host User') }}", cpu.host_user.toFixed(2)); + output += table_tr_kv("{{ lang._('Host System') }}", cpu.host_system.toFixed(2)); + output += table_tr_kv("{{ lang._('Remote Total') }}", cpu.remote_total.toFixed(2)); + output += table_tr_kv("{{ lang._('Remote User') }}", cpu.remote_user.toFixed(2)); + output += table_tr_kv("{{ lang._('Remote System') }}", cpu.remote_system.toFixed(2)); + output += "
"; + // performance data + output += "

{{ lang._('Performance Data') }}

"; + output += ''; + var fields = ['sum_sent', 'sum_received']; + output += table_tr_transpose("{{ lang._('Start') }}","start",fields, test_end); + output += table_tr_transpose("{{ lang._('End') }}","end",fields, test_end); + output += table_tr_transpose("{{ lang._('Seconds') }}","seconds",fields, test_end); + output += table_tr_transpose("{{ lang._('Bytes') }}","bytes",fields, test_end); + output += table_tr_transpose("{{ lang._('Bits Per Second') }}","bits_per_second",fields, test_end); + output += "
"; + } } } $('#resultcontainer').html(output);