Commit ef8bd18f authored by Michal Luczaj's avatar Michal Luczaj Committed by Jakub Kicinski
Browse files

vsock/test: Introduce option to select tests



Allow for selecting specific test IDs to be executed.

Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Signed-off-by: default avatarMichal Luczaj <mhal@rbox.co>
Link: https://patch.msgid.link/20241219-test-vsock-leaks-v4-2-a416e554d9d7@rbox.co


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f3af3ba1
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -486,8 +486,7 @@ void list_tests(const struct test_case *test_cases)
	exit(EXIT_FAILURE);
}

void skip_test(struct test_case *test_cases, size_t test_cases_len,
	       const char *test_id_str)
static unsigned long parse_test_id(const char *test_id_str, size_t test_cases_len)
{
	unsigned long test_id;
	char *endptr = NULL;
@@ -505,9 +504,35 @@ void skip_test(struct test_case *test_cases, size_t test_cases_len,
		exit(EXIT_FAILURE);
	}

	return test_id;
}

void skip_test(struct test_case *test_cases, size_t test_cases_len,
	       const char *test_id_str)
{
	unsigned long test_id = parse_test_id(test_id_str, test_cases_len);
	test_cases[test_id].skip = true;
}

void pick_test(struct test_case *test_cases, size_t test_cases_len,
	       const char *test_id_str)
{
	static bool skip_all = true;
	unsigned long test_id;

	if (skip_all) {
		unsigned long i;

		for (i = 0; i < test_cases_len; ++i)
			test_cases[i].skip = true;

		skip_all = false;
	}

	test_id = parse_test_id(test_id_str, test_cases_len);
	test_cases[test_id].skip = false;
}

unsigned long hash_djb2(const void *data, size_t len)
{
	unsigned long hash = 5381;
+2 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ void run_tests(const struct test_case *test_cases,
void list_tests(const struct test_case *test_cases);
void skip_test(struct test_case *test_cases, size_t test_cases_len,
	       const char *test_id_str);
void pick_test(struct test_case *test_cases, size_t test_cases_len,
	       const char *test_id_str);
unsigned long hash_djb2(const void *data, size_t len);
size_t iovec_bytes(const struct iovec *iov, size_t iovnum);
unsigned long iovec_hash_djb2(const struct iovec *iov, size_t iovnum);
+11 −0
Original line number Diff line number Diff line
@@ -1644,6 +1644,11 @@ static const struct option longopts[] = {
		.has_arg = required_argument,
		.val = 's',
	},
	{
		.name = "pick",
		.has_arg = required_argument,
		.val = 't',
	},
	{
		.name = "help",
		.has_arg = no_argument,
@@ -1681,6 +1686,8 @@ static void usage(void)
		"  --peer-cid <cid>       CID of the other side\n"
		"  --peer-port <port>     AF_VSOCK port used for the test [default: %d]\n"
		"  --list                 List of tests that will be executed\n"
		"  --pick <test_id>       Test ID to execute selectively;\n"
		"                         use multiple --pick options to select more tests\n"
		"  --skip <test_id>       Test ID to skip;\n"
		"                         use multiple --skip options to skip more tests\n",
		DEFAULT_PEER_PORT
@@ -1737,6 +1744,10 @@ int main(int argc, char **argv)
			skip_test(test_cases, ARRAY_SIZE(test_cases) - 1,
				  optarg);
			break;
		case 't':
			pick_test(test_cases, ARRAY_SIZE(test_cases) - 1,
				  optarg);
			break;
		case '?':
		default:
			usage();