Commit 91b2c0af authored by Yucong Sun's avatar Yucong Sun Committed by Andrii Nakryiko

selftests/bpf: Add parallelism to test_progs

This patch adds "-j" mode to test_progs, executing tests in multiple
process.  "-j" mode is optional, and works with all existing test
selection mechanism, as well as "-v", "-l" etc.

In "-j" mode, main process use UDS/SEQPACKET to communicate to each forked
worker, commanding it to run tests and collect logs. After all tests are
finished, a summary is printed. main process use multiple competing
threads to dispatch work to worker, trying to keep them all busy.

The test status will be printed as soon as it is finished, if there are
error logs, it will be printed after the final summary line.

By specifying "--debug", additional debug information on server/worker
communication will be printed.

Example output:
  > ./test_progs -n 15-20 -j
  [   12.801730] bpf_testmod: loading out-of-tree module taints kernel.
  Launching 8 workers.
  #20 btf_split:OK
  #16 btf_endian:OK
  #18 btf_module:OK
  #17 btf_map_in_map:OK
  #19 btf_skc_cls_ingress:OK
  #15 btf_dump:OK
  Summary: 6/20 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: default avatarYucong Sun <sunyucong@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211006185619.364369-2-fallentree@fb.com
parent a1852ce0
This diff is collapsed.
...@@ -62,6 +62,7 @@ struct test_env { ...@@ -62,6 +62,7 @@ struct test_env {
struct test_selector test_selector; struct test_selector test_selector;
struct test_selector subtest_selector; struct test_selector subtest_selector;
bool verifier_stats; bool verifier_stats;
bool debug;
enum verbosity verbosity; enum verbosity verbosity;
bool jit_enabled; bool jit_enabled;
...@@ -69,7 +70,8 @@ struct test_env { ...@@ -69,7 +70,8 @@ struct test_env {
bool get_test_cnt; bool get_test_cnt;
bool list_test_names; bool list_test_names;
struct prog_test_def *test; struct prog_test_def *test; /* current running tests */
FILE *stdout; FILE *stdout;
FILE *stderr; FILE *stderr;
char *log_buf; char *log_buf;
...@@ -82,6 +84,38 @@ struct test_env { ...@@ -82,6 +84,38 @@ struct test_env {
int skip_cnt; /* skipped tests */ int skip_cnt; /* skipped tests */
int saved_netns_fd; int saved_netns_fd;
int workers; /* number of worker process */
int worker_id; /* id number of current worker, main process is -1 */
pid_t *worker_pids; /* array of worker pids */
int *worker_socks; /* array of worker socks */
int *worker_current_test; /* array of current running test for each worker */
};
#define MAX_LOG_TRUNK_SIZE 8192
enum msg_type {
MSG_DO_TEST = 0,
MSG_TEST_DONE = 1,
MSG_TEST_LOG = 2,
MSG_EXIT = 255,
};
struct msg {
enum msg_type type;
union {
struct {
int test_num;
} do_test;
struct {
int test_num;
int sub_succ_cnt;
int error_cnt;
int skip_cnt;
bool have_log;
} test_done;
struct {
char log_buf[MAX_LOG_TRUNK_SIZE + 1];
bool is_last;
} test_log;
};
}; };
extern struct test_env env; extern struct test_env env;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment