Skip to content

Commit a4db7c1

Browse files
committed
test: add simple linux test for all function
1 parent f027a8b commit a4db7c1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

vmdetect/linux_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

0 commit comments

Comments
 (0)