aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
authorKris Alder <kalder@google.com>2023-02-22 10:20:49 -0800
committerTaras Madan <tarasmadan@google.com>2023-03-08 08:03:06 +0100
commitf6ef8c9d1dbba2449eec47d79ae047c30476dff2 (patch)
treee07a7e97494322adb0bdfdff8dfc27ee96a022b6 /vm
parentd2b001709254b71636892f5b9d0ed14a4ca04f61 (diff)
pkg/build: add build code for Android devices
Booting physical Android devices requires building a few artifacts, as described at https://source.android.com/docs/setup/build/building-kernels. When a ProxyVM type is used, we need to differentiate whether or not to use the Android build logic, so we add an additional mapping which uses a different name but the same VM logic.
Diffstat (limited to 'vm')
-rw-r--r--vm/vm.go13
-rw-r--r--vm/vm_test.go16
2 files changed, 27 insertions, 2 deletions
diff --git a/vm/vm.go b/vm/vm.go
index c340dfbf6..033e297db 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -14,6 +14,7 @@ import (
"io"
"os"
"path/filepath"
+ "strings"
"sync/atomic"
"time"
@@ -65,6 +66,14 @@ type BootErrorer interface {
BootError() (string, []byte)
}
+// vmType splits the VM type from any suffix (separated by ":"). This is mostly
+// useful for the "proxyapp" type, where pkg/build needs to specify/handle
+// sub-types.
+func vmType(fullName string) string {
+ name, _, _ := strings.Cut(fullName, ":")
+ return name
+}
+
// AllowsOvercommit returns if the instance type allows overcommit of instances
// (i.e. creation of instances out-of-thin-air). Overcommit is used during image
// and patch testing in syz-ci when it just asks for more than specified in config
@@ -74,12 +83,12 @@ type BootErrorer interface {
// override resource limits specified in config (e.g. can OOM). But it works and
// makes lots of things much simpler.
func AllowsOvercommit(typ string) bool {
- return vmimpl.Types[typ].Overcommit
+ return vmimpl.Types[vmType(typ)].Overcommit
}
// Create creates a VM pool that can be used to create individual VMs.
func Create(cfg *mgrconfig.Config, debug bool) (*Pool, error) {
- typ, ok := vmimpl.Types[cfg.Type]
+ typ, ok := vmimpl.Types[vmType(cfg.Type)]
if !ok {
return nil, fmt.Errorf("unknown instance type '%v'", cfg.Type)
}
diff --git a/vm/vm_test.go b/vm/vm_test.go
index d3429f5f7..9c190cf50 100644
--- a/vm/vm_test.go
+++ b/vm/vm_test.go
@@ -397,3 +397,19 @@ func testMonitorExecution(t *testing.T, test *Test) {
t.Fatalf("want output:\n%s\n\ngot output:\n%s\n", test.Report.Output, rep.Output)
}
}
+
+func TestVMType(t *testing.T) {
+ testCases := []struct {
+ in string
+ want string
+ }{
+ {"gvisor", "gvisor"},
+ {"proxyapp:android", "proxyapp"},
+ }
+
+ for _, tc := range testCases {
+ if got := vmType(tc.in); got != tc.want {
+ t.Errorf("vmType(%q) = %q, want %q", tc.in, got, tc.want)
+ }
+ }
+}