#!/usr/bin/env perl1#***************************************************************************2# _ _ ____ _3# Project ___| | | | _ \| |4# / __| | | | |_) | |5# | (__| |_| | _ <| |___6# \___|\___/|_| \_\_____|7#8# Copyright (C) Daniel Fandrich, et al.9#10# This software is licensed as described in the file COPYING, which11# you should have received as part of this distribution. The terms12# are also available at https://curl.se/docs/copyright.html.13#14# You may opt to use, copy, modify, merge, publish, distribute and/or sell15# copies of the Software, and permit persons to whom the Software is16# 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 ANY19# KIND, either express or implied.20#21# SPDX-License-Identifier: curl22#23###########################################################################2425# This script is intended for developers to test some internals of the26# runtests.pl harness. Don't try to use this unless you know what you're27# doing!2829# An example command-line that starts a test http server for test 11 and waits30# for the user before stopping it:31# ./devtest.pl --verbose serverfortest https echo "Started https" protoport https preprocess 11 pause echo Stopping stopservers echo Done32# curl can connect to the server while it's running like this:33# curl -vkL https://localhost:<protoport>/113435use strict;36use warnings;37use 5.006;3839BEGIN {40# Define srcdir to the location of the tests source directory. This is41# usually set by the Makefile, but for out-of-tree builds with direct42# invocation of runtests.pl, it may not be set.43if(!defined $ENV{'srcdir'}) {44use File::Basename;45$ENV{'srcdir'} = dirname(__FILE__);46}47push(@INC, $ENV{'srcdir'});48}4950use globalconfig;51use servers qw(52initserverconfig53protoport54serverfortest55stopservers56);57use runner qw(58readtestkeywords59singletest_preprocess60);61use testutil qw(62setlogfunc63);64use getpart;656667#######################################################################68# logmsg is our general message logging subroutine.69# This function is currently required to be here by servers.pm70# This is copied from runtests.pl71#72my $uname_release = `uname -r`;73my $is_wsl = $uname_release =~ /Microsoft$/;74sub logmsg {75for(@_) {76my $line = $_;77if ($is_wsl) {78# use \r\n for WSL shell79$line =~ s/\r?\n$/\r\n/g;80}81print "$line";82}83}8485#######################################################################86# Parse and store the protocols in curl's Protocols: line87# This is copied from runtests.pl88#89sub parseprotocols {90my ($line)=@_;9192@protocols = split(' ', lc($line));9394# Generate a "proto-ipv6" version of each protocol to match the95# IPv6 <server> name and a "proto-unix" to match the variant which96# uses Unix domain sockets. This works even if support isn't97# compiled in because the <features> test will fail.98push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);99100# 'http-proxy' is used in test cases to do CONNECT through101push @protocols, 'http-proxy';102103# 'none' is used in test cases to mean no server104push @protocols, 'none';105}106107108#######################################################################109# Initialize @protocols from the curl binary under test110#111sub init_protocols {112for (`$CURL -V 2>$dev_null`) {113if(m/^Protocols: (.*)$/) {114parseprotocols($1);115}116}117}118119120#######################################################################121# Initialize the test harness to run tests122#123sub init_tests {124setlogfunc(\&logmsg);125init_protocols();126initserverconfig();127}128129#######################################################################130# Main test loop131132init_tests();133134#***************************************************************************135# Parse command-line options and commands136#137while(@ARGV) {138if($ARGV[0] eq "-h") {139print "Usage: devtest.pl [--verbose] [command [arg]...]\n";140print "command is one of:\n";141print " echo X\n";142print " pause\n";143print " preprocess\n";144print " protocols *|X[,Y...]\n";145print " protoport X\n";146print " serverfortest X[,Y...]\n";147print " stopservers\n";148print " sleep N\n";149exit 0;150}151elsif($ARGV[0] eq "--verbose") {152$verbose = 1;153}154elsif($ARGV[0] eq "sleep") {155shift @ARGV;156sleep $ARGV[0];157}158elsif($ARGV[0] eq "echo") {159shift @ARGV;160print $ARGV[0] . "\n";161}162elsif($ARGV[0] eq "pause") {163print "Press Enter to continue: ";164readline STDIN;165}166elsif($ARGV[0] eq "protocols") {167shift @ARGV;168if($ARGV[0] eq "*") {169init_protocols();170}171else {172@protocols = split(",", $ARGV[0]);173}174print "Set " . scalar @protocols . " protocols\n";175}176elsif($ARGV[0] eq "preprocess") {177shift @ARGV;178loadtest("${TESTDIR}/test${ARGV[0]}");179readtestkeywords();180singletest_preprocess($ARGV[0]);181}182elsif($ARGV[0] eq "protoport") {183shift @ARGV;184my $port = protoport($ARGV[0]);185print "protoport: $port\n";186}187elsif($ARGV[0] eq "serverfortest") {188shift @ARGV;189my ($why, $e) = serverfortest(split(/,/, $ARGV[0]));190print "serverfortest: $e $why\n";191}192elsif($ARGV[0] eq "stopservers") {193my $err = stopservers();194print "stopservers: $err\n";195}196else {197print "Error: Unknown command: $ARGV[0]\n";198print "Continuing anyway\n";199}200shift @ARGV;201}202203204