Date: Tue, 19 Jul 2022 07:37:20 GMT From: Andrew Turner <andrew@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 3a5e46a3bf53 - stable/13 - Remove PAGE_SIZE from the kcov tests Message-ID: <202207190737.26J7bKFs021477@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=3a5e46a3bf5308de0123655c5c4f7ab4cfaefdf2 commit 3a5e46a3bf5308de0123655c5c4f7ab4cfaefdf2 Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2022-04-20 17:33:00 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2022-07-19 07:03:30 +0000 Remove PAGE_SIZE from the kcov tests To allow for a dynamic page size on arm64 remove the static valud from the kcov tests Sponsored by: The FreeBSD Foundation (cherry picked from commit 2ff6e4ee9762526ed1e924da838a760423271978) --- tests/sys/kern/kcov.c | 139 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 106 insertions(+), 33 deletions(-) diff --git a/tests/sys/kern/kcov.c b/tests/sys/kern/kcov.c index 0a59ddbeff73..64f75b8902ef 100644 --- a/tests/sys/kern/kcov.c +++ b/tests/sys/kern/kcov.c @@ -50,6 +50,14 @@ static const char *modes[] = { "comparison tracing", }; +static size_t page_size; + +static void +init_page_size(void) +{ + page_size = getpagesize(); +} + static int open_kcov(void) { @@ -62,7 +70,12 @@ open_kcov(void) return (fd); } -ATF_TC_WITHOUT_HEAD(kcov_bufsize); +ATF_TC(kcov_bufsize); +ATF_TC_HEAD(kcov_bufsize, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_bufsize, tc) { int fd; @@ -77,7 +90,12 @@ ATF_TC_BODY(kcov_bufsize, tc) close(fd); } -ATF_TC_WITHOUT_HEAD(kcov_mmap); +ATF_TC(kcov_mmap); +ATF_TC_HEAD(kcov_mmap, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_mmap, tc) { void *data1, *data2; @@ -85,19 +103,19 @@ ATF_TC_BODY(kcov_mmap, tc) fd = open_kcov(); - ATF_CHECK(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + ATF_CHECK(mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) == MAP_FAILED); ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, - 2 * PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); + 2 * page_size / KCOV_ENTRY_SIZE) == 0); - ATF_CHECK(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + ATF_CHECK(mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) == MAP_FAILED); - ATF_CHECK(mmap(NULL, 3 * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + ATF_CHECK(mmap(NULL, 3 * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) == MAP_FAILED); - ATF_REQUIRE((data1 = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, + ATF_REQUIRE((data1 = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) != MAP_FAILED); - ATF_REQUIRE((data2 = mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, + ATF_REQUIRE((data2 = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) != MAP_FAILED); *(uint64_t *)data1 = 0x123456789abcdeful; @@ -105,38 +123,48 @@ ATF_TC_BODY(kcov_mmap, tc) *(uint64_t *)data2 = 0xfedcba9876543210ul; ATF_REQUIRE(*(uint64_t *)data1 == 0xfedcba9876543210ull); - munmap(data1, 2 * PAGE_SIZE); - munmap(data2, 2 * PAGE_SIZE); + munmap(data1, 2 * page_size); + munmap(data2, 2 * page_size); close(fd); } /* This shouldn't panic */ -ATF_TC_WITHOUT_HEAD(kcov_mmap_no_munmap); +ATF_TC(kcov_mmap_no_munmap); +ATF_TC_HEAD(kcov_mmap_no_munmap, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_mmap_no_munmap, tc) { int fd; fd = open_kcov(); - ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); + ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, page_size / KCOV_ENTRY_SIZE) == 0); - ATF_CHECK(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + ATF_CHECK(mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) != MAP_FAILED); close(fd); } -ATF_TC_WITHOUT_HEAD(kcov_mmap_no_munmap_no_close); +ATF_TC(kcov_mmap_no_munmap_no_close); +ATF_TC_HEAD(kcov_mmap_no_munmap_no_close, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_mmap_no_munmap_no_close, tc) { int fd; fd = open_kcov(); - ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); + ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, page_size / KCOV_ENTRY_SIZE) == 0); - ATF_CHECK(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + ATF_CHECK(mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) != MAP_FAILED); } @@ -150,8 +178,8 @@ kcov_mmap_enable_thread(void *data) fd = open_kcov(); *(int *)data = fd; - ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); - ATF_CHECK(mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, + ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, page_size / KCOV_ENTRY_SIZE) == 0); + ATF_CHECK(mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) != MAP_FAILED); ATF_CHECK(ioctl(fd, KIOENABLE, KCOV_MODE_TRACE_PC) == 0); @@ -161,7 +189,12 @@ kcov_mmap_enable_thread(void *data) return (NULL); } -ATF_TC_WITHOUT_HEAD(kcov_mmap_enable_thread_close); +ATF_TC(kcov_mmap_enable_thread_close); +ATF_TC_HEAD(kcov_mmap_enable_thread_close, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_mmap_enable_thread_close, tc) { pthread_t thread; @@ -177,7 +210,12 @@ ATF_TC_BODY(kcov_mmap_enable_thread_close, tc) pthread_join(thread, NULL); } -ATF_TC_WITHOUT_HEAD(kcov_enable); +ATF_TC(kcov_enable); +ATF_TC_HEAD(kcov_enable, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_enable, tc) { int fd; @@ -186,7 +224,7 @@ ATF_TC_BODY(kcov_enable, tc) ATF_CHECK(ioctl(fd, KIOENABLE, KCOV_MODE_TRACE_PC) == -1); - ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); + ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, page_size / KCOV_ENTRY_SIZE) == 0); /* We need to enable before disable */ ATF_CHECK(ioctl(fd, KIODISABLE, 0) == -1); @@ -208,24 +246,34 @@ ATF_TC_BODY(kcov_enable, tc) close(fd); } -ATF_TC_WITHOUT_HEAD(kcov_enable_no_disable); +ATF_TC(kcov_enable_no_disable); +ATF_TC_HEAD(kcov_enable_no_disable, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_enable_no_disable, tc) { int fd; fd = open_kcov(); - ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); + ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, page_size / KCOV_ENTRY_SIZE) == 0); ATF_CHECK(ioctl(fd, KIOENABLE, KCOV_MODE_TRACE_PC) == 0); close(fd); } -ATF_TC_WITHOUT_HEAD(kcov_enable_no_disable_no_close); +ATF_TC(kcov_enable_no_disable_no_close); +ATF_TC_HEAD(kcov_enable_no_disable_no_close, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_enable_no_disable_no_close, tc) { int fd; fd = open_kcov(); - ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, PAGE_SIZE / KCOV_ENTRY_SIZE) == 0); + ATF_REQUIRE(ioctl(fd, KIOSETBUFSIZE, page_size / KCOV_ENTRY_SIZE) == 0); ATF_CHECK(ioctl(fd, KIOENABLE, KCOV_MODE_TRACE_PC) == 0); } @@ -238,10 +286,10 @@ common_head(int *fdp) fd = open_kcov(); ATF_REQUIRE_MSG(ioctl(fd, KIOSETBUFSIZE, - PAGE_SIZE / KCOV_ENTRY_SIZE) == 0, + page_size / KCOV_ENTRY_SIZE) == 0, "Unable to set the kcov buffer size"); - data = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + data = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ATF_REQUIRE_MSG(data != MAP_FAILED, "Unable to mmap the kcov buffer"); *fdp = fd; @@ -252,7 +300,7 @@ static void common_tail(int fd, void *data) { - ATF_REQUIRE_MSG(munmap(data, PAGE_SIZE) == 0, + ATF_REQUIRE_MSG(munmap(data, page_size) == 0, "Unable to unmap the kcov buffer"); close(fd); @@ -280,13 +328,23 @@ basic_test(u_int mode) common_tail(fd, buf); } -ATF_TC_WITHOUT_HEAD(kcov_basic_pc); +ATF_TC(kcov_basic_pc); +ATF_TC_HEAD(kcov_basic_pc, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_basic_pc, tc) { basic_test(KCOV_MODE_TRACE_PC); } -ATF_TC_WITHOUT_HEAD(kcov_basic_cmp); +ATF_TC(kcov_basic_cmp); +ATF_TC_HEAD(kcov_basic_cmp, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_basic_cmp, tc) { basic_test(KCOV_MODE_TRACE_CMP); @@ -327,13 +385,23 @@ thread_test(u_int mode) common_tail(fd, buf); } -ATF_TC_WITHOUT_HEAD(kcov_thread_pc); +ATF_TC(kcov_thread_pc); +ATF_TC_HEAD(kcov_thread_pc, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_thread_pc, tc) { thread_test(KCOV_MODE_TRACE_PC); } -ATF_TC_WITHOUT_HEAD(kcov_thread_cmp); +ATF_TC(kcov_thread_cmp); +ATF_TC_HEAD(kcov_thread_cmp, tc) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_thread_cmp, tc) { thread_test(KCOV_MODE_TRACE_CMP); @@ -364,7 +432,12 @@ multi_thread_test_helper(void *ptr) return (NULL); } -ATF_TC_WITHOUT_HEAD(kcov_enable_multi_thread); +ATF_TC(kcov_enable_multi_thread); +ATF_TC_HEAD(kcov_enable_multi_thread, t) +{ + init_page_size(); +} + ATF_TC_BODY(kcov_enable_multi_thread, t) { struct multi_thread_data data;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207190737.26J7bKFs021477>