Commit 197ebb71 authored by Vishal Annapurve's avatar Vishal Annapurve Committed by Sean Christopherson
Browse files

KVM: selftests: move common startup logic to kvm_util.c

Consolidate common startup logic in one place by implementing a single
setup function with __attribute((constructor)) for all selftests within
kvm_util.c.

This allows moving logic like:
        /* Tell stdout not to buffer its content */
        setbuf(stdout, NULL);
to a single file for all selftests.

This will also allow any required setup at entry in future to be done in
common main function.

Link: https://lore.kernel.org/lkml/Ywa9T+jKUpaHLu%2Fl@google.com


Suggested-by: default avatarSean Christopherson <seanjc@google.com>
Reviewed-by: default avatarAndrew Jones <andrew.jones@linux.dev>
Reviewed-by: default avatarPeter Gonda <pgonda@google.com>
Signed-off-by: default avatarVishal Annapurve <vannapurve@google.com>
Link: https://lore.kernel.org/r/20221115213845.3348210-2-vannapurve@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 96b69958
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -446,9 +446,6 @@ int main(int argc, char *argv[])
{
	struct kvm_vm *vm;

	/* Tell stdout not to buffer its content */
	setbuf(stdout, NULL);

	if (!parse_args(argc, argv))
		exit(KSFT_SKIP);

+0 −2
Original line number Diff line number Diff line
@@ -305,8 +305,6 @@ static void test_run(void)

int main(void)
{
	setbuf(stdout, NULL);

	test_run();
	return 0;
}
+0 −3
Original line number Diff line number Diff line
@@ -817,9 +817,6 @@ int main(int argc, char **argv)
	int opt;
	bool eoi_split = false;

	/* Tell stdout not to buffer its content */
	setbuf(stdout, NULL);

	while ((opt = getopt(argc, argv, "hn:e:l:")) != -1) {
		switch (opt) {
		case 'n':
+6 −0
Original line number Diff line number Diff line
@@ -2086,3 +2086,9 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data,
		break;
	}
}

void __attribute((constructor)) kvm_selftest_init(void)
{
	/* Tell stdout not to buffer its content. */
	setbuf(stdout, NULL);
}
+0 −3
Original line number Diff line number Diff line
@@ -994,9 +994,6 @@ int main(int argc, char *argv[])
	struct test_result rbestslottime;
	int tctr;

	/* Tell stdout not to buffer its content */
	setbuf(stdout, NULL);

	if (!parse_args(argc, argv, &targs))
		return -1;

Loading