Skip to content

Commit b83deea

Browse files
authored
Added %results% placeholder for logging and profiling end-to-end test configuration (#4980)
1 parent 2b227dd commit b83deea

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

tests/end-to-end.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ def __init__(
6969
self._test_sources_path = test_sources_path
7070
self._tools_path = tools_path
7171

72+
def _GetLoggingOptions(self, command, logging_options):
73+
"""Determines the logging options.
74+
75+
Args:
76+
command (str): command the logging options are for.
77+
logging_options (list[str]): logging options from the test definition.
78+
79+
Returns:
80+
[str]: logging options.
81+
"""
82+
return [
83+
option.replace('%command%', command).replace(
84+
'%results%', self._test_results_path)
85+
for option in logging_options]
86+
87+
def _GetProfilinggOptions(self, profiling_options):
88+
"""Determines the profiling options.
89+
90+
Args:
91+
profiling_options (list[str]): profiling options from the test definition.
92+
93+
Returns:
94+
[str]: profiling options.
95+
"""
96+
return [
97+
option.replace('%results%', self._test_results_path)
98+
for option in profiling_options]
99+
72100
def _RunCommand(self, command, stdout=None, stderr=None):
73101
"""Runs a command.
74102
@@ -632,9 +660,10 @@ def _RunPsort(
632660
if output_filter:
633661
output_options.append(output_filter)
634662

635-
logging_options = [
636-
option.replace('%command%', 'psort')
637-
for option in test_definition.logging_options]
663+
logging_options = self._GetLoggingOptions(
664+
'psort', test_definition.logging_options)
665+
profiling_options = self._GetProfilinggOptions(
666+
test_definition.profiling_options)
638667

639668
stdout_file = os.path.join(
640669
temp_directory, '{0:s}-psort.out'.format(test_definition.name))
@@ -646,7 +675,7 @@ def _RunPsort(
646675
command.extend(output_options)
647676
command.extend(logging_options)
648677
command.extend(['--status-view', 'none', '--unattended'])
649-
command.extend(test_definition.profiling_options)
678+
command.extend(profiling_options)
650679

651680
with open(stdout_file, 'w', encoding='utf-8') as stdout:
652681
with open(stderr_file, 'w', encoding='utf-8') as stderr:
@@ -758,18 +787,20 @@ def _RunLog2Timeline(
758787
self._test_sources_path, yara_rules_path)
759788
extract_options.extend(['--yara-rules', yara_rules_path])
760789

761-
logging_options = [
762-
option.replace('%command%', 'log2timeline')
763-
for option in test_definition.logging_options]
790+
logging_options = self._GetLoggingOptions(
791+
'log2timeline', test_definition.logging_options)
792+
profiling_options = self._GetProfilinggOptions(
793+
test_definition.profiling_options)
764794

765795
stdout_file = os.path.join(
766796
temp_directory, '{0:s}-log2timeline.out'.format(test_definition.name))
767797
stderr_file = os.path.join(
768798
temp_directory, '{0:s}-log2timeline.err'.format(test_definition.name))
799+
769800
command = [self._log2timeline_path]
770801
command.extend(extract_options)
771802
command.extend(logging_options)
772-
command.extend(test_definition.profiling_options)
803+
command.extend(profiling_options)
773804
command.extend(['--storage-file', storage_file, source_path])
774805

775806
with open(stdout_file, 'w', encoding='utf-8') as stdout:
@@ -972,9 +1003,10 @@ def _RunPsteal(
9721003
temp_directory, test_definition.output_file)
9731004
psteal_options.extend(['-w', output_file_path])
9741005

975-
logging_options = [
976-
option.replace('%command%', 'psteal')
977-
for option in test_definition.logging_options]
1006+
logging_options = self._GetLoggingOptions(
1007+
'psteal', test_definition.logging_options)
1008+
profiling_options = self._GetProfilinggOptions(
1009+
test_definition.profiling_options)
9781010

9791011
stdout_file = os.path.join(
9801012
temp_directory, '{0:s}-psteal.out'.format(test_definition.name))
@@ -986,7 +1018,7 @@ def _RunPsteal(
9861018
command.extend(logging_options)
9871019
command.extend(output_options)
9881020
command.extend(['--status-view', 'none', '--unattended'])
989-
command.extend(test_definition.profiling_options)
1021+
command.extend(profiling_options)
9901022

9911023
with open(stdout_file, 'w', encoding='utf-8') as stdout:
9921024
with open(stderr_file, 'w', encoding='utf-8') as stderr:
@@ -1451,9 +1483,10 @@ def _RunImageExport(self, test_definition, temp_directory, source_path):
14511483

14521484
output_options = ['-w', exported_files_path]
14531485

1454-
logging_options = [
1455-
option.replace('%command%', 'image_export')
1456-
for option in test_definition.logging_options]
1486+
logging_options = self._GetLoggingOptions(
1487+
'image_export', test_definition.logging_options)
1488+
profiling_options = self._GetProfilinggOptions(
1489+
test_definition.profiling_options)
14571490

14581491
stdout_file = os.path.join(
14591492
temp_directory, '{0:s}-image_export.out'.format(test_definition.name))
@@ -1464,7 +1497,7 @@ def _RunImageExport(self, test_definition, temp_directory, source_path):
14641497
command.extend(export_options)
14651498
command.extend(output_options)
14661499
command.extend(logging_options)
1467-
command.extend(test_definition.profiling_options)
1500+
command.extend(profiling_options)
14681501
command.append(source_path)
14691502

14701503
with open(stdout_file, 'w', encoding='utf-8') as stdout:

0 commit comments

Comments
 (0)