Tests: clean-up test utility functions
[deliverable/lttng-analyses.git] / tests / test_cputop.py
index 5e767e270cf661d5096dc0a6bd8a9d4e17cb5fbb..93943bbc42ed51b9dd7702e168c741d100873948 100644 (file)
@@ -1,48 +1,48 @@
-from TraceTest import AnalysesTest
-import sys
-
-
-class CpuTest(AnalysesTest):
-    def __init__(self, delete_trace=True, verbose=False):
-        super().__init__(delete_trace=delete_trace,
-                         verbose=verbose)
-        self.test_list = [('cputop', self.run_no_option)]
-
+# The MIT License (MIT)
+#
+# Copyright (C) 2016 - Julien Desfossez <jdesfossez@efficios.com>
+#                      Antoine Busque <abusque@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+from .analysis_test import AnalysisTest
+
+
+class CpuTest(AnalysisTest):
     def write_trace(self):
         # runs the whole time: 100%
-        self.t.write_sched_switch(1000, 5, "swapper/5", 0, "prog100pc-cpu5", 42)
+        self.trace_writer.write_sched_switch(1000, 5, 'swapper/5',
+                                             0, 'prog100pc-cpu5', 42)
         # runs for 2s alternating with swapper out every 100ms
-        self.t.sched_switch_50pc(1100, 5000, 0, 100,
-                                 "swapper/0", 0, "prog20pc-cpu0", 30664)
+        self.trace_writer.sched_switch_50pc(1100, 5000, 0, 100, 'swapper/0',
+                                            0, 'prog20pc-cpu0', 30664)
         # runs for 2.5s alternating with swapper out every 100ms
-        self.t.sched_switch_50pc(5100, 10000, 1, 100,
-                                 "swapper/1", 0, "prog25pc-cpu1", 30665)
+        self.trace_writer.sched_switch_50pc(5100, 10000, 1, 100, 'swapper/1',
+                                            0, 'prog25pc-cpu1', 30665)
         # switch out prog100pc-cpu5
-        self.t.write_sched_switch(11000, 5, "prog100pc-cpu5", 42, "swapper/5", 0)
-        self.t.flush()
-
-    def run_no_option(self):
-        expected = """Timerange: [1969-12-31 19:00:01.000000000, 1969-12-31 19:00:11.000000000]
-Per-TID CPU Usage
-###############################################################################
-██████████████████████████████████████████████████  100.00 %  prog100pc-cpu5 (42) (prio: 20)
-████████████                                        25.00 %  prog25pc-cpu1 (30665) (prio: 20)
-██████████                                          20.00 %  prog20pc-cpu0 (30664) (prio: 20)
-Per-CPU Usage
-###############################################################################
-█████████████                                                      20.00 %  CPU 0
-████████████████                                                   25.00 %  CPU 1
-█████████████████████████████████████████████████████████████████  100.00 %  CPU 5
-
-Total CPU Usage: 48.33%
-"""
-
-        return self.compare_output('%slttng-cputop %s "%s"' % (
-                       self.cmd_root, self.common_options, self.t.trace_root),
-                       expected)
+        self.trace_writer.write_sched_switch(11000, 5, 'prog100pc-cpu5',
+                                             42, 'swapper/5', 0)
+        self.trace_writer.flush()
 
+    def test_cputop(self):
+        test_name = 'cputop'
+        expected = self.get_expected_output(test_name)
+        result = self.get_cmd_output('lttng-cputop')
 
-def test_answer():
-    t = CpuTest(verbose=True)
-    ok = t.run()
-    assert(ok)
+        self._assertMultiLineEqual(result, expected, test_name)
This page took 0.024789 seconds and 5 git commands to generate.