Skip to content

Commit

Permalink
Merge pull request #818 from tlsfuzzer/runner-updates
Browse files Browse the repository at this point in the history
Runner updates
  • Loading branch information
tomato42 committed Jun 2, 2023
2 parents 0231222 + 21e1330 commit 32444fa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
9 changes: 9 additions & 0 deletions tests/test_tlsfuzzer_timing_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def test_create_dir(self):
TimingRunner("test", [], "/outdir", "localhost", 4433, "lo")
mock_mkdir.assert_called_once()

def test_create_dir_with_duplicate(self):
with mock.patch('tlsfuzzer.timing_runner.os.mkdir') as mock_mkdir:
if version_info > (3, 0):
mock_mkdir.side_effect = [FileExistsError("Dir exists"), None]
else:
mock_mkdir.side_effect = [OSError("Dir exists"), None]
TimingRunner("test", [], "/outdir", "localhost", 4433, "lo")
self.assertEqual(2, len(mock_mkdir.mock_calls))

def test_check_extraction_availability(self):
extraction_present = True
try:
Expand Down
27 changes: 21 additions & 6 deletions tlsfuzzer/timing_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def _report_progress(status): # pragma: no cover
elapsed = time.time()-start_exec
elapsed_str = TimingRunner._format_seconds(elapsed)
done = status[0]*100.0/status[1]
remaining = (100-done)*elapsed/done
try:
remaining = (100-done)*elapsed/done
except ZeroDivisionError:
remaining = status[1]*elapsed
remaining_str = TimingRunner._format_seconds(remaining)
eta = time.strftime("%H:%M:%S %d-%m-%Y",
time.localtime(time.time()+remaining))
Expand Down Expand Up @@ -241,7 +244,7 @@ def sniff(self):
self.port)
flags = ['-i', self.interface,
'-s', '0',
'--time-stamp-precision', 'nano'
'--time-stamp-precision', 'nano',
'--buffer-size=102400'] # units are KiB

output_file = os.path.join(self.out_dir, "capture.pcap")
Expand Down Expand Up @@ -333,8 +336,20 @@ def create_output_directory(self, name):
:param str name: Name of the test being run
:return: str Path to newly created directory
"""
test_name = os.path.basename(name)
out_dir = os.path.join(os.path.abspath(self.out_dir),
"{0}_{1}".format(test_name, int(time.time())))
os.mkdir(out_dir)
if sys.version_info >= (3, 0):
exc = FileExistsError
else:
exc = OSError

while True:
test_name = os.path.basename(name)
out_dir = os.path.join(os.path.abspath(self.out_dir),
"{0}_{1}".format(
test_name,
int(time.time())))
try:
os.mkdir(out_dir)
except exc:
continue
break
return out_dir

0 comments on commit 32444fa

Please sign in to comment.