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: rostedt@goodmis.org, warthog9@eaglescrag.net,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH v3 10/11] trace-cruncher: Add testing
Date: Thu,  1 Jul 2021 14:14:17 +0300	[thread overview]
Message-ID: <20210701111418.18386-11-y.karadz@gmail.com> (raw)
In-Reply-To: <20210701111418.18386-1-y.karadz@gmail.com>

Add basic infrastructure for CI testing.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 tests/0_get_data/__init__.py                  |   0
 tests/0_get_data/test_get_data.py             |  26 +
 tests/1_unit/__init__.py                      |   0
 tests/1_unit/test_01_ftracepy_unit.py         | 471 ++++++++++++++++++
 tests/1_unit/test_02_datawrapper_unit.py      |  41 ++
 tests/1_unit/test_03_ksharkpy_unit.py         |  72 +++
 tests/2_integration/__init__.py               |   0
 .../test_01_ftracepy_integration.py           | 113 +++++
 .../test_03_ksharkpy_integration.py           |  25 +
 tests/__init__.py                             |   0
 10 files changed, 748 insertions(+)
 create mode 100644 tests/0_get_data/__init__.py
 create mode 100755 tests/0_get_data/test_get_data.py
 create mode 100644 tests/1_unit/__init__.py
 create mode 100644 tests/1_unit/test_01_ftracepy_unit.py
 create mode 100755 tests/1_unit/test_02_datawrapper_unit.py
 create mode 100755 tests/1_unit/test_03_ksharkpy_unit.py
 create mode 100644 tests/2_integration/__init__.py
 create mode 100755 tests/2_integration/test_01_ftracepy_integration.py
 create mode 100755 tests/2_integration/test_03_ksharkpy_integration.py
 create mode 100644 tests/__init__.py

