testoc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testutil.h"
  17. #include "fspr_thread_proc.h"
  18. #include "fspr_errno.h"
  19. #include "fspr_general.h"
  20. #include "fspr_lib.h"
  21. #include "fspr_strings.h"
  22. #if APR_HAS_OTHER_CHILD
  23. static char reasonstr[256];
  24. static void ocmaint(int reason, void *data, int status)
  25. {
  26. switch (reason) {
  27. case APR_OC_REASON_DEATH:
  28. fspr_cpystrn(reasonstr, "APR_OC_REASON_DEATH",
  29. strlen("APR_OC_REASON_DEATH") + 1);
  30. break;
  31. case APR_OC_REASON_LOST:
  32. fspr_cpystrn(reasonstr, "APR_OC_REASON_LOST",
  33. strlen("APR_OC_REASON_LOST") + 1);
  34. break;
  35. case APR_OC_REASON_UNWRITABLE:
  36. fspr_cpystrn(reasonstr, "APR_OC_REASON_UNWRITEABLE",
  37. strlen("APR_OC_REASON_UNWRITEABLE") + 1);
  38. break;
  39. case APR_OC_REASON_RESTART:
  40. fspr_cpystrn(reasonstr, "APR_OC_REASON_RESTART",
  41. strlen("APR_OC_REASON_RESTART") + 1);
  42. break;
  43. }
  44. }
  45. #ifndef SIGKILL
  46. #define SIGKILL 1
  47. #endif
  48. /* It would be great if we could stress this stuff more, and make the test
  49. * more granular.
  50. */
  51. static void test_child_kill(abts_case *tc, void *data)
  52. {
  53. fspr_file_t *std = NULL;
  54. fspr_proc_t newproc;
  55. fspr_procattr_t *procattr = NULL;
  56. const char *args[3];
  57. fspr_status_t rv;
  58. args[0] = fspr_pstrdup(p, "occhild" EXTENSION);
  59. args[1] = fspr_pstrdup(p, "-X");
  60. args[2] = NULL;
  61. rv = fspr_procattr_create(&procattr, p);
  62. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  63. rv = fspr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_NO_PIPE,
  64. APR_NO_PIPE);
  65. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  66. rv = fspr_proc_create(&newproc, "./occhild" EXTENSION, args, NULL, procattr, p);
  67. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  68. ABTS_PTR_NOTNULL(tc, newproc.in);
  69. ABTS_PTR_EQUAL(tc, NULL, newproc.out);
  70. ABTS_PTR_EQUAL(tc, NULL, newproc.err);
  71. std = newproc.in;
  72. fspr_proc_other_child_register(&newproc, ocmaint, NULL, std, p);
  73. fspr_sleep(fspr_time_from_sec(1));
  74. rv = fspr_proc_kill(&newproc, SIGKILL);
  75. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  76. /* allow time for things to settle... */
  77. fspr_sleep(fspr_time_from_sec(3));
  78. fspr_proc_other_child_refresh_all(APR_OC_REASON_RUNNING);
  79. ABTS_STR_EQUAL(tc, "APR_OC_REASON_DEATH", reasonstr);
  80. }
  81. #else
  82. static void oc_not_impl(abts_case *tc, void *data)
  83. {
  84. ABTS_NOT_IMPL(tc, "Other child logic not implemented on this platform");
  85. }
  86. #endif
  87. abts_suite *testoc(abts_suite *suite)
  88. {
  89. suite = ADD_SUITE(suite)
  90. #if !APR_HAS_OTHER_CHILD
  91. abts_run_test(suite, oc_not_impl, NULL);
  92. #else
  93. abts_run_test(suite, test_child_kill, NULL);
  94. #endif
  95. return suite;
  96. }