Skip to contentSkip to conversation

Unit testing in openvpn?

Openvpn-devel Jens 7 participants 11 messages Apr 21, 2016 – Apr 23, 2016

lore
Share & tools
lore

Jens

author
#0 lore raw

Hi

I think that adding unit tests would greatly improve the ease of implementing new features for openvpn. I have spend a lot of time coding Java (and others), and unit testing greatly improved my code quality, my throughput, and last, but not least, my confidence in the code. Indeed I have become very humble when it comes to the question of ‘what could possibly go wrong with this small change?’

What would be the steps to include unit testing?
—————————————————————————————————

1) Decide /if/ we want unit tests
2) Decide /how/ we want unit tests (this includes questions like dependency management, and the build system)
3) Decide /which/ framework to use
4) do it

How: Dependency management
—————————————————————————————————

Adding a test framework would require a way to include & track this dependency.

I see three possibilities

* Copy-and-forget: Add a copy the upstream testing framework and add it as-is to the source code repo.
* Include-dependency-management: Add some kind of dependency management, e.g. cmake packages.
* Use-the-SCM: Use git submodules to add the dependency.

I dislike Copy-and-forget because it pollutes the repository, and makes tracking upstream changes very hard.

I have no experience with Makefile based dependency management

But I do know how to handle a git submodule.

I have a very strong preference to using a git submodule for unit testing.

Poll
—————————————————————————————————

What are your thoughts? Should we add unit tests at all? What would be your preferred way for dependency management. Please defer discussion on /which/ unit testing framework to use until we have an agreement on the /if/ and /how/ (just to prevent the ‘paint the bike shed’ discussion).

Cheers, Jens

#1 lore raw

the most comfortable for github is travis-ci (it runs tests even for pull requests).
we already use it for openvpn-gui and openvpn-build projects (just build, those projects do not have any tests yet):

https://travis-ci.org/OpenVPN/openvpn-gui
https://travis-ci.org/OpenVPN/openvpn-build

as for openvpn itself, there's special branch, which is used for coverity scan on travis-ci:

https://travis-ci.org/OpenVPN/openvpn

and there's some tests for openvpn:
https://github.com/OpenVPN/openvpn/tree/master/tests

2016-04-21 12:12 GMT+05:00 Jens <[email protected]...>:

Quoted 65 lines

Hi

I think that adding unit tests would greatly improve the ease of implementing new features for openvpn. I have spend a lot of time coding Java (and others), and unit testing greatly improved my code quality, my throughput, and last, but not least, my confidence in the code. Indeed I have become very humble when it comes to the question of ‘what could possibly go wrong with this small change?’

What would be the steps to include unit testing?
—————————————————————————————————

1) Decide /if/ we want unit tests
2) Decide /how/ we want unit tests (this includes questions like dependency management, and the build system)
3) Decide /which/ framework to use
4) do it

How: Dependency management
—————————————————————————————————

Adding a test framework would require a way to include & track this dependency.

I see three possibilities

* Copy-and-forget: Add a copy the upstream testing framework and add it as-is to the source code repo.
* Include-dependency-management: Add some kind of dependency management, e.g. cmake packages.
* Use-the-SCM: Use git submodules to add the dependency.

I dislike Copy-and-forget because it pollutes the repository, and makes tracking upstream changes very hard.

I have no experience with Makefile based dependency management

But I do know how to handle a git submodule.

I have a very strong preference to using a git submodule for unit testing.

Poll
—————————————————————————————————

What are your thoughts? Should we add unit tests at all? What would be your preferred way for dependency management. Please defer discussion on /which/ unit testing framework to use until we have an agreement on the /if/ and /how/ (just to prevent the ‘paint the bike shed’ discussion).

Cheers, Jens

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Openvpn-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#2 lore raw
In reply to Jens

Am 21.04.16 um 09:12 schrieb Jens:

Quoted 11 lines

Hi

I think that adding unit tests would greatly improve the ease of implementing new features for openvpn. I have spend a lot of time coding Java (and others), and unit testing greatly improved my code quality, my throughput, and last, but not least, my confidence in the code. Indeed I have become very humble when it comes to the question of ‘what could possibly go wrong with this small change?’

What would be the steps to include unit testing?
—————————————————————————————————

1) Decide /if/ we want unit tests
2) Decide /how/ we want unit tests (this includes questions like dependency management, and the build system)
3) Decide /which/ framework to use
4) do it

The problem with unit tests and existing software is that, if the software hasn't been written with testing in mind, it is often hard without major refactoring to do the small java style unit tests. Also someone has to write these unit tests and free time is currently sparse among the OpenVPN developers.

A more realistic first step for OpenVPN is a automated testing suite that goes beyond what we have at the moment in shell scripts. Setting up a mininet for example and automatically cofingure client and server, and see if everything works as expected as an example.

Quoted 9 lines

