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