@@ -1088,6 +1088,15 @@ pub mod tests {
1088
1088
. unwrap ( )
1089
1089
}
1090
1090
1091
+ fn cmdline_contains ( cmdline : & Cmdline , slug : & str ) -> bool {
1092
+ cmdline
1093
+ . as_cstring ( )
1094
+ . unwrap ( )
1095
+ . into_string ( )
1096
+ . unwrap ( )
1097
+ . contains ( slug)
1098
+ }
1099
+
1091
1100
pub ( crate ) fn default_kernel_cmdline ( ) -> Cmdline {
1092
1101
linux_loader:: cmdline:: Cmdline :: try_from ( DEFAULT_KERNEL_CMDLINE , arch:: CMDLINE_MAX_SIZE )
1093
1102
. unwrap ( )
@@ -1379,12 +1388,7 @@ pub mod tests {
1379
1388
let mut vmm = default_vmm ( ) ;
1380
1389
let mut cmdline = default_kernel_cmdline ( ) ;
1381
1390
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1382
- assert ! ( cmdline
1383
- . as_cstring( )
1384
- . unwrap( )
1385
- . into_string( )
1386
- . unwrap( )
1387
- . contains( "root=/dev/vda ro" ) ) ;
1391
+ assert ! ( cmdline_contains( & cmdline, "root=/dev/vda ro" ) ) ;
1388
1392
assert ! ( vmm
1389
1393
. mmio_device_manager
1390
1394
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , drive_id. as_str( ) )
@@ -1404,12 +1408,7 @@ pub mod tests {
1404
1408
let mut vmm = default_vmm ( ) ;
1405
1409
let mut cmdline = default_kernel_cmdline ( ) ;
1406
1410
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1407
- assert ! ( cmdline
1408
- . as_cstring( )
1409
- . unwrap( )
1410
- . into_string( )
1411
- . unwrap( )
1412
- . contains( "root=PARTUUID=0eaa91a0-01 rw" ) ) ;
1411
+ assert ! ( cmdline_contains( & cmdline, "root=PARTUUID=0eaa91a0-01 rw" ) ) ;
1413
1412
assert ! ( vmm
1414
1413
. mmio_device_manager
1415
1414
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , drive_id. as_str( ) )
@@ -1429,18 +1428,8 @@ pub mod tests {
1429
1428
let mut vmm = default_vmm ( ) ;
1430
1429
let mut cmdline = default_kernel_cmdline ( ) ;
1431
1430
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1432
- assert ! ( !cmdline
1433
- . as_cstring( )
1434
- . unwrap( )
1435
- . into_string( )
1436
- . unwrap( )
1437
- . contains( "root=PARTUUID=" ) ) ;
1438
- assert ! ( !cmdline
1439
- . as_cstring( )
1440
- . unwrap( )
1441
- . into_string( )
1442
- . unwrap( )
1443
- . contains( "root=/dev/vda" ) ) ;
1431
+ assert ! ( !cmdline_contains( & cmdline, "root=PARTUUID=" ) ) ;
1432
+ assert ! ( !cmdline_contains( & cmdline, "root=/dev/vda" ) ) ;
1444
1433
assert ! ( vmm
1445
1434
. mmio_device_manager
1446
1435
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , drive_id. as_str( ) )
@@ -1476,12 +1465,7 @@ pub mod tests {
1476
1465
let mut cmdline = default_kernel_cmdline ( ) ;
1477
1466
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1478
1467
1479
- assert ! ( cmdline
1480
- . as_cstring( )
1481
- . unwrap( )
1482
- . into_string( )
1483
- . unwrap( )
1484
- . contains( "root=PARTUUID=0eaa91a0-01 rw" ) ) ;
1468
+ assert ! ( cmdline_contains( & cmdline, "root=PARTUUID=0eaa91a0-01 rw" ) ) ;
1485
1469
assert ! ( vmm
1486
1470
. mmio_device_manager
1487
1471
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , "root" )
@@ -1497,15 +1481,11 @@ pub mod tests {
1497
1481
1498
1482
// Check if these three block devices are inserted in kernel_cmdline.
1499
1483
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1500
- assert ! ( cmdline
1501
- . as_cstring( )
1502
- . unwrap( )
1503
- . into_string( )
1504
- . unwrap( )
1505
- . contains(
1506
- "virtio_mmio.device=4K@0xd0000000:5 virtio_mmio.device=4K@0xd0001000:6 \
1507
- virtio_mmio.device=4K@0xd0002000:7"
1508
- ) ) ;
1484
+ assert ! ( cmdline_contains(
1485
+ & cmdline,
1486
+ "virtio_mmio.device=4K@0xd0000000:5 virtio_mmio.device=4K@0xd0001000:6 \
1487
+ virtio_mmio.device=4K@0xd0002000:7"
1488
+ ) ) ;
1509
1489
}
1510
1490
1511
1491
// Use case 5: root block device is rw.
@@ -1521,12 +1501,7 @@ pub mod tests {
1521
1501
let mut vmm = default_vmm ( ) ;
1522
1502
let mut cmdline = default_kernel_cmdline ( ) ;
1523
1503
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1524
- assert ! ( cmdline
1525
- . as_cstring( )
1526
- . unwrap( )
1527
- . into_string( )
1528
- . unwrap( )
1529
- . contains( "root=/dev/vda rw" ) ) ;
1504
+ assert ! ( cmdline_contains( & cmdline, "root=/dev/vda rw" ) ) ;
1530
1505
assert ! ( vmm
1531
1506
. mmio_device_manager
1532
1507
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , drive_id. as_str( ) )
@@ -1546,12 +1521,7 @@ pub mod tests {
1546
1521
let mut vmm = default_vmm ( ) ;
1547
1522
let mut cmdline = default_kernel_cmdline ( ) ;
1548
1523
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1549
- assert ! ( cmdline
1550
- . as_cstring( )
1551
- . unwrap( )
1552
- . into_string( )
1553
- . unwrap( )
1554
- . contains( "root=PARTUUID=0eaa91a0-01 ro" ) ) ;
1524
+ assert ! ( cmdline_contains( & cmdline, "root=PARTUUID=0eaa91a0-01 ro" ) ) ;
1555
1525
assert ! ( vmm
1556
1526
. mmio_device_manager
1557
1527
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , drive_id. as_str( ) )
@@ -1571,12 +1541,7 @@ pub mod tests {
1571
1541
let mut vmm = default_vmm ( ) ;
1572
1542
let mut cmdline = default_kernel_cmdline ( ) ;
1573
1543
insert_block_devices ( & mut vmm, & mut cmdline, & mut event_manager, block_configs) ;
1574
- assert ! ( cmdline
1575
- . as_cstring( )
1576
- . unwrap( )
1577
- . into_string( )
1578
- . unwrap( )
1579
- . contains( "root=/dev/vda rw" ) ) ;
1544
+ assert ! ( cmdline_contains( & cmdline, "root=/dev/vda rw" ) ) ;
1580
1545
assert ! ( vmm
1581
1546
. mmio_device_manager
1582
1547
. get_device( DeviceType :: Virtio ( TYPE_BLOCK ) , drive_id. as_str( ) )
@@ -1612,12 +1577,10 @@ pub mod tests {
1612
1577
insert_balloon_device ( & mut vmm, & mut cmdline, & mut event_manager, balloon_config) ;
1613
1578
// Check if the vsock device is described in kernel_cmdline.
1614
1579
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1615
- assert ! ( cmdline
1616
- . as_cstring( )
1617
- . unwrap( )
1618
- . into_string( )
1619
- . unwrap( )
1620
- . contains( "virtio_mmio.device=4K@0xd0000000:5" ) ) ;
1580
+ assert ! ( cmdline_contains(
1581
+ & cmdline,
1582
+ "virtio_mmio.device=4K@0xd0000000:5"
1583
+ ) ) ;
1621
1584
}
1622
1585
1623
1586
#[ test]
@@ -1633,12 +1596,10 @@ pub mod tests {
1633
1596
insert_vsock_device ( & mut vmm, & mut cmdline, & mut event_manager, vsock_config) ;
1634
1597
// Check if the vsock device is described in kernel_cmdline.
1635
1598
#[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
1636
- assert ! ( cmdline
1637
- . as_cstring( )
1638
- . unwrap( )
1639
- . into_string( )
1640
- . unwrap( )
1641
- . contains( "virtio_mmio.device=4K@0xd0000000:5" ) ) ;
1599
+ assert ! ( cmdline_contains(
1600
+ & cmdline,
1601
+ "virtio_mmio.device=4K@0xd0000000:5"
1602
+ ) ) ;
1642
1603
}
1643
1604
1644
1605
#[ test]
0 commit comments