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

selftest: move seek_to_smaps_entry() out of mlock2-tests.c

Function seek_to_smaps_entry() can be useful for other selftest
functionalities, so move it out to header file.

Link: http://lkml.kernel.org/r/1473325970-11393-3-git-send-email-wei.guo.simon@gmail.com
Signed-off-by: Simon Guo <wei.guo.simon@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Eric B Munson <emunson@akamai.com>
Cc: Simon Guo <wei.guo.simon@gmail.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Alexey Klimov <klimov.linux@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Simon Guo and committed by
Linus Torvalds
d5aed9c0 1448d4d8

+42 -42
-42
tools/testing/selftests/vm/mlock2-tests.c
··· 1 1 #define _GNU_SOURCE 2 2 #include <sys/mman.h> 3 3 #include <stdint.h> 4 - #include <stdio.h> 5 - #include <stdlib.h> 6 4 #include <unistd.h> 7 5 #include <string.h> 8 6 #include <sys/time.h> ··· 115 117 116 118 fclose(file); 117 119 return flags; 118 - } 119 - 120 - static FILE *seek_to_smaps_entry(unsigned long addr) 121 - { 122 - FILE *file; 123 - char *line = NULL; 124 - size_t size = 0; 125 - unsigned long start, end; 126 - char perms[5]; 127 - unsigned long offset; 128 - char dev[32]; 129 - unsigned long inode; 130 - char path[BUFSIZ]; 131 - 132 - file = fopen("/proc/self/smaps", "r"); 133 - if (!file) { 134 - perror("fopen smaps"); 135 - _exit(1); 136 - } 137 - 138 - while (getline(&line, &size, file) > 0) { 139 - if (sscanf(line, "%lx-%lx %s %lx %s %lu %s\n", 140 - &start, &end, perms, &offset, dev, &inode, path) < 6) 141 - goto next; 142 - 143 - if (start <= addr && addr < end) 144 - goto out; 145 - 146 - next: 147 - free(line); 148 - line = NULL; 149 - size = 0; 150 - } 151 - 152 - fclose(file); 153 - file = NULL; 154 - 155 - out: 156 - free(line); 157 - return file; 158 120 } 159 121 160 122 #define VMFLAGS "VmFlags:"
+42
tools/testing/selftests/vm/mlock2.h
··· 1 1 #include <syscall.h> 2 2 #include <errno.h> 3 + #include <stdio.h> 4 + #include <stdlib.h> 3 5 4 6 #ifndef MLOCK_ONFAULT 5 7 #define MLOCK_ONFAULT 1 ··· 19 17 errno = ENOSYS; 20 18 return -1; 21 19 #endif 20 + } 21 + 22 + static FILE *seek_to_smaps_entry(unsigned long addr) 23 + { 24 + FILE *file; 25 + char *line = NULL; 26 + size_t size = 0; 27 + unsigned long start, end; 28 + char perms[5]; 29 + unsigned long offset; 30 + char dev[32]; 31 + unsigned long inode; 32 + char path[BUFSIZ]; 33 + 34 + file = fopen("/proc/self/smaps", "r"); 35 + if (!file) { 36 + perror("fopen smaps"); 37 + _exit(1); 38 + } 39 + 40 + while (getline(&line, &size, file) > 0) { 41 + if (sscanf(line, "%lx-%lx %s %lx %s %lu %s\n", 42 + &start, &end, perms, &offset, dev, &inode, path) < 6) 43 + goto next; 44 + 45 + if (start <= addr && addr < end) 46 + goto out; 47 + 48 + next: 49 + free(line); 50 + line = NULL; 51 + size = 0; 52 + } 53 + 54 + fclose(file); 55 + file = NULL; 56 + 57 + out: 58 + free(line); 59 + return file; 22 60 }