Message ID | 20241029-arm64-mte-test-logging-v1-1-a128e732e36e@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | kselftest/arm64: Use ksft_perror() to log MTE failures | expand |
On Tue, Oct 29, 2024 at 12:34:21PM +0000, Mark Brown wrote: > The logging in the allocation helpers variously uses ksft_print_msg() with > very intermittent logging of errno and perror() (which won't produce KTAP > conformant output) when logging the result of API calls that set errno. > Standardise on using the ksft_perror() helper in these cases so that more > information is available should the tests fail. > > Signed-off-by: Mark Brown <broonie@kernel.org> Thanks very much for this! LGTM! Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> > --- > tools/testing/selftests/arm64/mte/mte_common_util.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c > index 00ffd34c66d301ee7d5c99e6b8d9d5d944520b7f..46958b58801e90ceb79be76f57c7f72b50d43b3c 100644 > --- a/tools/testing/selftests/arm64/mte/mte_common_util.c > +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c > @@ -150,13 +150,13 @@ static void *__mte_allocate_memory_range(size_t size, int mem_type, int mapping, > map_flag |= MAP_PRIVATE; > ptr = mmap(NULL, entire_size, prot_flag, map_flag, fd, 0); > if (ptr == MAP_FAILED) { > - ksft_print_msg("FAIL: mmap allocation\n"); > + ksft_perror("mmap()"); > return NULL; > } > if (mem_type == USE_MPROTECT) { > if (mprotect(ptr, entire_size, prot_flag | PROT_MTE)) { > + ksft_perror("mprotect(PROT_MTE)"); > munmap(ptr, size); > - ksft_print_msg("FAIL: mprotect PROT_MTE property\n"); > return NULL; > } > } > @@ -190,13 +190,13 @@ void *mte_allocate_file_memory(size_t size, int mem_type, int mapping, bool tags > lseek(fd, 0, SEEK_SET); > for (index = INIT_BUFFER_SIZE; index < size; index += INIT_BUFFER_SIZE) { > if (write(fd, buffer, INIT_BUFFER_SIZE) != INIT_BUFFER_SIZE) { > - perror("initialising buffer"); > + ksft_perror("initialising buffer"); > return NULL; > } > } > index -= INIT_BUFFER_SIZE; > if (write(fd, buffer, size - index) != size - index) { > - perror("initialising buffer"); > + ksft_perror("initialising buffer"); > return NULL; > } > return __mte_allocate_memory_range(size, mem_type, mapping, 0, 0, tags, fd); > @@ -217,12 +217,12 @@ void *mte_allocate_file_memory_tag_range(size_t size, int mem_type, int mapping, > lseek(fd, 0, SEEK_SET); > for (index = INIT_BUFFER_SIZE; index < map_size; index += INIT_BUFFER_SIZE) > if (write(fd, buffer, INIT_BUFFER_SIZE) != INIT_BUFFER_SIZE) { > - perror("initialising buffer"); > + ksft_perror("initialising buffer"); > return NULL; > } > index -= INIT_BUFFER_SIZE; > if (write(fd, buffer, map_size - index) != map_size - index) { > - perror("initialising buffer"); > + ksft_perror("initialising buffer"); > return NULL; > } > return __mte_allocate_memory_range(size, mem_type, mapping, range_before, > @@ -359,7 +359,7 @@ int create_temp_file(void) > /* Create a file in the tmpfs filesystem */ > fd = mkstemp(&filename[0]); > if (fd == -1) { > - perror(filename); > + ksft_perror(filename); > ksft_print_msg("FAIL: Unable to open temporary file\n"); > return 0; > } > > --- > base-commit: 8e929cb546ee42c9a61d24fae60605e9e3192354 > change-id: 20241028-arm64-mte-test-logging-6c6e737b1c62 > > Best regards, > -- > Mark Brown <broonie@kernel.org> >
On Tue, 29 Oct 2024 12:34:21 +0000, Mark Brown wrote: > The logging in the allocation helpers variously uses ksft_print_msg() with > very intermittent logging of errno and perror() (which won't produce KTAP > conformant output) when logging the result of API calls that set errno. > Standardise on using the ksft_perror() helper in these cases so that more > information is available should the tests fail. > > > [...] Applied to arm64 (for-next/kselftest), thanks! [1/1] kselftest/arm64: Use ksft_perror() to log MTE failures https://git.kernel.org/arm64/c/17a2409783f1
diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c index 00ffd34c66d301ee7d5c99e6b8d9d5d944520b7f..46958b58801e90ceb79be76f57c7f72b50d43b3c 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -150,13 +150,13 @@ static void *__mte_allocate_memory_range(size_t size, int mem_type, int mapping, map_flag |= MAP_PRIVATE; ptr = mmap(NULL, entire_size, prot_flag, map_flag, fd, 0); if (ptr == MAP_FAILED) { - ksft_print_msg("FAIL: mmap allocation\n"); + ksft_perror("mmap()"); return NULL; } if (mem_type == USE_MPROTECT) { if (mprotect(ptr, entire_size, prot_flag | PROT_MTE)) { + ksft_perror("mprotect(PROT_MTE)"); munmap(ptr, size); - ksft_print_msg("FAIL: mprotect PROT_MTE property\n"); return NULL; } } @@ -190,13 +190,13 @@ void *mte_allocate_file_memory(size_t size, int mem_type, int mapping, bool tags lseek(fd, 0, SEEK_SET); for (index = INIT_BUFFER_SIZE; index < size; index += INIT_BUFFER_SIZE) { if (write(fd, buffer, INIT_BUFFER_SIZE) != INIT_BUFFER_SIZE) { - perror("initialising buffer"); + ksft_perror("initialising buffer"); return NULL; } } index -= INIT_BUFFER_SIZE; if (write(fd, buffer, size - index) != size - index) { - perror("initialising buffer"); + ksft_perror("initialising buffer"); return NULL; } return __mte_allocate_memory_range(size, mem_type, mapping, 0, 0, tags, fd); @@ -217,12 +217,12 @@ void *mte_allocate_file_memory_tag_range(size_t size, int mem_type, int mapping, lseek(fd, 0, SEEK_SET); for (index = INIT_BUFFER_SIZE; index < map_size; index += INIT_BUFFER_SIZE) if (write(fd, buffer, INIT_BUFFER_SIZE) != INIT_BUFFER_SIZE) { - perror("initialising buffer"); + ksft_perror("initialising buffer"); return NULL; } index -= INIT_BUFFER_SIZE; if (write(fd, buffer, map_size - index) != map_size - index) { - perror("initialising buffer"); + ksft_perror("initialising buffer"); return NULL; } return __mte_allocate_memory_range(size, mem_type, mapping, range_before, @@ -359,7 +359,7 @@ int create_temp_file(void) /* Create a file in the tmpfs filesystem */ fd = mkstemp(&filename[0]); if (fd == -1) { - perror(filename); + ksft_perror(filename); ksft_print_msg("FAIL: Unable to open temporary file\n"); return 0; }
The logging in the allocation helpers variously uses ksft_print_msg() with very intermittent logging of errno and perror() (which won't produce KTAP conformant output) when logging the result of API calls that set errno. Standardise on using the ksft_perror() helper in these cases so that more information is available should the tests fail. Signed-off-by: Mark Brown <broonie@kernel.org> --- tools/testing/selftests/arm64/mte/mte_common_util.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- base-commit: 8e929cb546ee42c9a61d24fae60605e9e3192354 change-id: 20241028-arm64-mte-test-logging-6c6e737b1c62 Best regards,