File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ //go:build linux
2
+ // +build linux
3
+
4
+ package vmdetect
5
+
6
+ import (
7
+ "reflect"
8
+ "runtime"
9
+ "strings"
10
+ "testing"
11
+ )
12
+
13
+ func getFunctionName (f interface {}) string {
14
+ fn := runtime .FuncForPC (reflect .ValueOf (f ).Pointer ()).Name ()
15
+ i := strings .LastIndex (fn , "." )
16
+ if i > 0 {
17
+ return fn [i :]
18
+ }
19
+ return fn
20
+ }
21
+
22
+ func TestCheckDMITable (t * testing.T ) {
23
+ check := - 1
24
+ for i , f := range []func () bool {
25
+ checkDMITable ,
26
+ checkKernelRingBuffer ,
27
+ checkUML ,
28
+ checkSysInfo ,
29
+ checkDeviceTree ,
30
+ checkHypervisorType ,
31
+ checkXenProcFile ,
32
+ checkKernelModules ,
33
+ } {
34
+ inVm := f ()
35
+ t .Logf ("%s:%v" , getFunctionName (f ), inVm )
36
+ if inVm && check == - 1 {
37
+ check = i
38
+ }
39
+ }
40
+ inVM , msg := IsRunningInVirtualMachine ()
41
+ t .Log (msg )
42
+ if check == - 1 == inVM {
43
+ t .Errorf ("check:%d, inVm:%v" , check , inVM )
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments