On Sat, 17 Dec 2016 11:55:38 +0100 Jérémy Zurcher <jer...@asynk.ch> said:

yeah - this below is getitng close. i have to say i kind of agree with cedric
and ks that maybe instead of an init/shutdown we can have a "template.c"
perhaps like the below. this allows for test to declare callback funcs too as
long as FUNC is always there - consider it the main for a test... and macros.h
is just all our test macros for tests to use and main.c is the template that
sets up the test with includes, inits and calls FUNCCALL(); to do the test then
shuts down and exits cleanly (any failures should exit before here). we come up
with a new dir with a main.c in it per style/type of test that has a common
init/shutdown etc. scenario.


test_x.c:
FUNC {
  Eina_List *list = NULL;
  list = eina_list_append(list, (void *)123L);
  FAIL_IF(eina_list_data_find_list(list, (void *)123L) != list);
}


test_y.c:
FUNC {
  Eina_List *list = NULL;
  list = eina_list_prepend(list, (void *)123L);
  FAIL_IF(eina_list_data_find_list(list, (void *)123L) != list);
}


macros.h:
#define FAIL_IF(_x) if ((_x)) { fprintf(stderr, "fail\n"); exit(1); }
#define STR(x) #x


main.c:
#include "macros.h"
#include "eina_config.h"
#include "Eina.h"
#include "Efl_Config.h"

#include STR(TESTFILE)

int main(int argc, char **argv) {
  eina_init();

  FUNCCALL();

  eina_shutdown();
  return 0;
}

then to build the test:
#/bin/sh -e
TESTSRCDIR=/path/to/tests
TESTBINDIR=/tmp
for TEST in `/bin/ls $SRCDIR/test_*.c | sort`; do
  TEST=`basename $TEST .c`
  $CC $TESTSRCDIR/main.c \
   -o $TESTSRCDIR/$TEST \
   -DTESTFILE=$TEST.c \
   -DFUNC='static void '$TEST'(void)' \
   -DFUNCCALL=$TEST \
   -I/somthing -I/something2 \
   -L/link/dir -lsomething -lsomething2 ...
  echo "TESTING $TEST.c ... "
  if $TESTBINDIR/$TEST; then
    echo OK;
  else
    echo FAIL
    exit 42 # should we exit on first fail or keep going?
  fi
fi


i like that you handled build_dir stuff etc. too (out of tree builds) and so
on. so definitely keep a lot of that and maybe something like above?

