ACK and Pushed
Thanks
Hongming
On 04/24/2015 12:53 PM, Jianwei Hu wrote:
It's OK to me, please hongming help review it again.
BR,
Jianwei
----- Original Message -----
From: "Luyao Huang" <lhuang(a)redhat.com>
To: libvir-list(a)redhat.com
Cc: "Luyao Huang" <lhuang(a)redhat.com>
Sent: Wednesday, April 22, 2015 9:00:55 PM
Subject: [libvirt] [libvirt-test-api][PATCH 1/3] introduce 2 functions in utils
get_standard_deviation() is to get Standard Deviation, and
param_to_tuple_nolength() allow do not pass lengh when use
param_to_tuple().
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
utils/utils.py | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/utils/utils.py b/utils/utils.py
index c3e46f6..954b2bf 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -31,6 +31,7 @@ import string
import subprocess
import hashlib
import libvirt
+import math
from xml.dom import minidom
from urlparse import urlparse
@@ -896,3 +897,30 @@ def validate_remote_blk_type(hostname, username, password,
else:
logger.info("lspci and lsmod return nothing")
return 1
+
+def get_standard_deviation(cb1, cb2, opaque1, opaque2, number = 1000):
+ """ pass two callback functions and opaque return Standard
Deviation,
+ this function will be useful when need equal some quick change
+ value (like memory, cputime), default loop times are 1000,
+ and notice callback functions cb1 and cb2 should allways success
+ """
+ D = 0
+ for i in range(number):
+ a = cb1(opaque1)
+ b = cb2(opaque2)
+ D += (int(a) - int(b))**2
+ return math.sqrt(D/number)
+
+def param_to_tuple_nolength(paramlist):
+ """paramlist contains numbers which can be divided by '-',
'^' and
+ ',', return tuple only have True or False value
+ """
+ d = []
+ a = paramlist.split(',')
+ for i in range(len(a)):
+ if a[i].find('^') >= 0:
+ continue
+ d += a[i].split('-')
+ lengh = max(d)
+
+ return param_to_tuple(paramlist, int(lengh) + 1)