Skip to contentSkip to conversation

multipath-tools unit test fixups

PATCH In review [email protected] 3 participants 9 messages Mar 2, 2020 – Apr 29, 2020 Device mapper

lore
Share & tools
lore
#0 lore raw

cover multipath-tools unit test fixups

From: Martin Wilck <[email protected]>

Hi Christophe, hi Ben,

as announced in my previous post, here's a set of minor fixups for the unit tests. The README.md should have been created long ago. My main issue is that I'd prefer not to have a file under git control that is likely to be customized in every developer's environment and needs to be stashed away before every serious git work.

Martin Wilck (4):
Remove tests/directio_test_dev
tests/Makefile: allow setting DIO_TEST_DEV in the environment tests/Makefile: add test_clean target
tests: add README.md

 tests/Makefile          | 13 +++++---
 tests/README.md         | 72 +++++++++++++++++++++++++++++++++++++++++
 tests/directio_test_dev |  4 ---
 3 files changed, 81 insertions(+), 8 deletions(-)
 create mode 100644 tests/README.md
 delete mode 100644 tests/directio_test_dev
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/4 Remove tests/directio_test_dev

From: Martin Wilck <[email protected]>

This file is designed to be customized and will therefore differ from the committed version in every serious development environment. I find that inconvenient, as the file needs to be stashed away before every serious git activity, and could easily be committed by mistake.

Follow-up patches will enable various alternative ways to set the DIO_TEST_DEV during build.

---
 tests/directio_test_dev | 4 ----
 1 file changed, 4 deletions(-)
 delete mode 100644 tests/directio_test_dev
tests/directio_test_dev deleted +0 -4
deleted file mode 100644
index d64e6238..00000000
@@ -1,4 +0,0 @@
-# To run the directio tests on an actual block device, uncomment the line
-# starting with DIO_TES_DEV, and set it to the appropriate device
-
-# DIO_TEST_DEV=/dev/sdb
Signature · 1 line
2.25.0
#2 lore raw

PATCH 2/4 tests/Makefile: allow setting DIO_TEST_DEV in the environment

In reply to [email protected]

From: Martin Wilck <[email protected]>

This change has two effects: 1. no error message is printed if the directio_test_dev file doesn't exist, and 2. DIO_TEST_DEV can be set in the environment, or on the "make" command line. It's still possible to set DIO_TEST_DEV via the directio_test_dev file if preferred.

---
 tests/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/Makefile +4 -2
index 6e3e9ca2..5f6583a0 100644
@@ -18,12 +18,14 @@ TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \
 .SILENT: $(TESTS:%=%.o)
 .PRECIOUS: $(TESTS:%=%-test)
 
-DIO_TEST_DEV = $(shell sed -n -e 's/^[[:space:]]*DIO_TEST_DEV[[:space:]]*=[[:space:]]*\([^[:space:]\#]\+\).*/\1/p' < directio_test_dev)
-
 all:	$(TESTS:%=%.out)
 
 # test-specific compiler flags
 # XYZ-test_FLAGS: Additional compiler flags for this test
+
+ifneq ($(wildcard directio_test_dev),)
+DIO_TEST_DEV = $(shell sed -n -e 's/^[[:space:]]*DIO_TEST_DEV[[:space:]]*=[[:space:]]*\([^[:space:]\#]\+\).*/\1/p' < directio_test_dev)
+endif
 ifneq ($(DIO_TEST_DEV),)
 directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\"
 endif
Signature · 1 line
2.25.0
#3 lore raw

PATCH 3/4 tests/Makefile: add test_clean target

In reply to [email protected]

From: Martin Wilck <[email protected]>

