浏览代码

benchmarks: test with both the binary and the python code

we use forking mode always and either execute python with the archiver module or the "borg.exe" binary.
the cmd fixture alternates between 'python' and 'binary' mode and calls exec_cmd accordingly.
Thomas Waldmann 9 年之前
父节点
当前提交
4b7c02775e
共有 2 个文件被更改,包括 18 次插入6 次删除
  1. 7 2
      borg/testsuite/archiver.py
  2. 11 4
      borg/testsuite/benchmark.py

+ 7 - 2
borg/testsuite/archiver.py

@@ -71,10 +71,15 @@ class environment_variable:
                 os.environ[k] = v
                 os.environ[k] = v
 
 
 
 
-def exec_cmd(*args, archiver=None, fork=False, **kw):
+def exec_cmd(*args, archiver=None, fork=False, exe=None, **kw):
     if fork:
     if fork:
         try:
         try:
-            borg = (sys.executable, '-m', 'borg.archiver')
+            if exe is None:
+                borg = (sys.executable, '-m', 'borg.archiver')
+            elif isinstance(exe, str):
+                borg = (exe, )
+            elif not isinstance(exe, tuple):
+                raise ValueError('exe must be None, a tuple or a str')
             output = subprocess.check_output(borg + args)
             output = subprocess.check_output(borg + args)
             ret = 0
             ret = 0
         except subprocess.CalledProcessError as e:
         except subprocess.CalledProcessError as e:

+ 11 - 4
borg/testsuite/benchmark.py

@@ -13,10 +13,17 @@ import pytest
 from .archiver import changedir, exec_cmd
 from .archiver import changedir, exec_cmd
 
 
 
 
-# TODO: use fixture params to test python code and binary
-@pytest.fixture
-def cmd():
-    return exec_cmd
+@pytest.fixture(params=['python', 'binary'])
+def cmd(request):
+    if request.param == 'python':
+        exe = None
+    elif request.param == 'binary':
+        exe = 'borg.exe'
+    else:
+        raise ValueError("param must be 'python' or 'binary'")
+    def exec_fn(*args, **kw):
+        return exec_cmd(*args, exe=exe, fork=True, **kw)
+    return exec_fn
 
 
 
 
 @pytest.yield_fixture
 @pytest.yield_fixture