diff options
Diffstat (limited to 'src/testzzuf/test_get.c')
-rw-r--r-- | src/testzzuf/test_get.c | 107 |
1 files changed, 65 insertions, 42 deletions
diff --git a/src/testzzuf/test_get.c b/src/testzzuf/test_get.c index 904808bc..94a4e833 100644 --- a/src/testzzuf/test_get.c +++ b/src/testzzuf/test_get.c | |||
@@ -96,8 +96,14 @@ static int use_post_form; | |||
96 | static int use_long_header; | 96 | static int use_long_header; |
97 | static int use_long_uri; | 97 | static int use_long_uri; |
98 | static int use_close; | 98 | static int use_close; |
99 | static int run_with_socat; | ||
99 | 100 | ||
100 | #define TEST_BASE_URI "http:/" "/127.0.0.1/test_uri" | 101 | #define TEST_BASE_URI "http:/" "/127.0.0.1/test_uri" |
102 | #define TEST_BASE_URI_SOCAT "http:/" "/127.0.0.121/test_uri" | ||
103 | |||
104 | #define SOCAT_PORT 10121 | ||
105 | |||
106 | #define TEST_BASE_PORT 4010 | ||
101 | 107 | ||
102 | #define EMPTY_PAGE "Empty page." | 108 | #define EMPTY_PAGE "Empty page." |
103 | #define EMPTY_PAGE_ALT "Alternative empty page." | 109 | #define EMPTY_PAGE_ALT "Alternative empty page." |
@@ -959,19 +965,24 @@ setupCURL (struct CBC *cbc, uint16_t port | |||
959 | CURLcode e; | 965 | CURLcode e; |
960 | char *buf; | 966 | char *buf; |
961 | const char *uri_to_use; | 967 | const char *uri_to_use; |
968 | const char *base_uri; | ||
962 | 969 | ||
963 | #ifndef TEST_USE_STATIC_POST_DATA | 970 | #ifndef TEST_USE_STATIC_POST_DATA |
964 | *mime = NULL; | 971 | *mime = NULL; |
965 | #endif /* ! TEST_USE_STATIC_POST_DATA */ | 972 | #endif /* ! TEST_USE_STATIC_POST_DATA */ |
966 | 973 | ||
974 | base_uri = run_with_socat ? TEST_BASE_URI_SOCAT : TEST_BASE_URI; | ||
967 | if (! use_long_uri) | 975 | if (! use_long_uri) |
968 | { | 976 | { |
969 | uri_to_use = TEST_BASE_URI; | 977 | uri_to_use = base_uri; |
970 | buf = NULL; | 978 | buf = NULL; |
971 | } | 979 | } |
972 | else | 980 | else |
973 | { | 981 | { |
974 | size_t pos; | 982 | size_t pos; |
983 | size_t base_uri_len; | ||
984 | |||
985 | base_uri_len = strlen (base_uri); | ||
975 | buf = malloc (TEST_STRING_VLONG_LEN + 1); | 986 | buf = malloc (TEST_STRING_VLONG_LEN + 1); |
976 | if (NULL == buf) | 987 | if (NULL == buf) |
977 | { | 988 | { |
@@ -979,8 +990,8 @@ setupCURL (struct CBC *cbc, uint16_t port | |||
979 | "at line %d.\n", (int) __LINE__); | 990 | "at line %d.\n", (int) __LINE__); |
980 | return NULL; | 991 | return NULL; |
981 | } | 992 | } |
982 | memcpy (buf, TEST_BASE_URI, MHD_STATICSTR_LEN_ (TEST_BASE_URI)); | 993 | memcpy (buf, base_uri, base_uri_len); |
983 | for (pos = MHD_STATICSTR_LEN_ (TEST_BASE_URI); | 994 | for (pos = base_uri_len; |
984 | pos < TEST_STRING_VLONG_LEN; | 995 | pos < TEST_STRING_VLONG_LEN; |
985 | ++pos) | 996 | ++pos) |
986 | { | 997 | { |
@@ -993,6 +1004,8 @@ setupCURL (struct CBC *cbc, uint16_t port | |||
993 | buf[TEST_STRING_VLONG_LEN] = 0; | 1004 | buf[TEST_STRING_VLONG_LEN] = 0; |
994 | uri_to_use = buf; | 1005 | uri_to_use = buf; |
995 | } | 1006 | } |
1007 | if (run_with_socat) | ||
1008 | port = SOCAT_PORT; | ||
996 | 1009 | ||
997 | c = curl_easy_init (); | 1010 | c = curl_easy_init (); |
998 | if (NULL == c) | 1011 | if (NULL == c) |
@@ -1189,8 +1202,10 @@ start_daemon_for_test (unsigned int daemon_flags, uint16_t *pport, | |||
1189 | "at line %d.\n", (int) __LINE__); | 1202 | "at line %d.\n", (int) __LINE__); |
1190 | return NULL; | 1203 | return NULL; |
1191 | } | 1204 | } |
1205 | |||
1192 | /* Do not use accept4() as only accept() is intercepted by zzuf */ | 1206 | /* Do not use accept4() as only accept() is intercepted by zzuf */ |
1193 | MHD_avoid_accept4_ (d); | 1207 | if (! run_with_socat) |
1208 | MHD_avoid_accept4_ (d); | ||
1194 | 1209 | ||
1195 | if (0 == *pport) | 1210 | if (0 == *pport) |
1196 | { | 1211 | { |
@@ -1516,44 +1531,49 @@ run_all_checks (void) | |||
1516 | unsigned int testRes; | 1531 | unsigned int testRes; |
1517 | unsigned int ret = 0; | 1532 | unsigned int ret = 0; |
1518 | 1533 | ||
1519 | if (MHD_are_sanitizers_enabled_ ()) | 1534 | if (! run_with_socat) |
1520 | { | 1535 | { |
1521 | fprintf (stderr, "The test does not work with sanitizers. " | 1536 | if (MHD_are_sanitizers_enabled_ ()) |
1522 | "At line %d.\n", (int) __LINE__); | 1537 | { |
1523 | return 77; | 1538 | fprintf (stderr, "Direct run with zzuf does not work with sanitizers. " |
1524 | } | 1539 | "At line %d.\n", (int) __LINE__); |
1525 | if (! MHD_is_avoid_accept4_possible_ ()) | 1540 | return 77; |
1526 | { | 1541 | } |
1527 | fprintf (stderr, | 1542 | if (! MHD_is_avoid_accept4_possible_ ()) |
1528 | "Non-debug build of MHD on this platform use accept4() function. " | 1543 | { |
1529 | "Test with zzuf is not possible. " | 1544 | fprintf (stderr, |
1530 | "At line %d.\n", (int) __LINE__); | 1545 | "Non-debug build of MHD on this platform use accept4() function. " |
1531 | return 77; | 1546 | "Direct run with zzuf is not possible. " |
1547 | "At line %d.\n", (int) __LINE__); | ||
1548 | return 77; | ||
1549 | } | ||
1550 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | ||
1551 | port = 0; /* Use system automatic assignment */ | ||
1552 | else | ||
1553 | { | ||
1554 | port = TEST_BASE_PORT; /* Use predefined port, may break parallel testing of another MHD build */ | ||
1555 | if (oneone) | ||
1556 | port += 100; | ||
1557 | if (use_long_uri) | ||
1558 | port += 30; | ||
1559 | else if (use_long_header) | ||
1560 | port += 35; | ||
1561 | else if (use_get_chunked) | ||
1562 | port += 0; | ||
1563 | else if (use_get) | ||
1564 | port += 5; | ||
1565 | else if (use_post_form) | ||
1566 | port += 10; | ||
1567 | else if (use_post) | ||
1568 | port += 15; | ||
1569 | else if (use_put_large) | ||
1570 | port += 20; | ||
1571 | else if (use_put_chunked) | ||
1572 | port += 25; | ||
1573 | } | ||
1532 | } | 1574 | } |
1533 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | ||
1534 | port = 0; /* Use system automatic assignment */ | ||
1535 | else | 1575 | else |
1536 | { | 1576 | port = TEST_BASE_PORT; /* Use predefined port, may break parallel testing of another MHD build */ |
1537 | port = 4010; /* Use predefined port, may break parallel testing of another MHD build */ | ||
1538 | if (oneone) | ||
1539 | port += 100; | ||
1540 | if (use_long_uri) | ||
1541 | port += 30; | ||
1542 | else if (use_long_header) | ||
1543 | port += 35; | ||
1544 | else if (use_get_chunked) | ||
1545 | port += 0; | ||
1546 | else if (use_get) | ||
1547 | port += 5; | ||
1548 | else if (use_post_form) | ||
1549 | port += 10; | ||
1550 | else if (use_post) | ||
1551 | port += 15; | ||
1552 | else if (use_put_large) | ||
1553 | port += 20; | ||
1554 | else if (use_put_chunked) | ||
1555 | port += 25; | ||
1556 | } | ||
1557 | 1577 | ||
1558 | if (! dry_run && (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))) | 1578 | if (! dry_run && (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))) |
1559 | { | 1579 | { |
@@ -1600,6 +1620,7 @@ int | |||
1600 | main (int argc, char *const *argv) | 1620 | main (int argc, char *const *argv) |
1601 | { | 1621 | { |
1602 | unsigned int res; | 1622 | unsigned int res; |
1623 | int use_magic_exit_codes; | ||
1603 | 1624 | ||
1604 | oneone = ! has_in_name (argv[0], "10"); | 1625 | oneone = ! has_in_name (argv[0], "10"); |
1605 | use_get = has_in_name (argv[0], "_get"); | 1626 | use_get = has_in_name (argv[0], "_get"); |
@@ -1613,6 +1634,7 @@ main (int argc, char *const *argv) | |||
1613 | use_long_uri = has_in_name (argv[0], "_long_uri"); | 1634 | use_long_uri = has_in_name (argv[0], "_long_uri"); |
1614 | use_close = has_in_name (argv[0], "_close"); | 1635 | use_close = has_in_name (argv[0], "_close"); |
1615 | 1636 | ||
1637 | run_with_socat = has_param (argc, argv, "--with-socat"); | ||
1616 | dry_run = has_param (argc, argv, "--dry-run") || | 1638 | dry_run = has_param (argc, argv, "--dry-run") || |
1617 | has_param (argc, argv, "-n"); | 1639 | has_param (argc, argv, "-n"); |
1618 | 1640 | ||
@@ -1623,17 +1645,18 @@ main (int argc, char *const *argv) | |||
1623 | "for the test type.\n", argv[0] ? argv[0] : "(NULL)"); | 1645 | "for the test type.\n", argv[0] ? argv[0] : "(NULL)"); |
1624 | return 99; | 1646 | return 99; |
1625 | } | 1647 | } |
1648 | use_magic_exit_codes = run_with_socat || dry_run; | ||
1626 | 1649 | ||
1627 | /* zzuf cannot bypass exit values. | 1650 | /* zzuf cannot bypass exit values. |
1628 | Unless 'dry run' is used, do not return errors for external error | 1651 | Unless 'dry run' is used, do not return errors for external error |
1629 | conditions (like out-of-memory) as they will be reported as test failures. */ | 1652 | conditions (like out-of-memory) as they will be reported as test failures. */ |
1630 | if (! test_global_init ()) | 1653 | if (! test_global_init ()) |
1631 | return dry_run ? 99 : 0; | 1654 | return use_magic_exit_codes ? 99 : 0; |
1632 | res = run_all_checks (); | 1655 | res = run_all_checks (); |
1633 | test_global_deinit (); | 1656 | test_global_deinit (); |
1634 | if (99 == res) | 1657 | if (99 == res) |
1635 | return dry_run ? 99 : 0; | 1658 | return use_magic_exit_codes ? 99 : 0; |
1636 | if (77 == res) | 1659 | if (77 == res) |
1637 | return dry_run ? 77 : 0; | 1660 | return use_magic_exit_codes ? 77 : 0; |
1638 | return (0 == res) ? 0 : 1; /* 0 == pass */ | 1661 | return (0 == res) ? 0 : 1; /* 0 == pass */ |
1639 | } | 1662 | } |