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