For tests that need to allocate using vm_mmap() (e.g. usercopy and execve), provide the interface to have the allocation tracked by KUnit itself. This requires bringing up a placeholder userspace mm. This combines my earlier attempt at this with Mark Rutland's version[1]. Normally alloc_mm() and arch_pick_mmap_layout() aren't exported for modules, so export these only for KUnit testing.
Showing the changes to include/kunit (1 of 5 files). Show all
Unified · Split
| @@ -480,6 +480,23 @@ static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp · 479 unmodified lines | |||
| 480 | return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO); | 480 | return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO); |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | /** | ||
| 484 | * kunit_vm_mmap() - Allocate KUnit-tracked vm_mmap() area | ||
| 485 | * @test: The test context object. | ||
| 486 | * @file: struct file pointer to map from, if any | ||
| 487 | * @addr: desired address, if any | ||
| 488 | * @len: how many bytes to allocate | ||
| 489 | * @prot: mmap PROT_* bits | ||
| 490 | * @flag: mmap flags | ||
| 491 | * @offset: offset into @file to start mapping from. | ||
| 492 | * | ||
| 493 | * See vm_mmap() for more information. | ||
| 494 | */ | ||
| 495 | unsigned long kunit_vm_mmap(struct kunit *test, struct file *file, | ||
| 496 | unsigned long addr, unsigned long len, | ||
| 497 | unsigned long prot, unsigned long flag, | ||
| 498 | unsigned long offset); | ||
| 499 | |||
| 483 | void kunit_cleanup(struct kunit *test); | 500 | void kunit_cleanup(struct kunit *test); |
| 484 | 501 | ||
| 485 | void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...); | 502 | void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...); |