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

proc: more robust bulk read test

/proc may not be mounted and test will exit successfully.

Ensure proc is mounted at /proc.

Link: http://lkml.kernel.org/r/20190209105613.GA10384@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alexey Dobriyan and committed by
Linus Torvalds
332e0e80 e483b020

+14
+14
tools/testing/selftests/proc/read.c
··· 26 26 #include <dirent.h> 27 27 #include <stdbool.h> 28 28 #include <stdlib.h> 29 + #include <stdio.h> 29 30 #include <string.h> 30 31 #include <sys/stat.h> 32 + #include <sys/vfs.h> 31 33 #include <fcntl.h> 32 34 #include <unistd.h> 33 35 ··· 125 123 int main(void) 126 124 { 127 125 DIR *d; 126 + struct statfs sfs; 128 127 129 128 d = opendir("/proc"); 130 129 if (!d) 131 130 return 4; 131 + 132 + /* Ensure /proc is proc. */ 133 + if (fstatfs(dirfd(d), &sfs) == -1) { 134 + return 1; 135 + } 136 + if (sfs.f_type != 0x9fa0) { 137 + fprintf(stderr, "error: unexpected f_type %lx\n", (long)sfs.f_type); 138 + return 2; 139 + } 140 + 132 141 f(d, 0); 142 + 133 143 return 0; 134 144 }