proc: test /proc/self/wchan
Subsystems (2)
PATCH 1/2 proc: test /proc/self/wchan
This patch starts testing /proc. Many more tests to come (I promise).
Read from /proc/self/wchan should always return "0" as current is in TASK_RUNNING state while reading /proc/self/wchan.
Signed-off-by Alexey Dobriyan <[email protected]>
---
tools/testing/selftests/Makefile | 1 + tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 6 ++++++ tools/testing/selftests/proc/config | 1 + tools/testing/selftests/proc/proc-self-wchan.c | 25 +++++++++++++++++++++++++ 6 files changed, 35 insertions(+)
tools/testing/selftests/Makefile +1 -0
@@ -23,6 +23,7 @@ TARGETS += mqueue TARGETS += net TARGETS += nsfs TARGETS += powerpc +TARGETS += proc TARGETS += pstore TARGETS += ptrace TARGETS += seccomp
new file mode 100644
tools/testing/selftests/proc/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/proc-self-wchan
new file mode 100644
tools/testing/selftests/proc/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +CFLAGS += -Wall -O2 + +TEST_GEN_PROGS := +TEST_GEN_PROGS += proc-self-wchan + +include ../lib.mk
new file mode 100644
tools/testing/selftests/proc/config new file +1 -0
@@ -0,0 +1 @@ +CONFIG_PROC_FS=y
new file mode 100644
tools/testing/selftests/proc/proc-self-wchan.c new file +25 -0
@@ -0,0 +1,25 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <unistd.h> + +int main (void ) +{ +char buf[64 ]; +int fd; + + fd =open ("/proc/self/wchan" ,O_RDONLY ); +if (fd ==-1 ) { +if (errno ==ENOENT ) +return 2 ; +return 1 ; + } + + buf[0 ] ='\0' ; +if (read (fd, buf,sizeof (buf)) !=1 ) +return 1 ; +if (buf[0 ] !='0' ) +return 1 ; +return 0 ; +}