[svn r603] Uses Valgrind and Mudflap, to create cover tests, and make performance reports. trunk
authorrosfran
Thu Apr 26 16:07:27 2007 +0100 (2007-04-26)
branchtrunk
changeset 597945d3f5da6fc
parent 596 2097ef19ce9a
child 598 b66392e80922
[svn r603] Uses Valgrind and Mudflap, to create cover tests, and make performance reports.
gmyth/configure.ac
gmyth/src/gmyth_common.c
gmyth/src/gmyth_livetv.c
gmyth/tests/Makefile.am
gmyth/tests/coverage.py
gmyth/tests/gmyth_test_filetransfer.c
gmyth/tests/relink.py
gmyth/tests/suppressions
gmyth/tests/test_filetransfer.py
gmyth/tests/testing_tools.py
     1.1 --- a/gmyth/configure.ac	Wed Apr 25 21:31:00 2007 +0100
     1.2 +++ b/gmyth/configure.ac	Thu Apr 26 16:07:27 2007 +0100
     1.3 @@ -93,6 +93,25 @@
     1.4  
     1.5  AM_CONDITIONAL(GMYTH_USE_DEBUG, test "x$enable_debug" = "xyes")
     1.6  
     1.7 +AC_ARG_ENABLE(coverage,
     1.8 +        AS_HELP_STRING([--enable-coverage],
     1.9 +                [enable coverage (default = no)]),
    1.10 +                [
    1.11 +                        if test $enableval = no; then
    1.12 +                                USE_COVERAGE=no;
    1.13 +                        else
    1.14 +                                USE_COVERAGE=yes;
    1.15 +                        fi
    1.16 +                ],[
    1.17 +                        USE_COVERAGE=no;
    1.18 +                ]
    1.19 +)
    1.20 +
    1.21 +if [ test $USE_COVERAGE = yes ]; then
    1.22 +        CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage -O0"
    1.23 +        LDFLAGS="$LDFLAGS -lgcov"
    1.24 +fi
    1.25 +
    1.26  # Check for pkgconfig
    1.27  AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, yes, no)
    1.28  # Give error and exit if we don't have pkgconfig
     2.1 --- a/gmyth/src/gmyth_common.c	Wed Apr 25 21:31:00 2007 +0100
     2.2 +++ b/gmyth/src/gmyth_common.c	Thu Apr 26 16:07:27 2007 +0100
     2.3 @@ -137,7 +137,7 @@
     2.4      /* Frees the GMythChannelInfo structure */
     2.5      GMythChannelInfo *channel = (GMythChannelInfo*) data;
     2.6  
     2.7 -    gmyth_channel_info_free (channel);
     2.8 +    gmyth_channel_info_free(channel);
     2.9  }
    2.10  
    2.11  static void
     3.1 --- a/gmyth/src/gmyth_livetv.c	Wed Apr 25 21:31:00 2007 +0100
     3.2 +++ b/gmyth/src/gmyth_livetv.c	Thu Apr 26 16:07:27 2007 +0100
     3.3 @@ -835,7 +835,7 @@
     3.4  void
     3.5  gmyth_livetv_stop_playing (GMythLiveTV *livetv) 
     3.6  {
     3.7 -	gmyth_debug ("Stopping the LiveTV...\n");
     3.8 +    gmyth_debug ("Stopping the LiveTV...\n");
     3.9  
    3.10  	if (livetv->is_livetv) {
    3.11  		if ( !gmyth_recorder_stop_livetv (livetv->recorder) ) {
     4.1 --- a/gmyth/tests/Makefile.am	Wed Apr 25 21:31:00 2007 +0100
     4.2 +++ b/gmyth/tests/Makefile.am	Thu Apr 26 16:07:27 2007 +0100
     4.3 @@ -23,10 +23,12 @@
     4.4  	gmyth_test_transcode \
     4.5  	gmyth_test_vlc \
     4.6  	gmyth_test_livetv \
     4.7 -	gmyth_test_http
     4.8 +	gmyth_test_http \
     4.9 +	gmyth_test_filetransfer
    4.10  
    4.11  TESTS = \
    4.12  	test \
    4.13 +	relink.py \
    4.14  	test_connection.py \
    4.15  	test_epg.py \
    4.16  	test_recorder.py \
    4.17 @@ -34,9 +36,10 @@
    4.18  	test_transcode.py \
    4.19  	test_vlc.py \
    4.20  	test_livetv.py \
    4.21 -	test_http.py
    4.22 +	test_http.py \
    4.23 +	test_filetransfer.py
    4.24  
    4.25 -#TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) @GLIB_LIBS@ @GOBJECT_LIBS@ @LIBCURL_LIBS@
    4.26 +TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir)
    4.27  
    4.28  test_SOURCES = \
    4.29  	main.c
    4.30 @@ -65,3 +68,6 @@
    4.31  gmyth_test_livetv_SOURCES = \
    4.32  	gmyth_test_livetv.c
    4.33  
    4.34 +gmyth_test_filetransfer_SOURCES = \
    4.35 +	gmyth_test_filetransfer.c
    4.36 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/gmyth/tests/coverage.py	Thu Apr 26 16:07:27 2007 +0100
     5.3 @@ -0,0 +1,28 @@
     5.4 +#!/usr/bin/python
     5.5 +
     5.6 +import re
     5.7 +import sys
     5.8 +import os
     5.9 +import shutil
    5.10 +from test import is_coverage, get_gcda
    5.11 +
    5.12 +def build_dir(exe):
    5.13 +    t = get_gcda(exe)
    5.14 +    a = re.search("(/.*)/tests/regression/.*" ,t)
    5.15 +    return a.groups()[0]
    5.16 +
    5.17 +def gen_cov_info(build_dir):
    5.18 +    if os.path.exists('coverage'):
    5.19 +        shutil.rmtree('coverage')
    5.20 +    os.mkdir('coverage')
    5.21 +    os.chdir('coverage')
    5.22 +    os.system('lcov -d ' + build_dir + ' -b ../ -z')
    5.23 +    os.system('lcov -d ' + build_dir + ' -b ../ -c -o clinkc.info')
    5.24 +    os.system('genhtml clinkc.info')
    5.25 +
    5.26 +exe = 'mini_cp'
    5.27 +exe = '.libs/' + exe
    5.28 +if is_coverage(exe):
    5.29 +    bdir = build_dir(exe)
    5.30 +    gen_cov_info(bdir)
    5.31 +sys.exit(0)
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/gmyth/tests/gmyth_test_filetransfer.c	Thu Apr 26 16:07:27 2007 +0100
     6.3 @@ -0,0 +1,97 @@
     6.4 +#include <glib-object.h>
     6.5 +
     6.6 +#include "common.h"
     6.7 +
     6.8 +#include "gmyth_uri.h"
     6.9 +#include "gmyth_backendinfo.h"
    6.10 +#include "gmyth_livetv.h"
    6.11 +#include "gmyth_file.h"
    6.12 +#include "gmyth_file_transfer.h"
    6.13 +#include "gmyth_file_local.h"
    6.14 +#include "gmyth_common.h"
    6.15 +
    6.16 +#define URI_FILE_TRANSFER_DEFAULT	"myth://192.168.3.165:6543/"
    6.17 +
    6.18 +static gboolean
    6.19 +test_file_transfer_setup( gchar *uri ) {
    6.20 +    GMythLiveTV *livetv = NULL;
    6.21 +    GMythFile *file = NULL;
    6.22 +    gchar *channel_name = NULL;
    6.23 +    gboolean ret = TRUE;
    6.24 +    gboolean live_tv = FALSE;
    6.25 +
    6.26 +    if ( NULL == uri)
    6.27 +        uri = g_strdup( URI_FILE_TRANSFER_DEFAULT );
    6.28 +
    6.29 +    GMythURI *gmyth_uri = gmyth_uri_new_with_value( uri);
    6.30 +
    6.31 +    GMythBackendInfo* backend_info = gmyth_backend_info_new_with_uri(uri);
    6.32 +
    6.33 +    /* Check if the file is local to this specific client renderer, and tries to open
    6.34 +     * a local connection
    6.35 +     */
    6.36 +    if ( gmyth_uri_is_local_file(gmyth_uri)) {
    6.37 +        g_debug( "Opening local file connection to download...");
    6.38 +        file = GMYTH_FILE(gmyth_file_local_new(backend_info));
    6.39 +        ret = gmyth_file_local_open( GMYTH_FILE_LOCAL( file ) );
    6.40 +    } else {
    6.41 +        g_debug( "Opening remote file connection to download...");
    6.42 +        file = GMYTH_FILE(gmyth_file_transfer_new(backend_info));
    6.43 +        ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(file), uri);
    6.44 +    }
    6.45 +
    6.46 +    if (NULL == file) {
    6.47 +        g_debug("FileTransfer is NULL");
    6.48 +        ret = FALSE;
    6.49 +        goto init_failed;
    6.50 +    }
    6.51 +    
    6.52 +    g_debug( "uri = %s", uri);
    6.53 +
    6.54 +    if (ret == FALSE) {
    6.55 +        g_debug("MythTV FileTransfer request failed when setting up socket connection!");
    6.56 +        goto init_failed;
    6.57 +    }
    6.58 +
    6.59 +    g_debug( "MythTV FileTransfer filesize = %lld",
    6.60 +            gmyth_file_get_filesize( file));
    6.61 +
    6.62 +    init_failed: if ( livetv != NULL)
    6.63 +        g_object_unref(livetv);
    6.64 +
    6.65 +    if ( file != NULL)
    6.66 +        g_object_unref(file);
    6.67 +
    6.68 +    if ( gmyth_uri != NULL)
    6.69 +        g_object_unref( gmyth_uri);
    6.70 +
    6.71 +    if ( backend_info != NULL)
    6.72 +        g_object_unref( backend_info);
    6.73 +
    6.74 +    return ret;
    6.75 +
    6.76 +}
    6.77 +
    6.78 +gint
    6.79 +main(gint args, const gchar **argv) {
    6.80 +    gboolean ret = FALSE;
    6.81 +
    6.82 +    g_type_init();
    6.83 +
    6.84 +    g_thread_init(NULL);
    6.85 +
    6.86 +    fprintf(stdout, SYNC_STRING);
    6.87 +    fflush(NULL);
    6.88 +    getchar();
    6.89 +
    6.90 +    if ( args > 1)
    6.91 +        ret = test_file_transfer_setup( argv[1]);
    6.92 +
    6.93 +    if ( !ret)
    6.94 +        g_debug("Error when running LiveTV setup test script!");
    6.95 +    else
    6.96 +        g_debug("LiveTV setup test script finished with success.");
    6.97 +
    6.98 +    return (0);
    6.99 +}
   6.100 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/gmyth/tests/relink.py	Thu Apr 26 16:07:27 2007 +0100
     7.3 @@ -0,0 +1,30 @@
     7.4 +#!/usr/bin/python
     7.5 +
     7.6 +#doc: dummy test that relinks all test programs. Should be the first to run
     7.7 +
     7.8 +from testing_tools import relink_name
     7.9 +import sys
    7.10 +import os
    7.11 +import popen2
    7.12 +import signal
    7.13 +import time
    7.14 +
    7.15 +def relink_all():
    7.16 +    for i in os.listdir('.'):
    7.17 +        p = os.popen('file ' + i)
    7.18 +        d = p.read()
    7.19 +        p.close()
    7.20 +        if 'shell script' in d:
    7.21 +            relink(i)
    7.22 +
    7.23 +def relink(exe):
    7.24 +    rname = relink_name(exe)
    7.25 +    if not os.path.exists(rname):
    7.26 +        p = popen2.Popen3(['./' + exe], capturestderr = True)
    7.27 +        time.sleep(1)
    7.28 +        os.kill(p.pid, signal.SIGKILL)
    7.29 +        p.wait()
    7.30 +    assert os.path.exists(rname)
    7.31 +
    7.32 +relink_all()
    7.33 +sys.exit(0)
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/gmyth/tests/suppressions	Thu Apr 26 16:07:27 2007 +0100
     8.3 @@ -0,0 +1,8 @@
     8.4 +{
     8.5 +   getifaddrs1
     8.6 +   Memcheck:Param
     8.7 +   socketcall.sendto(msg)
     8.8 +   obj:/usr/lib/debug/libc-2.4.so
     8.9 +   fun:__netlink_request
    8.10 +   fun:getifaddrs
    8.11 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/gmyth/tests/test_filetransfer.py	Thu Apr 26 16:07:27 2007 +0100
     9.3 @@ -0,0 +1,10 @@
     9.4 +#!/usr/bin/python
     9.5 +
     9.6 +#doc: test gmyth_file_transfer_* methods
     9.7 +
     9.8 +from testing_tools import start, finish
     9.9 +import sys
    9.10 +
    9.11 +p = start('gmyth_test_filetransfer', ['myth://192.168.3.165:6543/1000_20070330144500.nuv'])
    9.12 +
    9.13 +sys.exit(finish(p))
    10.1 --- a/gmyth/tests/testing_tools.py	Wed Apr 25 21:31:00 2007 +0100
    10.2 +++ b/gmyth/tests/testing_tools.py	Thu Apr 26 16:07:27 2007 +0100
    10.3 @@ -21,7 +21,7 @@
    10.4  
    10.5  class executable:
    10.6      def __init__(self, cmd, ignore):
    10.7 -        #assert isinstance(cmd, list)
    10.8 +        assert isinstance(cmd, list)
    10.9          self.p = popen2.Popen3(cmd, capturestderr = True)
   10.10  	#self.p = popen2.Popen3(cmd)
   10.11  	print "Executing command... [ %s ]\n" % cmd
   10.12 @@ -37,12 +37,12 @@
   10.13  
   10.14  class simple_exe (executable):
   10.15      def __init__(self, exe, ignore):
   10.16 -        cmd = './' + exe
   10.17 +        cmd = ['./' + exe[0]] + exe[1:]
   10.18          executable.__init__(self, cmd, ignore)
   10.19  
   10.20  class mudflap_exe (executable):
   10.21      def __init__(self, exe, ignore):
   10.22 -        cmd = ['./' + exe]
   10.23 +        cmd = ['./' + exe[0]] + exe[1:]
   10.24          executable.__init__(self, cmd, ignore)
   10.25  
   10.26      #returns True if completed successfully
   10.27 @@ -57,9 +57,9 @@
   10.28  
   10.29  class valgrind_exe (executable):
   10.30      def __init__(self, exe, ignore):
   10.31 -        suppressions = os.environ['top_srcdir'] + '/tests/regression/suppressions'
   10.32 +        suppressions = os.environ['top_srcdir'] + '/tests/suppressions'
   10.33          cmd = ['/usr/bin/valgrind', '--suppressions=' + suppressions,
   10.34 -               '--leak-check=full', exe]
   10.35 +               '--leak-check=full'] + exe
   10.36          executable.__init__(self, cmd, ignore)
   10.37  
   10.38      #returns True if completed successfully
   10.39 @@ -81,7 +81,8 @@
   10.40          return errors == 0
   10.41  
   10.42  def get_gcda(exe):
   10.43 -    f = open(exe)
   10.44 +    #exe_args = exe.split(' ')
   10.45 +    f = open(exe[0])
   10.46      data = f.read()
   10.47      f.close()
   10.48      a = re.search('/.*\.gcda', data)
   10.49 @@ -103,9 +104,20 @@
   10.50      return '.libs/lt-' + exe
   10.51  
   10.52  def start(exe, params = [], ignore = 0):
   10.53 -    exe   = exe + ' ' +  ' '.join(params)
   10.54 +    #exe   = exe + ' ' +  ' '.join(params)
   10.55 +    exe   = [ relink_name(exe) ] + params
   10.56      print 'Executing the command line: ', exe
   10.57 -    p = simple_exe(exe, ignore)
   10.58 +    #p = simple_exe(exe, ignore)
   10.59 +    p     = None
   10.60 +    if is_coverage(exe):
   10.61 +        p = simple_exe(exe, ignore)
   10.62 +    elif is_mudflap(exe):
   10.63 +        p = mudflap_exe(exe, ignore)
   10.64 +    else:
   10.65 +        if os.path.exists('/usr/bin/valgrind'):
   10.66 +            p = valgrind_exe(exe, ignore)
   10.67 +        else:
   10.68 +            p = simple_exe(exe, ignore)
   10.69      wait_string(p.stdout, sync_string)
   10.70      return p
   10.71