fork.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __UTIL_UNITTESTS_FORK_H
  15. #define __UTIL_UNITTESTS_FORK_H 1
  16. #include <unistd.h>
  17. /**
  18. * @file fork.h
  19. * @short Help functions to fork the test case process.
  20. * Various functions to fork a process and feed some data to pipe, check
  21. * its output and such lives here.
  22. */
  23. namespace isc {
  24. namespace util {
  25. namespace unittests {
  26. /**
  27. * @short Checks that a process terminates correctly.
  28. * Waits for a process to terminate (with a short timeout, this should be
  29. * used whan the process is about tu terminate) and checks its exit code.
  30. *
  31. * @return True if the process terminates with 0, false otherwise.
  32. * @param process The ID of process to wait for.
  33. */
  34. bool
  35. process_ok(pid_t process);
  36. pid_t
  37. provide_input(int *read_pipe, const void *input, const size_t length);
  38. pid_t
  39. check_output(int *write_pipe, const void *output, const size_t length);
  40. } // End of the namespace
  41. }
  42. }
  43. #endif // __UTIL_UNITTESTS_FORK_H