This is a convenience target to remove only the test output files. It's useful for those tests which require root permissions to run, as "make" doesn't delete the .out file if a test fails (we could force "make" to do so, but we don't want to do that, because usually we want to inspect the output file when a test has failed). With test_clean, we can run "make" as normal user, then "make test_clean" and finally run "make" as root again.

---
 tests/Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/Makefile +5 -2
index 5f6583a0..77ff3249 100644
@@ -67,8 +67,11 @@ lib/libchecktur.so:
 
 OBJS = $(TESTS:%=%.o) test-lib.o
 
-clean: dep_clean
-	$(RM) $(TESTS:%=%-test) $(TESTS:%=%.out) $(OBJS) *.o.wrap
+test_clean:
+	$(RM) $(TESTS:%=%.out)
+
+clean: test_clean dep_clean
+	$(RM) $(TESTS:%=%-test) $(OBJS) *.o.wrap
 	$(RM) -rf lib
 
 .SECONDARY: $(OBJS)
Signature · 1 line
2.25.0
#4 lore raw

PATCH 4/4 tests: add README.md

In reply to [email protected]

From: Martin Wilck <[email protected]>

Add a README explaining how to run the tests, and some of less obvious stuff in the Makefile.

---
 tests/README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 tests/README.md
tests/README.md new file +72 -0
new file mode 100644
index 00000000..6438a828
@@ -0,0 +1,72 @@
+# multipath-tools unit tests
+
+Unit tests are built and run by running `make test` in the top directory,
+or simply `make` in the `tests` subdirectory. The test output is saved as
+`<testname>.out`. The test programs are called `<testname>-test`, and can
+be run standalone e.g. for debugging purposes.
+
+## Notes on individual tests
+
+### Tests that require root permissions
+
+The following tests must be run as root, otherwise some test items will be
+skipped because of missing permissions, or the test will fail outright:
+
+ * `dmevents`
+ * `directio` (if `DIO_TEST_DEV` is set, see below)
+
+To run these tests, after building the tests as non-root user, change to the
+`tests` directory and run `make test-clean`; then run `make` again as root.
+
+### directio test
+
+This test includes test items that require a access to a block device. The
+device will be opened in read-only mode; you don't need to worry about data
+loss. However, the user needs to specify a device to be used. Set the
+environment variable `DIO_TEST_DEV` to the path of the device.
+Alternatively, create a file `directio_test_dev` under
+the `tests` directory containting a single line that sets this environment
+variable in Bourne Shell syntax, like this:
+
+    DIO_TEST_DEV=/dev/sdc3
+
+After that, run `make directio.out` as root in the `tests` directory to
+perform the test.
+
+## Adding tests
+
+The unit tests are based on the [cmocka test framework](https://cmocka.org/),
+and make use of cmocka's "mock objects" feature to simulate how the code behaves
+for different input values. cmocka achieves this by modifying the symbol
+lookup at link time, substituting "wrapper functions" for the originally
+called function. The Makefile contains code to make sure that `__wrap_xyz()`
+wrapper functions are automatically passed to the linker with matching
+`-Wl,--wrap` command line arguments, so that tests are correctly rebuilt if
+wrapper functions are added or removed.
+
+### Making sure symbol wrapping works: OBJDEPS
+
+Special care must be taken to wrap function calls inside a library. Suppose you want
+to wrap a function which is both defined in libmultipath and called from other
+functions in libmultipath, such as `checker_check()`. When `libmultipath.so` is
+created, the linker resolves calls to `checker_check()` inside the `.so`
+file. When later the test executable is built by linking the test object file with
+`libmultipath.so`, these calls can't be wrapped any more, because they've
+already been resolved, and wrapping works only for *unresolved* symbols.
+Therefore, object files from libraries that contain calls to functions
+which need to be wrapped must be explicitly listed on the linker command line
+in order to make the wrapping work. To enforce this, add these object files to
+the `xyz-test_OBJDEPS` variable in the Makefile.
+
+### Using wrapper function libraries: TESTDEPS
+
+Some wrapper functions are useful in multiple tests. These are maintained in
+separate input files, such as `test-lib.c` or `test-log.c`. List these files
+in the `xyz-test_TESTDEPS` variable for your test program if you need these
+wrappers.
+
+### Specifying library dependencies: LIBDEPS
+
+In order to keep the tests lean, not all libraries that libmultipath
+normally pulls in are used for every test. Add libraries you need (such as
+`-lpthread`) to the `xyz-test_LIBDEPS` variable.
Signature · 1 line
2.25.0
#5 lore raw
In reply to [email protected]

Ben,

take the time you need for review,
I'll wait for this patchset before tagging the next version.

Best,
Christophe.

Quoted 27 lines · On Mon, Mar 2, 2020 at 11:20 PM <[email protected]> wrote:

From: Martin Wilck <[email protected]>

Hi Christophe, hi Ben,

as announced in my previous post, here's a set of minor fixups for the unit tests. The README.md should have been created long ago. My main issue is that I'd prefer not to have a file under git control that is likely to be customized in every developer's environment and needs to be stashed away before every serious git work.

Martin Wilck (4):
Remove tests/directio_test_dev
tests/Makefile: allow setting DIO_TEST_DEV in the environment tests/Makefile: add test_clean target
tests: add README.md

 tests/Makefile          | 13 +++++---
 tests/README.md         | 72 +++++++++++++++++++++++++++++++++++++++++
 tests/directio_test_dev |  4 ---
 3 files changed, 81 insertions(+), 8 deletions(-)
 create mode 100644 tests/README.md
 delete mode 100644 tests/directio_test_dev

--
2.25.0

#6 lore raw

Hello Christophe,

Quoted 4 lines · Christophe Varoqui

Ben,

take the time you need for review,
I'll wait for this patchset before tagging the next version.

did you notice that Ben acked this set on Mar 13th?

https://www.redhat.com/archives/dm-devel/2020-March/msg00044.html

Regards,
Martin

Quoted 36 lines

Best,
Christophe.

Quoted 31 lines · On Mon, Mar 2, 2020 at 11:20 PM <[email protected]> wrote:

From: Martin Wilck <[email protected]>

Hi Christophe, hi Ben,

as announced in my previous post, here's a set of minor fixups for the
unit tests. The README.md should have been created long ago. My main
issue is that I'd prefer not to have a file under git control that is
likely to be customized in every developer's environment and needs to be stashed away before every serious git work.

Martin Wilck (4):
Remove tests/directio_test_dev
tests/Makefile: allow setting DIO_TEST_DEV in the environment tests/Makefile: add test_clean target
tests: add README.md

 tests/Makefile          | 13 +++++---
 tests/README.md         | 72
+++++++++++++++++++++++++++++++++++++++++
 tests/directio_test_dev |  4 ---
 3 files changed, 81 insertions(+), 8 deletions(-)
 create mode 100644 tests/README.md
 delete mode 100644 tests/directio_test_dev

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#7 lore raw

Hi Martin,

Yes I did notice.
I got sidetracked by other projects, but I intent to merge this patch and tag the release this week.

Thank you for the notice,
Christophe.

Quoted 54 lines · Martin Wilck

Hello Christophe,

Quoted 4 lines · Christophe Varoqui

Ben,

take the time you need for review,
I'll wait for this patchset before tagging the next version.

did you notice that Ben acked this set on Mar 13th?

https://www.redhat.com/archives/dm-devel/2020-March/msg00044.html

Regards,
Martin

Quoted 36 lines

Best,
Christophe.

Quoted 31 lines · On Mon, Mar 2, 2020 at 11:20 PM <[email protected]> wrote:

From: Martin Wilck <[email protected]>

Hi Christophe, hi Ben,

as announced in my previous post, here's a set of minor fixups for the
unit tests. The README.md should have been created long ago. My main
issue is that I'd prefer not to have a file under git control that is
likely to be customized in every developer's environment and needs to be stashed away before every serious git work.

Martin Wilck (4):
Remove tests/directio_test_dev
tests/Makefile: allow setting DIO_TEST_DEV in the environment tests/Makefile: add test_clean target
tests: add README.md

 tests/Makefile          | 13 +++++---
 tests/README.md         | 72
+++++++++++++++++++++++++++++++++++++++++
 tests/directio_test_dev |  4 ---
 3 files changed, 81 insertions(+), 8 deletions(-)
 create mode 100644 tests/README.md
 delete mode 100644 tests/directio_test_dev

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#8 lore raw
In reply to [email protected]
Quoted 10 lines · On Mon, Mar 02, 2020 at 11:20:21PM +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

Hi Christophe, hi Ben,

as announced in my previous post, here's a set of minor fixups for the unit tests. The README.md should have been created long ago. My main issue is that I'd prefer not to have a file under git control that is likely to be customized in every developer's environment and needs to be stashed away before every serious git work.

Quoted 5 lines

Martin Wilck (4):
Remove tests/directio_test_dev
tests/Makefile: allow setting DIO_TEST_DEV in the environment tests/Makefile: add test_clean target
tests: add README.md

Sorry for the delay. ACK for the set.

-Ben

Quoted 10 lines
 tests/Makefile          | 13 +++++---
 tests/README.md         | 72 +++++++++++++++++++++++++++++++++++++++++
 tests/directio_test_dev |  4 ---
 3 files changed, 81 insertions(+), 8 deletions(-)
 create mode 100644 tests/README.md
 delete mode 100644 tests/directio_test_dev
Signature · 1 line
2.25.0