Thread (50 messages) flat view 50 messages, 5 authors, 2017-04-20

Re: [PATCH net-next v6 09/11] seccomp: Enhance test_harness with an assert step mechanism

From: Kees Cook <hidden>
Date: 2017-04-19 00:03:08
Also in: linux-security-module, lkml, netdev

On Tue, Mar 28, 2017 at 4:46 PM, Mickaël Salaün [off-list ref] wrote:
quoted hunk ↗ jump to hunk
This is useful to return an information about the error without being
able to write to TH_LOG_STREAM.

Helpers from test_harness.h may be useful outside of the seccomp
directory.

Signed-off-by: Mickaël Salaün <redacted>
Cc: Andy Lutomirski <redacted>
Cc: Arnaldo Carvalho de Melo <redacted>
Cc: Kees Cook <redacted>
Cc: Shuah Khan <redacted>
Cc: Will Drewry <redacted>
---
 tools/testing/selftests/seccomp/test_harness.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/seccomp/test_harness.h b/tools/testing/selftests/seccomp/test_harness.h
index a786c69c7584..77e407663e06 100644
--- a/tools/testing/selftests/seccomp/test_harness.h
+++ b/tools/testing/selftests/seccomp/test_harness.h
@@ -397,7 +397,7 @@ struct __test_metadata {
        const char *name;
        void (*fn)(struct __test_metadata *);
        int termsig;
-       int passed;
+       __s8 passed;
Why the reduction here? int is signed too?
quoted hunk ↗ jump to hunk
        int trigger; /* extra handler after the evaluation */
        struct __test_metadata *prev, *next;
 };
@@ -476,6 +476,12 @@ void __run_test(struct __test_metadata *t)
                                        "instead of by signal (code: %d)\n",
                                        t->name,
                                        WEXITSTATUS(status));
+                       } else if (t->passed < 0) {
+                               fprintf(TH_LOG_STREAM,
+                                       "%s: Failed at step #%d\n",
+                                       t->name,
+                                       t->passed * -1);
+                               t->passed = 0;
                        }
Instead of creating an overloaded mechanism here, perhaps have an
option reporting mechanism that can be enabled. Like adding to
__test_metadata "bool no_stream; int test_number;" and adding
test_number++ to each ASSERT/EXCEPT call, and doing something like:

if (t->no_stream) {
                              fprintf(TH_LOG_STREAM,
                                      "%s: Failed at step #%d\n",
                                      t->name,
                                       t->test_number);
}

It'd be a cleaner approach, maybe?

-Kees

-- 
Kees Cook
Pixel Security
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help