<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linux-kvm.org/index.php?action=history&amp;feed=atom&amp;title=KVM_Autotest_Refactor_page</id>
	<title>KVM Autotest Refactor page - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://linux-kvm.org/index.php?action=history&amp;feed=atom&amp;title=KVM_Autotest_Refactor_page"/>
	<link rel="alternate" type="text/html" href="https://linux-kvm.org/index.php?title=KVM_Autotest_Refactor_page&amp;action=history"/>
	<updated>2026-04-05T21:31:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://linux-kvm.org/index.php?title=KVM_Autotest_Refactor_page&amp;diff=3433&amp;oldid=prev</id>
		<title>Lmr at 01:16, 8 December 2010</title>
		<link rel="alternate" type="text/html" href="https://linux-kvm.org/index.php?title=KVM_Autotest_Refactor_page&amp;diff=3433&amp;oldid=prev"/>
		<updated>2010-12-08T01:16:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://linux-kvm.org/index.php?title=KVM_Autotest_Refactor_page&amp;amp;diff=3433&amp;amp;oldid=3432&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Lmr</name></author>
	</entry>
	<entry>
		<id>https://linux-kvm.org/index.php?title=KVM_Autotest_Refactor_page&amp;diff=3432&amp;oldid=prev</id>
		<title>Lmr at 01:09, 8 December 2010</title>
		<link rel="alternate" type="text/html" href="https://linux-kvm.org/index.php?title=KVM_Autotest_Refactor_page&amp;diff=3432&amp;oldid=prev"/>
		<updated>2010-12-08T01:09:11Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= KVM autotest refactor =&lt;br /&gt;
&lt;br /&gt;
== Suggested approach ==&lt;br /&gt;
&lt;br /&gt;
    1) Move code that has negligible impact [see table below] from &amp;#039;client/tests/kvm&amp;#039; to &amp;#039;client&amp;#039; ASAP&lt;br /&gt;
      + This would immediatelly benefit xen autotest, since it is frequently lagging behing features and fixes. One example is newer syntax in kvm_config.py that was not available in the xen autotest counterpart.&lt;br /&gt;
&lt;br /&gt;
    2) Synchronize that code (step 1) usage between kvm and xen autotest&lt;br /&gt;
      + Rewrite current tests, changing imports of modules from &amp;#039;kvm_*&amp;#039; and &amp;#039;xen_&amp;#039; to a common prefix (&amp;#039;virt_*&amp;#039; ?).&lt;br /&gt;
      + This can be done by an automated script and verified by the unit tests.&lt;br /&gt;