> <snip snip>
> 
> Hi,
> I wrote a quick and dirty POC ...
> comments welcome
> 
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> #! /bin/sh
> 
> SRC_D=src
> BUILD_D=src
> CONFIG_SH=config.sh
> INIT_C=init.c
> SHUTDOWN_C=shutdown.c
> C_FILE=/tmp/__efl_test.c
> O_FILE=/tmp/__efl_test.o
> DEBUG=0
> 
> SCRIPT_DIR=${0%/*}
> SCRIPT_FILE=${0##*/}
> 
> CC=${CC:-"clang"}
> LD=""
> INCLUDE=""
> 
> function fatal {
>    echo "FATAL $1"
>    exit 1
> }
> 
> while [ $# -ge 1 ]; do
>     case "$1" in
>         -s*|--src*)
>             shift
>             [ $# -lt 1 ] && fatal "option -s is missing directory argument"
>             SRC_D=$1
>             shift
>             ;;
>         -b*|--build*)
>             shift
>             [ $# -lt 1 ] && fatal "option -b is missing directory argument"
>             BUILD_D=$1
>             shift
>             ;;
> 
>         -h|--help)
>             echo "Usage:  $SCRIPT_FILE [options]"
>             echo
>             echo "Options:"
>             echo "    -s, --src directory    Directory to search tests into"
>             echo "    -b, --build directory  Directory to search built files
> into" echo "    -h, --help             This message."
>             exit 0
>             ;;
> 
>         *)
>             break
>     esac
> done
> 
> SRC_D=$(readlink -f $SRC_D)
> BUILD_D=$(readlink -f $BUILD_D)
> 
> [ -d "$SRC_D" -a -r "$SRC_D" ] || fatal "$SRC_D is not a valid directory"
> [ -d "$BUILD_D" -a -r "$BUILD_D" ] || fatal "$BUILD_D is not a valid
> directory"
> 
> function load_cfg {
>    unset LDS
>    unset INCLUDES
>    LDF=""
>    LDP=""
>    INCLUDE="-I .."
>    if [ -f $CONFIG_SH -a -r $CONFIG_SH ]
>    then
>       echo "    load $CONFIG_SH"
>       source ./$CONFIG_SH
>       for include in $INCLUDES
>       do
>          F=$(find $SRC_D -name $include)
>          if [ -z "$F" ]
>          then
>             F=$(find $BUILD_D -name $include)
>             [ ! -z "$F" ] || fatal "can't find $include in $SRC_D or $BUILD_D"
>          fi
>          INCLUDE="$INCLUDE -I ${F%/*}"
>       done
>       for ld in $LDS
>       do
>          F=$(find $BUILD_D -name $ld)
>          [ ! -z "$F" ] || fatal "can't find $ld in $BUILD_D"
>          F=$(readlink -f $F)
>          LDP="$LDP -L ${F%/*}"
>          lib=${F##*/lib}
>          lib=${lib%.so*}
>          LDF="$LDF -l$lib"
>       done
>    fi
> }
> 
> echo "search for tests into $SRC_D"
> for dir in $(find $SRC_D -type d -name tests)
> do
>    echo "  enter $dir"
>    pushd $dir > /dev/null || fatal "cannot enter $dir"
>    [ -f $INIT_C -a -r $INIT_C ] || fatal "missing mandatory file $INIT_C"
>    [ -f $SHUTDOWN_C -a -r $SHUTDOWN_C ] || fatal "missing mandatory file
> $SHUTDOWN_C" load_cfg
>    for test_c in $(ls -1 test_*.c)
>    do
>       echo -n "    compile and run $test_c"
>       cat $INIT_C $test_c $SHUTDOWN_C > $C_FILE
>       CMD="$CC $INCLUDE $LDP $LDF -o $C_FILE.o $O_FILE"
>       [ $DEBUG -eq 1 ] && echo "$CMD"
>       $CMD || fatal "compilation failed"
>       $O_FILE.o && echo " PASS" || fatal "test run failed"
>    done
>    echo "  leave"
>    popd > /dev/null
> done
> echo "done"
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> 
> this is what I've got in src/lib/eina/tests
> 
> jeyzu@bigdaddy: tests (master) $ cat config.sh
> INCLUDES="eina_config.h Eina.h Efl_Config.h"
> LDS="libeina.so"
> 
> jeyzu@bigdaddy: tests (master) $ cat init.c
> #include <Eina.h>
> 
> #define FAIL_IF(_x) if ((_x)) { fprintf(stderr, "fail\n"); exit(1); }
> 
> int main(int argc, char *argv[])
> {
>    eina_init();
> 
> jeyzu@bigdaddy: tests (master) $ cat shutdown.c
>   eina_shutdown();
>   return 0;
> }
> 
> jeyzu@bigdaddy: tests (master) $ cat test_list_append.c
> Eina_List *list = NULL;
> list = eina_list_append(list, (void *)123L);
> FAIL_IF(eina_list_data_find_list(list, (void *)123L) != list);
> 
> 
> run from topdir
> jeyzu@bigdaddy: efl (master) $ ./tests.sh -s src/lib/eina -b build
> search for tests into /home/jeyzu/usr/git/efl/core/efl/src/lib/eina
>   enter /home/jeyzu/usr/git/efl/core/efl/src/lib/eina/tests
>     load config.sh
>     compile and run test_list_append.c PASS
>   leave
> done
> 
> 
> --- Hell'O from Yverdoom
> 
> Jérémy (jeyzu)
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most 
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> enlightenment-devel mailing list
> enlightenment-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel


-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    ras...@rasterman.com


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to