devtest.pl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Daniel Fandrich, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. # This script is intended for developers to test some internals of the
  26. # runtests.pl harneess. Don't try to use this unless you know what you're
  27. # doing!
  28. # An example command-line that starts a test http server for test 11 and waits
  29. # for the user before stopping it:
  30. # ./devtest.pl --verbose serverfortest https echo "Started https" protoport https preprocess 11 pause echo Stopping stopservers echo Done
  31. # curl can connect to the server while it's running like this:
  32. # curl -vkL https://localhost:<protoport>/11
  33. use strict;
  34. use warnings;
  35. use 5.006;
  36. BEGIN {
  37. # Define srcdir to the location of the tests source directory. This is
  38. # usually set by the Makefile, but for out-of-tree builds with direct
  39. # invocation of runtests.pl, it may not be set.
  40. if(!defined $ENV{'srcdir'}) {
  41. use File::Basename;
  42. $ENV{'srcdir'} = dirname(__FILE__);
  43. }
  44. push(@INC, $ENV{'srcdir'});
  45. }
  46. use globalconfig;
  47. use servers;
  48. use runner qw(
  49. readtestkeywords
  50. singletest_preprocess
  51. );
  52. use getpart;
  53. #######################################################################
  54. # logmsg is our general message logging subroutine.
  55. # This function is currently required to be here by servers.pm
  56. # This is copied from runtests.pl
  57. #
  58. my $uname_release = `uname -r`;
  59. my $is_wsl = $uname_release =~ /Microsoft$/;
  60. sub logmsg {
  61. for(@_) {
  62. my $line = $_;
  63. if ($is_wsl) {
  64. # use \r\n for WSL shell
  65. $line =~ s/\r?\n$/\r\n/g;
  66. }
  67. print "$line";
  68. }
  69. }
  70. #######################################################################
  71. # Parse and store the protocols in curl's Protocols: line
  72. # This is copied from runtests.pl
  73. #
  74. sub parseprotocols {
  75. my ($line)=@_;
  76. @protocols = split(' ', lc($line));
  77. # Generate a "proto-ipv6" version of each protocol to match the
  78. # IPv6 <server> name and a "proto-unix" to match the variant which
  79. # uses Unix domain sockets. This works even if support isn't
  80. # compiled in because the <features> test will fail.
  81. push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
  82. # 'http-proxy' is used in test cases to do CONNECT through
  83. push @protocols, 'http-proxy';
  84. # 'none' is used in test cases to mean no server
  85. push @protocols, 'none';
  86. }
  87. #######################################################################
  88. # Initialize @protocols from the curl binary under test
  89. #
  90. sub init_protocols {
  91. for (`$CURL -V 2>/dev/null`) {
  92. if(m/^Protocols: (.*)$/) {
  93. parseprotocols($1);
  94. }
  95. }
  96. }
  97. #######################################################################
  98. # Initialize the test harness to run tests
  99. #
  100. sub init_tests {
  101. init_protocols();
  102. initserverconfig();
  103. }
  104. #######################################################################
  105. # Main test loop
  106. init_tests();
  107. #***************************************************************************
  108. # Parse command-line options and commands
  109. #
  110. while(@ARGV) {
  111. if($ARGV[0] eq "-h") {
  112. print "Usage: devtest.pl [--verbose] [command [arg]...]\n";
  113. print "command is one of:\n";
  114. print " echo X\n";
  115. print " pause\n";
  116. print " preprocess\n";
  117. print " protocols *|X[,Y...]\n";
  118. print " protoport X\n";
  119. print " serverfortest X[,Y...]\n";
  120. print " stopservers\n";
  121. print " sleep N\n";
  122. exit 0;
  123. }
  124. elsif($ARGV[0] eq "--verbose") {
  125. $verbose = 1;
  126. }
  127. elsif($ARGV[0] eq "sleep") {
  128. shift @ARGV;
  129. sleep $ARGV[0];
  130. }
  131. elsif($ARGV[0] eq "echo") {
  132. shift @ARGV;
  133. print $ARGV[0] . "\n";
  134. }
  135. elsif($ARGV[0] eq "pause") {
  136. print "Press Enter to continue: ";
  137. readline STDIN;
  138. }
  139. elsif($ARGV[0] eq "protocols") {
  140. shift @ARGV;
  141. if($ARGV[0] eq "*") {
  142. init_protocols();
  143. }
  144. else {
  145. @protocols = split(",", $ARGV[0]);
  146. }
  147. print "Set " . scalar @protocols . " protocols\n";
  148. }
  149. elsif($ARGV[0] eq "preprocess") {
  150. shift @ARGV;
  151. loadtest("${TESTDIR}/test${ARGV[0]}");
  152. readtestkeywords();
  153. singletest_preprocess($ARGV[0]);
  154. }
  155. elsif($ARGV[0] eq "protoport") {
  156. shift @ARGV;
  157. my $port = protoport($ARGV[0]);
  158. print "protoport: $port\n";
  159. }
  160. elsif($ARGV[0] eq "serverfortest") {
  161. shift @ARGV;
  162. my ($why, $e) = serverfortest(split(/,/, $ARGV[0]));
  163. print "serverfortest: $e $why\n";
  164. }
  165. elsif($ARGV[0] eq "stopservers") {
  166. my $err = stopservers();
  167. print "stopservers: $err\n";
  168. }
  169. else {
  170. print "Error: Unknown command: $ARGV[0]\n";
  171. print "Continuing anyway\n";
  172. }
  173. shift @ARGV;
  174. }