1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7import os
8
9from oeqa.runtime.case import OERuntimeTestCase
10from oeqa.core.decorator.data import skipIfNotFeature
11from oeqa.runtime.decorator.package import OEHasPackage
12
13class StapTest(OERuntimeTestCase):
14    @skipIfNotFeature('tools-profile', 'Test requires tools-profile to be in IMAGE_FEATURES')
15    @OEHasPackage(['systemtap'])
16    @OEHasPackage(['gcc-symlinks'])
17    @OEHasPackage(['kernel-devsrc'])
18    def test_stap(self):
19        try:
20            cmd = 'make -j -C /usr/src/kernel scripts prepare'
21            status, output = self.target.run(cmd, 900)
22            self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
23
24            cmd = 'stap -v -p4 -m stap-hello --disable-cache -DSTP_NO_VERREL_CHECK -e \'probe oneshot { print("Hello, "); println("SystemTap!") }\''
25            status, output = self.target.run(cmd, 900)
26            self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
27
28            cmd = 'staprun -v -R -b1 stap-hello.ko'
29            self.assertEqual(status, 0, msg='\n'.join([cmd, output]))
30            self.assertIn('Hello, SystemTap!', output, msg='\n'.join([cmd, output]))
31        except:
32            status, dmesg = self.target.run('dmesg')
33            if status == 0:
34                print(dmesg)
35