linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 3/8] trace-cruncher: Add tests for synth helper APIs
Date: Thu, 10 Feb 2022 17:23:34 +0200	[thread overview]
Message-ID: <20220210152339.363943-4-y.karadz@gmail.com> (raw)
In-Reply-To: <20220210152339.363943-1-y.karadz@gmail.com>

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 --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


  parent reply	other threads:[~2022-02-10 15:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 15:23 [PATCH 0/8] trace-cruncher:Fixes before v0.2 (Beta) Yordan Karadzhov (VMware)
2022-02-10 15:23 ` [PATCH 1/8] trace-cruncher: Prefix all python class names with 'tc_' Yordan Karadzhov (VMware)
2022-02-10 15:23 ` [PATCH 2/8] trace-cruncher: Fix bug in the constructor if tc_synth class Yordan Karadzhov (VMware)
2022-02-10 15:23 ` Yordan Karadzhov (VMware) [this message]
2022-02-10 15:23 ` [PATCH 4/8] trace-cruncher: Code cleanup in the constructor of tc_synth Yordan Karadzhov (VMware)
2022-02-10 15:23 ` [PATCH 5/8] trace-cruncher: Rename python function argument in PyFtrace_eprobe Yordan Karadzhov (VMware)
2022-02-10 15:23 ` [PATCH 6/8] trace-cruncher: Add tc_eprobe class to ft_utiles Yordan Karadzhov (VMware)
2022-02-10 15:23 ` [PATCH 7/8] trace-cruncher: Check kernel support in the eprobe constructor Yordan Karadzhov (VMware)
2022-02-10 15:23 ` [PATCH 8/8] trace-cruncher: Add more comments to the examples Yordan Karadzhov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220210152339.363943-4-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).