Exemplo n.º 1
0
    def test_build_with_kconfigfile(self, run_mock, check_call_mock):
        self.options.kconfigfile = 'config'
        with open(self.options.kconfigfile, 'w') as f:
            f.write('ACCEPT=y\n')

        plugin = kbuild.KBuildPlugin('test-part', self.options,
                                     self.project_options)

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertThat(check_call_mock.call_count, Equals(1))
        check_call_mock.assert_has_calls([
            mock.call('yes "" | make -j2 oldconfig',
                      shell=True,
                      cwd=plugin.builddir),
        ])

        self.assertThat(run_mock.call_count, Equals(2))
        run_mock.assert_has_calls([
            mock.call(['make', '-j2']),
            mock.call([
                'make', '-j2', 'CONFIG_PREFIX={}'.format(plugin.installdir),
                'install'
            ])
        ])

        config_file = os.path.join(plugin.builddir, '.config')
        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        self.assertThat(config_contents, Equals('ACCEPT=y\n'))
Exemplo n.º 2
0
    def test_build_with_defconfig_and_kconfigs(self, run_mock,
                                               check_call_mock):
        self.options.kdefconfig = ['defconfig']
        self.options.kconfigs = [
            'SOMETHING=y',
            'ACCEPT=n',
        ]

        plugin = kbuild.KBuildPlugin('test-part', self.options,
                                     self.project_options)

        config_file = os.path.join(plugin.builddir, '.config')

        def fake_defconfig(*args, **kwargs):
            if os.path.exists(config_file):
                return
            with open(config_file, 'w') as f:
                f.write('ACCEPT=y\n')

        run_mock.side_effect = fake_defconfig

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertThat(check_call_mock.call_count, Equals(1))
        check_call_mock.assert_has_calls([
            mock.call('yes "" | make -j2 oldconfig',
                      shell=True,
                      cwd=plugin.builddir),
        ])

        self.assertThat(run_mock.call_count, Equals(3))
        run_mock.assert_has_calls([
            mock.call(['make', '-j2']),
            mock.call([
                'make', '-j2', 'CONFIG_PREFIX={}'.format(plugin.installdir),
                'install'
            ])
        ])

        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        expected_config = """SOMETHING=y
ACCEPT=n

ACCEPT=y

SOMETHING=y
ACCEPT=n
"""
        self.assertThat(config_contents, Equals(expected_config))
Exemplo n.º 3
0
    def test_build_with_defconfig_and_kconfigs(self, run_mock, check_call_mock):
        self.options.kdefconfig = ["defconfig"]
        self.options.kconfigs = ["SOMETHING=y", "ACCEPT=n"]

        plugin = kbuild.KBuildPlugin("test-part", self.options, self.project_options)

        config_file = os.path.join(plugin.builddir, ".config")

        def fake_defconfig(*args, **kwargs):
            if os.path.exists(config_file):
                return
            with open(config_file, "w") as f:
                f.write("ACCEPT=y\n")

        run_mock.side_effect = fake_defconfig

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertThat(check_call_mock.call_count, Equals(1))
        check_call_mock.assert_has_calls(
            [mock.call('yes "" | make -j2 oldconfig', shell=True, cwd=plugin.builddir)]
        )

        self.assertThat(run_mock.call_count, Equals(3))
        run_mock.assert_has_calls(
            [
                mock.call(["make", "-j2"]),
                mock.call(
                    [
                        "make",
                        "-j2",
                        "CONFIG_PREFIX={}".format(plugin.installdir),
                        "install",
                    ]
                ),
            ]
        )

        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        expected_config = """SOMETHING=y
ACCEPT=n

ACCEPT=y

SOMETHING=y
ACCEPT=n
"""
        self.assertThat(config_contents, Equals(expected_config))
Exemplo n.º 4
0
    def test_build_with_kconfigfile_and_kconfigs(self, run_mock, check_call_mock):
        self.options.kconfigfile = "config"
        self.options.kconfigs = ["SOMETHING=y", "ACCEPT=n"]

        with open(self.options.kconfigfile, "w") as f:
            f.write("ACCEPT=y\n")

        plugin = kbuild.KBuildPlugin("test-part", self.options, self.project_options)

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertThat(check_call_mock.call_count, Equals(1))
        check_call_mock.assert_has_calls(
            [mock.call('yes "" | make -j2 oldconfig', shell=True, cwd=plugin.builddir)]
        )

        self.assertThat(run_mock.call_count, Equals(2))
        run_mock.assert_has_calls(
            [
                mock.call(["make", "-j2"]),
                mock.call(
                    [
                        "make",
                        "-j2",
                        "CONFIG_PREFIX={}".format(plugin.installdir),
                        "install",
                    ]
                ),
            ]
        )

        config_file = os.path.join(plugin.builddir, ".config")
        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        expected_config = """SOMETHING=y
ACCEPT=n

ACCEPT=y

SOMETHING=y
ACCEPT=n
"""
        self.assertThat(config_contents, Equals(expected_config))

        # Finally, ensure that the original kconfigfile was not modified (it's back in
        # the source tree)
        with open(self.options.kconfigfile, "r") as f:
            self.assertThat(f.read(), Equals("ACCEPT=y\n"))