&lt;br /&gt;
    3) Work gradually on code that would generate more impact, implementing abstractions and other mechanisms&lt;br /&gt;
      + The config file and thus the params passed to tests already add a lot of flexibility [see example snippet #1]&lt;br /&gt;
      + Improve monitor functionality, introducing methods that wrap the hypervisor instead of sending specific commands [see example snippet #2, #3]. &lt;br /&gt;
      + This would eventually become a rather large API. libvirt API should be evaluated and if considered sound and appropriate for autotest, could be made similar.&lt;br /&gt;
      + Modify tests so that they make use of improved Monitor/VM API&lt;br /&gt;
&lt;br /&gt;
    4) Publish resulting API and best practices documentation so that new tests writers may submit &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Other notes ==&lt;br /&gt;
&lt;br /&gt;
   * Regarding the prefix (virt_* ?), some functionality is not even tied to virtualization (such as the configuration format/parser) and could benefit other complex test modules;&lt;br /&gt;
&lt;br /&gt;
   * kvm_vm:&lt;br /&gt;
    - There are significant differences in (KVM) VM class and (xen) XendDomain. Methods such as create() are quite different in parameters in implementation&lt;br /&gt;
    - (KVM) VM uses a &amp;#039;monitor&amp;#039; to interact with qemu, whether (xen) XenDomain executes &amp;#039;xm&amp;#039; commands &lt;br /&gt;
    - the &amp;#039;monitor&amp;#039; abstraction is valid, but should have clear boundaries &lt;br /&gt;
    - xen autotest should also get a &amp;#039;monitor&amp;#039; implementation&lt;br /&gt;
    - this even paves the way to a libvirt based monitor implementation&lt;br /&gt;
    - probably a capabilities mechanism would be necessary to acomodate diferences between virt technologies (see kvm_monitor below)&lt;br /&gt;
&lt;br /&gt;
  * kvm_monitor&lt;br /&gt;
   - There are methods and parameters which do not map completely to Xen, specially PV guests (screendump, migrate with full disk copy, mouse move, etc)&lt;br /&gt;
   - Again, a capabilities mechanism could be used&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
== Example #1 (pci_hotplug.py) ==&lt;br /&gt;
&lt;br /&gt;
Parameters provide a lot of flexibility and diminish the need to implement a interface on a variant that does not need or cannot provide it. This code snippet:&lt;br /&gt;
&lt;br /&gt;
26    # Modprobe the module if specified in config file&lt;br /&gt;
27    module = params.get(&amp;quot;modprobe_module&amp;quot;)&lt;br /&gt;
28    if module:&lt;br /&gt;
29        session.cmd(&amp;quot;modprobe %s&amp;quot; % module)&lt;br /&gt;
&lt;br /&gt;
could be kept exactly like that, loading &amp;#039;acpiphp&amp;#039; as it does now for RHEL guests onon kvm and nothing for RHEL xen domU kernels (with XEN_PCIDEV_FRONTEND=y). &lt;br /&gt;
&lt;br /&gt;
If someone wants to test a xen domU kernel with modular XEN_PCIDEV_FRONTEND, only this parameter would have to be adjusted.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example #2 (pci_hotplug.py) ==&lt;br /&gt;
&lt;br /&gt;
Only operations from the monitor side (vm.monitor.*) would have to be implemented for each virtualization technology. On the guest side (session.cmd_output() and the like), things could go unchanged, helped by parameters when necessary.&lt;br /&gt;
&lt;br /&gt;
Curent code:&lt;br /&gt;
&lt;br /&gt;
31    # Get output of command &amp;#039;info pci&amp;#039; as reference&lt;br /&gt;
32    info_pci_ref = vm.monitor.info(&amp;quot;pci&amp;quot;)&lt;br /&gt;
33&lt;br /&gt;
34    # Get output of command as reference&lt;br /&gt;
35    reference = session.cmd_output(params.get(&amp;quot;reference_cmd&amp;quot;))&lt;br /&gt;
   &lt;br /&gt;
Suggested code:&lt;br /&gt;
&lt;br /&gt;
31    # Get output of command &amp;#039;info pci&amp;#039; as reference&lt;br /&gt;
32    info_pci_ref = vm.monitor.get_pci_info()&lt;br /&gt;
33&lt;br /&gt;
34    # Get output of command as reference&lt;br /&gt;
35    reference = session.cmd_output(params.get(&amp;quot;reference_cmd&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example #3 (pci_hotplug.py) ==&lt;br /&gt;
&lt;br /&gt;
Current test code not only interacts directly with qemu but also deals with different versions and syntaxes:&lt;br /&gt;
&lt;br /&gt;
41    # Probe qemu to verify what is the supported syntax for PCI hotplug&lt;br /&gt;
42    cmd_output = vm.monitor.cmd(&amp;quot;?&amp;quot;)&lt;br /&gt;
43    if len(re.findall(&amp;quot;\ndevice_add&amp;quot;, cmd_output)) &amp;gt; 0:&lt;br /&gt;
44        cmd_type = &amp;quot;device_add&amp;quot;&lt;br /&gt;
45    elif len(re.findall(&amp;quot;\npci_add&amp;quot;, cmd_output)) &amp;gt; 0:&lt;br /&gt;
46        cmd_type = &amp;quot;pci_add&amp;quot;&lt;br /&gt;
47    else:&lt;br /&gt;
48        raise error.TestError(&amp;quot;Unknow version of qemu&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Again, this should be abstracted in the monitor implementation, and consumed by the test code (this is even commented in the current code):&lt;br /&gt;
&lt;br /&gt;
59        # Execute pci_add (should be replaced by a proper monitor method call)&lt;br /&gt;
60        add_output = vm.monitor.cmd(pci_add_cmd)&lt;br /&gt;
61        if not &amp;quot;OK domain&amp;quot; in add_output:&lt;br /&gt;
62            raise error.TestFail(&amp;quot;Add PCI device failed. &amp;quot;&lt;br /&gt;
63                                 &amp;quot;Monitor command is: %s, Output: %r&amp;quot; %&lt;br /&gt;
64                                 (pci_add_cmd, add_output))&lt;br /&gt;
65        after_add = vm.monitor.info(&amp;quot;pci&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
This should become:&lt;br /&gt;
&lt;br /&gt;
59        # Execute pci_add &lt;br /&gt;
60        if not vm.monitor_pci_add(model):&lt;br /&gt;
61            raise error.TestFail(&amp;quot;Add PCI device failed.&amp;quot;)&lt;br /&gt;
62        after_add = vm.monitor.get_pci_info()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Library code under client/tests/kvm ==&lt;br /&gt;
&lt;br /&gt;
The componentes are sorted by depencies, so that working down the list would solve all depencies, except when circular dependencies exist.&lt;br /&gt;
&lt;br /&gt;
Filename		Impact		Dependencies		Spec  Tied   Xen&lt;br /&gt;
--------		------		------------		----  ----   ---&lt;br /&gt;
kmv_config.py		Negligible	kvm_utils (logging)	No    No     Yes&lt;br /&gt;
kvm_subprocess.py       Negligible	none	  		No    No     Yes&lt;br /&gt;
scan_results.py		Negligible	none			No    No     Yes&lt;br /&gt;
cd_hash.py		Negligible	kvm_utils (logging)	No    No     No&lt;br /&gt;
rss_file_transfer.py	Negligible	none			No    No     No&lt;br /&gt;
&lt;br /&gt;
kvm_monitor.py		High		kvm_utils (random_str)	No    Yes   No[1]&lt;br /&gt;
kvm_vm.py 		High		kvm_utils 		No    Yes   Yes&lt;br /&gt;
					kvm_subprocess&lt;br /&gt;
					kvm_monitor&lt;br /&gt;
					rss_file_transfer&lt;br /&gt;
&lt;br /&gt;
kvm_scheduler.py	Medium		kvm_utils		No[2] Yes[3] No &lt;br /&gt;
kvm_preprocessing.py	Medium		kvm_vm 	  		No    Yes[4] Yes&lt;br /&gt;
					kvm_utils&lt;br /&gt;
					kvm_subprocess&lt;br /&gt;
					kvm_monitor&lt;br /&gt;
kvm_utils.py		High		kvm_subprocess		No    Yes[5] Yes&lt;br /&gt;
&lt;br /&gt;
kvm_test_utils.py	High		kvm_utils		No    Yes    Yes&lt;br /&gt;
					kvm_vm&lt;br /&gt;
					kvm_subprocess&lt;br /&gt;
					scan_results&lt;br /&gt;
&lt;br /&gt;
Legend:&lt;br /&gt;
-------&lt;br /&gt;
- Spec: Specific for KVM (that is, not applicable to other virt technologies)&lt;br /&gt;
- Tied: Currently tied to KVM in its current implementation&lt;br /&gt;
- Xen: Currently used by xen autotest or has equivalent/derived implementation&lt;br /&gt;
&lt;br /&gt;
[1] - Xen autotest currently does not implement a monitor, but this analysis recommends one to be implemented&lt;br /&gt;
[2] - Currently xen autotest does not have a control file that uses parallel tests, so it&amp;#039;s low priority but could be useful&lt;br /&gt;
[3] - Tied only to kvm.VM and vm.monitor, used as abstractions&lt;br /&gt;
[4] - Tied only to kvm.VM and vm.monitor, used as abstractions&lt;br /&gt;
[5] - There&amp;#039;s both kvm specific code and code that should be shared between xen and kvm autotest&lt;/div&gt;</summary>
		<author><name>Lmr</name></author>
	</entry>
</feed>