[ovs-dev] [RFC PATCH ovn v2 0/3] Unit Testing in OVN

Mark Michelson mmichels at redhat.com
Wed Oct 28 14:53:42 UTC 2020


OVN has had a test framework for as long as I've been working on the
project. The test framework is designed for performing functional tests
of OVN. That is, with the entirety of OVN up and running, we can provide
configuration and test data and ensure that OVN does with that data what
we expect. This is 100% a good thing and has helped us to detect lots of
bugs before they can actually be merged in.

What's missing, though, are smaller-scale unit tests. As an example, if
I wanted to test ovn-northd's IPAM code, I would need to start up
ovn-northd, create a logical switch, configure that logical switch to
use IPAM, and then create logical switch ports to exercise the IPAM
code. This can be overkill if my only goal is to ensure that IPAM's
algorithm for selecting the next IP address is correct.

This patch series introduces a unit test framework and does some
refactoring to make unit testing easier. More refactoring will be
required to allow for more unit tests to be written. This is just a
starting point.

If you want to run the unit tests, you can do so in a couple of ways.

1) Within the testsuite.
   ./configure --with-ovs-source=/path/to/ovs --enable-unit-tests
   make check TESTSUITEFLAGS="-k unit"

2) One-off from the command line
   ./configure --with-ovs-source=/path/to/ovs --enable-unit-tests
   make sandbox
   ovn-appctl -t ovn-northd unit-test <test_name> [test_args]

Some notes on this patch series
1) Patch 1 is the most important one in the series. This is an RFC
because I'm trying to find out if the unit test framework itself is
good. The refactoring in patch 2 and the unit tests added in patch 3 are
meant to illustrate examples of the framework. They do not necessarily
need to be merged as-is. Feel free to comment on them if you'd like,
though.
2) This patch series only adds unit test capabilities to ovn-northd
since the subject of the unit testing is IPAM. However, it also is valid
to add unit testing for ovn-controller.
---
v1 -> v2:
  * Separated refactored IPAM code into ipam.c and ipam.h in northd/
  * Wrote merge-ready unit tests instead of toy examples
  * Made unit tests work based on command line arguments. Left pass/fail
    determination to the caller based on test output.
  * Two new tests use the new unit test framework, and one uses the
    pre-existing ovstest facility.

Mark Michelson (3):
  Add unit test framework.
  northd: refactor init_ipam_info_for_datapath
  northd: Add init_ipam unit tests.

 acinclude.m4        |  12 ++
 configure.ac        |   1 +
 lib/automake.mk     |   4 +-
 lib/unit-test.c     | 125 +++++++++++++++
 lib/unit-test.h     |  41 +++++
 northd/ovn-northd.c | 362 ++++++++++++++++++++++++++++++++++----------
 tests/atlocal.in    |   1 +
 tests/automake.mk   |   3 +-
 tests/testsuite.at  |   1 +
 9 files changed, 472 insertions(+), 78 deletions(-)
 create mode 100644 lib/unit-test.c
 create mode 100644 lib/unit-test.h

-- 
2.25.4



More information about the dev mailing list