aboutsummaryrefslogtreecommitdiffstats
path: root/docs/dev/testing.rst
blob: e3b86bf31864f834c5407d081a80e6b3b75f4071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.. _testing:

Testing
=======

All the mitmproxy projects strive to maintain 100% code coverage. In general,
patches and pull requests will be declined unless they're accompanied by a
suitable extension to the test suite.

Our tests are written for the `py.test`_ or nose_ test frameworks.
At the point where you send your pull request, a command like this:

>>> py.test -n 4 --cov mitmproxy

Should give output something like this:

.. code-block:: none

    > ---------- coverage: platform darwin, python 2.7.2-final-0 --
    > Name                   Stmts   Miss  Cover   Missing
    > ----------------------------------------------------
    > mitmproxy/__init__         0      0   100%
    > mitmproxy/app              4      0   100%
    > mitmproxy/cmdline        100      0   100%
    > mitmproxy/controller      69      0   100%
    > mitmproxy/dump           150      0   100%
    > mitmproxy/encoding        39      0   100%
    > mitmproxy/filt           201      0   100%
    > mitmproxy/flow           891      0   100%
    > mitmproxy/proxy          427      0   100%
    > mitmproxy/script          27      0   100%
    > mitmproxy/utils          133      0   100%
    > mitmproxy/version          4      0   100%
    > ----------------------------------------------------
    > TOTAL                   2045      0   100%
    > ----------------------------------------------------
    > Ran 251 tests in 11.864s


There are exceptions to the coverage requirement - for instance, much of the
console interface code can't sensibly be unit tested. These portions are
excluded from coverage analysis either in the **.coveragerc** file, or using
**#pragma no-cover** directives. To keep our coverage analysis relevant, we use
these measures as sparingly as possible.

.. _nose: https://nose.readthedocs.org/en/latest/
.. _py.test: https://pytest.org/
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \*/ #include <getopt.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include "xenctrl.h" #include "utils.h" #include "io.h" int main(int argc, char **argv) { const char *sopts = "hVvi"; struct option lopts[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "verbose", 0, 0, 'v' }, { "interactive", 0, 0, 'i' }, { 0 }, }; bool is_interactive = false; int ch; int syslog_option = LOG_CONS; int syslog_mask = LOG_WARNING; int opt_ind = 0; while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) { switch (ch) { case 'h': //usage(argv[0]); exit(0); case 'V': //version(argv[0]); exit(0); case 'v': syslog_option |= LOG_PERROR; syslog_mask = LOG_DEBUG; break; case 'i': is_interactive = true; break; case '?': fprintf(stderr, "Try `%s --help' for more information\n", argv[0]); exit(EINVAL); } } if (geteuid() != 0) { fprintf(stderr, "%s requires root to run.\n", argv[0]); exit(EPERM); } openlog("xenconsoled", syslog_option, LOG_DAEMON); setlogmask(syslog_mask); if (!is_interactive) { daemonize("/var/run/xenconsoled.pid"); } if (!xen_setup()) exit(1); enum_domains(); handle_io(); closelog(); return 0; }