Test cases for the helpers, providing a descriptor strings for synthetic fields. The patch includes a fix of a bug discovered with the new tests. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- tracecruncher/ft_utils.py | 6 ++--- .../tests/1_unit/test_01_ftracepy_unit.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tracecruncher/ft_utils.py b/tracecruncher/ft_utils.py index 7e0e642..6db426e 100644 --- a/tracecruncher/ft_utils.py +++ b/tracecruncher/ft_utils.py @@ -425,10 +425,8 @@ def synth_field_rename(event, field, name): def synth_field_deltaT(name='delta_T', hd=False): """ Create descriptor for time-diference synthetic field. """ - if hd: - return 'delta_t {0} hd'.format(name) - - return 'delta_t {0} hd'.format(name) + d = 'delta_t {0}'.format(name) + return (d, d+' hd')[hd] def synth_field_delta_start(name, start_field, end_field): diff --git a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py index aea29db..f942b6b 100644 --- a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py +++ b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py @@ -829,6 +829,28 @@ swaking = tc.tc_event('sched', 'sched_waking') sswitch = tc.tc_event('sched', 'sched_switch') class SynthOopTestCase(unittest.TestCase): + def test_field_deltaT(self): + f = tc.synth_field_deltaT() + self.assertEqual(f, 'delta_t delta_T') + f = tc.synth_field_deltaT(hd=True) + self.assertEqual(f, 'delta_t delta_T hd') + f = tc.synth_field_deltaT(name='dT', hd=True) + self.assertEqual(f, 'delta_t dT hd') + f = tc.synth_field_deltaT(name='dT', hd=False) + self.assertEqual(f, 'delta_t dT') + + def test_field_delta_start(self): + f = tc.synth_field_delta_start('dS', 'foo', 'bar') + self.assertEqual(f, 'delta_start dS foo bar') + + def test_field_delta_end(self): + f = tc.synth_field_delta_end('dE', 'foo', 'bar') + self.assertEqual(f, 'delta_end dE foo bar') + + def test_field_sum(self): + f = tc.synth_field_sum('Sm', 'foo', 'bar') + self.assertEqual(f, 'sum Sm foo bar') + def test_synt_create(self): start = tc.synth_event_item(event=swaking, fields=['target_cpu', 'prio'], -- 2.32.0