| 229 | } |
| 230 | |
| 231 | static void test_rdev_chain(void **state) |
| 232 | { |
| 233 | struct region_device child; |
| 234 | const size_t child_offs = VAL(2); |
| 235 | const size_t child_size = VAL(4); |
| 236 | const size_t offs = VAL(1); |
| 237 | const size_t ovrflw_size = child_size - offs + 1; |
| 238 | |
| 239 | /* The mock_size test is the only one that will go through to underlying rdev_ops. */ |
| 240 | expect_value(mock_mmap, offset, child_offs + offs); |
| 241 | expect_value(mock_readat, offset, child_offs + offs); |
| 242 | expect_value(mock_writeat, offset, child_offs + offs); |
| 243 | expect_value(mock_eraseat, offset, child_offs + offs); |
| 244 | |
| 245 | rdev_mock_defaults(); |
| 246 | |
| 247 | /* First a quick test for rdev_chain_full(). */ |
| 248 | assert_int_equal(rdev_chain_full(&child, &mock_rdev), 0); |
| 249 | assert_int_equal(region_device_sz(&child), region_device_sz(&mock_rdev)); |
| 250 | assert_int_equal(region_device_offset(&child), region_device_offset(&mock_rdev)); |
| 251 | assert_int_equal(rdev_relative_offset(&mock_rdev, &child), 0); |
| 252 | |
| 253 | /* Remaining tests use rdev chained to [child_offs:child_size) subregion. */ |
| 254 | assert_int_equal(rdev_chain(&child, &mock_rdev, child_offs, child_size), 0); |
| 255 | assert_int_equal(region_device_sz(&child), child_size); |
| 256 | assert_int_equal(region_device_offset(&child), child_offs); |
| 257 | assert_int_equal(region_device_last(&child), child_offs + child_size - 1); |
| 258 | assert_int_equal(rdev_relative_offset(&mock_rdev, &child), child_offs); |
| 259 | assert_int_equal(rdev_relative_offset(&child, &mock_rdev), -1); |
| 260 | |
| 261 | /* offs + mock_size < child_size, so will succeed. */ |
| 262 | assert_ptr_equal(rdev_mmap(&child, offs, mock_size), mmap_result); |
| 263 | assert_int_equal(rdev_munmap(&child, mmap_result), 0); |
| 264 | assert_int_equal(rdev_readat(&child, mock_buffer, offs, mock_size), mock_size); |
| 265 | assert_int_equal(rdev_writeat(&child, mock_buffer, offs, mock_size), mock_size); |
| 266 | assert_int_equal(rdev_eraseat(&child, offs, mock_size), mock_size); |
| 267 | |
| 268 | /* offs + ovrflw_size > child_size, so will fail. */ |
| 269 | assert_null(rdev_mmap(&child, offs, ovrflw_size)); |
| 270 | assert_int_equal(rdev_readat(&child, mock_buffer, offs, ovrflw_size), -1); |
| 271 | assert_int_equal(rdev_writeat(&child, mock_buffer, offs, ovrflw_size), -1); |
| 272 | assert_int_equal(rdev_eraseat(&child, offs, ovrflw_size), -1); |
| 273 | |
| 274 | /* Using child_size as offset, the start of the area will already be out of range. */ |
| 275 | assert_null(rdev_mmap(&child, child_size, mock_size)); |
| 276 | assert_int_equal(rdev_readat(&child, mock_buffer, child_size, mock_size), -1); |
| 277 | assert_int_equal(rdev_writeat(&child, mock_buffer, child_size, mock_size), -1); |
| 278 | assert_int_equal(rdev_eraseat(&child, child_size, mock_size), -1); |
| 279 | } |
| 280 | |
| 281 | static void test_rdev_double_chain(void **state) |
| 282 | { |
nothing calls this directly
no test coverage detected