xref: /kvm-unit-tests/lib/migrate.c (revision fa8914bccc226db86bd70d71bfd6022db252fc78)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Migration-related functions
4  *
5  * Copyright IBM Corp. 2022
6  * Author: Nico Boehr <nrb@linux.ibm.com>
7  */
8 #include <libcflat.h>
9 #include "migrate.h"
10 
11 /*
12  * Initiate migration and wait for it to complete.
13  */
14 void migrate(void)
15 {
16 	puts("Now migrate the VM, then press a key to continue...\n");
17 	(void)getchar();
18 	report_info("Migration complete");
19 }
20 
21 /*
22  * Like migrate() but suppress output and logs, useful for intensive
23  * migration stress testing without polluting logs. Test cases should
24  * provide relevant information about migration in failure reports.
25  */
26 void migrate_quiet(void)
27 {
28 	puts("Now migrate the VM (quiet)\n");
29 	(void)getchar();
30 }
31 
32 /*
33  * Initiate migration and wait for it to complete.
34  * If this function is called more than once, it is a no-op.
35  */
36 void migrate_once(void)
37 {
38 	static bool migrated;
39 
40 	if (migrated)
41 		return;
42 	migrated = true;
43 
44 	migrate();
45 }
46 
47 /*
48  * When the test has been started in migration mode, but the test case is
49  * skipped and no migration point is reached, this can be used to tell the
50  * harness not to mark it as a failure to migrate.
51  */
52 void migrate_skip(void)
53 {
54 	static bool did_migrate_skip;
55 
56 	if (did_migrate_skip)
57 		return;
58 	did_migrate_skip = true;
59 
60 	puts("Skipped VM migration (quiet)\n");
61 	(void)getchar();
62 }
63