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

selftests/vm: write strlen length instead of sizeof to nr_hugepages

When setting back the initial value to nr_hugepages, the
test was writing a length sizeof of the string and checking
that strlen was writen. Since those values are not the same,
use strlen in both place instead.

Also make the error messages more explicit to help in future
debugging.

Signed-off-by: Yannick Brosseau <scientist@fb.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>

authored by

Yannick Brosseau and committed by
Shuah Khan
ee65735d 3aefd1fe

+5 -5
+5 -5
tools/testing/selftests/vm/compaction_test.c
··· 101 101 102 102 /* Start with the initial condition of 0 huge pages*/ 103 103 if (write(fd, "0", sizeof(char)) != sizeof(char)) { 104 - perror("Failed to write to /proc/sys/vm/nr_hugepages\n"); 104 + perror("Failed to write 0 to /proc/sys/vm/nr_hugepages\n"); 105 105 goto close_fd; 106 106 } 107 107 ··· 110 110 /* Request a large number of huge pages. The Kernel will allocate 111 111 as much as it can */ 112 112 if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) { 113 - perror("Failed to write to /proc/sys/vm/nr_hugepages\n"); 113 + perror("Failed to write 100000 to /proc/sys/vm/nr_hugepages\n"); 114 114 goto close_fd; 115 115 } 116 116 117 117 lseek(fd, 0, SEEK_SET); 118 118 119 119 if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) { 120 - perror("Failed to read from /proc/sys/vm/nr_hugepages\n"); 120 + perror("Failed to re-read from /proc/sys/vm/nr_hugepages\n"); 121 121 goto close_fd; 122 122 } 123 123 ··· 136 136 printf("No of huge pages allocated = %d\n", 137 137 (atoi(nr_hugepages))); 138 138 139 - if (write(fd, initial_nr_hugepages, sizeof(initial_nr_hugepages)) 139 + if (write(fd, initial_nr_hugepages, strlen(initial_nr_hugepages)) 140 140 != strlen(initial_nr_hugepages)) { 141 - perror("Failed to write to /proc/sys/vm/nr_hugepages\n"); 141 + perror("Failed to write value to /proc/sys/vm/nr_hugepages\n"); 142 142 goto close_fd; 143 143 } 144 144