Skip to content

Commit

Permalink
proc: more robust bulk read test
Browse files Browse the repository at this point in the history
/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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Alexey Dobriyan authored and torvalds committed Mar 6, 2019
1 parent e483b02 commit 332e0e8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tools/testing/selftests/proc/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#include <dirent.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <fcntl.h>
#include <unistd.h>

Expand Down Expand Up @@ -123,10 +125,22 @@ static void f(DIR *d, unsigned int level)
int main(void)
{
DIR *d;
struct statfs sfs;

d = opendir("/proc");
if (!d)
return 4;

/* Ensure /proc is proc. */
if (fstatfs(dirfd(d), &sfs) == -1) {
return 1;
}
if (sfs.f_type != 0x9fa0) {
fprintf(stderr, "error: unexpected f_type %lx\n", (long)sfs.f_type);
return 2;
}

f(d, 0);

return 0;
}

0 comments on commit 332e0e8

Please sign in to comment.