selftests: add binderfs selftests
PATCH 1/1 selftests: add binderfs selftests
This adds the promised selftest for binderfs. It will verify the following things:
- binderfs mounting works
- binder device allocation works
- performing a binder ioctl() request through a binderfs device works
- binder device removal works
- binder-control removal fails
- binderfs unmounting works
---
/* Changelog */
v1:
- check for ENODEV on mount failure to detect whether binderfs is available
If it is not, skip the test and exit with success.
--- tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/binderfs/.gitignore | 1 + .../selftests/filesystems/binderfs/Makefile | 6 + .../filesystems/binderfs/binderfs_test.c | 126 ++++++++++++++++++ .../selftests/filesystems/binderfs/config | 3 + 5 files changed, 137 insertions(+) create mode 100644 tools/testing/selftests/filesystems/binderfs/.gitignore create mode 100644 tools/testing/selftests/filesystems/binderfs/Makefile create mode 100644 tools/testing/selftests/filesystems/binderfs/binderfs_test.c create mode 100644 tools/testing/selftests/filesystems/binderfs/config
tools/testing/selftests/Makefile +1 -0
@@ -10,6 +10,7 @@ TARGETS += drivers/dma-buf TARGETS += efivarfs TARGETS += exec TARGETS += filesystems +TARGETS += filesystems/binderfs TARGETS += firmware TARGETS += ftrace TARGETS += futex
tools/testing/selftests/filesystems/binderfs/.gitignore new file +1 -0
@@ -0,0 +1 @@ +binderfs_test
tools/testing/selftests/filesystems/binderfs/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I../../../../../usr/include/ +TEST_GEN_PROGS := binderfs_test + +include ../../lib.mk
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +126 -0
126 lines not on this page · raw message
tools/testing/selftests/filesystems/binderfs/config new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_ANDROID=y +CONFIG_ANDROID_BINDERFS=y +CONFIG_ANDROID_BINDER_IPC=y
Signature · 1 line
2.19.1
Quoted 107 lines · Christian Brauner
This adds the promised selftest for binderfs. It will verify the following things:
- binderfs mounting works
- binder device allocation works
- performing a binderioctl()request through a binderfs device works
- binder device removal works
- binder-control removal fails
- binderfs unmounting worksCc Todd Kjos <tkjos at google.com>Signed-off-by Christian Brauner <christian.brauner at ubuntu.com>---
/* Changelog */v1:
- check for ENODEV on mount failure to detect whether binderfs is available
If it is not, skip the test and exit with success.--- tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/binderfs/.gitignore | 1 + .../selftests/filesystems/binderfs/Makefile | 6 + .../filesystems/binderfs/binderfs_test.c | 126 ++++++++++++++++++ .../selftests/filesystems/binderfs/config | 3 + 5 files changed, 137 insertions(+) create mode 100644 tools/testing/selftests/filesystems/binderfs/.gitignore create mode 100644 tools/testing/selftests/filesystems/binderfs/Makefile create mode 100644 tools/testing/selftests/filesystems/binderfs/binderfs_test.c create mode 100644 tools/testing/selftests/filesystems/binderfs/configtools/testing/selftests/Makefile +1
-0@@ -10,6 +10,7 @@ TARGETS += drivers/dma-buf TARGETS += efivarfs TARGETS += exec TARGETS += filesystems +TARGETS += filesystems/binderfs TARGETS += firmware TARGETS += ftrace TARGETS += futextools/testing/selftests/filesystems/binderfs/.gitignore new file +1
-0@@ -0,0 +1 @@ +binderfs_testtools/testing/selftests/filesystems/binderfs/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I../../../../../usr/include/ +TEST_GEN_PROGS := binderfs_test + +include ../../lib.mktools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +40
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <linux/android/binder.h> +#include <linux/android/binderfs.h> +#include "../../kselftest.h" + +int main (int argc,char *argv[]) +{ +int fd, ret, saved_errno; +size_t len; +struct binderfs_device device = {0 }; +struct binder_version version = {0 }; + + ret =unshare (CLONE_NEWNS ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to unshare mount namespace\n" , +strerror (errno)); + + ret =mount (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to mount / as private\n" , +strerror (errno)); + + ret =mkdir ("/dev/binderfs" ,0755 ); +if (ret <0 && errno !=EEXIST ) +ksft_exit_fail_msg ( +"%s - Failed to create binderfs mountpoint\n" , +strerror (errno));
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 50
Quoted 10 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +10
-0+ + ret =mount (NULL ,"/dev/binderfs" ,"binder" ,0 ,0 ); +if (ret <0 ) { +if (errno !=ENODEV ) +ksft_exit_fail_msg ("%s - Failed to mount binderfs\n" , +strerror (errno)); + +ksft_test_result_skip ( +"The Android binderfs filesystem is not available\n" ); +ksft_exit_pass ();
Do you have to clean up your new directory you created and the mount? Or does exiting the code here somehow undo the unshare/mount/mkdir steps above??
Same type of question for the failure paths of the mkdir and mount calls.
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 62
Quoted 12 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +12
-0+ } + +/* binderfs mount test passed */ +ksft_inc_pass_cnt (); + +memcpy (device.name,"my-binder" ,strlen ("my-binder" )); + + fd =open ("/dev/binderfs/binder-control" ,O_RDONLY |O_CLOEXEC ); +if (fd <0 ) +ksft_exit_fail_msg ( +"%s - Failed to open binder-control device\n" , +strerror (errno));
No cleanup? Same for other calls to ksft_exit_fail_msg() later in this file.
thanks,
greg "error handling is hard!" k-h
Quoted 123 lines · Greg KH
Quoted 107 lines · Christian Brauner
This adds the promised selftest for binderfs. It will verify the following things:
- binderfs mounting works
- binder device allocation works
- performing a binderioctl()request through a binderfs device works
- binder device removal works
- binder-control removal fails
- binderfs unmounting worksCc Todd Kjos <tkjos at google.com>Signed-off-by Christian Brauner <christian.brauner at ubuntu.com>---
/* Changelog */v1:
- check for ENODEV on mount failure to detect whether binderfs is available
If it is not, skip the test and exit with success.--- tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/binderfs/.gitignore | 1 + .../selftests/filesystems/binderfs/Makefile | 6 + .../filesystems/binderfs/binderfs_test.c | 126 ++++++++++++++++++ .../selftests/filesystems/binderfs/config | 3 + 5 files changed, 137 insertions(+) create mode 100644 tools/testing/selftests/filesystems/binderfs/.gitignore create mode 100644 tools/testing/selftests/filesystems/binderfs/Makefile create mode 100644 tools/testing/selftests/filesystems/binderfs/binderfs_test.c create mode 100644 tools/testing/selftests/filesystems/binderfs/configtools/testing/selftests/Makefile +1
-0@@ -10,6 +10,7 @@ TARGETS += drivers/dma-buf TARGETS += efivarfs TARGETS += exec TARGETS += filesystems +TARGETS += filesystems/binderfs TARGETS += firmware TARGETS += ftrace TARGETS += futextools/testing/selftests/filesystems/binderfs/.gitignore new file +1
-0@@ -0,0 +1 @@ +binderfs_testtools/testing/selftests/filesystems/binderfs/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I../../../../../usr/include/ +TEST_GEN_PROGS := binderfs_test + +include ../../lib.mktools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +40
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <linux/android/binder.h> +#include <linux/android/binderfs.h> +#include "../../kselftest.h" + +int main (int argc,char *argv[]) +{ +int fd, ret, saved_errno; +size_t len; +struct binderfs_device device = {0 }; +struct binder_version version = {0 }; + + ret =unshare (CLONE_NEWNS ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to unshare mount namespace\n" , +strerror (errno)); + + ret =mount (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to mount / as private\n" , +strerror (errno)); + + ret =mkdir ("/dev/binderfs" ,0755 ); +if (ret <0 && errno !=EEXIST ) +ksft_exit_fail_msg ( +"%s - Failed to create binderfs mountpoint\n" , +strerror (errno));tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 50
Quoted 10 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +10
-0+ + ret =mount (NULL ,"/dev/binderfs" ,"binder" ,0 ,0 ); +if (ret <0 ) { +if (errno !=ENODEV ) +ksft_exit_fail_msg ("%s - Failed to mount binderfs\n" , +strerror (errno)); + +ksft_test_result_skip ( +"The Android binderfs filesystem is not available\n" ); +ksft_exit_pass ();Do you have to clean up your new directory you created and the mount? Or does exiting the code here somehow undo the unshare/mount/mkdir steps above??
Quoted 1 line
Same type of question for the failure paths of the mkdir and mount calls.
All mounts performed after a new mount namespace without propagation is setup for a process will die when all references to the mount namespace are dropped which in this case happens when the process dies.
Quoted 16 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 62
Quoted 13 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +12
-0+ } + +/* binderfs mount test passed */ +ksft_inc_pass_cnt (); + +memcpy (device.name,"my-binder" ,strlen ("my-binder" )); + + fd =open ("/dev/binderfs/binder-control" ,O_RDONLY |O_CLOEXEC ); +if (fd <0 ) +ksft_exit_fail_msg ( +"%s - Failed to open binder-control device\n" , +strerror (errno));No cleanup? Same for other calls to
ksft_exit_fail_msg()later in this file.
Same comment as above. :)
The thing we might want to cleanup is the mountpoint itself "/dev/binderfs".
Quoted 4 lines
thanks,
greg "error handling is hard!" k-h
That's fair. With patches purely for testing I always have to force myself to pay close attention because I implicitly and very much **falsely** keep thinking that the test is less important than the actual code. And I'm always a little ashamed of that. :)
Thanks!
Christian
shuah
maintainerHi Christian,
Quoted 9 lines · Christian Brauner
This adds the promised selftest for binderfs. It will verify the following things:
- binderfs mounting works
- binder device allocation works
- performing a binderioctl()request through a binderfs device works
- binder device removal works
- binder-control removal fails
- binderfs unmounting works
Thanks for the patch. A few comments below.
Quoted 83 lines
Cc Todd Kjos <tkjos at google.com>Signed-off-by Christian Brauner <christian.brauner at ubuntu.com>---
/* Changelog */v1:
- check for ENODEV on mount failure to detect whether binderfs is available
If it is not, skip the test and exit with success.--- tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/binderfs/.gitignore | 1 + .../selftests/filesystems/binderfs/Makefile | 6 + .../filesystems/binderfs/binderfs_test.c | 126 ++++++++++++++++++ .../selftests/filesystems/binderfs/config | 3 + 5 files changed, 137 insertions(+)create mode 100644
tools/testing/selftests/filesystems/binderfs/.gitignorecreate mode 100644tools/testing/selftests/filesystems/binderfs/Makefilecreate mode 100644tools/testing/selftests/filesystems/binderfs/binderfs_test.ccreate mode 100644tools/testing/selftests/filesystems/binderfs/configtools/testing/selftests/Makefile +1
-0@@ -10,6 +10,7 @@ TARGETS += drivers/dma-buf TARGETS += efivarfs TARGETS += exec TARGETS += filesystems +TARGETS += filesystems/binderfs TARGETS += firmware TARGETS += ftrace TARGETS += futextools/testing/selftests/filesystems/binderfs/.gitignore new file +1
-0@@ -0,0 +1 @@ +binderfs_testtools/testing/selftests/filesystems/binderfs/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I../../../../../usr/include/ +TEST_GEN_PROGS := binderfs_test + +include ../../lib.mktools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +25
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <linux/android/binder.h> +#include <linux/android/binderfs.h> +#include "../../kselftest.h" + +int main (int argc,char *argv[]) +{ +int fd, ret, saved_errno; +size_t len; +struct binderfs_device device = {0 }; +struct binder_version version = {0 }; +
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 35
Quoted 10 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +10
-0+ ret =unshare (CLONE_NEWNS ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to unshare mount namespace\n" , +strerror (errno)); + + ret =mount (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to mount / as private\n" , +strerror (errno)); +
If this test requires user to be root, please add check for root uid and do a skip the test with kselftest skip code.
Quoted 4 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +4
-0+ ret =mkdir ("/dev/binderfs" ,0755 ); +if (ret <0 && errno !=EEXIST ) + ksft_exit_fail_msg( + "%s - Failed to create binderfs mountpoint\n",
tools/testing/selftests/filesystems/binderfs/binderfs_test.c
Quoted 10 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +10
-0+ strerror(errno)); + + ret =mount (NULL ,"/dev/binderfs" ,"binder" ,0 ,0 ); +if (ret <0 ) { +if (errno !=ENODEV ) +ksft_exit_fail_msg ("%s - Failed to mount binderfs\n" , +strerror (errno)); + +ksft_test_result_skip ( +"The Android binderfs filesystem is not available\n" )
Use ksft_exit_skip() instead of ksft_test_result_skip()
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 50
Quoted 1 line
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +1
-0+ksft_exit_pass ();
ksft_exit_pass() would result in false pass cases. Skip is the correct exit code.
Think about other exit paths to see if skip is more appropriate.
thanks,
-- Shuah
Quoted 13 lines · shuah
Hi Christian,
Quoted 9 lines · Christian Brauner
This adds the promised selftest for binderfs. It will verify the following things:
- binderfs mounting works
- binder device allocation works
- performing a binderioctl()request through a binderfs device works
- binder device removal works
- binder-control removal fails
- binderfs unmounting works
Quoted 1 line
Thanks for the patch. A few comments below.
Thanks for the review!
Quoted 89 lines
Quoted 89 lines
Cc Todd Kjos <tkjos at google.com>Signed-off-by Christian Brauner <christian.brauner at ubuntu.com>---
/* Changelog */v1:
- check for ENODEV on mount failure to detect whether binderfs is available
If it is not, skip the test and exit with success.--- tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/binderfs/.gitignore | 1 + .../selftests/filesystems/binderfs/Makefile | 6 + .../filesystems/binderfs/binderfs_test.c | 126 ++++++++++++++++++ .../selftests/filesystems/binderfs/config | 3 + 5 files changed, 137 insertions(+)create mode 100644
tools/testing/selftests/filesystems/binderfs/.gitignorecreate mode 100644tools/testing/selftests/filesystems/binderfs/Makefilecreate mode 100644tools/testing/selftests/filesystems/binderfs/binderfs_test.ccreate mode 100644tools/testing/selftests/filesystems/binderfs/configtools/testing/selftests/Makefile +1
-0@@ -10,6 +10,7 @@ TARGETS += drivers/dma-buf TARGETS += efivarfs TARGETS += exec TARGETS += filesystems +TARGETS += filesystems/binderfs TARGETS += firmware TARGETS += ftrace TARGETS += futextools/testing/selftests/filesystems/binderfs/.gitignore new file +1
-0@@ -0,0 +1 @@ +binderfs_testtools/testing/selftests/filesystems/binderfs/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I../../../../../usr/include/ +TEST_GEN_PROGS := binderfs_test + +include ../../lib.mktools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +30
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define _GNU_SOURCE +#include <errno.h> +#include <fcntl.h> +#include <sched.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <linux/android/binder.h> +#include <linux/android/binderfs.h> +#include "../../kselftest.h" + +int main (int argc,char *argv[]) +{ +int fd, ret, saved_errno; +size_t len; +struct binderfs_device device = {0 }; +struct binder_version version = {0 }; + + ret =unshare (CLONE_NEWNS ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to unshare mount namespace\n" , +strerror (errno)); +
Quoted 8 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 35
Quoted 5 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +5
-0+ ret =mount (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +if (ret <0 ) +ksft_exit_fail_msg ("%s - Failed to mount / as private\n" , +strerror (errno)); +If this test requires user to be root, please add check for root uid and do a skip the test with kselftest skip code.
I think in addition to privileged tests I'll also add unprivileged tests when mounting binderfs inside a user namespace so that we a) can run this test as an unprivileged user and b) test that binderfs is mountable in user namespaces.
Quoted 18 lines
Quoted 5 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +4
-0+ ret =mkdir ("/dev/binderfs" ,0755 ); +if (ret <0 && errno !=EEXIST ) + ksft_exit_fail_msg( + "%s - Failed to create binderfs mountpoint\n",tools/testing/selftests/filesystems/binderfs/binderfs_test.c
Quoted 10 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +10
-0+ strerror(errno)); + + ret =mount (NULL ,"/dev/binderfs" ,"binder" ,0 ,0 ); +if (ret <0 ) { +if (errno !=ENODEV ) +ksft_exit_fail_msg ("%s - Failed to mount binderfs\n" , +strerror (errno)); + +ksft_test_result_skip ( +"The Android binderfs filesystem is not available\n" )Use
ksft_exit_skip()instead ofksft_test_result_skip()
Quoted 4 lines
tools/testing/selftests/filesystems/binderfs/binderfs_test.c line 50
Quoted 1 line
tools/testing/selftests/filesystems/binderfs/binderfs_test.c new file +1
-0+ksft_exit_pass ();
ksft_exit_pass()would result in false pass cases. Skip is the correct exit code.
Thanks, fixed now.
Christian