How: Dependency management
—————————————————————————————————

Adding a test framework would require a way to include & track this dependency.

I see three possibilities

* Copy-and-forget: Add a copy the upstream testing framework and add it as-is to the source code repo.
* Include-dependency-management: Add some kind of dependency management, e.g. cmake packages.

cmake vs autoconf/automake is somehwat heated discussion. At the moment the project is using autoconf/automake since it has always been using that.

Quoted 10 lines

* Use-the-SCM: Use git submodules to add the dependency.

I dislike Copy-and-forget because it pollutes the repository, and makes tracking upstream changes very hard.

I have no experience with Makefile based dependency management

But I do know how to handle a git submodule.

I have a very strong preference to using a git submodule for unit testing.

I think how to put a testing framework into git is secondary. If unit tests are useful in the current state, we can discuss about how to include them.

Arne

#3 lore raw
Quoted 17 lines
Quoted 7 lines

Adding a test framework would require a way to include & track this dependency.

I see three possibilities

* Copy-and-forget: Add a copy the upstream testing framework and add it as-is to the source code repo.
* Include-dependency-management: Add some kind of dependency management, e.g. cmake packages.

cmake vs autoconf/automake is somehwat heated discussion. At the moment the project is using autoconf/automake since it has always been using that.

Quoted 8 lines

* Use-the-SCM: Use git submodules to add the dependency.

I dislike Copy-and-forget because it pollutes the repository, and makes tracking upstream changes very hard.

I have no experience with Makefile based dependency management

But I do know how to handle a git submodule.

Quoted 7 lines
Quoted 2 lines

I have a very strong preference to using a git submodule for unit testing.

I think how to put a testing framework into git is secondary. If unit tests are useful in the current state, we can discuss about how to include them.

Arne

I think the first step would be to identify the places where unit tests could be implemented easily (if any), and where they would do most good. If something falls to both of these categories then writing a unit test there would probably make sense.

Then there's the other codebase (3.x) which, when publicly released, might be a good/better candidate for writing unit tests.

If we end up writing unit tests, I too would prefer the Git submodule approach.

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#4 lore raw

Hi Samuli,

[…]

Quoted 1 line

I think the first step would be to identify the places where unit tests could be implemented easily (if any), and where they would do most good. If something falls to both of these categories then writing a unit test there would probably make sense.

The first candidate would be the U2F integration that I’d like to write. A proven strategy for starting unit testing is to write tests for all new features. This way the up-front cost is reduced to the invest for “the first test”.

Quoted 2 lines

Then there's the other codebase (3.x) which, when publicly released, might be a good/better candidate for writing unit tests.

Please forgive my ignorance: Is this code base already a thing, and what is the time scale we are looking at (regarding “V3”)?

Quoted 2 lines

If we end up writing unit tests, I too would prefer the Git submodule approach.

Great :-)

Jens

Quoted 7 lines
Signature · 6 lines
-- 
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#8 lore raw
In reply to Arne Schwabe

Hi Arne,

[…]

Quoted 6 lines
Quoted 1 line

The problem with unit tests and existing software is that, if the software hasn't been written with testing in mind, it is often hard without major refactoring to do the small java style unit tests. Also someone has to write these unit tests and free time is currently sparse among the OpenVPN developers.

I agree - adding unit tests is difficult, when the project is not designed that way. But: Every journey starts with the first step. I am willing to go the first step. I just do not want to be alone after that.

Quoted 6 lines

A more realistic first step for OpenVPN is a automated testing suite that goes beyond what we have at the moment in shell scripts. Setting up a mininet for example and automatically cofingure client and server, and see if everything works as expected as an example.

Quoted 1 line

Now that you mention it: Please find attached my first pre-alpha version of a vagrant based test server for t_client.sh ;-)

It compiles & runs an openvpn server suitable for t_client.sh in a VM.

Comments welcome (the scripts will go into a dedicated folder, as will the Vagrant file. I’m in the middle of sketching this out)

- copy the Vagrant file in ./tests
- edit t_client.rc (see the diff of t_client.rc-sample)
- compiling/starting the server: see blow/in the Vagrant file
- start t_client.sh

#9 lore raw
In reply to Jens

Hi,

Quoted 6 lines · Jens

I think that adding unit tests would greatly improve the ease of implementing new features for openvpn. I have spend a lot of time coding Java (and others), and unit testing greatly improved my code quality, my throughput, and last, but not least, my confidence in the code. Indeed I have become very humble when it comes to the question of ???what could possibly go wrong with this small change????

I'm somewhat of a mixed mind on this.

Experience in the last few years after the current development team sort of "inherited" the OpenVPN code base was that *these* things that have blown up in a spectactular way were usually

- (unexpected) system dependencies - like, a totally harmless and well-tested change to the socket stuff which broke compilation on all *BSDs