diff --git a/tests/0_get_data/__init__.py b/tests/0_get_data/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/0_get_data/test_get_data.py b/tests/0_get_data/test_get_data.py
new file mode 100755
index 0000000..53decd0
--- /dev/null
+++ b/tests/0_get_data/test_get_data.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: LGPL-2.1
+
+Copyright (C) 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import os
+import sys
+import shutil
+import unittest
+import git
+
+class GetTestData(unittest.TestCase):
+    def test_get_data(self):
+        data_dir = 'testdata'
+        if os.path.exists(data_dir) and os.path.isdir(data_dir):
+            shutil.rmtree(data_dir)
+
+        github_repo = 'https://github.com/yordan-karadzhov/kernel-shark_testdata.git'
+        repo = git.Repo.clone_from(github_repo, data_dir)
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/1_unit/__init__.py b/tests/1_unit/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/1_unit/test_01_ftracepy_unit.py b/tests/1_unit/test_01_ftracepy_unit.py
new file mode 100644
index 0000000..e11c034
--- /dev/null
+++ b/tests/1_unit/test_01_ftracepy_unit.py
@@ -0,0 +1,471 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: LGPL-2.1
+
+Copyright (C) 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import os
+import sys
+import unittest
+import tracecruncher.ftracepy as ft
+
+instance_name = 'test_instance1'
+another_instance_name = 'test_instance2'
+
+class InstanceTestCase(unittest.TestCase):
+    def test_dir(self):
+        tracefs_dir = ft.dir()
+        self.assertTrue(os.path.isdir(tracefs_dir))
+        instances_dir = tracefs_dir + '/instances/'
+        self.assertTrue(os.path.isdir(instances_dir))
+
+    def test_create_instance(self):
+        ft.create_instance(instance_name)
+        self.assertTrue(ft.is_tracing_ON(instance_name))
+        instances_dir = ft.dir() + '/instances/'
+        self.assertTrue(os.path.isdir(instances_dir + instance_name))
+
+        auto_inst = ft.create_instance(tracing_on=False)
+        self.assertFalse(ft.is_tracing_ON(auto_inst))
+        ft.destroy_instance(auto_inst)
+
+    def test_destroy_instance(self):
+        ft.destroy_instance(instance_name)
+        instances_dir = ft.dir() + '/instances/'
+        self.assertFalse(os.path.isdir(instances_dir + instance_name))
+
+        err = 'Unable to destroy trace instances'
+        with self.assertRaises(Exception) as context:
+            ft.destroy_instance(instance_name)
+        self.assertTrue(err in str(context.exception))
+
+        ft.create_instance(instance_name)
+        ft.create_instance(another_instance_name)
+        ft.destroy_all_instances()
+        self.assertFalse(os.path.isdir(instances_dir + instance_name))
+
+        ft.create_instance(instance_name)
+        ft.create_instance(another_instance_name)
+        ft.destroy_instance('all')
+        self.assertFalse(os.path.isdir(instances_dir + instance_name))
+
+    def test_get_all(self):
+        ft.create_instance(instance_name)
+        ft.create_instance(another_instance_name)
+        self.assertEqual(ft.get_all_instances(),
+                         [instance_name, another_instance_name])
+        ft.destroy_all_instances()
+
+    def test_instance_dir(self):
+        ft.create_instance(instance_name)
+        tracefs_dir = ft.dir();
+        instance_dir = tracefs_dir + '/instances/' + instance_name
+        self.assertEqual(instance_dir, ft.instance_dir(instance_name))
+        ft.destroy_all_instances()
+
+class PyTepTestCase(unittest.TestCase):
+    def test_init_local(self):
+        tracefs_dir = ft.dir()
+        tep = ft.tep_handle();
+        tep.init_local(tracefs_dir);
+
+        tep.init_local(dir=tracefs_dir, systems=['sched', 'irq']);
+
+        ft.create_instance(instance_name)
+        tracefs_dir = ft.instance_dir(instance_name)
+        tep.init_local(dir=tracefs_dir, systems=['sched', 'irq']);
+
+        err='function missing required argument \'dir\''
+        with self.assertRaises(Exception) as context:
+            tep.init_local(systems=['sched', 'irq']);
+        self.assertTrue(err in str(context.exception))
+
+        err='Failed to get local events from \'no_dir\''
+        with self.assertRaises(Exception) as context:
+            tep.init_local(dir='no_dir', systems=['sched', 'irq']);
+        self.assertTrue(err in str(context.exception))
+        ft.destroy_all_instances()
+
+    def test_get_event(self):
+        tracefs_dir = ft.dir()
+        tep = ft.tep_handle();
+        tep.init_local(tracefs_dir);
+        evt = tep.get_event(system='sched', name='sched_switch');
+
+
+class PyTepEventTestCase(unittest.TestCase):
+    def test_name(self):
+        tracefs_dir = ft.dir()
+        tep = ft.tep_handle();
+        tep.init_local(tracefs_dir);
+        evt = tep.get_event(system='sched', name='sched_switch');
+        self.assertEqual(evt.name(), 'sched_switch');
+
+    def test_field_names(self):
+        tracefs_dir = ft.dir()
+        tep = ft.tep_handle();
+        tep.init_local(tracefs_dir);
+        evt = tep.get_event(system='sched', name='sched_switch');
+        fiels = evt.field_names()
+        self.assertEqual(fiels , ['common_type',
+                                  'common_flags',
+                                  'common_preempt_count',
+                                  'common_pid',
+                                  'prev_comm',
+                                  'prev_pid',
+                                  'prev_prio',
+                                  'prev_state',
+                                  'next_comm',
+                                  'next_pid',
+                                  'next_prio'])
+
+
+class TracersTestCase(unittest.TestCase):
+    def test_available_tracers(self):
+        tracers = ft.available_tracers()
+        self.assertTrue(len(tracers) > 1)
+        self.assertTrue('function' in tracers)
+
+    def test_set_tracer(self):
+        ft.set_current_tracer(tracer='function')
+        ft.set_current_tracer(tracer='')
+
+        err = 'Tracer \'zero\' is not available.'
+        with self.assertRaises(Exception) as context:
+            ft.set_current_tracer(tracer='zero')
+        self.assertTrue(err in str(context.exception))
+
+
+class EventsTestCase(unittest.TestCase):
+    def test_available_systems(self):
+        systems = ft.available_event_systems()
+        self.assertTrue(len(systems) > 1)
+        self.assertTrue('sched' in systems)
+
+        ft.create_instance(instance_name)
+        systems = ft.available_event_systems(instance_name)
+        self.assertTrue(len(systems) > 1)
+        self.assertTrue('sched' in systems)
+
+        ft.destroy_all_instances()
+
+    def test_available_system_events(self):
+        events = ft.available_system_events(system='sched')
+        self.assertTrue(len(events) > 1)
+        self.assertTrue('sched_switch' in events)
+
+        ft.create_instance(instance_name)
+        events = ft.available_system_events(instance=instance_name,
+                                              system='sched')
+        self.assertTrue(len(events) > 1)
+        self.assertTrue('sched_switch' in events)
+
+        err = 'function missing required argument'
+        with self.assertRaises(Exception) as context:
+            ft.available_system_events(instance=instance_name)
+        self.assertTrue(err in str(context.exception))
+
+        ft.destroy_all_instances()
+
+    def test_enable_event(self):
+        ft.create_instance(instance_name)
+
+        ret = ft.event_is_enabled(instance=instance_name, system='all')
+        self.assertEqual(ret, '0')
+        ft.enable_event(instance=instance_name, system='all')
+        ret = ft.event_is_enabled(instance=instance_name, system='all')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name, system='all')
+        ret = ft.event_is_enabled(instance=instance_name, system='all')
+        self.assertEqual(ret, '0')
+
+        ret = ft.event_is_enabled(instance=instance_name, event='all')
+        self.assertEqual(ret, '0')
+        ft.enable_event(instance=instance_name, event='all')
+        ret = ft.event_is_enabled(instance=instance_name, event='all')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name, event='all')
+        ret = ft.event_is_enabled(instance=instance_name, event='all')
+        self.assertEqual(ret, '0')
+
+        ret = ft.event_is_enabled(instance=instance_name, system='sched')
+        self.assertEqual(ret, '0')
+        ft.enable_event(instance=instance_name, system='sched')
+        ret = ft.event_is_enabled(instance=instance_name, system='sched')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name, system='sched')
+        ret = ft.event_is_enabled(instance=instance_name, system='sched')
+        self.assertEqual(ret, '0')
+
+        ft.enable_event(instance=instance_name,
+                        system='sched',
+                        event='sched_switch')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name,
+                         system='sched',
+                         event='sched_switch')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '0')
+
+        ft.enable_event(instance=instance_name,
+                        system='sched',
+                        event='all')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='all')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name,
+                         system='sched',
+                         event='all')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='all')
+        self.assertEqual(ret, '0')
+
+        ft.enable_event(instance=instance_name,
+                        event='sched_switch')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name,
+                         event='sched_switch')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '0')
+
+        ft.enable_event(instance=instance_name,
+                        system='all',
+                        event='sched_switch')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '1')
+        ft.disable_event(instance=instance_name,
+                         system='all',
+                         event='sched_switch')
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '0')
+
+        ft.destroy_all_instances()
+
+    def test_enable_event_err(self):
+        ft.create_instance(instance_name)
+
+        err = 'Failed to enable/disable event'
+        with self.assertRaises(Exception) as context:
+            ft.enable_event(instance=instance_name,
+                            system='zero')
+        self.assertTrue(err in str(context.exception))
+
+        with self.assertRaises(Exception) as context:
+            ft.enable_event(instance=instance_name,
+                            system='sched',
+                            event='zero')
+        self.assertTrue(err in str(context.exception))
+
+        ft.destroy_all_instances()
+
+    def test_enable_events(self):
+        ft.create_instance(instance_name)
+        ft.enable_events(instance=instance_name,
+                         events='all')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  event='all')
+        self.assertEqual(ret, '1')
+        ft.disable_events(instance=instance_name,
+                          events='all')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  event='all')
+        self.assertEqual(ret, '0')
+
+        ft.enable_events(instance=instance_name,
+                         systems=['sched', 'irq'])
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='all')
+        self.assertEqual(ret, '1')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='irq',
+                                  event='all')
+        self.assertEqual(ret, '1')
+
+        ft.disable_events(instance=instance_name,
+                          systems=['sched', 'irq'])
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='all')
+        self.assertEqual(ret, '0')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='irq',
+                                  event='all')
+        self.assertEqual(ret, '0')
+
+        ft.enable_events(instance=instance_name,
+                         systems=['sched', 'irq'],
+                         events=[['sched_switch', 'sched_waking'],
+                                 ['all']])
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '1')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_waking')
+        self.assertEqual(ret, '1')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_wakeup')
+        self.assertEqual(ret, '0')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='irq',
+                                  event='all')
+        self.assertEqual(ret, '1')
+
+        ft.disable_events(instance=instance_name,
+                          systems=['sched', 'irq'],
+                          events=[['sched_switch', 'sched_waking'],
+                                  ['all']])
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_switch')
+        self.assertEqual(ret, '0')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='sched',
+                                  event='sched_waking')
+        self.assertEqual(ret, '0')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                  system='irq',
+                                  event='all')
+        self.assertEqual(ret, '0')
+
+        ft.destroy_all_instances()
+
+    def test_enable_events_err(self):
+        ft.create_instance(instance_name)
+
+        err = 'Inconsistent \"events\" argument'
+        with self.assertRaises(Exception) as context:
+            ft.enable_events(instance=instance_name,
+                             systems=['sched'],
+                             events=['all'])
+        self.assertTrue(err in str(context.exception))
+
+        err = 'Failed to enable events for unspecified system'
+        with self.assertRaises(Exception) as context:
+            ft.enable_events(instance=instance_name,
+                             events=['sched_switch', 'sched_wakeup'])
+        self.assertTrue(err in str(context.exception))
+
+        err = 'Failed to enable/disable event'
+        with self.assertRaises(Exception) as context:
+            ft.enable_events(instance=instance_name,
+                             systems=['sched'],
+                             events=[['no_event']])
+        self.assertTrue(err in str(context.exception))
+
+        ft.destroy_all_instances()
+
+
+class OptionsTestCase(unittest.TestCase):
+    def test_enable_option(self):
+        ft.create_instance(instance_name)
+        opt = 'event-fork'
+        ret = ft.option_is_set(instance=instance_name,
+                                   option=opt)
+        self.assertFalse(ret)
+
+        ft.enable_option(instance=instance_name,
+                         option=opt)
+        ret = ft.option_is_set(instance=instance_name,
+                               option=opt)
+        self.assertTrue(ret)
+
+        ft.disable_option(instance=instance_name,
+                          option=opt)
+        ret = ft.option_is_set(instance=instance_name,
+                                   option=opt)
+        self.assertFalse(ret)
+
+        opt = 'no-opt'
+        err = 'Failed to set option \"no-opt\"'
+        with self.assertRaises(Exception) as context:
+            ft.enable_option(instance=instance_name,
+                             option=opt)
+        self.assertTrue(err in str(context.exception))
+
+        ft.destroy_all_instances()
+
+    def test_supported_options(self):
+        ft.create_instance(instance_name)
+        opts = ft.supported_options(instance_name)
+        self.assertTrue(len(opts) > 20)
+        self.assertTrue('event-fork' in opts)
+
+        ft.destroy_all_instances()
+
+    def test_enabled_options(self):
+        ft.create_instance(instance_name)
+        opts = ft.enabled_options(instance_name)
+        n = len(opts)
+        ft.enable_option(instance=instance_name, option='function-fork')
+        ft.enable_option(instance=instance_name, option='event-fork')
+        opts = ft.enabled_options(instance_name)
+
+        self.assertEqual(len(opts), n + 2)
+        self.assertTrue('event-fork' in opts)
+        self.assertTrue('function-fork' in opts)
+
+        ft.destroy_all_instances()
+
+
+class TracingOnTestCase(unittest.TestCase):
+    def test_ON_OF(self):
+        ft.tracing_ON()
+        self.assertTrue(ft.is_tracing_ON())
+        ft.tracing_OFF()
+
+        ft.create_instance(instance_name)
+        ft.tracing_ON(instance=instance_name)
+        self.assertTrue(ft.is_tracing_ON(instance=instance_name))
+        self.assertFalse(ft.is_tracing_ON())
+        ft.tracing_OFF(instance=instance_name)
+
+        ft.destroy_all_instances()
+
+    def test_err(self):
+        err = 'returned a result with an error set'
+        with self.assertRaises(Exception) as context:
+            ft.tracing_ON('zero')
+        self.assertTrue(err in str(context.exception))
+
+        with self.assertRaises(Exception) as context:
+            ft.tracing_OFF('zero')
+        self.assertTrue(err in str(context.exception))
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/1_unit/test_02_datawrapper_unit.py b/tests/1_unit/test_02_datawrapper_unit.py
new file mode 100755
index 0000000..58c8706
--- /dev/null
+++ b/tests/1_unit/test_02_datawrapper_unit.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: LGPL-2.1
+
+Copyright (C) 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import os
+import sys
+import unittest
+import tracecruncher.ksharkpy as ks
+import tracecruncher.npdatawrapper as dw
+
+file_1 = 'testdata/trace_test1.dat'
+
+class DwPyTestCase(unittest.TestCase):
+    def test_columns(self):
+        self.assertEqual(dw.columns(), ['event', 'cpu', 'pid', 'offset', 'time'])
+
+    def test_load(self):
+        sd = ks.open(file_1)
+        data = dw.load(sd)
+        self.assertEqual(len(dw.columns()), len(data))
+        self.assertEqual(data['pid'].size, 1530)
+
+        data_no_ts = dw.load(sd, ts_data=False)
+        self.assertEqual(data_no_ts['pid'].size, 1530)
+        self.assertEqual(len(dw.columns()) - 1, len(data_no_ts))
+
+        data_pid_cpu = dw.load(sd, evt_data=False,
+                                   ofst_data=False,
+                                   ts_data=False)
+        self.assertEqual(data_pid_cpu['cpu'].size, 1530)
+        self.assertEqual(2, len(data_pid_cpu))
+
+        ks.close()
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/1_unit/test_03_ksharkpy_unit.py b/tests/1_unit/test_03_ksharkpy_unit.py
new file mode 100755
index 0000000..c7da2a1
--- /dev/null
+++ b/tests/1_unit/test_03_ksharkpy_unit.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: LGPL-2.1
+
+Copyright (C) 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import os
+import sys
+import unittest
+import tracecruncher.ksharkpy as ks
+import tracecruncher.npdatawrapper as dw
+
+file_1 = 'testdata/trace_test1.dat'
+file_2 = 'testdata/trace_test2.dat'
+
+ss_id = 323
+
+class KsPyTestCase(unittest.TestCase):
+    def test_open_close(self):
+        sd = ks.open(file_1)
+        self.assertEqual(sd, 0)
+        sd = ks.open(file_2)
+        self.assertEqual(sd, 1)
+        ks.close()
+
+        sd = ks.open(file_1)
+        self.assertEqual(sd, 0)
+        ks.close()
+
+        err = 'Failed to open file'
+        with self.assertRaises(Exception) as context:
+            sd = ks.open('no_file')
+        self.assertTrue(err in str(context.exception))
+
+    def test_event_id(self):
+        sd = ks.open(file_1)
+        eid = ks.event_id(stream_id=sd, name='sched/sched_switch')
+        self.assertEqual(eid, ss_id)
+
+        err = 'Failed to retrieve the Id of event'
+        with self.assertRaises(Exception) as context:
+            eid = ks.event_id(stream_id=sd, name='sched/no_such_event')
+        self.assertTrue(err in str(context.exception))
+
+        ks.close()
+
+    def test_event_name(self):
+        sd = ks.open(file_1)
+        name = ks.event_name(stream_id=sd, event_id=ss_id)
+        self.assertEqual(name, 'sched/sched_switch')
+
+        err = 'Failed to retrieve the name of event'
+        with self.assertRaises(Exception) as context:
+            name = ks.event_name(stream_id=sd, event_id=2**30)
+        self.assertTrue(err in str(context.exception))
+
+        ks.close()
+
+    def read_field(self):
+        sd = ks.open(file_1)
+        data = dw.load(sd)
+        next_pid = read_event_field(stream_id=sd,
+                                    offset=data['offset'],
+                                    event_id=ss_id,
+                                    field='next_pid')
+        self.assertEqual(next_pid, 4182)
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/2_integration/__init__.py b/tests/2_integration/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/2_integration/test_01_ftracepy_integration.py b/tests/2_integration/test_01_ftracepy_integration.py
new file mode 100755
index 0000000..d3b2c6b
--- /dev/null
+++ b/tests/2_integration/test_01_ftracepy_integration.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: LGPL-2.1
+
+Copyright (C) 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import os
+import sys
+import unittest
+import tracecruncher.ftracepy as ft
+
+class InstanceTestCase(unittest.TestCase):
+    def test_create_instance(self):
+        tracefs_dir = ft.dir()
+        instances_dir = tracefs_dir + '/instances/'
+        self.assertEqual(len(os.listdir(instances_dir)), 0)
+
+        for i in range(25) :
+            instance_name = 'test_instance_%s' % i
+            ft.create_instance(instance_name)
+            self.assertTrue(os.path.isdir(instances_dir + instance_name))
+
+        for i in range(15) :
+            instance_name = 'test_instance_%s' % i
+            ft.destroy_instance(instance_name)
+            self.assertFalse(os.path.isdir(instances_dir + instance_name))
+
+        self.assertEqual(len(os.listdir(instances_dir)), 10)
+        ft.destroy_instance('all')
+        self.assertEqual(len(os.listdir(instances_dir)), 0)
+
+    def test_current_tracer(self):
+        current = ft.get_current_tracer()
+        self.assertEqual(current, 'nop')
+        ft.tracing_OFF()
+        name = 'function'
+        ft.set_current_tracer(tracer=name)
+        current = ft.get_current_tracer()
+        self.assertEqual(current, name)
+        ft.set_current_tracer()
+
+        instance_name = 'test_instance'
+        ft.create_instance(instance_name)
+        current = ft.get_current_tracer(instance=instance_name)
+        self.assertEqual(current, 'nop')
+        ft.tracing_OFF(instance=instance_name)
+        ft.set_current_tracer(instance=instance_name, tracer=name)
+        current = ft.get_current_tracer(instance=instance_name)
+        self.assertEqual(current, name)
+        ft.destroy_instance('all')
+
+    def test_enable_events(self):
+        instance_name = 'test_instance'
+        ft.create_instance(instance_name)
+        systems = ft.available_event_systems(instance=instance_name)
+        systems.remove('ftrace')
+        for s in systems:
+            ret = ft.event_is_enabled(instance=instance_name,
+                                       system=s)
+            self.assertEqual(ret, '0')
+            ft.enable_event(instance=instance_name,
+                             system=s)
+            ret = ft.event_is_enabled(instance=instance_name,
+                                       system=s)
+            self.assertEqual(ret, '1')
+
+            ft.disable_event(instance=instance_name,
+                             system=s)
+            events = ft.available_system_events(instance=instance_name,
+                                                 system=s)
+            for e in events:
+                ret = ft.event_is_enabled(instance=instance_name,
+                                           system=s,
+                                           event=e)
+                self.assertEqual(ret, '0')
+                ft.enable_event(instance=instance_name,
+                                 system=s,
+                                 event=e)
+                ret = ft.event_is_enabled(instance=instance_name,
+                                           system=s,
+                                           event=e)
+                self.assertEqual(ret, '1')
+                ret = ft.event_is_enabled(instance=instance_name,
+                                           system=s)
+                if e != events[-1]:
+                    self.assertEqual(ret, 'X')
+
+            ret = ft.event_is_enabled(instance=instance_name,
+                                       system=s)
+            self.assertEqual(ret, '1')
+
+        ret = ft.event_is_enabled(instance=instance_name,
+                                   system=s)
+        self.assertEqual(ret, '1')
+
+        ft.disable_event(instance=instance_name, event='all')
+        for s in systems:
+            ret = ft.event_is_enabled(instance=instance_name,
+                                       system=s)
+            self.assertEqual(ret, '0')
+            events = ft.available_system_events(instance=instance_name,
+                                                 system=s)
+            for e in events:
+                ret = ft.event_is_enabled(instance=instance_name,
+                                           system=s,
+                                           event=e)
+                self.assertEqual(ret, '0')
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/2_integration/test_03_ksharkpy_integration.py b/tests/2_integration/test_03_ksharkpy_integration.py
new file mode 100755
index 0000000..dd8e0b5
--- /dev/null
+++ b/tests/2_integration/test_03_ksharkpy_integration.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+"""
+SPDX-License-Identifier: LGPL-2.1
+
+Copyright (C) 2021 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@gmail.com>
+"""
+
+import os
+import sys
+import shutil
+import unittest
+import tracecruncher.ks_utils as tc
+
+class GetTestData(unittest.TestCase):
+    def test_open_and_read(self):
+        f = tc.open_file(file_name='testdata/trace_test1.dat')
+        data = f.load(pid_data=False)
+        tasks = f.get_tasks()
+        self.assertEqual(len(tasks), 29)
+        self.assertEqual(tasks['zoom'], [28121, 28137, 28141, 28199, 28201, 205666])
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
-- 
2.27.0


  parent reply	other threads:[~2021-07-01 11:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 11:14 [PATCH v3 00/11] Build trace-cruncher as Python pakage Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 01/11] trace-cruncher: Refactor the part that wraps ftrace Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 02/11] trace-cruncher: Add basic methods for tracing Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 03/11] trace-cruncher: Refactor the part that wraps libkshark Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 04/11] trace-cruncher: Add "utils" Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 05/11] trace-cruncher: Refactor the examples Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 06/11] trace-cruncher: Add ftracefy example Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 07/11] trace-cruncher: Add Makefile Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 08/11] trace-cruncher: Update README.md Yordan Karadzhov (VMware)
2021-07-01 11:14 ` [PATCH v3 09/11] trace-cruncher: Remove all leftover files Yordan Karadzhov (VMware)
2021-07-01 11:14 ` Yordan Karadzhov (VMware) [this message]
2021-07-01 11:14 ` [PATCH v3 11/11] trace-cruncher: Add github workflow for CI testing 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=20210701111418.18386-11-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=warthog9@eaglescrag.net \
    --subject='Re: [PATCH v3 10/11] trace-cruncher: Add testing' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox