Skip to content

Commit

Permalink
Merge pull request tlsfuzzer#898 from tlsfuzzer/minimal-analysis
Browse files Browse the repository at this point in the history
Ability to run minimal amount of analysis
  • Loading branch information
tomato42 authored Sep 12, 2024
2 parents b987f48 + b16c6d1 commit fdb6be2
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 85 deletions.
155 changes: 132 additions & 23 deletions tests/test_tlsfuzzer_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def test_report(
#mock_box.assert_called_once()
#mock_scatter.assert_called_once()
# we're writing to report.csv, legend.csv,
# sample_stats.csv, and report.txt
self.assertEqual(mock_open.call_count, 4)
# and report.txt
self.assertEqual(mock_open.call_count, 3)
self.assertEqual(ret, 0)

@mock.patch("tlsfuzzer.analysis.Analysis._convert_to_binary")
Expand Down Expand Up @@ -111,10 +111,39 @@ def test_report_multithreaded(
#mock_box.assert_called_once()
#mock_scatter.assert_called_once()
# we're writing to report.csv, legend.csv,
# sample_stats.csv, and report.txt
self.assertEqual(mock_open.call_count, 4)
# report.txt
self.assertEqual(mock_open.call_count, 3)
self.assertEqual(ret, 0)

@mock.patch("tlsfuzzer.analysis.Analysis._convert_to_binary")
@mock.patch("__main__.__builtins__.open", new_callable=mock.mock_open)
@mock.patch("builtins.print")
@mock.patch("tlsfuzzer.analysis.Analysis.load_data")
@mock.patch("tlsfuzzer.analysis.Analysis.graph_worst_pair")
@mock.patch("tlsfuzzer.analysis.Analysis.conf_interval_plot")
@mock.patch("tlsfuzzer.analysis.Analysis.diff_scatter_plot")
@mock.patch("tlsfuzzer.analysis.Analysis.scatter_plot")
@mock.patch("tlsfuzzer.analysis.Analysis.box_plot")
@mock.patch("tlsfuzzer.analysis.Analysis.diff_ecdf_plot")
@mock.patch("tlsfuzzer.analysis.Analysis.ecdf_plot")
def test_write_sample_stats(
self, mock_ecdf, mock_diff_ecdf, mock_box, mock_scatter,
mock_diff_scatter, mock_conf_int, mock_graph_worst_pair,
mock_load_data, mock_print, mock_open, mock_convert_to_binary,
):
mock_load_data.return_value = self.timings

analysis = Analysis("/tmp", verbose=True)
ret = analysis._write_sample_stats()

mock_load_data.assert_called()
#mock_ecdf.assert_called_once()
#mock_box.assert_called_once()
#mock_scatter.assert_called_once()
# we're writing to sample_stats.csv
self.assertEqual(mock_open.call_count, 1)
self.assertIsNone(ret)

@mock.patch("builtins.print")
@mock.patch("__main__.__builtins__.open", new_callable=mock.mock_open)
@mock.patch("scipy.stats.friedmanchisquare")
Expand Down Expand Up @@ -143,8 +172,8 @@ def test_report_neq(
#mock_box.assert_called_once()
#mock_scatter.assert_called_once()
# we're writing to report.csv, legend.csv,
# sample_stats.csv, and report.txt
self.assertEqual(mock_open.call_count, 4)
# and report.txt
self.assertEqual(mock_open.call_count, 3)
self.assertEqual(ret, 1)

@mock.patch("tlsfuzzer.analysis.Analysis._convert_to_binary")
Expand Down Expand Up @@ -896,7 +925,72 @@ def test_command_line(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True, True,
True, True, True)

def test_call_with_no_sample_stats(self):
output = "/tmp"
args = ["analysis.py", "-o", output, "--no-sample-stats"]
mock_init = mock.Mock()
mock_init.return_value = None
with mock.patch('tlsfuzzer.analysis.Analysis.generate_report') as mock_report:
with mock.patch('tlsfuzzer.analysis.Analysis.__init__', mock_init):
with mock.patch("sys.argv", args):
main()
mock_report.assert_called_once()
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True, True,
True, True, False)

def test_minimal_analysis(self):
output = "/tmp"
args = ["analysis.py", "-o", output, "--minimal-analysis"]
mock_init = mock.Mock()
mock_init.return_value = None
with mock.patch('tlsfuzzer.analysis.Analysis.generate_report') as mock_report:
with mock.patch('tlsfuzzer.analysis.Analysis.__init__', mock_init):
with mock.patch("sys.argv", args):
main()
mock_report.assert_called_once()
mock_init.assert_called_once_with(
output, False, False, False, False, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, False, False, True, False,
False, False, False)

def test_call_with_no_box_test(self):
output = "/tmp"
args = ["analysis.py", "-o", output, "--no-box-test"]
mock_init = mock.Mock()
mock_init.return_value = None
with mock.patch('tlsfuzzer.analysis.Analysis.generate_report') as mock_report:
with mock.patch('tlsfuzzer.analysis.Analysis.__init__', mock_init):
with mock.patch("sys.argv", args):
main()
mock_report.assert_called_once()
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True, True,
False, True, True)

def test_call_with_no_le_sign_test(self):
output = "/tmp"
args = ["analysis.py", "-o", output, "--no-le-sign-test"]
mock_init = mock.Mock()
mock_init.return_value = None
with mock.patch('tlsfuzzer.analysis.Analysis.generate_report') as mock_report:
with mock.patch('tlsfuzzer.analysis.Analysis.__init__', mock_init):
with mock.patch("sys.argv", args):
main()
mock_report.assert_called_once()
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True, True,
True, False, True)

