From 7009aebcd4c978e0f9d7cbb1f45c482104ff3019 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 16 Apr 2024 10:04:45 +0200 Subject: pkg/vminfo: add package This moves significant part of logic from the target to host (#1541), eventually this will allow us to switch target code from Go to C++. Currnetly syz-fuzzer parses a number of system files (/proc/cpuinfo) in non-trivial ways and passes that info to the host. This is problematic to recreate in C++. So instead make the fuzzer part as simple as possible: now it merely reads the gives set of files and returns contents. The rest of the parsing happens on the host (the new vminfo package). Package vminfo extracts information about the target VM. The package itself runs on the host, which may be a different OS/arch. User of the package first requests set of files that needs to be fetched from the VM (Checker.RequiredFiles), then fetches these files, and calls Checker.MachineInfo to parse the files and extract information about the VM. The information includes information about kernel modules and OS-specific info (for Linux that includes things like parsed /proc/cpuinfo). This also requires changing RPC flow between fuzzer and manager. Currently, Check call is optional and happens only for first VMs. With this change Check is always done because we need to return contents of the requested files always. The plan is to switch the rest of the pkg/host package to this scheme later: instead of some complex custom logic, we need to express it as some simple operations on the target (checking file presence, etc), and the rest of the logic on the host. --- pkg/vminfo/linux.go | 148 +++++++++++++++++++ pkg/vminfo/linux_test.go | 359 ++++++++++++++++++++++++++++++++++++++++++++++ pkg/vminfo/vminfo.go | 130 +++++++++++++++++ pkg/vminfo/vminfo_test.go | 52 +++++++ 4 files changed, 689 insertions(+) create mode 100644 pkg/vminfo/linux.go create mode 100644 pkg/vminfo/linux_test.go create mode 100644 pkg/vminfo/vminfo.go create mode 100644 pkg/vminfo/vminfo_test.go (limited to 'pkg/vminfo') diff --git a/pkg/vminfo/linux.go b/pkg/vminfo/linux.go new file mode 100644 index 000000000..c9cd1a3db --- /dev/null +++ b/pkg/vminfo/linux.go @@ -0,0 +1,148 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package vminfo + +import ( + "bufio" + "bytes" + "fmt" + "io" + "path" + "regexp" + "strconv" + "strings" + + "github.com/google/syzkaller/pkg/host" +) + +type linux int + +func (linux) RequiredFiles() []string { + return []string{ + "/proc/cpuinfo", + "/proc/modules", + "/sys/module/*/sections/.text", + "/sys/module/kvm*/parameters/*", + } +} + +func (linux) machineInfos() []machineInfoFunc { + return []machineInfoFunc{ + linuxReadCPUInfo, + linuxReadKVMInfo, + } +} + +func (linux) parseModules(files filesystem) ([]host.KernelModule, error) { + var modules []host.KernelModule + re := regexp.MustCompile(`(\w+) ([0-9]+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`) + modulesText, _ := files.ReadFile("/proc/modules") + for _, match := range re.FindAllSubmatch(modulesText, -1) { + name := string(match[1]) + modAddr, err := strconv.ParseUint(string(match[3]), 0, 64) + if err != nil { + // /proc/modules is broken, bail out. + return nil, fmt.Errorf("module %v address parsing error: %w", name, err) + } + textAddr, err := linuxModuleTextAddr(files, name) + if err != nil { + // Module address unavailable, .text is probably 0. Skip this module. + continue + } + modSize, err := strconv.ParseUint(string(match[2]), 0, 64) + if err != nil { + // /proc/modules is broken, bail out. + return nil, fmt.Errorf("module %v size parsing error: %w", name, err) + } + offset := modAddr - textAddr + modules = append(modules, host.KernelModule{ + Name: name, + Addr: textAddr, + Size: modSize - offset, + }) + } + return modules, nil +} + +func linuxModuleTextAddr(files filesystem, module string) (uint64, error) { + data, err := files.ReadFile("/sys/module/" + module + "/sections/.text") + if err != nil { + return 0, fmt.Errorf("could not read module %v .text address file: %w", module, err) + } + addrString := strings.TrimSpace(string(data)) + addr, err := strconv.ParseUint(addrString, 0, 64) + if err != nil { + return 0, fmt.Errorf("address parsing error in %v: %w", module, err) + } + return addr, nil +} + +func linuxReadCPUInfo(files filesystem, w io.Writer) (string, error) { + data, err := files.ReadFile("/proc/cpuinfo") + if err != nil { + return "", fmt.Errorf("error reading CPU info:: %w", err) + } + + keyIndices := make(map[string]int) + type keyValues struct { + key string + values []string + } + var info []keyValues + for s := bufio.NewScanner(bytes.NewReader(data)); s.Scan(); { + splitted := strings.Split(s.Text(), ":") + if len(splitted) != 2 { + continue + } + key := strings.TrimSpace(splitted[0]) + val := strings.TrimSpace(splitted[1]) + if idx, ok := keyIndices[key]; !ok { + idx = len(keyIndices) + keyIndices[key] = idx + info = append(info, keyValues{key, []string{val}}) + } else { + info[idx].values = append(info[idx].values, val) + } + } + + for _, kv := range info { + // It is guaranteed that len(vals) >= 1 + key := kv.key + vals := kv.values + if allEqual(vals) { + fmt.Fprintf(w, "%-20s: %s\n", key, vals[0]) + } else { + fmt.Fprintf(w, "%-20s: %s\n", key, strings.Join(vals, ", ")) + } + } + return "CPU Info", nil +} + +func allEqual(slice []string) bool { + for i := 1; i < len(slice); i++ { + if slice[i] != slice[0] { + return false + } + } + return true +} + +func linuxReadKVMInfo(files filesystem, w io.Writer) (string, error) { + for _, module := range files.ReadDir("/sys/module") { + if !strings.HasPrefix(module, "kvm") { + continue + } + paramPath := path.Join("/sys", "module", module, "parameters") + fmt.Fprintf(w, "/sys/module/%s:\n", module) + for _, param := range files.ReadDir(paramPath) { + data, err := files.ReadFile(path.Join(paramPath, param)) + if err != nil { + return "", fmt.Errorf("error reading KVM info: %w", err) + } + fmt.Fprintf(w, "\t%s: %s", param, data) + } + w.Write([]byte{'\n'}) + } + return "KVM", nil +} diff --git a/pkg/vminfo/linux_test.go b/pkg/vminfo/linux_test.go new file mode 100644 index 000000000..bdc018c11 --- /dev/null +++ b/pkg/vminfo/linux_test.go @@ -0,0 +1,359 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package vminfo + +import ( + "bufio" + "bytes" + "fmt" + "os" + "runtime" + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/syzkaller/pkg/host" + "github.com/google/syzkaller/sys/targets" + "github.com/stretchr/testify/assert" +) + +func TestReadKVMInfo(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("not linux") + } + _, files := hostChecker() + fs := createVirtualFilesystem(files) + buf := new(bytes.Buffer) + if _, err := linuxReadKVMInfo(fs, buf); err != nil { + t.Fatal(err) + } + for s := bufio.NewScanner(buf); s.Scan(); { + line := s.Text() + if line == "" { + continue + } + splitted := strings.Split(line, ":") + if len(splitted) != 2 { + t.Fatalf("the format of line \"%s\" is not correct", line) + } + key := strings.TrimSpace(splitted[0]) + if key == "" { + t.Fatalf("empty key") + } + if key[0] != '/' { + continue + } + + if !strings.HasPrefix(key, "/sys/module/kvm") { + t.Fatalf("the directory does not match /sys/module/kvm*") + } + } +} + +func TestCannedCPUInfoLinux(t *testing.T) { + tests := cpuInfoTests + if runtime.GOOS == "linux" { + data, err := os.ReadFile("/proc/cpuinfo") + if err != nil { + t.Fatal(err) + } + tests = append(tests, cannedTest{ + arch: runtime.GOARCH, + data: string(data), + }) + } + for i, test := range tests { + t.Run(fmt.Sprint(i), func(t *testing.T) { + files := createVirtualFilesystem([]host.FileInfo{{ + Name: "/proc/cpuinfo", + Exists: true, + Data: []byte(test.data), + }}) + buf := new(bytes.Buffer) + if _, err := linuxReadCPUInfo(files, buf); err != nil { + t.Fatal(err) + } + if test.want != "" { + if diff := cmp.Diff(buf.String(), test.want); diff != "" { + t.Fatal(diff) + } + return + } + checkCPUInfo(t, buf.Bytes(), test.arch) + }) + } +} + +func checkCPUInfo(t *testing.T, data []byte, arch string) { + keys := make(map[string]bool) + s := bufio.NewScanner(bytes.NewReader(data)) + s.Buffer(nil, 1<<20) + for s.Scan() { + splitted := strings.Split(s.Text(), ":") + if len(splitted) != 2 { + t.Fatalf("the format of line %q is not correct", s.Text()) + } + key := strings.TrimSpace(splitted[0]) + keys[key] = true + } + assert.Nil(t, s.Err(), "scanner failed reading the CpuInfo: %v", s.Err()) + + importantKeys := map[string][]string{ + targets.PPC64LE: {"cpu", "revision", "platform", "model", "machine"}, + targets.AMD64: {"vendor_id", "model", "flags"}, + targets.S390x: {"vendor_id", "processor 0", "features"}, + targets.I386: {"vendor_id", "model", "flags"}, + targets.ARM64: {"CPU implementer", "CPU part", "Features"}, + targets.ARM: {"CPU implementer", "CPU part", "Features"}, + targets.MIPS64LE: {"system type", "cpu model", "ASEs implemented"}, + targets.RiscV64: {"processor", "isa", "mmu"}, + } + archKeys := importantKeys[arch] + if len(archKeys) == 0 { + t.Fatalf("unknown arch %v", arch) + } + for _, name := range archKeys { + if !keys[name] { + t.Fatalf("key %q not found", name) + } + } +} + +type cannedTest struct { + arch string + data string + want string +} + +// nolint:lll +var cpuInfoTests = []cannedTest{ + { + arch: targets.PPC64LE, + data: ` +processor : 0 +cpu : POWER8 (architected), altivec supported +clock : 3425.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 1 +cpu : POWER8 (architected), altivec supported +clock : 3425.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 2 +cpu : POWER8 (architected), altivec supported +clock : 3425.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 3 +cpu : POWER8 (architected), altivec supported +clock : 3425.000000MHz +revision : 2.1 (pvr 004b 0201) + +timebase : 512000000 +platform : pSeries +model : IBM pSeries (emulated by qemu) +machine : CHRP IBM pSeries (emulated by qemu) +MMU : Hash +`, + }, + { + arch: targets.PPC64LE, + data: ` +processor : 0 +cpu : POWER8 (architected), altivec supported +clock : 3425.000000MHz +revision : 2.1 (pvr 004b 0201) + + + +processor : 63 +cpu : POWER8 (architected), altivec supported +clock : 3425.000000MHz +revision : 2.1 (pvr 004b 0201) + +timebase : 512000000 +platform : pSeries +model : IBM,8247-22L +machine : CHRP IBM,8247-22L +MMU : Hash +`, + }, + { + arch: targets.PPC64LE, + data: ` +processor : 0 +cpu : POWER8E, altivec supported +clock : 3358.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 8 +cpu : POWER8E, altivec supported +clock : 3358.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 16 +cpu : POWER8E, altivec supported +clock : 3358.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 24 +cpu : POWER8E, altivec supported +clock : 3358.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 32 +cpu : POWER8E, altivec supported +clock : 3358.000000MHz +revision : 2.1 (pvr 004b 0201) + +processor : 40 +cpu : POWER8E, altivec supported +clock : 3358.000000MHz +revision : 2.1 (pvr 004b 0201) + +timebase : 512000000 +platform : PowerNV +model : 8286-41A +machine : PowerNV 8286-41A +firmware : OPAL +MMU : Hash +`, + }, + { + arch: targets.AMD64, + data: ` +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 142 +model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz +stepping : 10 +microcode : 0xd6 +cpu MHz : 2015.517 +cache size : 8192 KB +physical id : 0 +siblings : 8 +core id : 0 +cpu cores : 4 +apicid : 0 +initial apicid : 0 +fpu : yes +fpu_exception : yes +cpuid level : 22 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d +vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple shadow_vmcs pml ept_mode_based_exec +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds +bogomips : 4199.88 +clflush size : 64 +cache_alignment : 64 +address sizes : 39 bits physical, 48 bits virtual +power management: + +processor : 1 +vendor_id : GenuineIntel +cpu family : 6 +model : 142 +model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz +stepping : 10 +microcode : 0xd6 +cpu MHz : 1384.935 +cache size : 8192 KB +physical id : 0 +siblings : 8 +core id : 1 +cpu cores : 4 +apicid : 2 +initial apicid : 2 +fpu : yes +fpu_exception : yes +cpuid level : 22 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d +vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple shadow_vmcs pml ept_mode_based_exec +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit srbds +bogomips : 4199.88 +clflush size : 64 +cache_alignment : 64 +address sizes : 39 bits physical, 48 bits virtual +power management: +`, + }, + { + arch: targets.AMD64, + data: ` +processor : 0 +vendor_id : GenuineIntel +cpu family : 6 +model : 85 +model name : Intel(R) Xeon(R) CPU @ 2.00GHz +stepping : 3 +microcode : 0x1 +cpu MHz : 2000.166 +cache size : 56320 KB +physical id : 0 +siblings : 64 +core id : 0 +cpu cores : 32 +apicid : 0 +initial apicid : 0 +fpu : yes +fpu_exception : yes +cpuid level : 13 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs +bogomips : 4000.33 +clflush size : 64 +cache_alignment : 64 +address sizes : 46 bits physical, 48 bits virtual +power management: + +processor : 1 +vendor_id : GenuineIntel +cpu family : 6 +model : 85 +model name : Intel(R) Xeon(R) CPU @ 2.00GHz +stepping : 3 +microcode : 0x1 +cpu MHz : 2000.166 +cache size : 56320 KB +physical id : 0 +siblings : 64 +core id : 1 +cpu cores : 32 +apicid : 2 +initial apicid : 2 +fpu : yes +fpu_exception : yes +cpuid level : 13 +wp : yes +flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves +bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs +bogomips : 4000.33 +clflush size : 64 +cache_alignment : 64 +address sizes : 46 bits physical, 48 bits virtual +power management: +`, + }, + { + data: `A: a +B: b + +C: c1 +D: d +C: c1 +D: d +C: c2 +D: d +`, + want: `A : a +B : b +C : c1, c1, c2 +D : d +`, + }, +} diff --git a/pkg/vminfo/vminfo.go b/pkg/vminfo/vminfo.go new file mode 100644 index 000000000..2b94cec19 --- /dev/null +++ b/pkg/vminfo/vminfo.go @@ -0,0 +1,130 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +// Package vminfo extracts information about the target VM. +// The package itself runs on the host, which may be a different OS/arch. +// User of the package first requests set of files that needs to be fetched from the VM +// (Checker.RequiredFiles), then fetches these files, and calls Checker.MachineInfo +// to parse the files and extract information about the VM. +// The information includes information about kernel modules and OS-specific info +// (for Linux that includes things like parsed /proc/cpuinfo). +package vminfo + +import ( + "bytes" + "errors" + "fmt" + "io" + "io/fs" + "os" + "strings" + + "github.com/google/syzkaller/pkg/host" + "github.com/google/syzkaller/pkg/mgrconfig" + "github.com/google/syzkaller/sys/targets" +) + +type Checker struct { + checker +} + +func New(cfg *mgrconfig.Config) *Checker { + switch { + case cfg.TargetOS == targets.Linux: + return &Checker{new(linux)} + default: + return &Checker{new(stub)} + } +} + +func (checker *Checker) MachineInfo(fileInfos []host.FileInfo) ([]host.KernelModule, []byte, error) { + files := createVirtualFilesystem(fileInfos) + modules, err := checker.parseModules(files) + if err != nil { + return nil, nil, err + } + info := new(bytes.Buffer) + tmp := new(bytes.Buffer) + for _, fn := range checker.machineInfos() { + tmp.Reset() + name, err := fn(files, tmp) + if err != nil { + if !os.IsNotExist(err) { + return nil, nil, err + } + continue + } + if tmp.Len() == 0 { + continue + } + fmt.Fprintf(info, "[%v]\n%s\n%v\n\n", name, tmp.Bytes(), strings.Repeat("-", 80)) + } + return modules, info.Bytes(), nil +} + +type machineInfoFunc func(files filesystem, w io.Writer) (string, error) + +type checker interface { + RequiredFiles() []string + parseModules(files filesystem) ([]host.KernelModule, error) + machineInfos() []machineInfoFunc +} + +type filesystem map[string]host.FileInfo + +func createVirtualFilesystem(fileInfos []host.FileInfo) filesystem { + files := make(filesystem) + for _, file := range fileInfos { + if file.Exists { + files[file.Name] = file + } + } + return files +} + +func (files filesystem) ReadFile(name string) ([]byte, error) { + file, ok := files[name] + if !ok { + return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist} + } + if file.Error != "" { + return nil, errors.New(file.Error) + } + return file.Data, nil +} + +func (files filesystem) ReadDir(dir string) []string { + var res []string + dedup := make(map[string]bool) + for _, file := range files { + if len(file.Name) < len(dir)+2 || + !strings.HasPrefix(file.Name, dir) || + file.Name[len(dir)] != '/' { + continue + } + name := file.Name[len(dir)+1:] + if slash := strings.Index(name, "/"); slash != -1 { + name = name[:slash] + } + if dedup[name] { + continue + } + dedup[name] = true + res = append(res, name) + } + return res +} + +type stub int + +func (stub) RequiredFiles() []string { + return nil +} + +func (stub) parseModules(files filesystem) ([]host.KernelModule, error) { + return nil, nil +} + +func (stub) machineInfos() []machineInfoFunc { + return nil +} diff --git a/pkg/vminfo/vminfo_test.go b/pkg/vminfo/vminfo_test.go new file mode 100644 index 000000000..e4dc1bfb8 --- /dev/null +++ b/pkg/vminfo/vminfo_test.go @@ -0,0 +1,52 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package vminfo + +import ( + "runtime" + "strings" + "testing" + + "github.com/google/syzkaller/pkg/host" + "github.com/google/syzkaller/pkg/mgrconfig" +) + +func TestHostMachineInfo(t *testing.T) { + checker, files := hostChecker() + dups := make(map[string]bool) + for _, file := range files { + if file.Name[0] != '/' || file.Name[len(file.Name)-1] == '/' || strings.Contains(file.Name, "\\") { + t.Errorf("malformed file %q", file.Name) + } + // Reading duplicate files leads to duplicate work. + if dups[file.Name] { + t.Errorf("duplicate file %q", file.Name) + } + dups[file.Name] = true + if file.Error != "" { + t.Logf("failed to read %q: %s", file.Name, file.Error) + } + } + modules, info, err := checker.MachineInfo(files) + if err != nil { + t.Fatal(err) + } + t.Logf("machine info:\n%s", info) + for _, module := range modules { + t.Logf("module %q: addr 0x%x size %v", module.Name, module.Addr, module.Size) + } +} + +func hostChecker() (*Checker, []host.FileInfo) { + cfg := &mgrconfig.Config{ + Derived: mgrconfig.Derived{ + TargetOS: runtime.GOOS, + TargetArch: runtime.GOARCH, + TargetVMArch: runtime.GOARCH, + }, + } + checker := New(cfg) + files := host.ReadFiles(checker.RequiredFiles()) + return checker, files +} -- cgit mrf-deployment