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