c-ares/test
Carsten Larsen 2811e30d49 Release 1.12.0 2017-04-12 01:21:06 +02:00
..
fuzzinput
gmock-1.7.0
.gitignore test: Get test code building under Windows 2016-02-02 10:13:48 +00:00
Makefile.am Release 1.12.0 2017-04-12 01:21:06 +02:00
Makefile.inc Release 1.12.0 2017-04-12 01:21:06 +02:00
Makefile.m32 test: Build with MinGW on AppVeyor 2016-03-03 13:57:45 +00:00
Makefile.msvc test: Get test code building under Windows 2016-02-02 10:13:48 +00:00
README.md
ares-fuzz.c Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-fuzz.cc
ares-test-fuzz.c Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-test-fuzz.cc
ares-test-init.cc Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-test-internal.cc test: Get test code building under Windows 2016-02-02 10:13:48 +00:00
ares-test-live.cc Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-test-main.cc Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-test-misc.cc Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-test-mock.cc Release 1.12.0 2017-04-12 01:21:06 +02:00
ares-test-ns.cc test: Improve containerized test mechanism 2016-02-02 10:13:49 +00:00
ares-test-parse-a.cc
ares-test-parse-aaaa.cc
ares-test-parse-mx.cc
ares-test-parse-naptr.cc
ares-test-parse-ns.cc
ares-test-parse-ptr.cc test: Make failure tests more robust 2016-02-02 10:13:48 +00:00
ares-test-parse-soa.cc
ares-test-parse-srv.cc
ares-test-parse-txt.cc test: Check ares_parse_txt_reply_ext() entrypoint 2016-02-04 10:09:22 +00:00
ares-test-parse.cc
ares-test.cc test: avoid in6addr_* constants 2016-03-03 13:57:16 +00:00
ares-test.h test: Improve containerized test mechanism 2016-02-02 10:13:49 +00:00
buildconf
configure.ac test/configure: build silently by default 2016-02-13 10:56:28 +01:00
dns-dump.cc Release 1.12.0 2017-04-12 01:21:06 +02:00
dns-proto-test.cc
dns-proto.cc test: add missing #includes for dns-proto.cc 2016-03-03 13:57:16 +00:00
dns-proto.h

README.md

c-ares Unit Test Suite

This directory holds unit tests for the c-ares library. To build the tests:

  • Build the main c-ares library first, in the directory above this. To enable tests of internal functions, configure the library build to expose hidden symbols with ./configure --disable-symbol-hiding.
  • Generate a configure file by running autoreconf -iv (which requires a local installation of autotools).
  • ./configure
  • make
  • Run the tests with ./arestest, or ./arestest -v for extra debug info.

Points to note:

  • The tests are written in C++11, and so need a C++ compiler that supports this. To avoid adding this as a requirement for the library, the configuration and build of the tests is independent from the library.
  • The tests include some live queries, which will fail when run on a machine without internet connectivity. To skip live tests, run with ./arestest --gtest_filter=-*.Live*.
  • The tests include queries of a mock DNS server. This server listens on port 5300 by default, but the port can be changed with the -p 5300 option to arestest.

Test Types

The test suite includes various different types of test.

  • There are live tests (ares-test-live.cc), which assume that the current machine has a valid DNS setup and connection to the internet; these tests issue queries for real domains but don't particularly check what gets returned. The tests will fail on an offline machine.
  • There are some mock tests (ares-test-mock.cc) that set up a fake DNS server and inject its port into the c-ares library configuration. These tests allow specific response messages to be crafted and injected, and so are likely to be used for many more tests in future.
    • To make this generation/injection easier, the dns-proto.h file includes C++ helper classes for building DNS packets.
  • Other library entrypoints that don't require network activity (e.g. ares_parse_*_reply) are tested directly.
  • A couple of the tests use a helper method of the test fixture to inject memory allocation failures, using a recent change to the c-ares library that allows override of malloc/free.
  • There are some tests of the internal entrypoints of the library (ares-test-internal.c), but these are only enabled if the library was configured with --disable-symbol-hiding and/or --enable-expose-statics.
  • There is also an entrypoint to allow Clang's libfuzzer to drive the packet parsing code in ares_parse_*_reply, together with a standalone wrapper for it (./aresfuzz) to allow use of command line fuzzers (such as afl-fuzz) for further fuzz testing.

Code Coverage Information

To generate code coverage information:

  • Configure both the library and the tests with ./configure --enable-code-coverage before building. This requires the relevant code coverage tools (gcov, lcov) to be installed locally.
  • Run the tests with test/arestest.
  • Generate code coverage output with make code-coverage-capture in the library directory (i.e. not in test/).