diff mbox series

[3/8] trace-cruncher: Add tests for synth helper APIs

Message ID 20220210152339.363943-4-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series trace-cruncher:Fixes before v0.2 (Beta) | expand

Commit Message

Yordan Karadzhov Feb. 10, 2022, 3:23 p.m. UTC
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@gmail.com>
---
 tracecruncher/ft_utils.py                     |  6 ++---
 .../tests/1_unit/test_01_ftracepy_unit.py     | 22 +++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
diff mbox series

Patch

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'],