Wireshark-dev: Re: [Wireshark-dev] Unit testing dissector code

From: João Valverde <joao.valverde@xxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Jun 2021 01:33:07 +0100
Hi Martin,

This is promising. I think dissecting a TVB and walking the proto_tree to assert the result is probably the way to go about implementing a dissector test suite (instead of reading a pcap with tshark and grepping the output).

But regarding your PoC having to give extern linkage to the internal dissector code is a big drawback IMO, even if it isn't visible in a DLL (because we use default hidden visibility when the compiler supports it).

Maybe that could be solved by including the dissector source file in the test source file?

/* test_packet-bt-dht.c */

#include <epan/dissectors/packet-bt-dht.c>

void  test_foo(void)
{...}

int main(void)
{...}

/* end test_packet-bt-dht.c */

Just something to consider. Build time will be slowish with a large test suite, but running the test suite should be several orders of magnitude faster. And there are no binaries committed to the repo tree for dissectors (assuming the TVB data is included as a C array).

BR,

João

On 01/03/21 19:40, Martin Nyhus wrote:
Hi,
since the happy-shark discussion died out I've been looking at other
ways of adding test coverage for some bug fixes I've been preparing to
push, and right now the idea is to add a new unit test suite based on
wmem_test for dissector code. I think this should solve the concern that
was mentioned about build/CI runtime, but I'm not sure how people feel
about the effect on the source tarballs and the repository.

My attempt at implementing this is merge request 2250 [0], and I've got
some more tests I'd like to add on a branch in my own fork [1].

I'd like to hear what people think about this approach to testing
dissector code.

- Martin

[0] https://gitlab.com/wireshark/wireshark/-/merge_requests/2250
[1]
https://gitlab.com/zidel_/wireshark/-/commit/e6f4a741599ac162d168497e45452c1379bac23e
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-dev
              mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe