xref: /OK3568_Linux_fs/yocto/poky/bitbake/lib/bb/tests/siggen.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# BitBake Test for lib/bb/siggen.py
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# Copyright (C) 2020 Jean-François Dagenais
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only
7*4882a593Smuzhiyun#
8*4882a593Smuzhiyun
9*4882a593Smuzhiyunimport unittest
10*4882a593Smuzhiyunimport logging
11*4882a593Smuzhiyunimport bb
12*4882a593Smuzhiyunimport time
13*4882a593Smuzhiyun
14*4882a593Smuzhiyunlogger = logging.getLogger('BitBake.TestSiggen')
15*4882a593Smuzhiyun
16*4882a593Smuzhiyunimport bb.siggen
17*4882a593Smuzhiyun
18*4882a593Smuzhiyunclass SiggenTest(unittest.TestCase):
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun    def test_clean_basepath_simple_target_basepath(self):
21*4882a593Smuzhiyun        basepath = '/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask'
22*4882a593Smuzhiyun        expected_cleaned = 'helloworld/helloworld_1.2.3.bb:do_sometask'
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun        actual_cleaned = bb.siggen.clean_basepath(basepath)
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun        self.assertEqual(actual_cleaned, expected_cleaned)
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun    def test_clean_basepath_basic_virtual_basepath(self):
29*4882a593Smuzhiyun        basepath = 'virtual:something:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask'
30*4882a593Smuzhiyun        expected_cleaned = 'helloworld/helloworld_1.2.3.bb:do_sometask:virtual:something'
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun        actual_cleaned = bb.siggen.clean_basepath(basepath)
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun        self.assertEqual(actual_cleaned, expected_cleaned)
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun    def test_clean_basepath_mc_basepath(self):
37*4882a593Smuzhiyun        basepath = 'mc:somemachine:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask'
38*4882a593Smuzhiyun        expected_cleaned = 'helloworld/helloworld_1.2.3.bb:do_sometask:mc:somemachine'
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun        actual_cleaned = bb.siggen.clean_basepath(basepath)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun        self.assertEqual(actual_cleaned, expected_cleaned)
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun    def test_clean_basepath_virtual_long_prefix_basepath(self):
45*4882a593Smuzhiyun        basepath = 'virtual:something:A:B:C:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask'
46*4882a593Smuzhiyun        expected_cleaned = 'helloworld/helloworld_1.2.3.bb:do_sometask:virtual:something:A:B:C'
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun        actual_cleaned = bb.siggen.clean_basepath(basepath)
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun        self.assertEqual(actual_cleaned, expected_cleaned)
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun    def test_clean_basepath_mc_virtual_basepath(self):
53*4882a593Smuzhiyun        basepath = 'mc:somemachine:virtual:something:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask'
54*4882a593Smuzhiyun        expected_cleaned = 'helloworld/helloworld_1.2.3.bb:do_sometask:virtual:something:mc:somemachine'
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun        actual_cleaned = bb.siggen.clean_basepath(basepath)
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun        self.assertEqual(actual_cleaned, expected_cleaned)
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun    def test_clean_basepath_mc_virtual_long_prefix_basepath(self):
61*4882a593Smuzhiyun        basepath = 'mc:X:virtual:something:C:B:A:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask'
62*4882a593Smuzhiyun        expected_cleaned = 'helloworld/helloworld_1.2.3.bb:do_sometask:virtual:something:C:B:A:mc:X'
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun        actual_cleaned = bb.siggen.clean_basepath(basepath)
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun        self.assertEqual(actual_cleaned, expected_cleaned)
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun    # def test_clean_basepath_performance(self):
70*4882a593Smuzhiyun    #     input_basepaths = [
71*4882a593Smuzhiyun    #         'mc:X:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
72*4882a593Smuzhiyun    #         'mc:X:virtual:something:C:B:A:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
73*4882a593Smuzhiyun    #         'virtual:something:C:B:A:/different/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
74*4882a593Smuzhiyun    #         'virtual:something:A:/full/path/to/poky/meta/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
75*4882a593Smuzhiyun    #         '/this/is/most/common/input/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
76*4882a593Smuzhiyun    #         '/and/should/be/tested/with/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
77*4882a593Smuzhiyun    #         '/more/weight/recipes-whatever/helloworld/helloworld_1.2.3.bb:do_sometask',
78*4882a593Smuzhiyun    #     ]
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun    #     time_start = time.time()
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun    #     i = 2000000
83*4882a593Smuzhiyun    #     while i >= 0:
84*4882a593Smuzhiyun    #         for basepath in input_basepaths:
85*4882a593Smuzhiyun    #             bb.siggen.clean_basepath(basepath)
86*4882a593Smuzhiyun    #         i -= 1
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun    #     elapsed = time.time() - time_start
89*4882a593Smuzhiyun    #     print('{} ({}s)'.format(self.id(), round(elapsed, 3)))
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun    #     self.assertTrue(False)
92