• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "seccomp_bpf_tests.h"
18 
19 #include <android/log.h>
20 #include <string.h>
21 
22 static const char TAG[] = "SeccompBpfTest-Native";
23 
24 /* Forward declare from seccomp_bpf_tests.c. */
25 struct __test_metadata {
26 	const char *name;
27 	void (*fn)(struct __test_metadata *);
28 	int termsig;
29 	int passed;
30 	int trigger; /* extra handler after the evaluation */
31 	struct __test_metadata *prev, *next;
32 };
33 extern struct __test_metadata* get_seccomp_test_list();
34 extern void __run_test(struct __test_metadata*);
35 
run_seccomp_test(const char * name)36 int run_seccomp_test(const char* name) {
37     for (struct __test_metadata* t = get_seccomp_test_list(); t; t = t->next) {
38         if (strcmp(t->name, name) == 0) {
39             __android_log_print(ANDROID_LOG_INFO, TAG, "Start: %s", t->name);
40             __run_test(t);
41             __android_log_print(ANDROID_LOG_INFO, TAG, "%s: %s",
42                 t->passed ? "PASS" : "FAIL", t->name);
43             return t->passed;
44         }
45     }
46     return 0;
47 }
48