def test_call_with_delay_and_CR(self):
output = "/tmp"
Expand All @@ -912,7 +1006,8 @@ def test_call_with_delay_and_CR(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, 3.5, '\n', False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_workers(self):
output = "/tmp"
Expand All @@ -927,7 +1022,8 @@ def test_call_with_workers(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
200, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_verbose(self):
output = "/tmp"
Expand All @@ -942,7 +1038,8 @@ def test_call_with_verbose(self):
mock_init.assert_called_once_with(
output, True, True, True, False, True, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_multithreaded_plots(self):
output = "/tmp"
Expand All @@ -957,12 +1054,14 @@ def test_call_with_multithreaded_plots(self):
mock_init.assert_called_once_with(
output, True, True, True, True, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_no_plots(self):
output = "/tmp"
args = ["analysis.py", "-o", output, "--no-ecdf-plot",
"--no-scatter-plot", "--no-conf-interval-plot"]
"--no-scatter-plot", "--no-conf-interval-plot",
"--no-box-plot"]
mock_init = mock.Mock()
mock_init.return_value = None
with mock.patch('tlsfuzzer.analysis.Analysis.generate_report') as mock_report:
Expand All @@ -973,7 +1072,8 @@ def test_call_with_no_plots(self):
mock_init.assert_called_once_with(
output, False, False, False, False, False, None, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
False, True, True, True)

def test_call_with_frequency(self):
output = "/tmp"
Expand All @@ -988,7 +1088,8 @@ def test_call_with_frequency(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, 10*1e6, None,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_alpha(self):
output = "/tmp"
Expand All @@ -1003,7 +1104,8 @@ def test_call_with_alpha(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, 1e-3,
None, None, None, False, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_bit_size_measurements(self):
output = "/tmp"
Expand All @@ -1020,7 +1122,8 @@ def test_call_with_bit_size_measurements(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, True, True, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_skip_sanity(self):
output = "/tmp"
Expand All @@ -1037,7 +1140,8 @@ def test_call_with_skip_sanity(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, True, True, 1e-09, 4,
'measurements.csv', True, True, True, True)
'measurements.csv', True, True, True, True,
True, True, True, True)

def test_call_with_custom_measurements_filename(self):
output = "/tmp"
Expand All @@ -1056,7 +1160,8 @@ def test_call_with_custom_measurements_filename(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, True, True, 1e-09, 4,
measurements_filename, False, True, True, True)
measurements_filename, False, True, True, True,
True, True, True, True)

def test_call_with_no_smart_analysis(self):
output = "/tmp"
Expand All @@ -1074,7 +1179,8 @@ def test_call_with_no_smart_analysis(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, True, False, 1e-09, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_parametrized_smart_analysis(self):
output = "/tmp"
Expand All @@ -1096,7 +1202,8 @@ def test_call_with_parametrized_smart_analysis(self):
output, True, True, True, False, False, None, None,
None, None, None, True, True,
bit_size_desire_ci * 1e-9, bit_recognition_size,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)

def test_call_with_Hamming_weight(self):
output = "/tmp"
Expand All @@ -1112,7 +1219,8 @@ def test_call_with_Hamming_weight(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, True, True, 1e-9, 4,
'measurements.csv', False, True, True, True)
'measurements.csv', False, True, True, True,
True, True, True, True)
mock_report.assert_called_once_with(
bit_size=False, hamming_weight=True)

Expand All @@ -1131,7 +1239,8 @@ def test_call_Hamming_weight_with_minimal_analysis(self):
mock_init.assert_called_once_with(
output, True, True, True, False, False, None, None,
None, None, None, True, True, 1e-9, 4,
'measurements.csv', False, False, False, False)
'measurements.csv', False, False, False, False,
True, True, True, True)
mock_report.assert_called_once_with(
bit_size=False, hamming_weight=True)

Expand Down Expand Up @@ -2380,4 +2489,4 @@ def test_hamming_analysis_not_verbose(self):
self.assertLess(1e-6, analysis.skillings_mack_test(
os.path.join(tmpdirname, "measurements.bin")))

self.assertEqual(ret, 0)
self.assertEqual(ret, 0)
Loading

0 comments on commit fdb6be2

Please sign in to comment.