- too many options, and users using "unexpected" combinations of options - so you change something, you are aware that it's an intrusive change, and all your individual tests work out nicely - but then, incoming user complaint, because "if I use this with systemd *and* a password-protected key *and* <x>, it fails!"

- operating systems changing behind us, like MacOS 64 bit keeping binary compatibility with MacOS 32 bit for some structures, thus breaking source API compatibility (use uint32_t instead of "int" now)

some of theses can be fairly well tested in our current buildbot framework (= each commit is built on nearly all supported platforms, and runs "make check", which does a full "setup network, transfer data, close down network, see if it cleans up properly" check if t_client.rc is there), but some are really hard to test for, like the constant --multihome brokenness on one or the other platform (because you need that platform, more than one IP address configured, and actual UDP packets being sent back and forth to excercise the problem)...

So, I'm all for doing more extensive testing, but unit testing will not catch those things that have bitten us big time in the past - because when we do "big changes", on purpose, but forget about combinations of options, all the unit tests will succeed (because the individual units are all well-behaved, just the combination isn't)

Quoted 4 lines

What would be the steps to include unit testing? ???????????????????????????????????????????????????????????????????????????????????????????????????

1) Decide /if/ we want unit tests

Yes :-)

But it will be hard. The current source code does not lend itself very nicely to unit testing (and those bits that *do*, like buffer.c, are so well established and tested by now that we tend to never having to touch anything there anyway)...

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#5 lore raw
In reply to Jens Neuhalfen

Hi,

Quoted 4 lines · Jens Neuhalfen

The first candidate would be the U2F integration that I???d like to write. A proven strategy for starting unit testing is to write tests for all new features. This way the up-front cost is reduced to the invest for ???the first test???.

A test driver for the plugin API is actually something which might work reasonably well as test rig...

OTOH, testing one-time-passwords in an automated manner sounds complicated.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#6 lore raw
Quoted 11 lines · Gert Doering

Hi,

Quoted 4 lines · Jens Neuhalfen

The first candidate would be the U2F integration that I???d like to write. A proven strategy for starting unit testing is to write tests for all new features. This way the up-front cost is reduced to the invest for ???the first test???.

A test driver for the plugin API is actually something which might work reasonably well as test rig...

I have started working on a patch set to make it possible to unit test plug-ins more easily. But for this to make sense, I need to clean up the OpenVPN code somewhat so it is possible to base it on much of the code base already existing in OpenVPN. That's a good way to also test the OpenVPN side of the plug-in API.

Now all that sounds easy enough. Then I realised a massive code clean-up is needed, as there are some cross-dependencies where the plug-in unit test framework would suddenly need the full network stack in OpenVPN (which plug-in code paths never cross - yes socket.c, route.c and forward.c was needed in my first attempts). I did come quite a good step forward on the last hackathon ... unfortunately my work+family situation have made it hard to hack further on that in a long while. But I have good hopes to believe I'll be able to spend more time on this in not very far future.

The reason for looking into a test framework for plug-ins is that we have some auth-pam patches we've been very cautious with due to lack of testability. And many more plug-ins can benefit from such a test framework too.

Quoted 2 lines

OTOH, testing one-time-passwords in an automated manner sounds complicated.

Not really, there are pretty solid TOTP/HOTP libraries which can be integrated into test frameworks without too much hassle. You just need some keying material to be consistent between server side and client side of the test. I've already poked into this a few times.

Signature · 3 lines
kind regards,

David Sommerseth
#7 lore raw
In reply to Jens Neuhalfen
Quoted 4 lines
Quoted 2 lines

Then there's the other codebase (3.x) which, when publicly released, might be a good/better candidate for writing unit tests.

Please forgive my ignorance: Is this code base already a thing, and what is the time scale we are looking at (regarding “V3”)?

The 3.x codebase is included in OpenVPN Connect clients. It will be released in GitHub when James Yonan (the original author of OpenVPN) has some extra time to clean up the codebase up and make the release. This could take a few weeks or a few months, but there is nothing really blocking the release afaik.

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#10 lore raw
In reply to Jens
Quoted 1 line · Jens

What are your thoughts? Should we add unit tests at all? What would be your preferred way for dependency management. Please defer discussion on /which/ unit testing framework to use until we have an agreement on the /if/ and /how/ (just to prevent the ‘paint the bike shed’ discussion).

Yes, adding unit tests (or at least, a working framework to create unit tests) is welcome. We should realize that a large part of the 2.x codebase is really hard to test this way, but for those parts we can isolate, this still makes sense.

We currently do dependency management through configure / autoconf. It's not perfect, but we have it in place. I think I'd prefer using that for a test framework too, if possible (ie, if 'link to libxyztest' suffices).

I recognize the risk of bike shedding, but I'm afraid the way we would integrate a test framework greatly depends on how it works... Do you know what are common C test suites / do you have any suggestions? (For C, I've only worked with proprietary test suites before).

-Steffan