Lines Matching +full:buffer +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* I/O iterator tests. This can only test kernel-backed iterator types.
35 { -1 }
54 void *buffer; in iov_kunit_create_buffer() local
67 pages[i]->index = i; in iov_kunit_create_buffer()
69 buffer = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL); in iov_kunit_create_buffer()
70 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); in iov_kunit_create_buffer()
72 kunit_add_action_or_reset(test, iov_kunit_unmap, buffer); in iov_kunit_create_buffer()
73 return buffer; in iov_kunit_create_buffer()
79 void *buffer, size_t bufsize, in iov_kunit_load_kvec() argument
82 size_t size = 0; in iov_kunit_load_kvec() local
86 if (pr->from < 0) in iov_kunit_load_kvec()
88 KUNIT_ASSERT_GE(test, pr->to, pr->from); in iov_kunit_load_kvec()
89 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_load_kvec()
90 kvec[i].iov_base = buffer + pr->from; in iov_kunit_load_kvec()
91 kvec[i].iov_len = pr->to - pr->from; in iov_kunit_load_kvec()
92 size += pr->to - pr->from; in iov_kunit_load_kvec()
94 KUNIT_ASSERT_LE(test, size, bufsize); in iov_kunit_load_kvec()
96 iov_iter_kvec(iter, dir, kvec, i, size); in iov_kunit_load_kvec()
100 * Test copying to a ITER_KVEC-type iterator.
108 u8 *scratch, *buffer; in iov_kunit_copy_to_kvec() local
109 size_t bufsize, npages, size, copied; in iov_kunit_copy_to_kvec() local
119 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_to_kvec()
120 memset(buffer, 0, bufsize); in iov_kunit_copy_to_kvec()
123 buffer, bufsize, kvec_test_ranges); in iov_kunit_copy_to_kvec()
124 size = iter.count; in iov_kunit_copy_to_kvec()
126 copied = copy_to_iter(scratch, size, &iter); in iov_kunit_copy_to_kvec()
128 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_to_kvec()
132 /* Build the expected image in the scratch buffer. */ in iov_kunit_copy_to_kvec()
135 for (pr = kvec_test_ranges; pr->from >= 0; pr++) in iov_kunit_copy_to_kvec()
136 for (i = pr->from; i < pr->to; i++) in iov_kunit_copy_to_kvec()
141 KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); in iov_kunit_copy_to_kvec()
142 if (buffer[i] != scratch[i]) in iov_kunit_copy_to_kvec()
150 * Test copying from a ITER_KVEC-type iterator.
158 u8 *scratch, *buffer; in iov_kunit_copy_from_kvec() local
159 size_t bufsize, npages, size, copied; in iov_kunit_copy_from_kvec() local
165 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_from_kvec()
167 buffer[i] = pattern(i); in iov_kunit_copy_from_kvec()
173 buffer, bufsize, kvec_test_ranges); in iov_kunit_copy_from_kvec()
174 size = min(iter.count, bufsize); in iov_kunit_copy_from_kvec()
176 copied = copy_from_iter(scratch, size, &iter); in iov_kunit_copy_from_kvec()
178 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_from_kvec()
182 /* Build the expected image in the main buffer. */ in iov_kunit_copy_from_kvec()
184 memset(buffer, 0, bufsize); in iov_kunit_copy_from_kvec()
185 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_from_kvec()
186 for (j = pr->from; j < pr->to; j++) { in iov_kunit_copy_from_kvec()
187 buffer[i++] = pattern(j); in iov_kunit_copy_from_kvec()
196 KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); in iov_kunit_copy_from_kvec()
197 if (scratch[i] != buffer[i]) in iov_kunit_copy_from_kvec()
217 { -1, -1, -1 }
228 size_t size = 0; in iov_kunit_load_bvec() local
232 if (pr->from < 0) in iov_kunit_load_bvec()
234 KUNIT_ASSERT_LT(test, pr->page, npages); in iov_kunit_load_bvec()
235 KUNIT_ASSERT_LT(test, pr->page * PAGE_SIZE, bufsize); in iov_kunit_load_bvec()
236 KUNIT_ASSERT_GE(test, pr->from, 0); in iov_kunit_load_bvec()
237 KUNIT_ASSERT_GE(test, pr->to, pr->from); in iov_kunit_load_bvec()
238 KUNIT_ASSERT_LE(test, pr->to, PAGE_SIZE); in iov_kunit_load_bvec()
240 page = pages[pr->page]; in iov_kunit_load_bvec()
241 if (pr->from == 0 && pr->from != pr->to && page == can_merge) { in iov_kunit_load_bvec()
242 i--; in iov_kunit_load_bvec()
243 bvec[i].bv_len += pr->to; in iov_kunit_load_bvec()
245 bvec_set_page(&bvec[i], page, pr->to - pr->from, pr->from); in iov_kunit_load_bvec()
248 size += pr->to - pr->from; in iov_kunit_load_bvec()
249 if ((pr->to & ~PAGE_MASK) == 0) in iov_kunit_load_bvec()
250 can_merge = page + pr->to / PAGE_SIZE; in iov_kunit_load_bvec()
255 iov_iter_bvec(iter, dir, bvec, i, size); in iov_kunit_load_bvec()
259 * Test copying to a ITER_BVEC-type iterator.
267 u8 *scratch, *buffer; in iov_kunit_copy_to_bvec() local
268 size_t bufsize, npages, size, copied; in iov_kunit_copy_to_bvec() local
278 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_to_bvec()
279 memset(buffer, 0, bufsize); in iov_kunit_copy_to_bvec()
283 size = iter.count; in iov_kunit_copy_to_bvec()
285 copied = copy_to_iter(scratch, size, &iter); in iov_kunit_copy_to_bvec()
287 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_to_bvec()
291 /* Build the expected image in the scratch buffer. */ in iov_kunit_copy_to_bvec()
295 for (pr = bvec_test_ranges; pr->from >= 0; pr++, b++) { in iov_kunit_copy_to_bvec()
296 u8 *p = scratch + pr->page * PAGE_SIZE; in iov_kunit_copy_to_bvec()
298 for (i = pr->from; i < pr->to; i++) in iov_kunit_copy_to_bvec()
304 KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); in iov_kunit_copy_to_bvec()
305 if (buffer[i] != scratch[i]) in iov_kunit_copy_to_bvec()
313 * Test copying from a ITER_BVEC-type iterator.
321 u8 *scratch, *buffer; in iov_kunit_copy_from_bvec() local
322 size_t bufsize, npages, size, copied; in iov_kunit_copy_from_bvec() local
328 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_from_bvec()
330 buffer[i] = pattern(i); in iov_kunit_copy_from_bvec()
337 size = iter.count; in iov_kunit_copy_from_bvec()
339 copied = copy_from_iter(scratch, size, &iter); in iov_kunit_copy_from_bvec()
341 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_from_bvec()
345 /* Build the expected image in the main buffer. */ in iov_kunit_copy_from_bvec()
347 memset(buffer, 0, bufsize); in iov_kunit_copy_from_bvec()
348 for (pr = bvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_from_bvec()
349 size_t patt = pr->page * PAGE_SIZE; in iov_kunit_copy_from_bvec()
351 for (j = pr->from; j < pr->to; j++) { in iov_kunit_copy_from_bvec()
352 buffer[i++] = pattern(patt + j); in iov_kunit_copy_from_bvec()
361 KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); in iov_kunit_copy_from_bvec()
362 if (scratch[i] != buffer[i]) in iov_kunit_copy_from_bvec()
374 next = folioq->next; in iov_kunit_destroy_folioq()
388 size_t size = 0; in iov_kunit_load_folioq() local
393 p->next = kzalloc(sizeof(struct folio_queue), GFP_KERNEL); in iov_kunit_load_folioq()
394 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p->next); in iov_kunit_load_folioq()
395 folioq_init(p->next); in iov_kunit_load_folioq()
396 p->next->prev = p; in iov_kunit_load_folioq()
397 p = p->next; in iov_kunit_load_folioq()
400 size += PAGE_SIZE; in iov_kunit_load_folioq()
402 iov_iter_folio_queue(iter, dir, folioq, 0, 0, size); in iov_kunit_load_folioq()
417 * Test copying to a ITER_FOLIOQ-type iterator.
425 u8 *scratch, *buffer; in iov_kunit_copy_to_folioq() local
426 size_t bufsize, npages, size, copied; in iov_kunit_copy_to_folioq() local
438 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_to_folioq()
439 memset(buffer, 0, bufsize); in iov_kunit_copy_to_folioq()
444 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_to_folioq()
445 size = pr->to - pr->from; in iov_kunit_copy_to_folioq()
446 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_copy_to_folioq()
448 iov_iter_folio_queue(&iter, READ, folioq, 0, 0, pr->to); in iov_kunit_copy_to_folioq()
449 iov_iter_advance(&iter, pr->from); in iov_kunit_copy_to_folioq()
450 copied = copy_to_iter(scratch + i, size, &iter); in iov_kunit_copy_to_folioq()
452 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_to_folioq()
454 KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to % PAGE_SIZE); in iov_kunit_copy_to_folioq()
455 i += size; in iov_kunit_copy_to_folioq()
456 if (test->status == KUNIT_FAILURE) in iov_kunit_copy_to_folioq()
460 /* Build the expected image in the scratch buffer. */ in iov_kunit_copy_to_folioq()
463 for (pr = kvec_test_ranges; pr->from >= 0; pr++) in iov_kunit_copy_to_folioq()
464 for (i = pr->from; i < pr->to; i++) in iov_kunit_copy_to_folioq()
469 KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); in iov_kunit_copy_to_folioq()
470 if (buffer[i] != scratch[i]) in iov_kunit_copy_to_folioq()
479 * Test copying from a ITER_FOLIOQ-type iterator.
487 u8 *scratch, *buffer; in iov_kunit_copy_from_folioq() local
488 size_t bufsize, npages, size, copied; in iov_kunit_copy_from_folioq() local
496 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_from_folioq()
498 buffer[i] = pattern(i); in iov_kunit_copy_from_folioq()
506 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_from_folioq()
507 size = pr->to - pr->from; in iov_kunit_copy_from_folioq()
508 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_copy_from_folioq()
510 iov_iter_folio_queue(&iter, WRITE, folioq, 0, 0, pr->to); in iov_kunit_copy_from_folioq()
511 iov_iter_advance(&iter, pr->from); in iov_kunit_copy_from_folioq()
512 copied = copy_from_iter(scratch + i, size, &iter); in iov_kunit_copy_from_folioq()
514 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_from_folioq()
516 KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to % PAGE_SIZE); in iov_kunit_copy_from_folioq()
517 i += size; in iov_kunit_copy_from_folioq()
520 /* Build the expected image in the main buffer. */ in iov_kunit_copy_from_folioq()
522 memset(buffer, 0, bufsize); in iov_kunit_copy_from_folioq()
523 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_from_folioq()
524 for (j = pr->from; j < pr->to; j++) { in iov_kunit_copy_from_folioq()
525 buffer[i++] = pattern(j); in iov_kunit_copy_from_folioq()
534 KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); in iov_kunit_copy_from_folioq()
535 if (scratch[i] != buffer[i]) in iov_kunit_copy_from_folioq()
555 size_t size = 0; in iov_kunit_load_xarray() local
562 size += PAGE_SIZE; in iov_kunit_load_xarray()
564 iov_iter_xarray(iter, dir, xarray, 0, size); in iov_kunit_load_xarray()
579 * Test copying to a ITER_XARRAY-type iterator.
587 u8 *scratch, *buffer; in iov_kunit_copy_to_xarray() local
588 size_t bufsize, npages, size, copied; in iov_kunit_copy_to_xarray() local
600 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_to_xarray()
601 memset(buffer, 0, bufsize); in iov_kunit_copy_to_xarray()
606 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_to_xarray()
607 size = pr->to - pr->from; in iov_kunit_copy_to_xarray()
608 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_copy_to_xarray()
610 iov_iter_xarray(&iter, READ, xarray, pr->from, size); in iov_kunit_copy_to_xarray()
611 copied = copy_to_iter(scratch + i, size, &iter); in iov_kunit_copy_to_xarray()
613 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_to_xarray()
615 KUNIT_EXPECT_EQ(test, iter.iov_offset, size); in iov_kunit_copy_to_xarray()
616 i += size; in iov_kunit_copy_to_xarray()
619 /* Build the expected image in the scratch buffer. */ in iov_kunit_copy_to_xarray()
622 for (pr = kvec_test_ranges; pr->from >= 0; pr++) in iov_kunit_copy_to_xarray()
623 for (i = pr->from; i < pr->to; i++) in iov_kunit_copy_to_xarray()
628 KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); in iov_kunit_copy_to_xarray()
629 if (buffer[i] != scratch[i]) in iov_kunit_copy_to_xarray()
637 * Test copying from a ITER_XARRAY-type iterator.
645 u8 *scratch, *buffer; in iov_kunit_copy_from_xarray() local
646 size_t bufsize, npages, size, copied; in iov_kunit_copy_from_xarray() local
654 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_copy_from_xarray()
656 buffer[i] = pattern(i); in iov_kunit_copy_from_xarray()
664 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_from_xarray()
665 size = pr->to - pr->from; in iov_kunit_copy_from_xarray()
666 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_copy_from_xarray()
668 iov_iter_xarray(&iter, WRITE, xarray, pr->from, size); in iov_kunit_copy_from_xarray()
669 copied = copy_from_iter(scratch + i, size, &iter); in iov_kunit_copy_from_xarray()
671 KUNIT_EXPECT_EQ(test, copied, size); in iov_kunit_copy_from_xarray()
673 KUNIT_EXPECT_EQ(test, iter.iov_offset, size); in iov_kunit_copy_from_xarray()
674 i += size; in iov_kunit_copy_from_xarray()
677 /* Build the expected image in the main buffer. */ in iov_kunit_copy_from_xarray()
679 memset(buffer, 0, bufsize); in iov_kunit_copy_from_xarray()
680 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_copy_from_xarray()
681 for (j = pr->from; j < pr->to; j++) { in iov_kunit_copy_from_xarray()
682 buffer[i++] = pattern(j); in iov_kunit_copy_from_xarray()
691 KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); in iov_kunit_copy_from_xarray()
692 if (scratch[i] != buffer[i]) in iov_kunit_copy_from_xarray()
700 * Test the extraction of ITER_KVEC-type iterators.
708 u8 *buffer; in iov_kunit_extract_pages_kvec() local
710 size_t bufsize, size = 0, npages; in iov_kunit_extract_pages_kvec() local
716 buffer = iov_kunit_create_buffer(test, &bpages, npages); in iov_kunit_extract_pages_kvec()
719 buffer, bufsize, kvec_test_ranges); in iov_kunit_extract_pages_kvec()
720 size = iter.count; in iov_kunit_extract_pages_kvec()
723 from = pr->from; in iov_kunit_extract_pages_kvec()
737 KUNIT_EXPECT_LE(test, len, size); in iov_kunit_extract_pages_kvec()
738 KUNIT_EXPECT_EQ(test, iter.count, size - len); in iov_kunit_extract_pages_kvec()
739 size -= len; in iov_kunit_extract_pages_kvec()
746 ssize_t part = min_t(ssize_t, len, PAGE_SIZE - offset0); in iov_kunit_extract_pages_kvec()
750 while (from == pr->to) { in iov_kunit_extract_pages_kvec()
752 from = pr->from; in iov_kunit_extract_pages_kvec()
762 len -= part; in iov_kunit_extract_pages_kvec()
769 if (test->status == KUNIT_FAILURE) in iov_kunit_extract_pages_kvec()
774 KUNIT_EXPECT_EQ(test, size, 0); in iov_kunit_extract_pages_kvec()
780 * Test the extraction of ITER_BVEC-type iterators.
789 size_t bufsize, size = 0, npages; in iov_kunit_extract_pages_bvec() local
798 size = iter.count; in iov_kunit_extract_pages_bvec()
801 from = pr->from; in iov_kunit_extract_pages_bvec()
815 KUNIT_EXPECT_LE(test, len, size); in iov_kunit_extract_pages_bvec()
816 KUNIT_EXPECT_EQ(test, iter.count, size - len); in iov_kunit_extract_pages_bvec()
817 size -= len; in iov_kunit_extract_pages_bvec()
824 ssize_t part = min_t(ssize_t, len, PAGE_SIZE - offset0); in iov_kunit_extract_pages_bvec()
828 while (from == pr->to) { in iov_kunit_extract_pages_bvec()
830 from = pr->from; in iov_kunit_extract_pages_bvec()
834 ix = pr->page + from / PAGE_SIZE; in iov_kunit_extract_pages_bvec()
840 len -= part; in iov_kunit_extract_pages_bvec()
847 if (test->status == KUNIT_FAILURE) in iov_kunit_extract_pages_bvec()
852 KUNIT_EXPECT_EQ(test, size, 0); in iov_kunit_extract_pages_bvec()
858 * Test the extraction of ITER_FOLIOQ-type iterators.
867 size_t bufsize, size = 0, npages; in iov_kunit_extract_pages_folioq() local
878 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_extract_pages_folioq()
879 from = pr->from; in iov_kunit_extract_pages_folioq()
880 size = pr->to - from; in iov_kunit_extract_pages_folioq()
881 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_extract_pages_folioq()
883 iov_iter_folio_queue(&iter, WRITE, folioq, 0, 0, pr->to); in iov_kunit_extract_pages_folioq()
897 KUNIT_EXPECT_LE(test, len, size); in iov_kunit_extract_pages_folioq()
898 KUNIT_EXPECT_EQ(test, iter.count, size - len); in iov_kunit_extract_pages_folioq()
901 size -= len; in iov_kunit_extract_pages_folioq()
907 ssize_t part = min_t(ssize_t, len, PAGE_SIZE - offset0); in iov_kunit_extract_pages_folioq()
917 len -= part; in iov_kunit_extract_pages_folioq()
924 if (test->status == KUNIT_FAILURE) in iov_kunit_extract_pages_folioq()
928 KUNIT_EXPECT_EQ(test, size, 0); in iov_kunit_extract_pages_folioq()
937 * Test the extraction of ITER_XARRAY-type iterators.
946 size_t bufsize, size = 0, npages; in iov_kunit_extract_pages_xarray() local
957 for (pr = kvec_test_ranges; pr->from >= 0; pr++) { in iov_kunit_extract_pages_xarray()
958 from = pr->from; in iov_kunit_extract_pages_xarray()
959 size = pr->to - from; in iov_kunit_extract_pages_xarray()
960 KUNIT_ASSERT_LE(test, pr->to, bufsize); in iov_kunit_extract_pages_xarray()
962 iov_iter_xarray(&iter, WRITE, xarray, from, size); in iov_kunit_extract_pages_xarray()
975 KUNIT_EXPECT_LE(test, len, size); in iov_kunit_extract_pages_xarray()
976 KUNIT_EXPECT_EQ(test, iter.count, size - len); in iov_kunit_extract_pages_xarray()
979 size -= len; in iov_kunit_extract_pages_xarray()
985 ssize_t part = min_t(ssize_t, len, PAGE_SIZE - offset0); in iov_kunit_extract_pages_xarray()
995 len -= part; in iov_kunit_extract_pages_xarray()
1002 if (test->status == KUNIT_FAILURE) in iov_kunit_extract_pages_xarray()
1006 KUNIT_EXPECT_EQ(test, size, 0); in iov_kunit_extract_pages_xarray()
1008 KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to - pr->from); in iov_kunit_extract_pages_xarray()