File: vars_internal_linux_test.go

package info (click to toggle)
golang-github-canonical-go-efilib 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,836 kB
  • sloc: makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download
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
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.

package efi

import (
	"syscall"
	"unsafe"

	"golang.org/x/sys/unix"

	. "gopkg.in/check.v1"
)

type varsLinuxSuite struct{}

var _ = Suite(&varsLinuxSuite{})

func (s *varsLinuxSuite) TestProbeEfivarfs(c *C) {
	restore := MockUnixStatfs(func(path string, st *unix.Statfs_t) error {
		if path != "/sys/firmware/efi/efivars" {
			return syscall.ENOENT
		}

		if err := unix.Statfs("testdata", st); err != nil {
			return err
		}
		*(*uint)(unsafe.Pointer(&st.Type)) = uint(unix.EFIVARFS_MAGIC)
		return nil
	})
	defer restore()

	c.Check(probeEfivarfs(), Equals, true)
}

func (s *varsLinuxSuite) TestProbeEfivarfsNOENT(c *C) {
	restore := MockUnixStatfs(func(path string, st *unix.Statfs_t) error {
		return syscall.ENOENT
	})
	defer restore()

	c.Check(probeEfivarfs(), Equals, false)
}

func (s *varsLinuxSuite) TestProbeEfivarfsBadFS(c *C) {
	restore := MockUnixStatfs(func(path string, st *unix.Statfs_t) error {
		unix.Statfs("testdata", st)
		st.Type = unix.SYSFS_MAGIC
		return nil
	})
	defer restore()

	c.Check(probeEfivarfs(), Equals, false)
}