Messages in this thread | | | Date | Thu, 8 Sep 2022 14:21:52 -0700 | From | David Matlack <> | Subject | Re: [V1 PATCH 2/5] selftests: kvm: Introduce kvm_arch_main and helpers |
| |
On Tue, Sep 06, 2022 at 03:46:20PM -0700, Vishal Annapurve wrote: > On Mon, Sep 5, 2022 at 12:46 AM Andrew Jones <andrew.jones@linux.dev> wrote: > > > > On Sat, Sep 03, 2022 at 01:28:46AM +0000, Vishal Annapurve wrote: > > > Introduce following APIs: > > > 1) kvm_arch_main : to be called at the startup of each test. > > > > With this, AArch64 can move the content of its constructor, > > init_guest_modes(), into kvm_arch_main(). Or, instead of the > > > > main() > > { > > /* common main stuff */ > > kvm_arch_main(); > > __main(); > > } > > > > approach we could have each arch provide a constructor > > > > arch_init() > > { > > common_pre_main_stuff(); > > /* arch specific pre-main stuff */ > > } > > > > I personally prefer the latter. > > > > I agree with your suggestion of using constructors here. This will > help avoid changes in all the selftests. > Maybe I can add a common constructor that can invoke arch specific > init. I will add this change in the next series.
In case anyone else is confused like me: "constructor" refers to __attribute__ ((constructor)), which causes the function to run before main().
I have a slight preference for having as few constructors as possible, since they are somewhat subtle. So how about one constructor for all selftests, e.g.:
void __attribute__ ((constructor)) kvm_selftest_init(void) { /* Tell stdout not to buffer its content. */ setbuf(stdout, NULL);
kvm_selftest_arch_init(); }
Per-arch:
void kvm_selftest_arch_init(void) { /* arch-specific pre-main stuff */ }
| |