[Dnsmasq-discuss] [PATCH] dnsmasq unit tests!

Petr Menšík pemensik at redhat.com
Thu May 14 15:19:55 BST 2020


Hi Geert,

I have made some modifications and cleanup. I added make check target to
main Makefile, otherwise it is kept separate.

Because I have discovered today kyua tool is not packaged (yet) in
Debian (and also Ubuntu), I made just a simple shell wrapper around
tests in Makefile. It produces more detailed text output.

I were also able to run automated checks on every push, using commit
[1]. Check actions in my project copy [2]. Seems pretty cool.

1.
https://github.com/InfrastructureServices/dnsmasq/commit/2411fe8aa4aefefedb01c7c3a0846995f65fd789
2. https://github.com/InfrastructureServices/dnsmasq/actions

On 5/12/20 10:51 PM, Geert Stappers wrote:
> On Mon, May 04, 2020 at 05:02:38PM +0200, Petr Menšík wrote:
>> Hello everyone,
>>
>> we have merged support for multiple IPv6 addresses to our release in
>> RHEL. We tried to ensure it does not break anything and we failed.
>>
>> I made already some dnsmasq tests in separate repository [1], running in
>> network namespaces. There are two kinds of tests. Simple shell backed
>> bats tests in bash. bats and bash packages are required to run them.
>> Second kind are few tests in beakerlib [2], which is test framework used
>> in Fedora and RHEL testing. They exist and can test few things.
>>
>> But now, I have accomplished creating few unit tests [3] for dnsmasq.
>> They are kind of hack, but they should allow basic testing of options
>> working. I used cmocka library. Dnsmasq is not very well prepared for
>> unit testing, but some parts can be tested. It is much easier to test
>> just code, without providing fake network configuration. I want to use
>> it to ensure no change in DHCP breaks expected behaviour. It is much
>> easier to prepare code changes than full fledged functional test,
>> emulating real request over network.
>>
>> I would love if you could try it and tell me what you think about it.
> 
> I think it is great to have unittests.
> 
> 
>> I am attaching squished patch, separate commits are at our github [3].
>> If someone would like to add some test, please create a pull request!
>>
>> If you would like to try it:
>> git clone -b unittests https://github.com/InfrastructureServices/dnsmasq.git
>> cd dnsmasq
>> make
>> cd tests
>> make
>> ./option_test
>> ./dhcp_test
>>
>> Since these are related to dnsmasq internals, I think merge to master
>> would be nice eventually. Some parts of dnsmasq should be adjusted for
>> easier testing, I have to prepare some changes. It might be starting
>> block to ensure new releases do not break existing functionality.
>>
>> Any opinions would be appreciated too.
> 
> <quote from="Harry Callahan" skipped="yes"/>
I do not know Harry Callahan. What would he say?
> 
> 
> 
>  
>> Cheers,
>> Petr
>>
>> 1. https://github.com/InfrastructureServices/dnsmasq-tests
>> 2. https://github.com/beakerlib/beakerlib
>> 3. https://github.com/InfrastructureServices/dnsmasq/tree/unittests/tests
>>
>> Petr Menšík
>> Software Engineer
> 
> Be aware that I'm a "sysadmin",  not a programmer ...
> 
I have got also few functional tests[1] if you are more interested in
those. But also sysadmin experience is welcome ;)
> 
>> >From 9395cc84f93c63573ba28e4e349c44adb5dbb34d Mon Sep 17 00:00:00 2001
>> From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik at redhat.com>
>> Date: Mon, 4 May 2020 16:26:17 +0200
>> Subject: [PATCH] Create unittests with dhcp and option tests
>> MIME-Version: 1.0
>> Content-Type: text/plain; charset=UTF-8
>> Content-Transfer-Encoding: 8bit
>>
>> diff --git a/Makefile b/Makefile
>> index 78e25f0..e390745 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -24,7 +24,7 @@ MANDIR        = $(PREFIX)/share/man
>>  LOCALEDIR     = $(PREFIX)/share/locale
>>  BUILDDIR      = $(SRC)
>>  DESTDIR       = 
>> -CFLAGS        = -Wall -W -O2
>> +CFLAGS        = -Wall -W -O2 -ggdb
> 
> How does that effect the regular builds?
Adds unnecessary debug information. This was added by my mistake, it was
not intended to be there. In new patch, it is removed.
> 
> 
> 
>>  LDFLAGS       = 
>>  COPTS         = 
>>  RPM_OPT_FLAGS = 
> 
>       ....
> 
> 
> <screenshot says="stappers takes a deeper dive">
> stappers at alpaca:~/src/dnsmasq
> $ git am unittests.patch 
> Patch format detection failed.
> stappers at alpaca:~/src/dnsmasq
> $ git am < unittests.patch 
> Applying: Create unittests with dhcp and option tests
> /home/stappers/src/dnsmasq/.git/rebase-apply/patch:469: trailing
> whitespace.
>   
> /home/stappers/src/dnsmasq/.git/rebase-apply/patch:535: trailing
> whitespace.
>   /* Min buffer size: we check after adding each record, so there must
>  * be 
> /home/stappers/src/dnsmasq/.git/rebase-apply/patch:538: trailing
> whitespace.
>      This might be increased is EDNS packet size if greater than the
> minimum. */ 
> /home/stappers/src/dnsmasq/.git/rebase-apply/patch:541: trailing
> whitespace.
>   
> /home/stappers/src/dnsmasq/.git/rebase-apply/patch:610: trailing
> whitespace.
> size_t answer_auth(struct dns_header *header, char *limit, size_t qlen,
> time_t now, union mysockaddr *peer_addr, 
> warning: squelched 1 whitespace error
> warning: 6 lines add whitespace errors.
> stappers at alpaca:~/src/dnsmasq
> $ 
> </screenshot>
> 
> To be continued ...
Should now apply without warnings this time.

-- 
Petr Menšík
Software Engineer
Red Hat, http://www.redhat.com/
email: pemensik at redhat.com
PGP: DFCF908DB7C87E8E529925BC4931CA5B6C9FC5CB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dnsmasq-unittests.patch
Type: text/x-patch
Size: 36324 bytes
Desc: not available
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20200514/8df85507/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20200514/8df85507/attachment-0001.sig>


More information about the Dnsmasq-discuss mailing list