[RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add defines for the file path names to avoid duplicate strings
in print messages and make it easier to maintain.

Signed-off-by: Aryabhatta Dey <aryabhattadey35@xxxxxxxxx>
---
 tools/testing/selftests/mm/compaction_test.c | 46 ++++++++++----------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
index e140558e6f53..8f46431a9182 100644
--- a/tools/testing/selftests/mm/compaction_test.c
+++ b/tools/testing/selftests/mm/compaction_test.c
@@ -21,6 +21,9 @@
 #define MAP_SIZE_MB	100
 #define MAP_SIZE	(MAP_SIZE_MB * 1024 * 1024)
 
+#define COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH "/proc/sys/vm/compact_unevictable_allowed"
+#define NR_HUGEPAGES_FILE_NAME_PATH "/proc/sys/vm/nr_hugepages"
+
 struct map_list {
 	void *map;
 	struct map_list *next;
@@ -59,17 +62,16 @@ int prereq(void)
 	char allowed;
 	int fd;
 
-	fd = open("/proc/sys/vm/compact_unevictable_allowed",
-		  O_RDONLY | O_NONBLOCK);
+	fd = open(COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, O_RDONLY | O_NONBLOCK);
 	if (fd < 0) {
-		ksft_print_msg("Failed to open /proc/sys/vm/compact_unevictable_allowed: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to open %s: %s\n",
+			       COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, strerror(errno));
 		return -1;
 	}
 
 	if (read(fd, &allowed, sizeof(char)) != sizeof(char)) {
-		ksft_print_msg("Failed to read from /proc/sys/vm/compact_unevictable_allowed: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to read from %s: %s\n",
+			       COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, strerror(errno));
 		close(fd);
 		return -1;
 	}
@@ -97,10 +99,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
 	   in to play */
 	mem_free = mem_free * 0.8;
 
-	fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
+	fd = open(NR_HUGEPAGES_FILE_NAME_PATH, O_RDWR | O_NONBLOCK);
 	if (fd < 0) {
-		ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to open %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		ret = -1;
 		goto out;
 	}
@@ -108,16 +110,16 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
 	/* Request a large number of huge pages. The Kernel will allocate
 	   as much as it can */
 	if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) {
-		ksft_print_msg("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to write 100000 to %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		goto close_fd;
 	}
 
 	lseek(fd, 0, SEEK_SET);
 
 	if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
-		ksft_print_msg("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to re-read from %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		goto close_fd;
 	}
 
@@ -134,8 +136,8 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
 
 	if (write(fd, init_nr_hugepages, strlen(init_nr_hugepages))
 	    != strlen(init_nr_hugepages)) {
-		ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to write value to %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		goto close_fd;
 	}
 
@@ -162,15 +164,15 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
 	int fd, ret = -1;
 	char nr_hugepages[20] = {0};
 
-	fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
+	fd = open(NR_HUGEPAGES_FILE_NAME_PATH, O_RDWR | O_NONBLOCK);
 	if (fd < 0) {
-		ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to open %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		goto out;
 	}
 	if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
-		ksft_print_msg("Failed to read from /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to read from %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		goto close_fd;
 	}
 
@@ -178,8 +180,8 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
 
 	/* Start with the initial condition of 0 huge pages */
 	if (write(fd, "0", sizeof(char)) != sizeof(char)) {
-		ksft_print_msg("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n",
-			       strerror(errno));
+		ksft_print_msg("Failed to write 0 to %s: %s\n",
+			       NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
 		goto close_fd;
 	}
 
-- 
2.46.0





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux