# HG changeset patch # User rosfran # Date 1177459676 -3600 # Node ID 95263ab433f1d5848421faa992b5e80d18ba64f5 # Parent 0f77fcb97269a1b2214c97bc719f233526c353ae [svn r599] Automated test scripts in Python (it will runs over gcov, and generate reports on GMyth library running). diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/Makefile.am --- a/gmyth/tests/Makefile.am Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/Makefile.am Wed Apr 25 01:07:56 2007 +0100 @@ -27,14 +27,14 @@ TESTS = \ test \ - gmyth_test_connection \ - gmyth_test_epg \ - gmyth_test_recorder \ - gmyth_test_recordings \ - gmyth_test_transcode \ - gmyth_test_vlc \ - gmyth_test_livetv \ - gmyth_test_http + test_connection.py \ + test_epg.py \ + test_recorder.py \ + test_recordings.py \ + test_transcode.py \ + test_vlc.py \ + test_livetv.py \ + test_http.py #TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) @GLIB_LIBS@ @GOBJECT_LIBS@ @LIBCURL_LIBS@ diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/common.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/common.h Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,2 @@ + +#define SYNC_STRING "===SYNC===\n" diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/compile --- a/gmyth/tests/compile Tue Apr 24 19:45:27 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/bin/bash -gcc -g $1 -o $2 `pkg-config --cflags --libs gmyth-0.1 glib-2.0 gthread-2.0` - diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/compile_file_exists --- a/gmyth/tests/compile_file_exists Tue Apr 24 19:45:27 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -gcc -o test_file_exists test_file_exists.c -DBIG_JOINS=1 -I/usr/include/mysql -I/usr/local/include/gmyth -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -L/usr/local/lib -lmysqlclient -lz -lcrypt -lnsl -lm -lgmyth -lgobject-2.0 -lglib-2.0 diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/compile_test_connection --- a/gmyth/tests/compile_test_connection Tue Apr 24 19:45:27 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -gcc -o gmyth_test_connection gmyth_test_connection.c `pkg-config --cflags --libs gmyth-0.1 glib-2.0` diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/compile_test_epg --- a/gmyth/tests/compile_test_epg Tue Apr 24 19:45:27 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -gcc -o gmyth_test_epg gmyth_test_epg.c `pkg-config --cflags --libs gmyth glib-2.0` diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/compile_test_recorder --- a/gmyth/tests/compile_test_recorder Tue Apr 24 19:45:27 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -gcc -o gmyth_test_recorder gmyth_test_recorder.c `pkg-config --cflags --libs gmyth-0.1` diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/compile_test_recordings --- a/gmyth/tests/compile_test_recordings Tue Apr 24 19:45:27 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -gcc -o gmyth_test_recordings gmyth_test_recordings.c `pkg-config --cflags --libs gmyth-0.1 glib-2.0` diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_connection.c --- a/gmyth/tests/gmyth_test_connection.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_connection.c Wed Apr 25 01:07:56 2007 +0100 @@ -1,10 +1,15 @@ #include +#include +#include + #include "gmyth_uri.h" #include "gmyth_backendinfo.h" #include "gmyth_socket.h" #include "gmyth_query.h" +#include "common.h" + static gboolean test_backend_connection1 (GMythBackendInfo *backend_info) { @@ -67,6 +72,13 @@ test_backend_connection1 (backend_info); test_backend_connection2 (backend_info); test_mysql_connection1 (backend_info); + + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + return (0); + } diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_epg.c --- a/gmyth/tests/gmyth_test_epg.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_epg.c Wed Apr 25 01:07:56 2007 +0100 @@ -2,6 +2,8 @@ #include "gmyth_backendinfo.h" #include "gmyth_epg.h" +#include "common.h" + static gboolean test_epg_connection (GMythBackendInfo *backend_info) { @@ -104,10 +106,14 @@ backend_info = gmyth_backend_info_new_with_uri (argv[1]); + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + test_epg_connection (backend_info); test_epg_get_channels (backend_info); test_epg_get_channel_icon (backend_info); - return 0; + return(0); } diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_http.c --- a/gmyth/tests/gmyth_test_http.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_http.c Wed Apr 25 01:07:56 2007 +0100 @@ -2,6 +2,8 @@ #include "gmyth.h" #include +#include "common.h" + int main (int args, const char **argv) { @@ -52,6 +54,9 @@ gint ret = gmyth_http_retrieve_job_status(backend_info, 1000, start); printf("Status: %d\n\n", ret); + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); - return 0; + return(0); } diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_livetv.c --- a/gmyth/tests/gmyth_test_livetv.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_livetv.c Wed Apr 25 01:07:56 2007 +0100 @@ -1,5 +1,7 @@ #include +#include "common.h" + #include "gmyth_uri.h" #include "gmyth_backendinfo.h" #include "gmyth_livetv.h" @@ -131,6 +133,12 @@ g_debug ("Error when running LiveTV setup test script!"); else g_debug ("LiveTV setup test script finished with success."); + + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + return(0); } diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_recorder.c --- a/gmyth/tests/gmyth_test_recorder.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_recorder.c Wed Apr 25 01:07:56 2007 +0100 @@ -6,6 +6,7 @@ #include "gmyth_epg.h" #include "gmyth_common.h" +#include "common.h" static gboolean test_recorder_availability (GMythBackendInfo *backend_info) @@ -102,7 +103,6 @@ int main (int args, const char **argv) { - const char* uri = argv[1]; GMythBackendInfo *backend_info; g_type_init (); @@ -115,6 +115,13 @@ printf ("******** Testing recorder check channels function ***********\n"); test_recorder_check_channels (backend_info); + + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + return(0); + } diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_recordings.c --- a/gmyth/tests/gmyth_test_recordings.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_recordings.c Wed Apr 25 01:07:56 2007 +0100 @@ -6,6 +6,8 @@ #include "gmyth_epg.h" #include "gmyth_common.h" +#include "common.h" + static gboolean test_recording_list (GMythBackendInfo *backend_info) { @@ -44,16 +46,17 @@ int main (int args, const char **argv) { - const char* uri = argv[1]; - GMythBackendInfo *backend_info; g_type_init (); backend_info = gmyth_backend_info_new_with_uri (argv[1]); test_recording_list (backend_info); + + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + return(0); } - - - diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_transcode.c --- a/gmyth/tests/gmyth_test_transcode.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_transcode.c Wed Apr 25 01:07:56 2007 +0100 @@ -7,6 +7,8 @@ #include #include +#include "common.h" + int main (int args, const char **argv) { @@ -33,8 +35,11 @@ teste = gmyth_jobqueue_change_cmd(transcode, "STOP", "JOB_TRANSCODE"); + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); + + return(0); + } - - - diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/gmyth_test_vlc.c --- a/gmyth/tests/gmyth_test_vlc.c Tue Apr 24 19:45:27 2007 +0100 +++ b/gmyth/tests/gmyth_test_vlc.c Wed Apr 25 01:07:56 2007 +0100 @@ -2,6 +2,8 @@ #include "gmyth.h" #include +#include "common.h" + int main (int args, const char **argv) { @@ -30,6 +32,9 @@ //gchar* teste = gmyth_http_retrieve_setting(backend_info, "RecordFilePrefix", "hmelo-desktop"); + fprintf(stdout, SYNC_STRING); + fflush(NULL); + getchar(); - return 0; + return(0); } diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_connection.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_connection.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,11 @@ +#!/usr/bin/python + +#doc: test gmyth_socket_connection_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_connection', ['myth://192.168.3.165:6543/livetv?channel=1']) +#p = start('gmyth_test_connection', ['livetv']) + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_epg.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_epg.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_epg_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_epg', ['myth://mythtv:mythtv@192.168.3.165:6543/?mythconverg']) + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_http.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_http.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_http_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_http') + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_livetv.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_livetv.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_livetv_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_livetv') + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_recorder.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_recorder.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_recorder_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_recorder', ['myth://mythtv:mythtv@192.168.3.165:6543/?mythconverg']) + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_recordings.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_recordings.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_epg_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_recordings', ['myth://mythtv:mythtv@192.168.3.165:6543/?mythconverg']) + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_transcode.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_transcode.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_transcoder_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_transcode') + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/test_vlc.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/test_vlc.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,10 @@ +#!/usr/bin/python + +#doc: test gmyth_vlc_* methods + +from testing_tools import start, finish +import sys + +p = start('gmyth_test_vlc') + +sys.exit(finish(p)) diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/testing_tools.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/testing_tools.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,118 @@ +import re +import os +import time +import signal +import sys +import popen2 +from utils import wait_string, sync_string + +def wait(p): + r = p.poll() + if r != -1: + return r + for i in range(5): + time.sleep(1) + r = p.poll() + if r != -1: + return r + print 'killed!' + os.kill(p.pid, signal.SIGKILL) + return p.wait() + +class executable: + def __init__(self, cmd, ignore): + #assert isinstance(cmd, list) + self.p = popen2.Popen3(cmd, capturestderr = True) + print "Executing command... [ %s ]\n" % cmd + self.stdin = self.p.tochild + self.stdout = self.p.fromchild + self.stderr = self.p.childerr + self.ignore = ignore + + #returns True if completed successfully + def finish(self): + r = wait(self.p) + return r == 0 + +class simple_exe (executable): + def __init__(self, exe, ignore): + cmd = './' + exe + executable.__init__(self, cmd, ignore) + +class mudflap_exe (executable): + def __init__(self, exe, ignore): + cmd = ['./' + exe] + executable.__init__(self, cmd, ignore) + + #returns True if completed successfully + def finish(self): + r = wait(self.p) + data = self.stderr.read() + if r != 0: + print data + return False + viols = filter (lambda x: "mudflap violation" in x, data.split('\n')) + return len(viols) <= self.ignore + +class valgrind_exe (executable): + def __init__(self, exe, ignore): + suppressions = os.environ['top_srcdir'] + '/tests/regression/suppressions' + cmd = ['/usr/bin/valgrind', '--suppressions=' + suppressions, + '--leak-check=full', exe] + executable.__init__(self, cmd, ignore) + + #returns True if completed successfully + def finish(self): + r = wait(self.p) + data = self.stderr.read() + if r != 0: + print data + return False + a = re.search('ERROR SUMMARY: *(.*) err.*', data) + errors = int(a.groups()[0]) + a = re.search('definitely lost: (.*) bytes', data) + if a: + a = int(a.groups()[0]) + if a != 0: + errors += 1 + if errors != 0: + print data + return errors == 0 + +def get_gcda(exe): + f = open(exe) + data = f.read() + f.close() + a = re.search('/.*\.gcda', data) + if a == None: + return None + return a.group() + +def is_coverage(exe): + t = get_gcda(exe) + return t != None + +def is_mudflap(exe): + p = popen2.Popen3(['ldd', exe]) + data = p.fromchild.read() + p.wait() + return 'libmudflapth' in data + +def relink_name(exe): + return '.libs/lt-' + exe + +def start(exe, params = [], ignore = 0): + exe = exe + ' ' + ' '.join(params) + print 'Executing the command line: ', exe + p = simple_exe(exe, ignore) + wait_string(p.stdout, sync_string) + return p + +def finish(p): + p.stdin.write('\n') + p.stdin.flush() + r = p.finish() + if r == True: + return 0 + else: + return 1 diff -r 0f77fcb97269 -r 95263ab433f1 gmyth/tests/utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/utils.py Wed Apr 25 01:07:56 2007 +0100 @@ -0,0 +1,11 @@ +import os +import signal +import time + +def wait_string(file, string): + while True: + line = file.readline().strip() + if line == string: + return + +sync_string = '===SYNC==='