LCOV - code coverage report
Current view: top level - test - test-local-addresses.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 20 20 100.0 %
Date: 2019-08-23 13:36:53 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <stdio.h>
       4                 :            : 
       5                 :            : #include "af-list.h"
       6                 :            : #include "alloc-util.h"
       7                 :            : #include "in-addr-util.h"
       8                 :            : #include "local-addresses.h"
       9                 :            : #include "tests.h"
      10                 :            : 
      11                 :          8 : static void print_local_addresses(struct local_address *a, unsigned n) {
      12                 :            :         unsigned i;
      13                 :            : 
      14         [ +  + ]:         40 :         for (i = 0; i < n; i++) {
      15                 :         32 :                 _cleanup_free_ char *b = NULL;
      16                 :            : 
      17         [ -  + ]:         32 :                 assert_se(in_addr_to_string(a[i].family, &a[i].address, &b) >= 0);
      18                 :         32 :                 printf("%s if%i scope=%i metric=%u address=%s\n", af_to_name(a[i].family), a[i].ifindex, a[i].scope, a[i].metric, b);
      19                 :            :         }
      20                 :          8 : }
      21                 :            : 
      22                 :          4 : int main(int argc, char *argv[]) {
      23                 :            :         struct local_address *a;
      24                 :            :         int n;
      25                 :            : 
      26                 :          4 :         test_setup_logging(LOG_DEBUG);
      27                 :            : 
      28                 :          4 :         a = NULL;
      29                 :          4 :         n = local_addresses(NULL, 0, AF_UNSPEC, &a);
      30         [ -  + ]:          4 :         assert_se(n >= 0);
      31                 :            : 
      32                 :          4 :         printf("Local Addresses:\n");
      33                 :          4 :         print_local_addresses(a, (unsigned) n);
      34                 :          4 :         a = mfree(a);
      35                 :            : 
      36                 :          4 :         n = local_gateways(NULL, 0, AF_UNSPEC, &a);
      37         [ -  + ]:          4 :         assert_se(n >= 0);
      38                 :            : 
      39                 :          4 :         printf("Local Gateways:\n");
      40                 :          4 :         print_local_addresses(a, (unsigned) n);
      41                 :          4 :         free(a);
      42                 :            : 
      43                 :          4 :         return 0;
      44                 :            : }

Generated by: LCOV version 1.14