@@ -397,7 +397,7 @@ mod tests {
397397 let mut disk = UbuntuDiskConfig :: new ( FOCAL_IMAGE_NAME . to_owned ( ) ) ;
398398 let guest = Guest :: new ( & mut disk) ;
399399
400- let domain_path = guest. create_domain ( VcpuConfig { boot : 4 , max : 4 } , DEFAULT_RAM_SIZE ) ;
400+ let domain_path = guest. create_domain ( VcpuConfig { boot : 2 , max : 4 } , DEFAULT_RAM_SIZE ) ;
401401
402402 let r = std:: panic:: catch_unwind ( || {
403403 spawn_virsh ( & [ "create" , domain_path. to_str ( ) . unwrap ( ) ] )
@@ -407,24 +407,51 @@ mod tests {
407407
408408 guest. wait_vm_boot ( None ) . unwrap ( ) ;
409409
410- assert_eq ! ( guest. get_cpu_count( ) . unwrap_or_default( ) , 4 ) ;
410+ // Check the number of vCPUs matches 'boot' parameter.
411+ assert_eq ! ( guest. get_cpu_count( ) . unwrap_or_default( ) , 2 ) ;
411412
412413 #[ cfg( target_arch = "x86_64" ) ]
413414 assert_eq ! (
414415 guest
415416 . ssh_command( r#"dmesg | grep "smpboot: Allowing" | sed "s/\[\ *[0-9.]*\] //""# )
416417 . unwrap( )
417418 . trim( ) ,
418- "smpboot: Allowing 4 CPUs, 0 hotplug CPUs"
419+ "smpboot: Allowing 4 CPUs, 2 hotplug CPUs"
419420 ) ;
420421 #[ cfg( target_arch = "aarch64" ) ]
421422 assert_eq ! (
422423 guest
423424 . ssh_command( r#"dmesg | grep "smp: Brought up" | sed "s/\[\ *[0-9.]*\] //""# )
424425 . unwrap( )
425426 . trim( ) ,
426- "smp: Brought up 1 node, 4 CPUs"
427+ "smp: Brought up 1 node, 2 CPUs"
427428 ) ;
429+
430+ // Hotplug 2 vCPUs
431+ spawn_virsh ( & [ "setvcpus" , & guest. vm_name , "4" ] )
432+ . unwrap ( )
433+ . wait ( )
434+ . unwrap ( ) ;
435+
436+ // Online them from the guest
437+ guest
438+ . ssh_command ( "echo 1 | sudo tee /sys/bus/cpu/devices/cpu2/online" )
439+ . unwrap ( ) ;
440+ guest
441+ . ssh_command ( "echo 1 | sudo tee /sys/bus/cpu/devices/cpu3/online" )
442+ . unwrap ( ) ;
443+
444+ // Check the number of vCPUs has been increased.
445+ assert_eq ! ( guest. get_cpu_count( ) . unwrap_or_default( ) , 4 ) ;
446+
447+ // Unplug 3 vCPUs
448+ spawn_virsh ( & [ "setvcpus" , & guest. vm_name , "1" ] )
449+ . unwrap ( )
450+ . wait ( )
451+ . unwrap ( ) ;
452+
453+ // Check the number of vCPUs has been reduced.
454+ assert_eq ! ( guest. get_cpu_count( ) . unwrap_or_default( ) , 1 ) ;
428455 } ) ;
429456
430457 spawn_virsh ( & [ "destroy" , & guest. vm_name ] )
0 commit comments