From c6f1976b32d9da7a361e082161e2dd62d26212d7 Mon Sep 17 00:00:00 2001
From: Zhu Huankai <zhuhuankai1@huawei.com>
Date: Sat, 5 Dec 2020 11:22:22 +0800
Subject: [PATCH] vmtop:Modify vmtop cfg structure and some comment.

vmtop cfg structure was not reasonable, and cmdline 'd' was not invalid cmd.

Add positive_test and negative_test to distinguish normal and error testcases.

Signed-off-by: Zhu Huankai <zhuhuankai1@huawei.com>
---
 libvirt/tests/cfg/virt_cmd/vmtop.cfg | 52 +++++++++++++++-------------
 libvirt/tests/src/virt_cmd/vmtop.py  | 44 ++++++++++++-----------
 2 files changed, 50 insertions(+), 46 deletions(-)

diff --git a/libvirt/tests/cfg/virt_cmd/vmtop.cfg b/libvirt/tests/cfg/virt_cmd/vmtop.cfg
index d01588e8..25e0501a 100644
--- a/libvirt/tests/cfg/virt_cmd/vmtop.cfg
+++ b/libvirt/tests/cfg/virt_cmd/vmtop.cfg
@@ -8,36 +8,38 @@
     vm_num = 1
     only aarch64
     variants:
-        - life_cycle:
+        - positive_test:
             variants:
-                - start:
-                    test_type = start
-                - destroy:
-                    test_type = destroy
-                - reboot:
-                    test_type = reboot
-                - pause_resume:
-                    test_type = pause
+                - life_cycle:
+                    variants:
+                        - start:
+                            test_type = start
+                        - destroy:
+                            test_type = destroy
+                        - reboot:
+                            test_type = reboot
+                        - pause_resume:
+                            test_type = pause
+                - data_events:
+                    test_type = data_events
+                - cmdline_d:
+                    option = "d"
+                    interval = 2
+                - multivmtop:
+                    test_type = multivmtop
+                    vmtopnum = 6
+                - vcpu_hotplug:
+                    test_type = vcpu_hotplug
+                    vcpu_placement = "static"
             variants:
                 - single_vm:
                     test_type = single_vm
                     vm_num = 1
                 - multi_vms:
-                    only start
                     test_type = multi_vms
                     vm_num = 3
-        - data_events:
-            test_type = data_events
-        - invalid_cmdline:
-            test_type = invalid_cmdline
-            option = "x"
-        - cmdline_d:
-            test_type = invalid_cmdline
-            option = "d"
-            interval = 2
-        - multivmtop:
-            test_type = multivmtop
-            vmtopnum = 6
-        - vcpu_hotplug:
-            test_type = vcpu_hotplug
-            vcpu_placement = "static"
+                    only life_cycle.start
+        - negative_test:
+            variants:
+                - invalid_cmdline:
+                    option = "x"
diff --git a/libvirt/tests/src/virt_cmd/vmtop.py b/libvirt/tests/src/virt_cmd/vmtop.py
index ace20fbd..3751b0b8 100644
--- a/libvirt/tests/src/virt_cmd/vmtop.py
+++ b/libvirt/tests/src/virt_cmd/vmtop.py
@@ -98,7 +98,7 @@ def run(test, params, env):
 
         virsh.start(vmname, ignore_status=True)
 
-        #install vmtop command
+        #Install vmtop command
         install_cmd = "yum install -y vmtop"
         process.run(install_cmd, shell=True)
         #Find vmtop command
@@ -107,7 +107,7 @@ def run(test, params, env):
         except path.CmdNotFoundError as info:
             raise exceptions.TestSkipError("No vmtop command found - %s" % info)
 
-        #test vmtop when start vm
+        #Test vmtop when start vm
         res = vmtop_info(vmtop, output_path, info_type="Domains")
         if int(res) != vm_num:
             test.fail("start failed and the res = %s" % res)
@@ -121,7 +121,7 @@ def run(test, params, env):
                     test.fail("error event:%s" % event)
                 order = order + 1
 
-        #test vmtop when other vm action happened
+        #Test vmtop when other vm action happened
         if test_type == "destroy":
             vm.destroy()
             res = vmtop_info(vmtop, output_path, info_type="Domains")
@@ -145,24 +145,19 @@ def run(test, params, env):
             if int(res) != vm_num:
                 test.fail("resume failed and the res = %s" % res)
 
-        #test vmtop with invalid cmdline
-        if option:
-            if option == "x":
-                cmd = "%s -%s" % (vmtop, option)
-                res = process.run(cmd, ignore_status=True, shell=True)
-                libvirt.check_exit_status(res, expect_error=True)
-            elif option == "d":
-                res = vmtop_interval(vmtop, interval, output_path)
-                output = res.splitlines()
-                fir_time = output[0].split()
-                sec_time = output[1].split()
-                if (int(sec_time[0]) - int(fir_time[0])) == int(interval)\
+        # Test vmtop with invalid cmdline
+        if option == "d":
+            res = vmtop_interval(vmtop, interval, output_path)
+            output = res.splitlines()
+            fir_time = output[0].split()
+            sec_time = output[1].split()
+            if (int(sec_time[0]) - int(fir_time[0])) == int(interval) \
                     or (int(sec_time[0]) + 60 - int(fir_time[0])) == int(interval):
-                    logging.info("Test option -d successfully")
-                else:
-                    test.fail("Interval error!")
+                logging.info("Test option -d successfully")
+            else:
+                test.fail("Interval error!")
 
-        #test multivmtop
+        #Test multivmtop
         if vmtopnum:
             cmd = " nohup vmtop -n 10 2>&1 &"
             num = 0
@@ -174,7 +169,7 @@ def run(test, params, env):
             if int(res) != vm_num:
                 test.fail("multivntop start failed and the res = %s" % res)
 
-        #test vcpu_hotpulggable
+        #Test vcpu_hotpulggable
         if test_type == "vcpu_hotplug":
             virsh.setvcpus(vmname, vcpu_live, ignore_status=False, debug=True)
             res = vmtop_info(vmtop, output, info_type="Cpu")
@@ -184,8 +179,15 @@ def run(test, params, env):
             else:
                 test.fail("Error result:%s" % res)
 
+        #Test vmtop with invalid cmdline
+        if option == "x":
+            cmd = "%s -%s" % (vmtop, option)
+            res = process.run(cmd, ignore_status=True, shell=True)
+            libvirt.check_exit_status(res, expect_error=True)
+
+
     finally:
-        # destroy vm_clone
+        # Destroy vm_clone
         if test_type == "multi_vms":
             num = 1
             while num < vm_num:
-- 
2.27.0

