LCOV - code coverage report
Current view: top level - tests/cmocka - dummy_child.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 0 46 0.0 %
Date: 2015-10-19 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     Tests -- a simple test process that echoes input back
       5             : 
       6             :     Authors:
       7             :         Jakub Hrozek <jhrozek@redhat.com>
       8             : 
       9             :     Copyright (C) 2014 Red Hat
      10             : 
      11             :     This program is free software; you can redistribute it and/or modify
      12             :     it under the terms of the GNU General Public License as published by
      13             :     the Free Software Foundation; either version 3 of the License, or
      14             :     (at your option) any later version.
      15             : 
      16             :     This program is distributed in the hope that it will be useful,
      17             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :     GNU General Public License for more details.
      20             : 
      21             :     You should have received a copy of the GNU General Public License
      22             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include <sys/types.h>
      26             : #include <unistd.h>
      27             : #include <stdlib.h>
      28             : #include <popt.h>
      29             : 
      30             : #include "util/util.h"
      31             : #include "util/child_common.h"
      32             : 
      33           0 : int main(int argc, const char *argv[])
      34             : {
      35             :     int opt;
      36           0 :     int debug_fd = -1;
      37             :     poptContext pc;
      38             :     ssize_t len;
      39             :     ssize_t written;
      40             :     errno_t ret;
      41             :     uint8_t buf[IN_BUF_SIZE];
      42           0 :     const char *action = NULL;
      43             :     const char *guitar;
      44             :     const char *drums;
      45             : 
      46           0 :     struct poptOption long_options[] = {
      47             :         POPT_AUTOHELP
      48             :         {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0,
      49           0 :          _("Debug level"), NULL},
      50             :         {"debug-timestamps", 0, POPT_ARG_INT, &debug_timestamps, 0,
      51           0 :          _("Add debug timestamps"), NULL},
      52             :         {"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0,
      53           0 :          _("Show timestamps with microseconds"), NULL},
      54             :         {"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
      55           0 :          _("An open file descriptor for the debug logs"), NULL},
      56             :         {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &debug_to_stderr, 0, \
      57           0 :          _("Send the debug output to stderr directly."), NULL },
      58           0 :         {"guitar", 0, POPT_ARG_STRING, &guitar, 0, _("Who plays guitar"), NULL },
      59           0 :         {"drums", 0, POPT_ARG_STRING, &drums, 0, _("Who plays drums"), NULL },
      60             :         POPT_TABLEEND
      61             :     };
      62             : 
      63             :     /* Set debug level to invalid value so we can decide if -d 0 was used. */
      64           0 :     debug_level = SSSDBG_INVALID;
      65             : 
      66           0 :     pc = poptGetContext(argv[0], argc, argv, long_options, 0);
      67           0 :     while((opt = poptGetNextOpt(pc)) != -1) {
      68             :         switch(opt) {
      69             :         default:
      70           0 :         fprintf(stderr, "\nInvalid option %s: %s\n\n",
      71             :                   poptBadOption(pc, 0), poptStrerror(opt));
      72           0 :             poptPrintUsage(pc, stderr, 0);
      73           0 :             poptFreeContext(pc);
      74           0 :             _exit(1);
      75             :         }
      76             :     }
      77           0 :     poptFreeContext(pc);
      78             : 
      79           0 :     action = getenv("TEST_CHILD_ACTION");
      80           0 :     if (action) {
      81           0 :         if (strcasecmp(action, "check_extra_args") == 0) {
      82           0 :             if (!(strcmp(guitar, "george") == 0 \
      83           0 :                         && strcmp(drums, "ringo") == 0)) {
      84           0 :                 DEBUG(SSSDBG_CRIT_FAILURE, "This band sounds weird\n");
      85           0 :                 _exit(1);
      86             :             }
      87           0 :         } else if (strcasecmp(action, "echo") == 0) {
      88           0 :             errno = 0;
      89           0 :             len = sss_atomic_read_s(STDIN_FILENO, buf, IN_BUF_SIZE);
      90           0 :             if (len == -1) {
      91           0 :                 ret = errno;
      92           0 :                 DEBUG(SSSDBG_CRIT_FAILURE, "read failed [%d][%s].\n", ret, strerror(ret));
      93           0 :                 _exit(1);
      94             :             }
      95           0 :             close(STDIN_FILENO);
      96             : 
      97           0 :             errno = 0;
      98           0 :             written = sss_atomic_write_s(3, buf, len);
      99           0 :             if (written == -1) {
     100           0 :                 ret = errno;
     101           0 :                 DEBUG(SSSDBG_CRIT_FAILURE, "write failed [%d][%s].\n", ret,
     102             :                             strerror(ret));
     103           0 :                 _exit(1);
     104             :             }
     105           0 :             close(STDOUT_FILENO);
     106             : 
     107           0 :             if (written != len) {
     108           0 :                 DEBUG(SSSDBG_CRIT_FAILURE, "Expected to write %zu bytes, wrote %zu\n",
     109             :                       len, written);
     110           0 :                 _exit(1);
     111             :             }
     112             :         }
     113             :     }
     114             : 
     115           0 :     DEBUG(SSSDBG_TRACE_FUNC, "test_child completed successfully\n");
     116           0 :     _exit(0);
     117             : }

Generated by: LCOV version 1.10