github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/bootloader/androidboot_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2017 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package bootloader_test 21 22 import ( 23 "path/filepath" 24 25 . "gopkg.in/check.v1" 26 27 "github.com/snapcore/snapd/boot" 28 "github.com/snapcore/snapd/bootloader" 29 "github.com/snapcore/snapd/osutil" 30 "github.com/snapcore/snapd/snap" 31 "github.com/snapcore/snapd/snap/snapfile" 32 "github.com/snapcore/snapd/snap/snaptest" 33 ) 34 35 type androidBootTestSuite struct { 36 baseBootenvTestSuite 37 } 38 39 var _ = Suite(&androidBootTestSuite{}) 40 41 func (s *androidBootTestSuite) SetUpTest(c *C) { 42 s.baseBootenvTestSuite.SetUpTest(c) 43 44 // the file needs to exist for androidboot object to be created 45 bootloader.MockAndroidBootFile(c, s.rootdir, 0644) 46 } 47 48 func (s *androidBootTestSuite) TestNewAndroidboot(c *C) { 49 a := bootloader.NewAndroidBoot(s.rootdir) 50 c.Assert(a, NotNil) 51 } 52 53 func (s *androidBootTestSuite) TestSetGetBootVar(c *C) { 54 a := bootloader.NewAndroidBoot(s.rootdir) 55 bootVars := map[string]string{"snap_mode": boot.TryStatus} 56 a.SetBootVars(bootVars) 57 58 v, err := a.GetBootVars("snap_mode") 59 c.Assert(err, IsNil) 60 c.Check(v, HasLen, 1) 61 c.Check(v["snap_mode"], Equals, boot.TryStatus) 62 } 63 64 func (s *androidBootTestSuite) TestExtractKernelAssetsNoUnpacksKernel(c *C) { 65 a := bootloader.NewAndroidBoot(s.rootdir) 66 67 c.Assert(a, NotNil) 68 69 files := [][]string{ 70 {"kernel.img", "I'm a kernel"}, 71 {"initrd.img", "...and I'm an initrd"}, 72 {"meta/kernel.yaml", "version: 4.2"}, 73 } 74 si := &snap.SideInfo{ 75 RealName: "ubuntu-kernel", 76 Revision: snap.R(42), 77 } 78 fn := snaptest.MakeTestSnapWithFiles(c, packageKernel, files) 79 snapf, err := snapfile.Open(fn) 80 c.Assert(err, IsNil) 81 82 info, err := snap.ReadInfoFromSnapFile(snapf, si) 83 c.Assert(err, IsNil) 84 85 err = a.ExtractKernelAssets(info, snapf) 86 c.Assert(err, IsNil) 87 88 // kernel is *not* here 89 kernimg := filepath.Join(s.rootdir, "boot", "androidboot", "ubuntu-kernel_42.snap", "kernel.img") 90 c.Assert(osutil.FileExists(kernimg), Equals, false) 91 }