Files
snapd/bootloader/androidboot_test.go

106 lines
2.9 KiB
Go
Raw Permalink Normal View History

// -*- Mode: Go; indent-tabs-mode: t -*-
/*
2017-05-17 14:56:55 +02:00
* 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"
2017-05-17 14:56:55 +02:00
. "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"
)
2017-05-17 16:49:39 +02:00
type androidBootTestSuite struct {
baseBootenvTestSuite
}
2017-05-17 16:49:39 +02:00
var _ = Suite(&androidBootTestSuite{})
2017-05-17 14:56:55 +02:00
func (s *androidBootTestSuite) SetUpTest(c *C) {
s.baseBootenvTestSuite.SetUpTest(c)
2017-05-17 14:56:55 +02:00
2017-05-17 16:49:39 +02:00
// the file needs to exist for androidboot object to be created
bootloader.MockAndroidBootFile(c, s.rootdir, 0644)
}
2017-05-17 16:49:39 +02:00
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)
}
2017-05-17 16:49:39 +02:00
func (s *androidBootTestSuite) TestSetGetBootVar(c *C) {
a := bootloader.NewAndroidBoot(s.rootdir)
bootVars := map[string]string{"snap_mode": boot.TryStatus}
a.SetBootVars(bootVars)
2017-04-27 11:09:39 +02:00
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)
}