File: version.go

package info (click to toggle)
golang-github-jsimonetti-rtnetlink 2.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,264 kB
  • sloc: makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (2)
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
package testutils

import (
	"bytes"
	"fmt"
	"testing"

	"golang.org/x/sys/unix"
)

func getKernelVersion(tb testing.TB) (maj, min, patch uint32) {
	tb.Helper()

	var uname unix.Utsname
	if err := unix.Uname(&uname); err != nil {
		tb.Fatalf("getting uname: %s", err)
	}

	end := bytes.IndexByte(uname.Release[:], 0)
	versionStr := uname.Release[:end]

	if count, _ := fmt.Sscanf(string(versionStr), "%d.%d.%d", &maj, &min, &patch); count < 2 {
		tb.Fatalf("failed to parse kernel version from %s", string(versionStr))
	}
	return
}

// SkipOnOldKernel skips the test if the host's kernel is lower than the given
// x.y target version.
func SkipOnOldKernel(tb testing.TB, target, reason string) {
	maj, min, _ := getKernelVersion(tb)

	var maj_t, min_t, patch_t uint32
	if count, _ := fmt.Sscanf(target, "%d.%d.%d", &maj_t, &min_t, &patch_t); count < 2 {
		tb.Fatalf("failed to parse target version from %s", target)
	}

	if maj < maj_t || maj == maj_t && min < min_t {
		tb.Skipf("host kernel (%d.%d) too old (minimum %d.%d): %s", maj, min, maj_t, min_t, reason)
	}
}