From: Nir Soffer <nsoffer(a)redhat.com>
Add python based automated tests.
This will make it easy to tests the funcionllity of the sanlock
executable on a developer machine, or in CI environment.
Nir Soffer (2):
Start python based tests
Run the tests from anywhere in the tree
.gitignore | 1 +
README.dev | 16 ++++++++++++++++
tests/direct_test.py | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+)
create mode 100644 README.dev
create mode 100644 tests/direct_test.py
--
2.9.5
Show replies by thread
From: Nir Soffer <nsoffer(a)redhat.com>
Add README.dev with instructions on how to run the tests, and add couple
of basic tests for "sanlock direct ...". Testing the direct commands is
easy. More infrastructure is needed to test the daemon.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
.gitignore | 1 +
README.dev | 16 ++++++++++++++++
tests/direct_test.py | 33 +++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+)
create mode 100644 README.dev
create mode 100644 tests/direct_test.py
diff --git a/.gitignore b/.gitignore
index 05f923a..d46effb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ tests/killpath
tests/sanlk_client
tests/sanlk_load
tests/sanlk_path
+tests/__pycache__/
diff --git a/README.dev b/README.dev
new file mode 100644
index 0000000..6e81ee0
--- /dev/null
+++ b/README.dev
@@ -0,0 +1,16 @@
+How to test sanlock
+===================
+
+To run the python based tests, you need pytest. The best way to install a
+recent version is to use pip:
+
+ $ pip install pytest
+
+Before running the tests, you need to build sanlock and wdmd:
+
+ $ make -C wdmd
+ $ make -C src
+
+To run the tests:
+
+ $ pytest
diff --git a/tests/direct_test.py b/tests/direct_test.py
new file mode 100644
index 0000000..b9966f3
--- /dev/null
+++ b/tests/direct_test.py
@@ -0,0 +1,33 @@
+"""
+Test sanlock direct options.
+"""
+
+import io
+import struct
+import subprocess
+
+SANLOCK = "src/sanlock"
+
+
+def test_init_lockspace(tmpdir):
+ path = tmpdir.join("lockspace")
+ with io.open(str(path), "wb") as f:
+ # Poison with junk data.
+ f.write(b"x" * 1024**2 + b"X" * 512)
+
+ lockspace = "name:1:%s:0" % path
+ run(SANLOCK, "direct", "init", "-s", lockspace)
+
+ with io.open(str(path), "rb") as f:
+ magic, = struct.unpack("< I", f.read(4))
+ assert magic == 0x12212010
+
+ # TODO: check more stuff here...
+
+ # Do not modify data after the lockspace area.
+ f.seek(1024**2, io.SEEK_SET)
+ assert f.read(512) == b"X" * 512
+
+
+def run(*args):
+ return subprocess.check_output(args)
--
2.9.5
From: Nir Soffer <nsoffer(a)redhat.com>
We locate the sanlock executable using the path of the test module,
instead of assuming that the tests are run from the root of the tree.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tests/direct_test.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tests/direct_test.py b/tests/direct_test.py
index b9966f3..3536f5e 100644
--- a/tests/direct_test.py
+++ b/tests/direct_test.py
@@ -3,10 +3,12 @@ Test sanlock direct options.
"""
import io
+import os
import struct
import subprocess
-SANLOCK = "src/sanlock"
+tests_dir = os.path.dirname(__file__)
+SANLOCK = os.path.join(tests_dir, os.pardir, "src", "sanlock")
def test_init_lockspace(tmpdir):
--
2.9.5