@@ -1090,4 +1090,66 @@ mod tests {
1090
1090
assert_eq ! ( options, expected_options) ;
1091
1091
}
1092
1092
}
1093
+
1094
+ #[ cfg( feature = "async" ) ]
1095
+ #[ test]
1096
+ fn test_mount_rootfs_umount_recursive ( ) {
1097
+ let target = tempfile:: tempdir ( ) . expect ( "create target dir error" ) ;
1098
+ let lower1 = tempfile:: tempdir ( ) . expect ( "create lower1 dir error" ) ;
1099
+ let lower2 = tempfile:: tempdir ( ) . expect ( "create lower2 dir error" ) ;
1100
+ let upperdir = tempfile:: tempdir ( ) . expect ( "create upperdir dir error" ) ;
1101
+ let workdir = tempfile:: tempdir ( ) . expect ( "create workdir dir error" ) ;
1102
+ let options = vec ! [
1103
+ "lowerdir=" . to_string( )
1104
+ + lower1. path( ) . to_str( ) . expect( "lower1 path to str error" )
1105
+ + ":"
1106
+ + lower2. path( ) . to_str( ) . expect( "lower2 path to str error" ) ,
1107
+ "upperdir=" . to_string( )
1108
+ + upperdir
1109
+ . path( )
1110
+ . to_str( )
1111
+ . expect( "upperdir path to str error" ) ,
1112
+ "workdir=" . to_string( ) + workdir. path( ) . to_str( ) . expect( "workdir path to str error" ) ,
1113
+ ] ;
1114
+ // mount target.
1115
+ let result = mount_rootfs ( Some ( "overlay" ) , Some ( "overlay" ) , & options, & target) ;
1116
+ assert ! ( result. is_ok( ) ) ;
1117
+ let mut mountinfo = get_mounts ( Some ( prefix_filter (
1118
+ target
1119
+ . path ( )
1120
+ . to_str ( )
1121
+ . expect ( "target path to str error" )
1122
+ . to_string ( ) ,
1123
+ ) ) )
1124
+ . expect ( "get_mounts error" ) ;
1125
+ // make sure the target has been mounted.
1126
+ assert_ne ! ( 0 , mountinfo. len( ) ) ;
1127
+ // umount target.
1128
+ let result = umount_recursive ( target. path ( ) . to_str ( ) , 0 ) ;
1129
+ assert ! ( result. is_ok( ) ) ;
1130
+ mountinfo = get_mounts ( Some ( prefix_filter (
1131
+ target
1132
+ . path ( )
1133
+ . to_str ( )
1134
+ . expect ( "target path to str error" )
1135
+ . to_string ( ) ,
1136
+ ) ) )
1137
+ . expect ( "get_mounts error" ) ;
1138
+ // make sure the target has been unmounted.
1139
+ assert_eq ! ( 0 , mountinfo. len( ) ) ;
1140
+ }
1141
+
1142
+ #[ cfg( feature = "async" ) ]
1143
+ #[ test]
1144
+ fn test_setup_loop_dev ( ) {
1145
+ let path = tempfile:: NamedTempFile :: new ( ) . expect ( "cannot create tempfile" ) ;
1146
+ let backing_file = path. path ( ) . to_str ( ) ;
1147
+ let params = LoopParams {
1148
+ readonly : false ,
1149
+ auto_clear : true ,
1150
+ direct : false ,
1151
+ } ;
1152
+ let result = setup_loop ( backing_file, params) ;
1153
+ assert ! ( result. is_ok( ) ) ;
1154
+ }
1093
1155
}
0 commit comments