2016-11-01 10:21:29 +01:00
|
|
|
// -*- Mode: Go; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
|
|
/*
|
2017-05-17 14:56:55 +02:00
|
|
|
* Copyright (C) 2017 Canonical Ltd
|
2016-11-01 10:21:29 +01:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-19 12:00:37 +01:00
|
|
|
package bootloader_test
|
2016-11-01 10:21:29 +01:00
|
|
|
|
|
|
|
|
import (
|
2020-11-19 15:26:47 -06:00
|
|
|
"os"
|
2019-04-05 12:09:17 +01:00
|
|
|
"path/filepath"
|
|
|
|
|
|
2017-05-17 14:56:55 +02:00
|
|
|
. "gopkg.in/check.v1"
|
2016-11-01 10:21:29 +01:00
|
|
|
|
2020-02-24 16:51:16 -06:00
|
|
|
"github.com/snapcore/snapd/boot"
|
2019-03-19 12:00:37 +01:00
|
|
|
"github.com/snapcore/snapd/bootloader"
|
2019-04-05 12:09:17 +01:00
|
|
|
"github.com/snapcore/snapd/osutil"
|
|
|
|
|
"github.com/snapcore/snapd/snap"
|
2020-05-26 01:55:37 -05:00
|
|
|
"github.com/snapcore/snapd/snap/snapfile"
|
2019-04-05 12:09:17 +01:00
|
|
|
"github.com/snapcore/snapd/snap/snaptest"
|
2016-11-01 10:21:29 +01:00
|
|
|
)
|
|
|
|
|
|
2017-05-17 16:49:39 +02:00
|
|
|
type androidBootTestSuite struct {
|
2019-06-21 11:11:14 +02:00
|
|
|
baseBootenvTestSuite
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-17 16:49:39 +02:00
|
|
|
var _ = Suite(&androidBootTestSuite{})
|
2017-05-17 14:56:55 +02:00
|
|
|
|
2019-06-21 11:11:14 +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
|
2019-09-05 19:32:04 +02:00
|
|
|
bootloader.MockAndroidBootFile(c, s.rootdir, 0644)
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-17 16:49:39 +02:00
|
|
|
func (s *androidBootTestSuite) TestNewAndroidboot(c *C) {
|
2020-11-19 15:26:47 -06:00
|
|
|
// no files means bl is not present, but we can still create the bl object
|
|
|
|
|
c.Assert(os.RemoveAll(s.rootdir), IsNil)
|
2019-09-05 19:32:04 +02:00
|
|
|
a := bootloader.NewAndroidBoot(s.rootdir)
|
2017-04-26 14:35:04 +02:00
|
|
|
c.Assert(a, NotNil)
|
2020-11-19 15:26:47 -06:00
|
|
|
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)
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-17 16:49:39 +02:00
|
|
|
func (s *androidBootTestSuite) TestSetGetBootVar(c *C) {
|
2019-09-05 19:32:04 +02:00
|
|
|
a := bootloader.NewAndroidBoot(s.rootdir)
|
2020-02-24 16:51:16 -06:00
|
|
|
bootVars := map[string]string{"snap_mode": boot.TryStatus}
|
2017-04-26 14:35:04 +02:00
|
|
|
a.SetBootVars(bootVars)
|
2016-11-01 10:21:29 +01:00
|
|
|
|
2017-04-27 11:09:39 +02:00
|
|
|
v, err := a.GetBootVars("snap_mode")
|
2016-11-01 10:21:29 +01:00
|
|
|
c.Assert(err, IsNil)
|
|
|
|
|
c.Check(v, HasLen, 1)
|
2020-02-24 16:51:16 -06:00
|
|
|
c.Check(v["snap_mode"], Equals, boot.TryStatus)
|
2016-11-01 10:21:29 +01:00
|
|
|
}
|
2019-04-05 12:09:17 +01:00
|
|
|
|
|
|
|
|
func (s *androidBootTestSuite) TestExtractKernelAssetsNoUnpacksKernel(c *C) {
|
2019-09-05 19:32:04 +02:00
|
|
|
a := bootloader.NewAndroidBoot(s.rootdir)
|
2019-04-05 12:09:17 +01:00
|
|
|
|
|
|
|
|
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)
|
2020-05-26 01:55:37 -05:00
|
|
|
snapf, err := snapfile.Open(fn)
|
2019-04-05 12:09:17 +01:00
|
|
|
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
|
2019-09-05 19:32:04 +02:00
|
|
|
kernimg := filepath.Join(s.rootdir, "boot", "androidboot", "ubuntu-kernel_42.snap", "kernel.img")
|
2019-04-05 12:09:17 +01:00
|
|
|
c.Assert(osutil.FileExists(kernimg), Equals, false)
|
|
|
|
|
}
|