Exemplo n.º 5
0
    def test_build_with_kconfigfile_and_kconfigs(self, run_mock,
                                                 check_call_mock):
        self.options.kconfigfile = 'config'
        self.options.kconfigs = [
            'SOMETHING=y',
            'ACCEPT=n',
        ]

        with open(self.options.kconfigfile, 'w') as f:
            f.write('ACCEPT=y\n')

        plugin = kbuild.KBuildPlugin('test-part', self.options,
                                     self.project_options)

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertEqual(1, check_call_mock.call_count)
        check_call_mock.assert_has_calls([
            mock.call('yes "" | make -j2 oldconfig',
                      shell=True,
                      cwd=plugin.builddir),
        ])

        self.assertEqual(2, run_mock.call_count)
        run_mock.assert_has_calls([
            mock.call(['make', '-j2']),
            mock.call([
                'make', '-j2', 'CONFIG_PREFIX={}'.format(plugin.installdir),
                'install'
            ])
        ])

        config_file = os.path.join(plugin.builddir, '.config')
        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        expected_config = """SOMETHING=y
ACCEPT=n

ACCEPT=y

SOMETHING=y
ACCEPT=n
"""
        self.assertEqual(config_contents, expected_config)
Exemplo n.º 6
0
    def test_cross_compile(self, run_mock, check_call_mock):
        plugin = kbuild.KBuildPlugin('test-part', self.options,
                                     self.project_options)
        plugin.enable_cross_compilation()

        plugin.build()
        run_mock.assert_has_calls([
            mock.call(['make', '-j1', 'ARCH={}'.format(
                           self.project_options.kernel_arch),
                       'CROSS_COMPILE={}'.format(
                           self.project_options.cross_compiler_prefix),
                       'PATH={}:/usr/{}/bin'.format(
                           os.environ.copy().get('PATH', ''),
                           self.project_options.arch_triplet)]),
        ])
Exemplo n.º 7
0
    def test_cross_compile(self, run_mock, check_call_mock):
        plugin = kbuild.KBuildPlugin("test-part", self.options, self.project)
        plugin.enable_cross_compilation()

        plugin.build()
        run_mock.assert_has_calls([
            mock.call([
                "make",
                "-j1",
                "ARCH={}".format(self.project.kernel_arch),
                "CROSS_COMPILE={}".format(self.project.cross_compiler_prefix),
                "PATH={}:/usr/{}/bin".format(os.environ.copy().get("PATH", ""),
                                             self.project.arch_triplet),
            ])
        ])
Exemplo n.º 8
0
    def test_build_verbose_with_kconfigfile(self, run_mock, check_call_mock):
        fake_logger = fixtures.FakeLogger(level=logging.DEBUG)
        self.useFixture(fake_logger)

        self.options.kconfigfile = "config"
        with open(self.options.kconfigfile, "w") as f:
            f.write("ACCEPT=y\n")

        plugin = kbuild.KBuildPlugin("test-part", self.options, self.project_options)

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertThat(check_call_mock.call_count, Equals(1))
        check_call_mock.assert_has_calls(
            [
                mock.call(
                    'yes "" | make -j2 V=1 oldconfig', shell=True, cwd=plugin.builddir
                )
            ]
        )

        self.assertThat(run_mock.call_count, Equals(2))
        run_mock.assert_has_calls(
            [
                mock.call(["make", "-j2", "V=1"]),
                mock.call(
                    [
                        "make",
                        "-j2",
                        "V=1",
                        "CONFIG_PREFIX={}".format(plugin.installdir),
                        "install",
                    ]
                ),
            ]
        )

        config_file = os.path.join(plugin.builddir, ".config")
        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        self.assertThat(config_contents, Equals("ACCEPT=y\n"))
Exemplo n.º 9
0
    def test_build_verbose_with_kconfigfile(self, run_mock, check_call_mock):
        fake_logger = fixtures.FakeLogger(level=logging.DEBUG)
        self.useFixture(fake_logger)

        self.options.kconfigfile = 'config'
        with open(self.options.kconfigfile, 'w') as f:
            f.write('ACCEPT=y\n')

        plugin = kbuild.KBuildPlugin('test-part', self.options,
                                     self.project_options)

        os.makedirs(plugin.builddir)

        plugin.build()

        self.assertEqual(1, check_call_mock.call_count)
        check_call_mock.assert_has_calls([
            mock.call('yes "" | make -j2 V=1 oldconfig',
                      shell=True,
                      cwd=plugin.builddir),
        ])

        self.assertEqual(2, run_mock.call_count)
        run_mock.assert_has_calls([
            mock.call(['make', '-j2', 'V=1']),
            mock.call([
                'make', '-j2', 'V=1',
                'CONFIG_PREFIX={}'.format(plugin.installdir), 'install'
            ])
        ])

        config_file = os.path.join(plugin.builddir, '.config')
        self.assertTrue(os.path.exists(config_file))

        with open(config_file) as f:
            config_contents = f.read()

        self.assertEqual(config_contents, 'ACCEPT=y\n')