Add start-microdroid command to vm_shell.sh
This command also accepts --auto-connect argument. It can be used to
automatically connect to the started Microdroid VM.
Bug: 254912288
Test: vm_shell start-microdroid
Test: vm_shell start-microdroid --auto-connect
Test: vm_shell start-microdroid -- --cpu 5
Change-Id: I7b5008a153692ef1c16baf6ffcd63ede1cd687af
diff --git a/vm/vm_shell.sh b/vm/vm_shell.sh
index 02ec98a..29cc7da 100755
--- a/vm/vm_shell.sh
+++ b/vm/vm_shell.sh
@@ -24,6 +24,16 @@
echo " cid - cid of the VM to connect to. If not specified user will "
echo " be promted to select one from the list of available cids"
echo ""
+ echo " start-microdroid [--auto-connect] [-- extra_args]"
+ echo " Starts a Microdroid VM. Args after the -- will be"
+ echo " passed through to the invocation of the "
+ echo " /apex/com.android.virt/bin/vm run-microdroid binary."
+ echo ""
+ echo " E.g.:"
+ echo " vm_shell start-microdroid -- --cpu 5"
+ echo ""
+ echo " --auto-connect - automatically connects to the started VMs"
+ echo ""
echo " help - prints this help message"
}
@@ -72,11 +82,30 @@
connect_vm ${selected_cid}
}
+function handle_start_microdroid_cmd() {
+ while [[ "$#" -gt 0 ]]; do
+ case $1 in
+ --auto-connect) auto_connect=true; ;;
+ --) shift; passthrough_args="$@"; break ;;
+ *) echo "Unknown argument: $1"; exit 1 ;;
+ esac
+ shift
+ done
+ if [[ "${auto_connect}" == true ]]; then
+ adb shell /apex/com.android.virt/bin/vm run-microdroid -d "${passthrough_args}"
+ sleep 2
+ handle_connect_cmd
+ else
+ adb shell /apex/com.android.virt/bin/vm run-microdroid "${passthrough_args}"
+ fi
+}
+
cmd=$1
shift
case $cmd in
connect) handle_connect_cmd "$@" ;;
+ start-microdroid) handle_start_microdroid_cmd "$@" ;;
help) print_help ;;
*) print_help; exit 1 ;;
esac