From dd551b8686f7bb28adbf2e05c5de38cadfbf9dd5 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 30 Sep 2015 18:26:44 +0200 Subject: [PATCH 1/1] [tesh] Write self-tests in perl (we may not have cc at hand) Also, revive the setenv test and make it work (the forked environment was not modified but only the command line rewriting mechanism) --- tools/cmake/AddTests.cmake | 1 + tools/tesh/background.tesh | 49 +++++++---------------------------- tools/tesh/bg-set-signal.tesh | 15 ++++------- tools/tesh/catch-return.tesh | 22 +++------------- tools/tesh/catch-signal.tesh | 15 +++++------ tools/tesh/set-return.tesh | 19 +++----------- tools/tesh/setenv.tesh | 28 +++++--------------- tools/tesh/tesh.pl | 2 +- 8 files changed, 36 insertions(+), 115 deletions(-) diff --git a/tools/cmake/AddTests.cmake b/tools/cmake/AddTests.cmake index f978abd982..ef53354277 100644 --- a/tools/cmake/AddTests.cmake +++ b/tools/cmake/AddTests.cmake @@ -67,6 +67,7 @@ IF(NOT enable_memcheck) ### TESH ### ADD_TESH(tesh-self-basic --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/basic.tesh) ADD_TESH(tesh-self-cd --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/cd.tesh) + ADD_TESH(tesh-self-setenv --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/setenv.tesh) ADD_TESH(tesh-self-IO-broken-pipe --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/IO-broken-pipe.tesh) ADD_TESH(tesh-self-IO-orders --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/IO-orders.tesh) ADD_TESH(tesh-self-IO-bigsize --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/IO-bigsize.tesh) diff --git a/tools/tesh/background.tesh b/tools/tesh/background.tesh index 1029d89c3a..8b177fe48a 100644 --- a/tools/tesh/background.tesh +++ b/tools/tesh/background.tesh @@ -3,49 +3,18 @@ $ rm -rf temp_testdir_background $ mkdir temp_testdir_background $ cd temp_testdir_background -< #include -< #include -< #include -< #include -< #include -< #include -< #ifdef WIN32 -< #include "windows.h" -< #endif -< -< int main() { -< char buff[2048]; -< int got; -< int in; +< use strict; +< sleep(2); +< open (FILE, "0) { -< int w = write(1,&buff,got); -< if (w<0) { -< perror("Error while writing:"); -< exit(1); -< } -< } -< if (got < 0) { -< perror("Error while reading:"); -< exit(1); -< } -< return 0; +< while () { +< print; < } -$ mkfile delayed_cat.c +< exit 0; +< +$ mkfile delayed_cat.pl -$ cc -Wall -o delayed_cat delayed_cat.c - -& ./delayed_cat +& perl delayed_cat.pl > TOTO < TOTO diff --git a/tools/tesh/bg-set-signal.tesh b/tools/tesh/bg-set-signal.tesh index ff9c3d5401..172435dd40 100644 --- a/tools/tesh/bg-set-signal.tesh +++ b/tools/tesh/bg-set-signal.tesh @@ -5,17 +5,12 @@ $ rm -rf temp_testdir-bg-set-signal $ mkdir temp_testdir-bg-set-signal -$ cd temp_testdir-bg-set-signal -< #include -< int main(void) { -< char *A=NULL; -< *A = 1; -< } -$ mkfile segfault.c +$ cd temp_testdir-catch-signal +< kill 'SEGV', $$; +$ mkfile segfault.pl -$ cc -o segfault segfault.c ! expect signal SIGSEGV -& ./segfault -$ sleep 1 +& perl segfault.pl + $ cd .. $ rm -rf temp_testdir-bg-set-signal diff --git a/tools/tesh/catch-return.tesh b/tools/tesh/catch-return.tesh index 8e36d41598..210d6607a7 100644 --- a/tools/tesh/catch-return.tesh +++ b/tools/tesh/catch-return.tesh @@ -2,26 +2,10 @@ # This suite builds and uses a program returning 1. # tesh must detect this condition and report the issue. -$ rm -rf temp_testdir-catch-return -$ mkdir temp_testdir-catch-return - -$ cd temp_testdir-catch-return -< #include -< int main(void) { -< exit(1); -< } -$ mkfile return1.c - -$ cc -o return1 return1.c - ! expect return 41 -< $ ./return1 -$ ../tesh --enable-coverage -> Enable coverage +< $ perl -e "exit 1" +$ ./tesh > Test suite from stdin -> [(stdin):1] ./return1 +> [(stdin):1] perl -e "exit 1" > Test suite `(stdin)': NOK (<(stdin):1> returned code 1) > <(stdin):1> No output so far. - -$ cd .. -$ rm -rf temp_testdir-catch-return diff --git a/tools/tesh/catch-signal.tesh b/tools/tesh/catch-signal.tesh index 892245ea5c..3a7727f3e9 100644 --- a/tools/tesh/catch-signal.tesh +++ b/tools/tesh/catch-signal.tesh @@ -6,21 +6,18 @@ $ rm -rf temp_testdir-catch-signal $ mkdir temp_testdir-catch-signal $ cd temp_testdir-catch-signal -< #include -< int main(void) { -< char *A=NULL; -< *A = 1; -< } -$ mkfile segfault.c +< kill 'SEGV', $$; +$ mkfile segfault.pl -$ cc -o segfault segfault.c +! expect signal SIGSEGV +$ perl segfault.pl ! expect return 15 -< $ ./segfault +< $ perl segfault.pl $ ../tesh --enable-coverage > Enable coverage > Test suite from stdin -> [(stdin):1] ./segfault +> [(stdin):1] perl segfault.pl > Test suite `(stdin)': NOK (<(stdin):1> got signal SIGSEGV) > <(stdin):1> No output so far. diff --git a/tools/tesh/set-return.tesh b/tools/tesh/set-return.tesh index 679234de34..4ff56982dc 100644 --- a/tools/tesh/set-return.tesh +++ b/tools/tesh/set-return.tesh @@ -2,19 +2,8 @@ # This suite builds and uses a program returning 1. # tesh is instructed of this return code and must not whine. -$ rm -rf temp_testdir-set-return -$ mkdir temp_testdir-set-return - -$ cd temp_testdir-set-return -< #include -< int main(void) { -< exit(1); -< } -$ mkfile return1.c - -$ cc -o return1 return1.c - ! expect return 1 -$ ./return1 -$ cd .. -$ rm -rf temp_testdir-set-return +$ perl -e "exit 1" + +! expect return 42 +$ perl -e "exit 42" diff --git a/tools/tesh/setenv.tesh b/tools/tesh/setenv.tesh index 632fd8bb44..d93221700c 100644 --- a/tools/tesh/setenv.tesh +++ b/tools/tesh/setenv.tesh @@ -2,30 +2,16 @@ # This suite builds and uses a program returning 1. # tesh is instructed of this return code and must not whine. -$ rm -rf temp_testdir-setenv -$ mkdir temp_testdir-setenv +$ rm -rf temp_testdir_setenv +$ mkdir temp_testdir_setenv +$ cd temp_testdir_setenv -$ cd temp_testdir-setenv - -< #include -< #include -< extern char **environ; -< int main(void) { -< char **env_iter=environ; -< while (*env_iter) { -< if (!strncmp(*env_iter,"tesh_test_toto=",strlen("tesh_test_toto="))) -< printf("%s\n",*env_iter); -< env_iter++; -< } -< return 0; -< } -$ mkfile getenv.c - -$ cc -o getenv getenv.c -g +< print "tesh_test_toto=$ENV{tesh_test_toto}"; +$ mkfile testenv.pl ! setenv tesh_test_toto=blah -$ ./getenv +$ perl testenv.pl > tesh_test_toto=blah $ cd .. -$ rm -rf temp_testdir-setenv +$ rm -rf temp_testdir_setenv diff --git a/tools/tesh/tesh.pl b/tools/tesh/tesh.pl index 29f141b2c9..5ee51aae20 100755 --- a/tools/tesh/tesh.pl +++ b/tools/tesh/tesh.pl @@ -470,7 +470,6 @@ LINE: while ( defined( my $line = <$infh> ) and not $error ) { exec_cmd( \%cmd ); %cmd = (); } - print "hey\n"; $cmd{'expect'} = "$1"; } elsif ( $line =~ /^!\s*expect return/ ) { #expect return if ( defined( $cmd{'cmd'} ) ) { @@ -630,6 +629,7 @@ sub setenv_cmd($) { my ( $var, $ctn ) = ( $1, $2 ); print "[Tesh/INFO] setenv $var=$ctn\n"; $environ{$var} = $ctn; + $ENV{$var} = $ctn; } else { die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$arg'\n"; } -- 2.20.1