Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kselftest/arm64: Use ksft_perror() to log MTE failures

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>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/r/20241029-arm64-mte-test-logging-v1-1-a128e732e36e@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Mark Brown and committed by
Catalin Marinas
17a24097 dca93d29

+7 -7
+7 -7
tools/testing/selftests/arm64/mte/mte_common_util.c
··· 150 150 map_flag |= MAP_PRIVATE; 151 151 ptr = mmap(NULL, entire_size, prot_flag, map_flag, fd, 0); 152 152 if (ptr == MAP_FAILED) { 153 - ksft_print_msg("FAIL: mmap allocation\n"); 153 + ksft_perror("mmap()"); 154 154 return NULL; 155 155 } 156 156 if (mem_type == USE_MPROTECT) { 157 157 if (mprotect(ptr, entire_size, prot_flag | PROT_MTE)) { 158 + ksft_perror("mprotect(PROT_MTE)"); 158 159 munmap(ptr, size); 159 - ksft_print_msg("FAIL: mprotect PROT_MTE property\n"); 160 160 return NULL; 161 161 } 162 162 } ··· 190 190 lseek(fd, 0, SEEK_SET); 191 191 for (index = INIT_BUFFER_SIZE; index < size; index += INIT_BUFFER_SIZE) { 192 192 if (write(fd, buffer, INIT_BUFFER_SIZE) != INIT_BUFFER_SIZE) { 193 - perror("initialising buffer"); 193 + ksft_perror("initialising buffer"); 194 194 return NULL; 195 195 } 196 196 } 197 197 index -= INIT_BUFFER_SIZE; 198 198 if (write(fd, buffer, size - index) != size - index) { 199 - perror("initialising buffer"); 199 + ksft_perror("initialising buffer"); 200 200 return NULL; 201 201 } 202 202 return __mte_allocate_memory_range(size, mem_type, mapping, 0, 0, tags, fd); ··· 217 217 lseek(fd, 0, SEEK_SET); 218 218 for (index = INIT_BUFFER_SIZE; index < map_size; index += INIT_BUFFER_SIZE) 219 219 if (write(fd, buffer, INIT_BUFFER_SIZE) != INIT_BUFFER_SIZE) { 220 - perror("initialising buffer"); 220 + ksft_perror("initialising buffer"); 221 221 return NULL; 222 222 } 223 223 index -= INIT_BUFFER_SIZE; 224 224 if (write(fd, buffer, map_size - index) != map_size - index) { 225 - perror("initialising buffer"); 225 + ksft_perror("initialising buffer"); 226 226 return NULL; 227 227 } 228 228 return __mte_allocate_memory_range(size, mem_type, mapping, range_before, ··· 358 358 /* Create a file in the tmpfs filesystem */ 359 359 fd = mkstemp(&filename[0]); 360 360 if (fd == -1) { 361 - perror(filename); 361 + ksft_perror(filename); 362 362 ksft_print_msg("FAIL: Unable to open temporary file\n"); 363 363 return 0; 364 364 }