selftests/mm: compaction_test: Fix trivial test pass on Aarch64 when nr_hugepages = 0
Subsystems (3)
PATCH 1/1 selftests/mm: compaction_test: Fix trivial test pass on Aarch64 when nr_hugepages = 0
Currently, if at runtime we are not able to allocate a huge page, the test will trivially pass on Aarch64 due to no exception being raised on division by zero while computing compaction_index. Fix that by checking for nr_hugepages == 0. Anyways, in general, avoid a division by zero by exiting the program beforehand. While at it, fix a typo.
Signed-off-by Dev Jain <[email protected]>
--- tools/testing/selftests/mm/compaction_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/compaction_test.c +5 -1
@@ -134,6 +134,10 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size)/* We should have been able to request at least 1/3 rd of the memory in huge pages */ +if (!atoi (nr_hugepages)) { +ksft_print_msg ("ERROR: No memory is available as huge pages\n" ); + goto close_fd; + } compaction_index = mem_free/(atoi (nr_hugepages) * hugepage_size);lseek (fd,0 ,SEEK_SET );
@@ -149,7 +153,7 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) atoi(nr_hugepages));if (compaction_index >3 ) { -ksft_print_msg ("ERROR: Less that 1/%d of memory is available\n" +ksft_print_msg ("ERROR: Less than 1/%d of memory is available\n" "as huge pages\n" , compaction_index); goto close_fd; }
Signature · 1 line
2.39.2