Message ID | 20221130142249.3558647-2-nrb@linux.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | lib: add function to request migration | expand |
On Wed, 30 Nov 2022 15:22:46 +0100 Nico Boehr <nrb@linux.ibm.com> wrote: > Migration tests can ask migrate_cmd to migrate them to a new QEMU > process. Requesting migration and waiting for completion is hence a > common pattern which is repeated all over the code base. Add a function > which does all of that to avoid repeating the same pattern. > > Since migrate_cmd currently can only migrate exactly once, this function > is called migrate_once() and is a no-op when it has been called before. > This can simplify the control flow, especially when tests are skipped. > > Suggested-by: Claudio Imbrenda <imbrenda@linux.ibm.com> > Signed-off-by: Nico Boehr <nrb@linux.ibm.com> I like the code, I only have one concern > --- > lib/migrate.c | 34 ++++++++++++++++++++++++++++++++++ > lib/migrate.h | 9 +++++++++ > 2 files changed, 43 insertions(+) > create mode 100644 lib/migrate.c > create mode 100644 lib/migrate.h > > diff --git a/lib/migrate.c b/lib/migrate.c > new file mode 100644 > index 000000000000..50e78fb08865 > --- /dev/null > +++ b/lib/migrate.c > @@ -0,0 +1,34 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Migration-related functions > + * > + * Copyright IBM Corp. 2022 > + * Author: Nico Boehr <nrb@linux.ibm.com> > + */ > +#include <libcflat.h> > +#include "migrate.h" > + > +/* static for now since we only support migrating exactly once per test. */ > +static void migrate(void) > +{ > + puts("Please migrate me, then press return\n"); the other architectures use a slightly different message, maybe we should use that also on s390x? In the end it _should_ not matter, since the migrate_cmd looks for one specific keyword, but I still think we should try to minimize the impact of this series. And I know that changing the migration message will not break anything on s390x. > + (void)getchar(); > + report_info("Migration complete"); > +} > + > +/* > + * Initiate migration and wait for it to complete. > + * If this function is called more than once, it is a no-op. > + * Since migrate_cmd can only migrate exactly once this function can > + * simplify the control flow, especially when skipping tests. > + */ > +void migrate_once(void) > +{ > + static bool migrated; > + > + if (migrated) > + return; > + > + migrated = true; > + migrate(); > +} > diff --git a/lib/migrate.h b/lib/migrate.h > new file mode 100644 > index 000000000000..3c94e6af761c > --- /dev/null > +++ b/lib/migrate.h > @@ -0,0 +1,9 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Migration-related functions > + * > + * Copyright IBM Corp. 2022 > + * Author: Nico Boehr <nrb@linux.ibm.com> > + */ > + > +void migrate_once(void);
Quoting Claudio Imbrenda (2022-11-30 18:30:06) > On Wed, 30 Nov 2022 15:22:46 +0100 > Nico Boehr <nrb@linux.ibm.com> wrote: [...] > > diff --git a/lib/migrate.c b/lib/migrate.c > > new file mode 100644 > > index 000000000000..50e78fb08865 > > --- /dev/null > > +++ b/lib/migrate.c > > @@ -0,0 +1,34 @@ > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > +/* > > + * Migration-related functions > > + * > > + * Copyright IBM Corp. 2022 > > + * Author: Nico Boehr <nrb@linux.ibm.com> > > + */ > > +#include <libcflat.h> > > +#include "migrate.h" > > + > > +/* static for now since we only support migrating exactly once per test. */ > > +static void migrate(void) > > +{ > > + puts("Please migrate me, then press return\n"); > > the other architectures use a slightly different message, maybe we > should use that also on s390x? > > In the end it _should_ not matter, since the migrate_cmd looks for one > specific keyword, but I still think we should try to minimize the > impact of this series. And I know that changing the migration message > will not break anything on s390x. Oh yes, that's a very good point. Changed.
diff --git a/lib/migrate.c b/lib/migrate.c new file mode 100644 index 000000000000..50e78fb08865 --- /dev/null +++ b/lib/migrate.c @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Migration-related functions + * + * Copyright IBM Corp. 2022 + * Author: Nico Boehr <nrb@linux.ibm.com> + */ +#include <libcflat.h> +#include "migrate.h" + +/* static for now since we only support migrating exactly once per test. */ +static void migrate(void) +{ + puts("Please migrate me, then press return\n"); + (void)getchar(); + report_info("Migration complete"); +} + +/* + * Initiate migration and wait for it to complete. + * If this function is called more than once, it is a no-op. + * Since migrate_cmd can only migrate exactly once this function can + * simplify the control flow, especially when skipping tests. + */ +void migrate_once(void) +{ + static bool migrated; + + if (migrated) + return; + + migrated = true; + migrate(); +} diff --git a/lib/migrate.h b/lib/migrate.h new file mode 100644 index 000000000000..3c94e6af761c --- /dev/null +++ b/lib/migrate.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Migration-related functions + * + * Copyright IBM Corp. 2022 + * Author: Nico Boehr <nrb@linux.ibm.com> + */ + +void migrate_once(void);
Migration tests can ask migrate_cmd to migrate them to a new QEMU process. Requesting migration and waiting for completion is hence a common pattern which is repeated all over the code base. Add a function which does all of that to avoid repeating the same pattern. Since migrate_cmd currently can only migrate exactly once, this function is called migrate_once() and is a no-op when it has been called before. This can simplify the control flow, especially when tests are skipped. Suggested-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Signed-off-by: Nico Boehr <nrb@linux.ibm.com> --- lib/migrate.c | 34 ++++++++++++++++++++++++++++++++++ lib/migrate.h | 9 +++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/migrate.c create mode 100644 lib/migrate.h