def test_cross_compile(mock_check_call, monkeypatch, mock_run, deb_arch): monkeypatch.setattr(snapcraft.project.Project, "is_cross_compiling", True) class Options: build_parameters = [] kconfigfile = None kconfigflavour = None kdefconfig = [] kconfigs = [] build_attributes = [] project = snapcraft.project.Project(target_deb_arch=deb_arch) project._snap_meta = meta.snap.Snap(name="test-snap", base="core18") plugin = kbuild.KBuildPlugin("test-part", Options(), project) plugin.enable_cross_compilation() plugin.build() mock_run.assert_has_calls( [ mock.call( [ "make", "-j1", f"ARCH={project.kernel_arch}", f"CROSS_COMPILE={project.cross_compiler_prefix}", mock.ANY, ] ) ] )
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) 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))
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) 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"))
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), ]) ])
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) 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"))