* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-15 16:59 ` keescook
0 siblings, 0 replies; 9+ messages in thread
From: Kees Cook @ 2018-03-15 16:59 UTC (permalink / raw)
To: Shuah Khan
Cc: linux-kernel, linux-kselftest, Andy Lutomirski, Will Drewry,
Tycho Andersen
Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
test if the ptrace reports it as missing.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
tools/testing/selftests/kselftest_harness.h | 26 +++++++++++++++++++++++++-
tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++--
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index e81bd28bdd89..6ae3730c4ee3 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -107,6 +107,27 @@
__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
/**
+ * XFAIL(statement, fmt, ...)
+ *
+ * @statement: statement to run after reporting XFAIL
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * This forces a "pass" after reporting a failure with an XFAIL prefix,
+ * and runs "statement", which is usually "return" or "goto skip".
+ */
+#define XFAIL(statement, fmt, ...) do { \
+ if (TH_LOG_ENABLED) { \
+ fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
+ ##__VA_ARGS__); \
+ } \
+ /* TODO: find a way to pass xfail to test runner process. */ \
+ _metadata->passed = 1; \
+ _metadata->trigger = 0; \
+ statement; \
+} while (0)
+
+/**
* TEST(test_name) - Defines the test function and creates the registration
* stub
*
@@ -198,7 +219,7 @@
/**
* FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
- * *_metadata* is included so that ASSERT_* work as a convenience
+ * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
*
* @fixture_name: fixture name
*
@@ -221,6 +242,7 @@
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
/**
* FIXTURE_TEARDOWN(fixture_name)
+ * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
*
* @fixture_name: fixture name
*
@@ -253,6 +275,8 @@
* Defines a test that depends on a fixture (e.g., is part of a test case).
* Very similar to TEST() except that *self* is the setup instance of fixture's
* datatype exposed for use by the implementation.
+ *
+ * Warning: use of ASSERT_* here will skip TEARDOWN.
*/
/* TODO(wad) register fixtures on dedicated test lists. */
#define TEST_F(fixture_name, test_name) \
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 92db48825dc1..d7e54031e26b 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -2860,6 +2860,7 @@ TEST(get_metadata)
int pipefd[2];
char buf;
struct seccomp_metadata md;
+ long ret;
ASSERT_EQ(0, pipe(pipefd));
@@ -2893,16 +2894,26 @@ TEST(get_metadata)
ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
ASSERT_EQ(pid, waitpid(pid, NULL, 0));
+ /* Past here must not use ASSERT or child process is never killed. */
+
md.filter_off = 0;
- ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
+ errno = 0;
+ ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
+ EXPECT_EQ(sizeof(md), ret) {
+ if (errno == EINVAL)
+ XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
+ }
+
EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
EXPECT_EQ(md.filter_off, 0);
md.filter_off = 1;
- ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
+ ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
+ EXPECT_EQ(sizeof(md), ret);
EXPECT_EQ(md.flags, 0);
EXPECT_EQ(md.filter_off, 1);
+skip:
ASSERT_EQ(0, kill(pid, SIGKILL));
}
--
2.7.4
--
Kees Cook
Pixel Security
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-15 16:59 ` keescook
0 siblings, 0 replies; 9+ messages in thread
From: keescook @ 2018-03-15 16:59 UTC (permalink / raw)
Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
test if the ptrace reports it as missing.
Signed-off-by: Kees Cook <keescook at chromium.org>
---
tools/testing/selftests/kselftest_harness.h | 26 +++++++++++++++++++++++++-
tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++--
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index e81bd28bdd89..6ae3730c4ee3 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -107,6 +107,27 @@
__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
/**
+ * XFAIL(statement, fmt, ...)
+ *
+ * @statement: statement to run after reporting XFAIL
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * This forces a "pass" after reporting a failure with an XFAIL prefix,
+ * and runs "statement", which is usually "return" or "goto skip".
+ */
+#define XFAIL(statement, fmt, ...) do { \
+ if (TH_LOG_ENABLED) { \
+ fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
+ ##__VA_ARGS__); \
+ } \
+ /* TODO: find a way to pass xfail to test runner process. */ \
+ _metadata->passed = 1; \
+ _metadata->trigger = 0; \
+ statement; \
+} while (0)
+
+/**
* TEST(test_name) - Defines the test function and creates the registration
* stub
*
@@ -198,7 +219,7 @@
/**
* FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
- * *_metadata* is included so that ASSERT_* work as a convenience
+ * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
*
* @fixture_name: fixture name
*
@@ -221,6 +242,7 @@
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
/**
* FIXTURE_TEARDOWN(fixture_name)
+ * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
*
* @fixture_name: fixture name
*
@@ -253,6 +275,8 @@
* Defines a test that depends on a fixture (e.g., is part of a test case).
* Very similar to TEST() except that *self* is the setup instance of fixture's
* datatype exposed for use by the implementation.
+ *
+ * Warning: use of ASSERT_* here will skip TEARDOWN.
*/
/* TODO(wad) register fixtures on dedicated test lists. */
#define TEST_F(fixture_name, test_name) \
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 92db48825dc1..d7e54031e26b 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -2860,6 +2860,7 @@ TEST(get_metadata)
int pipefd[2];
char buf;
struct seccomp_metadata md;
+ long ret;
ASSERT_EQ(0, pipe(pipefd));
@@ -2893,16 +2894,26 @@ TEST(get_metadata)
ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
ASSERT_EQ(pid, waitpid(pid, NULL, 0));
+ /* Past here must not use ASSERT or child process is never killed. */
+
md.filter_off = 0;
- ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
+ errno = 0;
+ ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
+ EXPECT_EQ(sizeof(md), ret) {
+ if (errno == EINVAL)
+ XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
+ }
+
EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
EXPECT_EQ(md.filter_off, 0);
md.filter_off = 1;
- ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
+ ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
+ EXPECT_EQ(sizeof(md), ret);
EXPECT_EQ(md.flags, 0);
EXPECT_EQ(md.filter_off, 1);
+skip:
ASSERT_EQ(0, kill(pid, SIGKILL));
}
--
2.7.4
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-15 16:59 ` keescook
0 siblings, 0 replies; 9+ messages in thread
From: Kees Cook @ 2018-03-15 16:59 UTC (permalink / raw)
Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
test if the ptrace reports it as missing.
Signed-off-by: Kees Cook <keescook at chromium.org>
---
tools/testing/selftests/kselftest_harness.h | 26 +++++++++++++++++++++++++-
tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++--
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index e81bd28bdd89..6ae3730c4ee3 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -107,6 +107,27 @@
__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
/**
+ * XFAIL(statement, fmt, ...)
+ *
+ * @statement: statement to run after reporting XFAIL
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * This forces a "pass" after reporting a failure with an XFAIL prefix,
+ * and runs "statement", which is usually "return" or "goto skip".
+ */
+#define XFAIL(statement, fmt, ...) do { \
+ if (TH_LOG_ENABLED) { \
+ fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
+ ##__VA_ARGS__); \
+ } \
+ /* TODO: find a way to pass xfail to test runner process. */ \
+ _metadata->passed = 1; \
+ _metadata->trigger = 0; \
+ statement; \
+} while (0)
+
+/**
* TEST(test_name) - Defines the test function and creates the registration
* stub
*
@@ -198,7 +219,7 @@
/**
* FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
- * *_metadata* is included so that ASSERT_* work as a convenience
+ * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
*
* @fixture_name: fixture name
*
@@ -221,6 +242,7 @@
FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
/**
* FIXTURE_TEARDOWN(fixture_name)
+ * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
*
* @fixture_name: fixture name
*
@@ -253,6 +275,8 @@
* Defines a test that depends on a fixture (e.g., is part of a test case).
* Very similar to TEST() except that *self* is the setup instance of fixture's
* datatype exposed for use by the implementation.
+ *
+ * Warning: use of ASSERT_* here will skip TEARDOWN.
*/
/* TODO(wad) register fixtures on dedicated test lists. */
#define TEST_F(fixture_name, test_name) \
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 92db48825dc1..d7e54031e26b 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -2860,6 +2860,7 @@ TEST(get_metadata)
int pipefd[2];
char buf;
struct seccomp_metadata md;
+ long ret;
ASSERT_EQ(0, pipe(pipefd));
@@ -2893,16 +2894,26 @@ TEST(get_metadata)
ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
ASSERT_EQ(pid, waitpid(pid, NULL, 0));
+ /* Past here must not use ASSERT or child process is never killed. */
+
md.filter_off = 0;
- ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
+ errno = 0;
+ ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
+ EXPECT_EQ(sizeof(md), ret) {
+ if (errno == EINVAL)
+ XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
+ }
+
EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
EXPECT_EQ(md.filter_off, 0);
md.filter_off = 1;
- ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
+ ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
+ EXPECT_EQ(sizeof(md), ret);
EXPECT_EQ(md.flags, 0);
EXPECT_EQ(md.filter_off, 1);
+skip:
ASSERT_EQ(0, kill(pid, SIGKILL));
}
--
2.7.4
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
2018-03-15 16:59 ` keescook
(?)
@ 2018-03-15 17:14 ` tycho
-1 siblings, 0 replies; 9+ messages in thread
From: Tycho Andersen @ 2018-03-15 17:14 UTC (permalink / raw)
To: Kees Cook
Cc: Shuah Khan, linux-kernel, linux-kselftest, Andy Lutomirski, Will Drewry
On Thu, Mar 15, 2018 at 09:59:16AM -0700, Kees Cook wrote:
> Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
> test if the ptrace reports it as missing.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Tycho Andersen <tycho@tycho.ws>
Thanks, Kees.
> ---
> tools/testing/selftests/kselftest_harness.h | 26 +++++++++++++++++++++++++-
> tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++--
> 2 files changed, 38 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index e81bd28bdd89..6ae3730c4ee3 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -107,6 +107,27 @@
> __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
>
> /**
> + * XFAIL(statement, fmt, ...)
> + *
> + * @statement: statement to run after reporting XFAIL
> + * @fmt: format string
> + * @...: optional arguments
> + *
> + * This forces a "pass" after reporting a failure with an XFAIL prefix,
> + * and runs "statement", which is usually "return" or "goto skip".
> + */
> +#define XFAIL(statement, fmt, ...) do { \
> + if (TH_LOG_ENABLED) { \
> + fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
> + ##__VA_ARGS__); \
> + } \
> + /* TODO: find a way to pass xfail to test runner process. */ \
> + _metadata->passed = 1; \
> + _metadata->trigger = 0; \
> + statement; \
> +} while (0)
> +
> +/**
> * TEST(test_name) - Defines the test function and creates the registration
> * stub
> *
> @@ -198,7 +219,7 @@
>
> /**
> * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
> - * *_metadata* is included so that ASSERT_* work as a convenience
> + * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
> *
> * @fixture_name: fixture name
> *
> @@ -221,6 +242,7 @@
> FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
> /**
> * FIXTURE_TEARDOWN(fixture_name)
> + * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
> *
> * @fixture_name: fixture name
> *
> @@ -253,6 +275,8 @@
> * Defines a test that depends on a fixture (e.g., is part of a test case).
> * Very similar to TEST() except that *self* is the setup instance of fixture's
> * datatype exposed for use by the implementation.
> + *
> + * Warning: use of ASSERT_* here will skip TEARDOWN.
> */
> /* TODO(wad) register fixtures on dedicated test lists. */
> #define TEST_F(fixture_name, test_name) \
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index 92db48825dc1..d7e54031e26b 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -2860,6 +2860,7 @@ TEST(get_metadata)
> int pipefd[2];
> char buf;
> struct seccomp_metadata md;
> + long ret;
>
> ASSERT_EQ(0, pipe(pipefd));
>
> @@ -2893,16 +2894,26 @@ TEST(get_metadata)
> ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
> ASSERT_EQ(pid, waitpid(pid, NULL, 0));
>
> + /* Past here must not use ASSERT or child process is never killed. */
> +
> md.filter_off = 0;
> - ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
> + errno = 0;
> + ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
> + EXPECT_EQ(sizeof(md), ret) {
> + if (errno == EINVAL)
> + XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
> + }
> +
> EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
> EXPECT_EQ(md.filter_off, 0);
>
> md.filter_off = 1;
> - ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
> + ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
> + EXPECT_EQ(sizeof(md), ret);
> EXPECT_EQ(md.flags, 0);
> EXPECT_EQ(md.filter_off, 1);
>
> +skip:
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
>
> --
> 2.7.4
>
>
> --
> Kees Cook
> Pixel Security
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-15 17:14 ` tycho
0 siblings, 0 replies; 9+ messages in thread
From: tycho @ 2018-03-15 17:14 UTC (permalink / raw)
On Thu, Mar 15, 2018 at 09:59:16AM -0700, Kees Cook wrote:
> Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
> test if the ptrace reports it as missing.
>
> Signed-off-by: Kees Cook <keescook at chromium.org>
Acked-by: Tycho Andersen <tycho at tycho.ws>
Thanks, Kees.
> ---
> tools/testing/selftests/kselftest_harness.h | 26 +++++++++++++++++++++++++-
> tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++--
> 2 files changed, 38 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index e81bd28bdd89..6ae3730c4ee3 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -107,6 +107,27 @@
> __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
>
> /**
> + * XFAIL(statement, fmt, ...)
> + *
> + * @statement: statement to run after reporting XFAIL
> + * @fmt: format string
> + * @...: optional arguments
> + *
> + * This forces a "pass" after reporting a failure with an XFAIL prefix,
> + * and runs "statement", which is usually "return" or "goto skip".
> + */
> +#define XFAIL(statement, fmt, ...) do { \
> + if (TH_LOG_ENABLED) { \
> + fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
> + ##__VA_ARGS__); \
> + } \
> + /* TODO: find a way to pass xfail to test runner process. */ \
> + _metadata->passed = 1; \
> + _metadata->trigger = 0; \
> + statement; \
> +} while (0)
> +
> +/**
> * TEST(test_name) - Defines the test function and creates the registration
> * stub
> *
> @@ -198,7 +219,7 @@
>
> /**
> * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
> - * *_metadata* is included so that ASSERT_* work as a convenience
> + * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
> *
> * @fixture_name: fixture name
> *
> @@ -221,6 +242,7 @@
> FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
> /**
> * FIXTURE_TEARDOWN(fixture_name)
> + * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
> *
> * @fixture_name: fixture name
> *
> @@ -253,6 +275,8 @@
> * Defines a test that depends on a fixture (e.g., is part of a test case).
> * Very similar to TEST() except that *self* is the setup instance of fixture's
> * datatype exposed for use by the implementation.
> + *
> + * Warning: use of ASSERT_* here will skip TEARDOWN.
> */
> /* TODO(wad) register fixtures on dedicated test lists. */
> #define TEST_F(fixture_name, test_name) \
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index 92db48825dc1..d7e54031e26b 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -2860,6 +2860,7 @@ TEST(get_metadata)
> int pipefd[2];
> char buf;
> struct seccomp_metadata md;
> + long ret;
>
> ASSERT_EQ(0, pipe(pipefd));
>
> @@ -2893,16 +2894,26 @@ TEST(get_metadata)
> ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
> ASSERT_EQ(pid, waitpid(pid, NULL, 0));
>
> + /* Past here must not use ASSERT or child process is never killed. */
> +
> md.filter_off = 0;
> - ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
> + errno = 0;
> + ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
> + EXPECT_EQ(sizeof(md), ret) {
> + if (errno == EINVAL)
> + XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
> + }
> +
> EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
> EXPECT_EQ(md.filter_off, 0);
>
> md.filter_off = 1;
> - ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
> + ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
> + EXPECT_EQ(sizeof(md), ret);
> EXPECT_EQ(md.flags, 0);
> EXPECT_EQ(md.filter_off, 1);
>
> +skip:
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
>
> --
> 2.7.4
>
>
> --
> Kees Cook
> Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-15 17:14 ` tycho
0 siblings, 0 replies; 9+ messages in thread
From: Tycho Andersen @ 2018-03-15 17:14 UTC (permalink / raw)
On Thu, Mar 15, 2018@09:59:16AM -0700, Kees Cook wrote:
> Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
> test if the ptrace reports it as missing.
>
> Signed-off-by: Kees Cook <keescook at chromium.org>
Acked-by: Tycho Andersen <tycho at tycho.ws>
Thanks, Kees.
> ---
> tools/testing/selftests/kselftest_harness.h | 26 +++++++++++++++++++++++++-
> tools/testing/selftests/seccomp/seccomp_bpf.c | 15 +++++++++++++--
> 2 files changed, 38 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index e81bd28bdd89..6ae3730c4ee3 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -107,6 +107,27 @@
> __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
>
> /**
> + * XFAIL(statement, fmt, ...)
> + *
> + * @statement: statement to run after reporting XFAIL
> + * @fmt: format string
> + * @...: optional arguments
> + *
> + * This forces a "pass" after reporting a failure with an XFAIL prefix,
> + * and runs "statement", which is usually "return" or "goto skip".
> + */
> +#define XFAIL(statement, fmt, ...) do { \
> + if (TH_LOG_ENABLED) { \
> + fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \
> + ##__VA_ARGS__); \
> + } \
> + /* TODO: find a way to pass xfail to test runner process. */ \
> + _metadata->passed = 1; \
> + _metadata->trigger = 0; \
> + statement; \
> +} while (0)
> +
> +/**
> * TEST(test_name) - Defines the test function and creates the registration
> * stub
> *
> @@ -198,7 +219,7 @@
>
> /**
> * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
> - * *_metadata* is included so that ASSERT_* work as a convenience
> + * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
> *
> * @fixture_name: fixture name
> *
> @@ -221,6 +242,7 @@
> FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
> /**
> * FIXTURE_TEARDOWN(fixture_name)
> + * *_metadata* is included so that EXPECT_* and ASSERT_* work correctly.
> *
> * @fixture_name: fixture name
> *
> @@ -253,6 +275,8 @@
> * Defines a test that depends on a fixture (e.g., is part of a test case).
> * Very similar to TEST() except that *self* is the setup instance of fixture's
> * datatype exposed for use by the implementation.
> + *
> + * Warning: use of ASSERT_* here will skip TEARDOWN.
> */
> /* TODO(wad) register fixtures on dedicated test lists. */
> #define TEST_F(fixture_name, test_name) \
> diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
> index 92db48825dc1..d7e54031e26b 100644
> --- a/tools/testing/selftests/seccomp/seccomp_bpf.c
> +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
> @@ -2860,6 +2860,7 @@ TEST(get_metadata)
> int pipefd[2];
> char buf;
> struct seccomp_metadata md;
> + long ret;
>
> ASSERT_EQ(0, pipe(pipefd));
>
> @@ -2893,16 +2894,26 @@ TEST(get_metadata)
> ASSERT_EQ(0, ptrace(PTRACE_ATTACH, pid));
> ASSERT_EQ(pid, waitpid(pid, NULL, 0));
>
> + /* Past here must not use ASSERT or child process is never killed. */
> +
> md.filter_off = 0;
> - ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
> + errno = 0;
> + ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
> + EXPECT_EQ(sizeof(md), ret) {
> + if (errno == EINVAL)
> + XFAIL(goto skip, "Kernel does not support PTRACE_SECCOMP_GET_METADATA (missing CONFIG_CHECKPOINT_RESTORE?)");
> + }
> +
> EXPECT_EQ(md.flags, SECCOMP_FILTER_FLAG_LOG);
> EXPECT_EQ(md.filter_off, 0);
>
> md.filter_off = 1;
> - ASSERT_EQ(sizeof(md), ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md));
> + ret = ptrace(PTRACE_SECCOMP_GET_METADATA, pid, sizeof(md), &md);
> + EXPECT_EQ(sizeof(md), ret);
> EXPECT_EQ(md.flags, 0);
> EXPECT_EQ(md.filter_off, 1);
>
> +skip:
> ASSERT_EQ(0, kill(pid, SIGKILL));
> }
>
> --
> 2.7.4
>
>
> --
> Kees Cook
> Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
2018-03-15 17:14 ` tycho
(?)
@ 2018-03-21 16:48 ` shuah
-1 siblings, 0 replies; 9+ messages in thread
From: Shuah Khan @ 2018-03-21 16:48 UTC (permalink / raw)
To: Tycho Andersen, Kees Cook
Cc: linux-kernel, linux-kselftest, Andy Lutomirski, Will Drewry,
Shuah Khan, Shuah Khan
On 03/15/2018 11:14 AM, Tycho Andersen wrote:
> On Thu, Mar 15, 2018 at 09:59:16AM -0700, Kees Cook wrote:
>> Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
>> test if the ptrace reports it as missing.
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>
> Acked-by: Tycho Andersen <tycho@tycho.ws>
>
> Thanks, Kees.
>
Thanks. Applied to linux-kselftest next for 4.17-rc1
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-21 16:48 ` shuah
0 siblings, 0 replies; 9+ messages in thread
From: shuah @ 2018-03-21 16:48 UTC (permalink / raw)
On 03/15/2018 11:14 AM, Tycho Andersen wrote:
> On Thu, Mar 15, 2018 at 09:59:16AM -0700, Kees Cook wrote:
>> Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
>> test if the ptrace reports it as missing.
>>
>> Signed-off-by: Kees Cook <keescook at chromium.org>
>
> Acked-by: Tycho Andersen <tycho at tycho.ws>
>
> Thanks, Kees.
>
Thanks. Applied to linux-kselftest next for 4.17-rc1
thanks,
-- Shuah
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] selftests/seccomp: Allow get_metadata to XFAIL
@ 2018-03-21 16:48 ` shuah
0 siblings, 0 replies; 9+ messages in thread
From: Shuah Khan @ 2018-03-21 16:48 UTC (permalink / raw)
On 03/15/2018 11:14 AM, Tycho Andersen wrote:
> On Thu, Mar 15, 2018@09:59:16AM -0700, Kees Cook wrote:
>> Since seccomp_get_metadata() depends on CHECKPOINT_RESTORE, XFAIL the
>> test if the ptrace reports it as missing.
>>
>> Signed-off-by: Kees Cook <keescook at chromium.org>
>
> Acked-by: Tycho Andersen <tycho at tycho.ws>
>
> Thanks, Kees.
>
Thanks. Applied to linux-kselftest next for 4.17-rc1
thanks,
-- Shuah
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-03-21 16:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-15 16:59 [PATCH] selftests/seccomp: Allow get_metadata to XFAIL Kees Cook
2018-03-15 16:59 ` Kees Cook
2018-03-15 16:59 ` keescook
2018-03-15 17:14 ` Tycho Andersen
2018-03-15 17:14 ` Tycho Andersen
2018-03-15 17:14 ` tycho
2018-03-21 16:48 ` Shuah Khan
2018-03-21 16:48 ` Shuah Khan
2018-03-21 16:48 ` shuah
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.