lib1553.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "test.h"
  25. #include "testutil.h"
  26. #include "testtrace.h"
  27. #include "warnless.h"
  28. #include "memdebug.h"
  29. #define TEST_HANG_TIMEOUT 60 * 1000
  30. static int xferinfo(void *p,
  31. curl_off_t dltotal, curl_off_t dlnow,
  32. curl_off_t ultotal, curl_off_t ulnow)
  33. {
  34. (void)p;
  35. (void)dlnow;
  36. (void)dltotal;
  37. (void)ulnow;
  38. (void)ultotal;
  39. fprintf(stderr, "xferinfo fail!\n");
  40. return 1; /* fail as fast as we can */
  41. }
  42. CURLcode test(char *URL)
  43. {
  44. CURL *curls = NULL;
  45. CURLM *multi = NULL;
  46. int still_running;
  47. CURLcode i = CURLE_OK;
  48. CURLcode res = CURLE_OK;
  49. curl_mimepart *field = NULL;
  50. curl_mime *mime = NULL;
  51. int counter = 1;
  52. start_test_timing();
  53. global_init(CURL_GLOBAL_ALL);
  54. multi_init(multi);
  55. easy_init(curls);
  56. mime = curl_mime_init(curls);
  57. field = curl_mime_addpart(mime);
  58. curl_mime_name(field, "name");
  59. curl_mime_data(field, "value", CURL_ZERO_TERMINATED);
  60. easy_setopt(curls, CURLOPT_URL, URL);
  61. easy_setopt(curls, CURLOPT_HEADER, 1L);
  62. easy_setopt(curls, CURLOPT_VERBOSE, 1L);
  63. easy_setopt(curls, CURLOPT_MIMEPOST, mime);
  64. easy_setopt(curls, CURLOPT_USERPWD, "u:s");
  65. easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, xferinfo);
  66. easy_setopt(curls, CURLOPT_NOPROGRESS, 1L);
  67. libtest_debug_config.nohex = 1;
  68. libtest_debug_config.tracetime = 1;
  69. test_setopt(curls, CURLOPT_DEBUGDATA, &libtest_debug_config);
  70. easy_setopt(curls, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
  71. easy_setopt(curls, CURLOPT_VERBOSE, 1L);
  72. multi_add_handle(multi, curls);
  73. multi_perform(multi, &still_running);
  74. abort_on_test_timeout();
  75. while(still_running && counter--) {
  76. CURLMcode mres;
  77. int num;
  78. mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
  79. if(mres != CURLM_OK) {
  80. printf("curl_multi_wait() returned %d\n", mres);
  81. res = TEST_ERR_MAJOR_BAD;
  82. goto test_cleanup;
  83. }
  84. abort_on_test_timeout();
  85. multi_perform(multi, &still_running);
  86. abort_on_test_timeout();
  87. }
  88. test_cleanup:
  89. curl_mime_free(mime);
  90. curl_multi_remove_handle(multi, curls);
  91. curl_multi_cleanup(multi);
  92. curl_easy_cleanup(curls);
  93. curl_global_cleanup();
  94. if(res)
  95. i = res;
  96. return i; /* return the final return code */
  97. }