binderfs: port tests to test harness infrastructure
Makes for nicer output and prepares for additional tests. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20200313152420.138777-1-christian.brauner@ubuntu.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
095cf502b3
commit
6e29225af9
2 changed files with 17 additions and 16 deletions
|
@ -3,4 +3,6 @@
|
||||||
CFLAGS += -I../../../../../usr/include/
|
CFLAGS += -I../../../../../usr/include/
|
||||||
TEST_GEN_PROGS := binderfs_test
|
TEST_GEN_PROGS := binderfs_test
|
||||||
|
|
||||||
|
binderfs_test: binderfs_test.c ../../kselftest.h ../../kselftest_harness.h
|
||||||
|
|
||||||
include ../../lib.mk
|
include ../../lib.mk
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <linux/android/binder.h>
|
#include <linux/android/binder.h>
|
||||||
#include <linux/android/binderfs.h>
|
#include <linux/android/binderfs.h>
|
||||||
|
|
||||||
#include "../../kselftest.h"
|
#include "../../kselftest.h"
|
||||||
|
#include "../../kselftest_harness.h"
|
||||||
|
|
||||||
static ssize_t write_nointr(int fd, const void *buf, size_t count)
|
static ssize_t write_nointr(int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
|
@ -132,7 +134,7 @@ static void rmdir_protect_errno(const char *dir)
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __do_binderfs_test(void)
|
static int __do_binderfs_test(void)
|
||||||
{
|
{
|
||||||
int fd, ret, saved_errno;
|
int fd, ret, saved_errno;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -160,8 +162,7 @@ static void __do_binderfs_test(void)
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
keep ? : rmdir_protect_errno("/dev/binderfs");
|
keep ? : rmdir_protect_errno("/dev/binderfs");
|
||||||
ksft_exit_skip(
|
return 1;
|
||||||
"The Android binderfs filesystem is not available\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* binderfs mount test passed */
|
/* binderfs mount test passed */
|
||||||
|
@ -250,26 +251,24 @@ on_error:
|
||||||
|
|
||||||
/* binderfs unmount test passed */
|
/* binderfs unmount test passed */
|
||||||
ksft_inc_pass_cnt();
|
ksft_inc_pass_cnt();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void binderfs_test_privileged()
|
TEST(binderfs_test_privileged)
|
||||||
{
|
{
|
||||||
if (geteuid() != 0)
|
if (geteuid() != 0)
|
||||||
ksft_print_msg(
|
XFAIL(return, "Tests are not run as root. Skipping privileged tests");
|
||||||
"Tests are not run as root. Skipping privileged tests\n");
|
|
||||||
else
|
if (__do_binderfs_test() == 1)
|
||||||
__do_binderfs_test();
|
XFAIL(return, "The Android binderfs filesystem is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void binderfs_test_unprivileged()
|
TEST(binderfs_test_unprivileged)
|
||||||
{
|
{
|
||||||
change_to_userns();
|
change_to_userns();
|
||||||
__do_binderfs_test();
|
|
||||||
|
if (__do_binderfs_test() == 1)
|
||||||
|
XFAIL(return, "The Android binderfs filesystem is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
TEST_HARNESS_MAIN
|
||||||
{
|
|
||||||
binderfs_test_privileged();
|
|
||||||
binderfs_test_unprivileged();
|
|
||||||
ksft_exit_pass();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue