From 8e22a00c0908fbe998cfb2af66b4e35d7a397b80 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Mar 06 2018 21:04:26 +0000 Subject: [PATCH 1/4] Add FIXME about consolelog.gettraces() output --- diff --git a/skt/reporter.py b/skt/reporter.py index d0bfb01..772e8d1 100644 --- a/skt/reporter.py +++ b/skt/reporter.py @@ -162,6 +162,8 @@ class consolelog(object): insplat = False inct = False tmpdata = [] + # FIXME Check if line == True otherwise it adds an empty line at the + # end of the extracted trace. for line in self.data: if self.oopspattern.search(line): insplat = True From 29faecae3bfa9e63928ac671729276f579a5a005 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Mar 06 2018 21:15:55 +0000 Subject: [PATCH 2/4] Add basic reporter tests --- diff --git a/README b/README index 07c5cc0..8b187c6 100644 --- a/README +++ b/README @@ -11,6 +11,10 @@ Here's how to install the dependencies of skt like this: $ sudo yum install python2 python2-junit_xml beaker-client +Extra dependencies needed for running the testsuite: + + $ sudo yum install python2-mock + Run tests --------- diff --git a/tests/assets/x86_one_trace.txt b/tests/assets/x86_one_trace.txt new file mode 100644 index 0000000..500e6ee --- /dev/null +++ b/tests/assets/x86_one_trace.txt @@ -0,0 +1,43 @@ +[ 0.000000] Linux version 4-5-fake (debian-kernel@lists.debian.org) (gcc version 7.3.0 (Debian 7.3.0-3)) #1 SMP Debian 4.15.4-1 (2018-02-18) +[166357.529863] BUG: unable to handle kernel paging request at ffffffe8 +[166357.529901] IP: [] alloc_vmap_area.isra.20+0x12a/0x2c0 +[166357.529924] *pdpt = 0000000001f1c001 *pde = 0000000001f20067 *pte = 0000000000000000 +[166357.529950] Oops: 0000 [#1] PREEMPT SMP +[166357.529973] Modules linked in: atomisp_css2300 lm3554 mt9m114 ov8830 compat(O) rmi4 st_drv videobuf_vmalloc videobuf_core matrix(O) hdmi_audio pvrsgx wl12xx(O) mac80211(O) cfg80211(O) wl12xx_sdio(O) pnwdisp +[166357.530079] CPU: 1 PID: 6779 Comm: iptables Tainted: G W O 3.10.20-262458-ge1b992c #1 +[166357.530090] Hardware name: Intel Corporation CloverTrail/FFRD, BIOS 406 2013.10.16:10.18.10 +[166357.530102] task: cd195110 ti: cd5b8000 task.ti: cd5b8000 +[166357.530117] EIP: 0060:[] EFLAGS: 00010213 CPU: 1 +[166357.530134] EIP is at alloc_vmap_area.isra.20+0x12a/0x2c0 +[166357.530145] EAX: e8db4000 EBX: 00000000 ECX: 00000000 EDX: e8db2000 +[166357.530154] ESI: ffffffe8 EDI: 00001000 EBP: cd5b9dcc ESP: cd5b9d98 +[166357.530165] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068 +[166357.530175] CR0: 80050033 CR2: ffffffe8 CR3: 0d5b6000 CR4: 000007f0 +[166357.530185] DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000 +[166357.530195] DR6: ffff0ff0 DR7: 00000400 +[166357.530204] Stack: +[166357.530212] cd5b9dcc c132b08a 00002000 c75ca600 00000000 00000000 dec00000 ffffffff +[166357.530261] dec00000 00000001 c75ca180 00000022 00000001 cd5b9dec c131f177 ffbfe000 +[166357.530304] 000080d2 00001000 ffbfe000 80000000 ffffffff cd5b9e20 c131fe47 dec00000 +[166357.530354] Call Trace: +[166357.530371] [] ? kmem_cache_alloc_trace+0xaa/0x170 +[166357.530388] [] __get_vm_area_node.isra.21+0x87/0x160 +[166357.530402] [] __vmalloc_node_range+0x57/0x200 +[166357.530417] [] ? do_ipt_get_ctl+0x1a6/0x320 +[166357.530431] [] __vmalloc_node+0x62/0x70 +[166357.530445] [] ? do_ipt_get_ctl+0x1a6/0x320 +[166357.530459] [] vzalloc+0x38/0x40 +[166357.530473] [] ? do_ipt_get_ctl+0x1a6/0x320 +[166357.530488] [] do_ipt_get_ctl+0x1a6/0x320 +[166357.530503] [] ? avc_has_perm_flags+0xc7/0x170 +[166357.530521] [] nf_getsockopt+0x40/0x60 +[166357.530536] [] ip_getsockopt+0x84/0xc0 +[166357.530551] [] raw_getsockopt+0x32/0xb0 +[166357.530567] [] sock_common_getsockopt+0x27/0x40 +[166357.530582] [] SyS_getsockopt+0x6e/0xe0 +[166357.530598] [] SyS_socketcall+0x2b9/0x300 +[166357.530615] [] ? trace_hardirqs_on_thunk+0xc/0x10 +[166357.530631] [] syscall_call+0x7/0xb +[166357.530642] Code: 16 01 00 00 39 45 08 72 60 8b 3d 40 09 fb c1 89 5d d4 eb 27 90 8d 74 26 00 8b 4e 18 81 f9 fc c3 de c1 0f 84 e9 00 00 00 8d 71 e8 <8b> 49 e8 39 c1 0f 83 db 00 00 00 3b 45 08 77 20 8d 04 17 89 cb +[166357.530945] EIP: [] alloc_vmap_area.isra.20+0x12a/0x2c0 SS:ESP 0068:cd5b9d98 +[166357.530971] CR2: 00000000ffffffe8 diff --git a/tests/assets/x86_three_traces.txt b/tests/assets/x86_three_traces.txt new file mode 100644 index 0000000..a08d756 --- /dev/null +++ b/tests/assets/x86_three_traces.txt @@ -0,0 +1,110 @@ +[ 0.000000] Linux version 4.16-fake (debian-kernel@lists.debian.org) (gcc version 7.3.0 (Debian 7.3.0-3)) #1 SMP Debian 4.15.4-1 (2018-02-18) +[ 0.066297] general protection fault: 0000 [#1] SMP PTI +[ 0.067000] Modules linked in: +[ 0.067000] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.16.0-rc1-00044-g11d88c812 #153 +[ 0.067000] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 +[ 0.067000] RIP: 0010:sync_sched_exp_handler+0x14/0x96 +[ 0.067000] RSP: 0000:ffffb08f40197d10 EFLAGS: 00010287 +[ 0.067000] RAX: deacd7b935400000 RBX: ffffffffb6a831c0 RCX: 0000000000000003 +[ 0.067000] RDX: 0000000000000000 RSI: ffffffffb6a7f2c0 RDI: ffffffffb6a835c8 +[ 0.067000] RBP: ffffffffb6a831c0 R08: 00000000e272d5c3 R09: 0000000000000004 +[ 0.067000] R10: ffff890c349c8040 R11: 0000000000000001 R12: 0000000fffffffe0 +[ 0.067000] R13: ffffffffb511fa14 R14: ffffffffb6a835c8 R15: 0000000000000000 +[ 0.067000] FS: 0000000000000000(0000) GS:ffff890c35400000(0000) knlGS:0000000000000000 +[ 0.067000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 0.067000] CR2: 00000000ffffffff CR3: 0000000031a24000 CR4: 00000000000006f0 +[ 0.067000] Call Trace: +[ 0.067000] sync_rcu_exp_select_cpus+0x3da/0x44c +[ 0.067000] _synchronize_rcu_expedited+0x6e2/0x83f +[ 0.067000] ? _raw_spin_unlock_irq+0x29/0x39 +[ 0.067000] ? finish_task_switch+0x163/0x22d +[ 0.067000] ? finish_task_switch+0x1dc/0x22d +[ 0.067000] ? __schedule+0xa24/0xa8d +[ 0.067000] synchronize_sched+0xca/0x102 +[ 0.067000] ? trace_hardirqs_on_caller+0x177/0x191 +[ 0.067000] ? unregister_nmi_handler+0xac/0xbb +[ 0.067000] test_nmi_ipi+0x6e/0x7f +[ 0.067000] dotest+0x7/0x65 +[ 0.067000] nmi_selftest+0x59/0x152 +[ 0.067000] native_smp_cpus_done+0x65/0xfc +[ 0.067000] kernel_init_freeable+0x123/0x25a +[ 0.067000] ? rest_init+0x22e/0x22e +[ 0.067000] kernel_init+0xa/0xf0 +[ 0.067000] ret_from_fork+0x3a/0x50 +[ 0.067000] Code: 4a 48 89 df e8 10 88 ce 00 66 c7 83 3a 17 00 00 06 00 e9 b1 ec ff ff 66 66 66 66 90 48 8b 87 98 16 00 00 65 48 03 05 10 f7 ee 4a <48> 8b 50 20 48 8b 52 70 48 85 50 28 74 73 65 8a 05 dc 36 0c 4b +[ 0.067000] RIP: sync_sched_exp_handler+0x14/0x96 RSP: ffffb08f40197d10 +[ 0.067040] ---[ end trace 52ba43a846e7343b ]--- +nt [92047.021654] IPv6: ADDRCONF(NETDEV_CHANGE): wlp5s0: link becomes ready +nt [92029.923741] IRQ 122: no longer affine to CPU3 +nt [92029.924766] smpboot: CPU 3 is now offline +[ 0.066297] general protection fault: 0000 [#1] SMP PTI +[ 0.067000] Modules linked in: +[ 0.067000] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.16.0-rc1-00044-g11d88c812 #153 +[ 0.067000] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 +[ 0.067000] RIP: 0010:sync_sched_exp_handler+0x14/0x96 +[ 0.067000] RSP: 0000:ffffb08f40197d10 EFLAGS: 00010287 +[ 0.067000] RAX: deacd7b935400000 RBX: ffffffffb6a831c0 RCX: 0000000000000003 +[ 0.067000] RDX: 0000000000000000 RSI: ffffffffb6a7f2c0 RDI: ffffffffb6a835c8 +[ 0.067000] RBP: ffffffffb6a831c0 R08: 00000000e272d5c3 R09: 0000000000000004 +[ 0.067000] R10: ffff890c349c8040 R11: 0000000000000001 R12: 0000000fffffffe0 +[ 0.067000] R13: ffffffffb511fa14 R14: ffffffffb6a835c8 R15: 0000000000000000 +[ 0.067000] FS: 0000000000000000(0000) GS:ffff890c35400000(0000) knlGS:0000000000000000 +[ 0.067000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 0.067000] CR2: 00000000ffffffff CR3: 0000000031a24000 CR4: 00000000000006f0 +[ 0.067000] Call Trace: +[ 0.067000] sync_rcu_exp_select_cpus+0x3da/0x44c +[ 0.067000] _synchronize_rcu_expedited+0x6e2/0x83f +[ 0.067000] ? _raw_spin_unlock_irq+0x29/0x39 +[ 0.067000] ? finish_task_switch+0x163/0x22d +[ 0.067000] ? finish_task_switch+0x1dc/0x22d +[ 0.067000] ? __schedule+0xa24/0xa8d +[ 0.067000] synchronize_sched+0xca/0x102 +[ 0.067000] ? trace_hardirqs_on_caller+0x177/0x191 +[ 0.067000] ? unregister_nmi_handler+0xac/0xbb +[ 0.067000] test_nmi_ipi+0x6e/0x7f +[ 0.067000] dotest+0x7/0x65 +[ 0.067000] nmi_selftest+0x59/0x152 +[ 0.067000] native_smp_cpus_done+0x65/0xfc +[ 0.067000] kernel_init_freeable+0x123/0x25a +[ 0.067000] ? rest_init+0x22e/0x22e +[ 0.067000] kernel_init+0xa/0xf0 +[ 0.067000] ret_from_fork+0x3a/0x50 +[ 0.067000] Code: 4a 48 89 df e8 10 88 ce 00 66 c7 83 3a 17 00 00 06 00 e9 b1 ec ff ff 66 66 66 66 90 48 8b 87 98 16 00 00 65 48 03 05 10 f7 ee 4a <48> 8b 50 20 48 8b 52 70 48 85 50 28 74 73 65 8a 05 dc 36 0c 4b +[ 0.067000] RIP: sync_sched_exp_handler+0x14/0x96 RSP: ffffb08f40197d10 +[ 0.067040] ---[ end trace 52ba43a846e7343b ]--- +nt [92032.111092] PM: suspend exit +[ 0.066297] general protection fault: 0000 [#1] SMP PTI +[ 0.067000] Modules linked in: +[ 0.067000] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.16.0-rc1-00044-g11d88c812 #153 +[ 0.067000] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 +[ 0.067000] RIP: 0010:sync_sched_exp_handler+0x14/0x96 +[ 0.067000] RSP: 0000:ffffb08f40197d10 EFLAGS: 00010287 +[ 0.067000] RAX: deacd7b935400000 RBX: ffffffffb6a831c0 RCX: 0000000000000003 +[ 0.067000] RDX: 0000000000000000 RSI: ffffffffb6a7f2c0 RDI: ffffffffb6a835c8 +[ 0.067000] RBP: ffffffffb6a831c0 R08: 00000000e272d5c3 R09: 0000000000000004 +[ 0.067000] R10: ffff890c349c8040 R11: 0000000000000001 R12: 0000000fffffffe0 +[ 0.067000] R13: ffffffffb511fa14 R14: ffffffffb6a835c8 R15: 0000000000000000 +[ 0.067000] FS: 0000000000000000(0000) GS:ffff890c35400000(0000) knlGS:0000000000000000 +[ 0.067000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 0.067000] CR2: 00000000ffffffff CR3: 0000000031a24000 CR4: 00000000000006f0 +[ 0.067000] Call Trace: +[ 0.067000] sync_rcu_exp_select_cpus+0x3da/0x44c +[ 0.067000] _synchronize_rcu_expedited+0x6e2/0x83f +[ 0.067000] ? _raw_spin_unlock_irq+0x29/0x39 +[ 0.067000] ? finish_task_switch+0x163/0x22d +[ 0.067000] ? finish_task_switch+0x1dc/0x22d +[ 0.067000] ? __schedule+0xa24/0xa8d +[ 0.067000] synchronize_sched+0xca/0x102 +[ 0.067000] ? trace_hardirqs_on_caller+0x177/0x191 +[ 0.067000] ? unregister_nmi_handler+0xac/0xbb +[ 0.067000] test_nmi_ipi+0x6e/0x7f +[ 0.067000] dotest+0x7/0x65 +[ 0.067000] nmi_selftest+0x59/0x152 +[ 0.067000] native_smp_cpus_done+0x65/0xfc +[ 0.067000] kernel_init_freeable+0x123/0x25a +[ 0.067000] ? rest_init+0x22e/0x22e +[ 0.067000] kernel_init+0xa/0xf0 +[ 0.067000] ret_from_fork+0x3a/0x50 +[ 0.067000] Code: 4a 48 89 df e8 10 88 ce 00 66 c7 83 3a 17 00 00 06 00 e9 b1 ec ff ff 66 66 66 66 90 48 8b 87 98 16 00 00 65 48 03 05 10 f7 ee 4a <48> 8b 50 20 48 8b 52 70 48 85 50 28 74 73 65 8a 05 dc 36 0c 4b +[ 0.067000] RIP: sync_sched_exp_handler+0x14/0x96 RSP: ffffb08f40197d10 +[ 0.067040] ---[ end trace 52ba43a846e7343b ]--- diff --git a/tests/misc.py b/tests/misc.py new file mode 100644 index 0000000..616f154 --- /dev/null +++ b/tests/misc.py @@ -0,0 +1,42 @@ +""" +Miscellaneous for tests. +""" +# Copyright (c) 2018 Red Hat, Inc. All rights reserved. This copyrighted material +# is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General +# Public License v.2 or later. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import os + + +ASSETS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'assets') + + +def get_asset_path(filename): + """Return the absolute path of an asset passed as parameter. + + Args: + filename: Asset's filename. + Returns: + The absolute path of the corresponding asset. + """ + return os.path.join(ASSETS_DIR, filename) + + +def get_asset_content(filename): + """Return the content of an asset passed as parameter. + + Args: + filename: Asset's filename. + Returns: + The content of the corresponding asset. + """ + with open(get_asset_path(filename)) as asset: + return asset.read() diff --git a/tests/test_reporter.py b/tests/test_reporter.py new file mode 100644 index 0000000..ebdea55 --- /dev/null +++ b/tests/test_reporter.py @@ -0,0 +1,93 @@ +""" +Test cases for reporter module. +""" +# Copyright (c) 2018 Red Hat, Inc. All rights reserved. This copyrighted material +# is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General +# Public License v.2 or later. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import unittest +from contextlib import contextmanager +import re +import mock +from skt import reporter +from tests import misc + + +class TestConsoleLog(unittest.TestCase): + """Test cases for reporter.consolelog class""" + @staticmethod + @contextmanager + def request_get_mocked(filename): + """Mock request.get to allow feeding consolelog with known inputs. When + request.get is called, it "fetches" the content of the asset passed as + parameter. + + Args: + filename: Asset's filename. + """ + get_mocked = mock.Mock() + def remove_nt_marker(line): + """Filter function for removing the 'nt ' markers on assets""" + return not re.match(r'^nt ', line) + get_mocked.text = filter(remove_nt_marker, + misc.get_asset_content(filename)) + with mock.patch('requests.get', mock.Mock(return_value=get_mocked)): + yield + + @staticmethod + def get_expected_traces(filename): + """Return expected traces from an asset. Each line started with 'nt ' + is discarded. + + Args: + filename: Asset's filename. + Returns: + A list where every member is a trace. + """ + expected_traces = [] + tmp_trace = [] + for line in misc.get_asset_content(filename).splitlines()[1:]: + if line.startswith('nt '): + if tmp_trace: + expected_traces.append('\n'.join(tmp_trace)) + tmp_trace = [] + else: + tmp_trace.append(line) + expected_traces.append('\n'.join(tmp_trace)) + return expected_traces + + def test_kernel_version_unmatch(self): + """Check it doesn't catch any trace when kernel version doesn't match""" + consolelog = reporter.consolelog('4-4', 'someurl') + with self.request_get_mocked('x86_one_trace.txt'): + traces = consolelog.gettraces() + self.assertListEqual(traces, []) + + def test_match_one_trace(self): + """Check one trace can be extracted from a console log""" + consolelog = reporter.consolelog('4-5-fake', 'someurl') + with self.request_get_mocked('x86_one_trace.txt'): + traces = consolelog.gettraces() + self.assertEqual(len(traces), 1) + expected_trace = self.get_expected_traces('x86_one_trace.txt')[0] + '\n' + self.assertEqual(expected_trace, traces[0]) + + def test_match_three_traces(self): + """Check three traces can be extracted from a console log""" + consolelog = reporter.consolelog('4.16-fake', 'someurl') + with self.request_get_mocked('x86_three_traces.txt'): + traces = consolelog.gettraces() + self.assertEqual(len(traces), 3) + expected_traces = self.get_expected_traces('x86_three_traces.txt') + for idx, trace in enumerate(traces): + msg = ("Trace_{} doesn't match.\n" + "{!r} != {!r}").format(idx, trace, expected_traces[idx]) + self.assertEqual(trace, expected_traces[idx], msg=msg) From 3e99d791bcbab2697882b8036f3c3c37e9f4dbee Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Mar 06 2018 21:15:56 +0000 Subject: [PATCH 3/4] Document tests/test_publisher.py code --- diff --git a/tests/test_publisher.py b/tests/test_publisher.py index 1ed1f6d..713e9fa 100644 --- a/tests/test_publisher.py +++ b/tests/test_publisher.py @@ -1,8 +1,13 @@ +""" +Test cases for publisher module. +""" import unittest from skt import publisher class TestPublisher(unittest.TestCase): + """Test cases for publisher.publisher class""" def test_geturl(self): + """Check if the source url is built correctly""" pub = publisher.publisher('dest', 'file:///tmp/test') self.assertEqual(pub.geturl('source'), 'file:///tmp/test/source') From 79b664cecee33584e91d10e1d18797942bec1a10 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Mar 06 2018 21:15:56 +0000 Subject: [PATCH 4/4] Add license header to tests/test_publisher.py --- diff --git a/tests/test_publisher.py b/tests/test_publisher.py index 713e9fa..b3be138 100644 --- a/tests/test_publisher.py +++ b/tests/test_publisher.py @@ -1,6 +1,18 @@ """ Test cases for publisher module. """ +# Copyright (c) 2018 Red Hat, Inc. All rights reserved. This copyrighted material +# is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General +# Public License v.2 or later. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import unittest from skt import publisher