From b03388f11299bc5ba723d61fafb9da4609e8b28a Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Jan 08 2018 19:35:26 +0000 Subject: Start python based tests 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 --- 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..52bc828 --- /dev/null +++ b/README.dev @@ -0,0 +1,20 @@ +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 use libsanlock.so and libwdmd.so from the source tree: + + $ export LD_LIBRARY_PATH=$PWD/src:$PWD/wdmd + +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)