[VM] Check imported VM and original VM have the same CDI

Test: atest MicrodroidTests
Bug: 243129654
Change-Id: I1cbf4996255efb3a3331163c5c5c5822c003b1d6
This commit is contained in:
Alice Wang 2022-11-17 10:10:14 +00:00
parent 5449f31039
commit 6b40c48a51
1 changed files with 32 additions and 1 deletions

View File

@ -600,6 +600,36 @@ public class MicrodroidTests extends MicrodroidDeviceTestBase {
assertThat(vm).isNotEqualTo(newVm);
}
@Test
public void importedVmAndOriginalVmHaveTheSameCdi() throws Exception {
assumeSupportedKernel();
// Arrange
grantPermission(VirtualMachine.USE_CUSTOM_VIRTUAL_MACHINE_PERMISSION);
VirtualMachineConfig config =
mInner.newVmConfigBuilder()
.setPayloadConfigPath("assets/vm_config.json")
.setDebugLevel(DEBUG_LEVEL_FULL)
.build();
String vmNameOrig = "test_vm_orig";
String vmNameImport = "test_vm_import";
VirtualMachine vmOrig = mInner.forceCreateNewVirtualMachine(vmNameOrig, config);
VmCdis origCdis = launchVmAndGetCdis(vmNameOrig);
assertThat(origCdis.instanceSecret).isNotNull();
VirtualMachineDescriptor descriptor = vmOrig.toDescriptor();
VirtualMachineManager vmm = mInner.getVirtualMachineManager();
if (vmm.get(vmNameImport) != null) {
vmm.delete(vmNameImport);
}
// Action
// The imported VM will be fetched by name later.
VirtualMachine unusedVmImport = vmm.importFromDescriptor(vmNameImport, descriptor);
// Asserts
VmCdis importCdis = launchVmAndGetCdis(vmNameImport);
assertThat(origCdis.instanceSecret).isEqualTo(importCdis.instanceSecret);
}
@Test
public void importedVmIsEqualToTheOriginalVm() throws Exception {
// Arrange
@ -608,7 +638,8 @@ public class MicrodroidTests extends MicrodroidDeviceTestBase {
.setPayloadBinaryPath("MicrodroidTestNativeLib.so")
.setDebugLevel(DEBUG_LEVEL_NONE)
.build();
String vmNameOrig = "test_vm_orig", vmNameImport = "test_vm_import";
String vmNameOrig = "test_vm_orig";
String vmNameImport = "test_vm_import";
VirtualMachine vmOrig = mInner.forceCreateNewVirtualMachine(vmNameOrig, config);
// Run something to make the instance.img different with the initialized one.
TestResults origTestResults = runVmTestService(vmOrig);