From d716d75cf7e105028855ae39da568d60a6a9bf34 Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Tue, 3 Aug 2021 22:40:25 -0400 Subject: tests: add a util_gcov_rules() utility function As documented in the function header: "This function is to make it easier for developers to temporarily add support for gcov/lcov to a test program; it likely should not be used in the normal regression tests. Further, this should only be necessary for the "live" tests." Acked-by: Tom Hromatka Signed-off-by: Paul Moore (imported from commit cc8d19b69aaadff2172b04fa37d4995ae63e895a) --- tests/util.c | 40 ++++++++++++++++++++++++++++++++++++++++ tests/util.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/tests/util.c b/tests/util.c index d212c04..f978e8a 100644 --- a/tests/util.c +++ b/tests/util.c @@ -47,6 +47,46 @@ static void _trap_handler(int signal, siginfo_t *info, void *ctx) _exit(161); } +/** + * Add rules for gcov/lcov + * @param ctx the filter context + * @param action the action for the rules + * + * This function is to make it easier for developers to temporarily add support + * for gcov/lcov to a test program; it likely should not be used in the normal + * regression tests. Further, this should only be necessary for the "live" + * tests. + * + */ +int util_gcov_rules(const scmp_filter_ctx ctx, int action) +{ + int rc; + + rc = seccomp_rule_add(ctx, action, SCMP_SYS(open), 0); + if (rc != 0) + return rc; + rc = seccomp_rule_add(ctx, action, SCMP_SYS(openat), 0); + if (rc != 0) + return rc; + rc = seccomp_rule_add(ctx, action, SCMP_SYS(fcntl), 0); + if (rc != 0) + return rc; + rc = seccomp_rule_add(ctx, action, SCMP_SYS(lseek), 0); + if (rc != 0) + return rc; + rc = seccomp_rule_add(ctx, action, SCMP_SYS(read), 0); + if (rc != 0) + return rc; + rc = seccomp_rule_add(ctx, action, SCMP_SYS(write), 0); + if (rc != 0) + return rc; + rc = seccomp_rule_add(ctx, action, SCMP_SYS(getpid), 0); + if (rc != 0) + return rc; + + return 0; +} + /** * Parse the arguments passed to main * @param argc the argument count diff --git a/tests/util.h b/tests/util.h index b3c5a29..909bef5 100644 --- a/tests/util.h +++ b/tests/util.h @@ -28,6 +28,8 @@ struct util_options { int util_getopt(int argc, char *argv[], struct util_options *opts); +int util_gcov_rules(const scmp_filter_ctx ctx, int action); + int util_filter_output(const struct util_options *opts, const scmp_filter_ctx ctx); -- cgit v1.2.1