Run tests on make check
--- Makefile.ug | 6 +- configure.ac | 1 + m4/ugly-stamp.m4 | 2 +- medit/Makefile.ug | 4 + medit/run-tests.sh | 3 + tests/Makefile.am | 43 ++++++-------- tests/testthreads.c | 127 +++++++++++++++++++++++++++++++++++----- tests/testthreads2.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/testthreads2.sh | 6 ++ 9 files changed, 303 insertions(+), 44 deletions(-) create mode 100755 medit/run-tests.sh create mode 100644 tests/testthreads2.c create mode 100755 tests/testthreads2.sh
This commit is contained in:
parent
65c67d6eac
commit
7d739c8fbd
@ -14,16 +14,16 @@ EXTRA_DIST += \
|
||||
@MOO_PO_SUBDIRS_RULE2@
|
||||
BUILT_SOURCES += po-subdirs-stamp po-subdirs-stamp-2
|
||||
|
||||
DIST_SUBDIRS = moo medit po po-gsv doc
|
||||
DIST_SUBDIRS = moo medit po po-gsv doc tests
|
||||
|
||||
if MOO_ENABLE_NLS
|
||||
po_subdirs = po po-gsv
|
||||
endif
|
||||
|
||||
if MOO_BUILD_MEDIT
|
||||
SUBDIRS = . $(po_subdirs) doc moo medit
|
||||
SUBDIRS = . $(po_subdirs) doc moo medit tests
|
||||
else
|
||||
SUBDIRS = . $(po_subdirs) doc moo
|
||||
SUBDIRS = . $(po_subdirs) doc moo tests
|
||||
endif
|
||||
|
||||
moo-config-dirs.h: moo-config-dirs.h.stamp
|
||||
|
@ -53,6 +53,7 @@ moo/mooutils/Makefile
|
||||
moo/mooutils/newgtk/Makefile
|
||||
moo/mooutils/pcre/Makefile
|
||||
medit/Makefile
|
||||
tests/Makefile
|
||||
po/Makefile.in
|
||||
po-gsv/Makefile.in
|
||||
])
|
||||
|
@ -19,7 +19,7 @@ d5aeeaa47fa88297cc36e17fbbc47102 moo-lib.m4
|
||||
87cb0e8cdecb72d87d7404eb20546f26 moo-python-cross-mingw.m4
|
||||
12a5998e546fe6991597af5dc0cebda1 moo-python.m4
|
||||
9b1a1ecc886394e26ba9ff62a057d687 moo-xml.m4
|
||||
c22713636d2667f37b298db25d2da3db configure.ac
|
||||
bc98c93988f2674585e76829e8b172e0 configure.ac
|
||||
])
|
||||
|
||||
AC_DEFUN([UGLY_STAMP],[])
|
||||
|
@ -64,9 +64,13 @@ uninstall-hook:
|
||||
@if echo "Updating icon cache" && $(update_icon_cache); then echo "Done."; else echo "Failed."; fi
|
||||
endif
|
||||
|
||||
TESTS =
|
||||
EXTRA_DIST += run-tests.sh
|
||||
|
||||
if MOO_ENABLE_UNIT_TESTS
|
||||
AM_CFLAGS += -DSRCDIR=\"$(shell cd $(srcdir) && pwd)\" -DTOP_SRCDIR=\"$(shell cd $(top_srcdir) && pwd)\"
|
||||
AM_CXXFLAGS += -DSRCDIR=\"$(shell cd $(srcdir) && pwd)\" -DTOP_SRCDIR=\"$(shell cd $(top_srcdir) && pwd)\"
|
||||
TESTS += run-tests.sh
|
||||
endif
|
||||
|
||||
EXTRA_DIST += \
|
||||
|
3
medit/run-tests.sh
Normal file
3
medit/run-tests.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#! /bin/sh
|
||||
|
||||
exec ./medit --ut
|
@ -1,33 +1,34 @@
|
||||
AM_CFLAGS = $(MOO_CFLAGS)
|
||||
AM_CXXFLAGS = $(MOO_CXXFLAGS)
|
||||
|
||||
noinst_PROGRAMS =
|
||||
|
||||
test_programs = \
|
||||
markup testpaned miniglade \
|
||||
testobject testthreads
|
||||
check_PROGRAMS = \
|
||||
markup testpaned \
|
||||
miniglade testobject \
|
||||
testthreads testthreads2
|
||||
TESTS = \
|
||||
testthreads \
|
||||
testthreads2.sh \
|
||||
markup
|
||||
|
||||
if MOO_BUILD_EDIT
|
||||
test_programs += \
|
||||
check_PROGRAMS += \
|
||||
testtext testfileview \
|
||||
testpanedfileview testfold \
|
||||
testkeyfile
|
||||
TESTS += \
|
||||
testfold
|
||||
endif
|
||||
if MOO_BUILD_APP
|
||||
test_programs += testhtml
|
||||
check_PROGRAMS += testhtml
|
||||
endif
|
||||
|
||||
EXTRA_PROGRAMS = $(test_programs)
|
||||
EXTRA_DIST = testthreads2.sh
|
||||
|
||||
if MOO_ENABLE_TESTS
|
||||
noinst_PROGRAMS += $(test_programs)
|
||||
endif
|
||||
|
||||
all-tests: $(EXTRA_PROGRAMS)
|
||||
all-tests: $(check_PROGRAMS)
|
||||
|
||||
if MOO_BUILD_UTILS
|
||||
if !MOO_BUILD_EDIT
|
||||
noinst_PROGRAMS += testfileview
|
||||
check_PROGRAMS += testfileview
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -35,24 +36,14 @@ ldflags = -export-dynamic $(PYTHON_EXTRA_LDFLAGS)
|
||||
include ../moo/moo-comps.mk
|
||||
ldadd = $(moo_app_ldadd)
|
||||
|
||||
# if MOO_OS_MINGW
|
||||
# ldflags += -mwindows
|
||||
# endif MOO_OS_MINGW
|
||||
|
||||
run_tests_LDFLAGS = $(ldflags)
|
||||
run_tests_LDADD = $(ldadd)
|
||||
|
||||
|
||||
testfold_LDFLAGS = $(ldflags)
|
||||
testfold_LDADD = $(ldadd)
|
||||
testfold_SOURCES = testfold.c
|
||||
|
||||
|
||||
testtext_LDFLAGS = $(ldflags)
|
||||
testtext_LDADD = $(ldadd)
|
||||
testtext_SOURCES = testtext.c
|
||||
|
||||
|
||||
testkeyfile_LDFLAGS = $(ldflags)
|
||||
testkeyfile_LDADD = $(ldadd)
|
||||
testkeyfile_SOURCES = testkeyfile.c
|
||||
@ -61,6 +52,10 @@ testthreads_LDFLAGS = $(ldflags)
|
||||
testthreads_LDADD = $(ldadd) $(GTHREAD_LIBS)
|
||||
testthreads_SOURCES = testthreads.c
|
||||
|
||||
testthreads2_LDFLAGS = $(ldflags)
|
||||
testthreads2_LDADD = $(ldadd) $(GTHREAD_LIBS)
|
||||
testthreads2_SOURCES = testthreads2.c
|
||||
|
||||
testhtml_LDFLAGS = $(ldflags)
|
||||
testhtml_LDADD = $(ldadd)
|
||||
testhtml_SOURCES = testhtml.c
|
||||
|
@ -14,56 +14,151 @@
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-debug.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
static void hole (G_GNUC_UNUSED const char *format, ...)
|
||||
{
|
||||
}
|
||||
|
||||
#define printf hole
|
||||
|
||||
static int thread_count;
|
||||
static GtkWidget *textview;
|
||||
|
||||
static void
|
||||
callback (void)
|
||||
print (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *string;
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
va_start (args, format);
|
||||
string = g_strdup_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
{
|
||||
GtkTextIter iter;
|
||||
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
|
||||
gtk_text_buffer_get_end_iter (buffer, &iter);
|
||||
gtk_text_buffer_place_cursor (buffer, &iter);
|
||||
gtk_text_buffer_insert_at_cursor (buffer, string, -1);
|
||||
gtk_text_buffer_insert_at_cursor (buffer, "\n", -1);
|
||||
gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (textview),
|
||||
gtk_text_buffer_get_insert (buffer));
|
||||
}
|
||||
|
||||
g_free (string);
|
||||
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
guint id;
|
||||
guint event_id;
|
||||
} ThreadData;
|
||||
|
||||
static void
|
||||
callback (GList *messages,
|
||||
ThreadData *tdata)
|
||||
{
|
||||
print ("thread %d: sent %d messages", tdata->id, g_list_length (messages));
|
||||
while (messages)
|
||||
{
|
||||
print (" %s", (char*) messages->data);
|
||||
messages = messages->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
queue_notify (ThreadData *tdata)
|
||||
{
|
||||
int threads_left;
|
||||
|
||||
gdk_threads_enter ();
|
||||
threads_left = --thread_count;
|
||||
gdk_threads_leave ();
|
||||
|
||||
print ("thread %d is dead, %d left", tdata->id, threads_left);
|
||||
printf ("thread %d is dead, %d left\n", tdata->id, threads_left);
|
||||
|
||||
if (!threads_left)
|
||||
{
|
||||
gdk_threads_enter ();
|
||||
gtk_main_quit ();
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
thread_main (gpointer data)
|
||||
thread_main (ThreadData *tdata)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_usleep (1000);
|
||||
|
||||
/* g_print may not be used here */
|
||||
printf ("thread %d: starting\n", GPOINTER_TO_UINT (data));
|
||||
print ("thread %d: starting", tdata->id);
|
||||
printf ("thread %d: starting\n", tdata->id);
|
||||
|
||||
for (i = 0; i < 10; ++i)
|
||||
{
|
||||
_moo_message_async ("thread %d: hi there #%d", GPOINTER_TO_UINT (data), i);
|
||||
g_usleep (g_random_int_range (10, 100) * 1000);
|
||||
gdk_threads_enter ();
|
||||
_moo_message ("thread %d: hi there #%d again", GPOINTER_TO_UINT (data), i);
|
||||
gdk_threads_leave ();
|
||||
printf ("thread %d: hi there #%d", tdata->id, i);
|
||||
_moo_event_queue_push (tdata->event_id,
|
||||
g_strdup_printf ("thread %d: hi there #%d", tdata->id, i),
|
||||
g_free);
|
||||
g_usleep (g_random_int_range (10, 100) * 10000);
|
||||
printf ("thread %d: hi there #%d again", tdata->id, i);
|
||||
print ("thread %d: hi there #%d again", tdata->id, i);
|
||||
g_usleep (g_random_int_range (10, 100) * 1000);
|
||||
}
|
||||
|
||||
printf ("thread %d: exiting\n", GPOINTER_TO_UINT (data));
|
||||
print ("thread %d: exiting", tdata->id);
|
||||
printf ("thread %d: exiting\n", tdata->id);
|
||||
|
||||
_moo_event_queue_disconnect (tdata->event_id);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define NTHREADS 10
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
guint i;
|
||||
GError *error = NULL;
|
||||
GThread *threads[NTHREADS];
|
||||
GtkWidget *window, *swin;
|
||||
|
||||
g_thread_init (NULL);
|
||||
gdk_threads_init ();
|
||||
gdk_threads_enter ();
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
moo_set_log_func_window (TRUE);
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
|
||||
swin = gtk_scrolled_window_new (NULL, NULL);
|
||||
textview = gtk_text_view_new ();
|
||||
gtk_container_add (GTK_CONTAINER (window), swin);
|
||||
gtk_container_add (GTK_CONTAINER (swin), textview);
|
||||
gtk_widget_show_all (window);
|
||||
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
_moo_message ("Hi there");
|
||||
print ("Hi there");
|
||||
|
||||
_moo_event_queue_connect ((MooEventQueueCallback) callback, NULL, NULL);
|
||||
|
||||
for (i = 0; i < 10; ++i)
|
||||
if (!g_thread_create (thread_main, GUINT_TO_POINTER (i), FALSE, NULL))
|
||||
thread_count = NTHREADS;
|
||||
for (i = 0; i < NTHREADS; ++i)
|
||||
{
|
||||
ThreadData *data = moo_new0 (ThreadData);
|
||||
data->id = i;
|
||||
data->event_id =
|
||||
_moo_event_queue_connect ((MooEventQueueCallback) callback, data,
|
||||
(GDestroyNotify) queue_notify);
|
||||
if (!(threads[i] = g_thread_create ((GThreadFunc) thread_main, data, FALSE, NULL)))
|
||||
g_error ("%s", error->message);
|
||||
}
|
||||
|
||||
gdk_threads_enter ();
|
||||
gtk_main ();
|
||||
gdk_threads_leave ();
|
||||
|
||||
|
155
tests/testthreads2.c
Normal file
155
tests/testthreads2.c
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* testthreads.c
|
||||
*
|
||||
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#include "mooutils/mooutils-thread.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-debug.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
G_GNUC_UNUSED static void
|
||||
hole (G_GNUC_UNUSED const char *format, ...)
|
||||
{
|
||||
}
|
||||
|
||||
#define printf hole
|
||||
|
||||
static int thread_count;
|
||||
|
||||
// static void
|
||||
// print (const char *format, ...)
|
||||
// {
|
||||
// va_list args;
|
||||
// char *string;
|
||||
//
|
||||
// gdk_threads_enter ();
|
||||
//
|
||||
// va_start (args, format);
|
||||
// string = g_strdup_vprintf (format, args);
|
||||
// va_end (args);
|
||||
//
|
||||
// {
|
||||
// GtkTextIter iter;
|
||||
// GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
|
||||
// gtk_text_buffer_get_end_iter (buffer, &iter);
|
||||
// gtk_text_buffer_place_cursor (buffer, &iter);
|
||||
// gtk_text_buffer_insert_at_cursor (buffer, string, -1);
|
||||
// gtk_text_buffer_insert_at_cursor (buffer, "\n", -1);
|
||||
// gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (textview),
|
||||
// gtk_text_buffer_get_insert (buffer));
|
||||
// }
|
||||
//
|
||||
// g_free (string);
|
||||
//
|
||||
// gdk_threads_leave ();
|
||||
// }
|
||||
|
||||
typedef struct {
|
||||
guint id;
|
||||
guint event_id;
|
||||
} ThreadData;
|
||||
|
||||
static void
|
||||
callback (GList *messages,
|
||||
ThreadData *tdata)
|
||||
{
|
||||
g_print ("thread %d: sent %d messages\n", tdata->id, g_list_length (messages));
|
||||
while (messages)
|
||||
{
|
||||
g_print (" %s\n", (char*) messages->data);
|
||||
messages = messages->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
queue_notify (ThreadData *tdata)
|
||||
{
|
||||
int threads_left;
|
||||
|
||||
gdk_threads_enter ();
|
||||
threads_left = --thread_count;
|
||||
gdk_threads_leave ();
|
||||
|
||||
g_print ("thread %d is dead, %d left\n", tdata->id, threads_left);
|
||||
printf ("thread %d is dead, %d left\n", tdata->id, threads_left);
|
||||
|
||||
if (!threads_left)
|
||||
{
|
||||
gdk_threads_enter ();
|
||||
gtk_main_quit ();
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
thread_main (ThreadData *tdata)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_usleep (1000);
|
||||
|
||||
g_print ("thread %d: starting\n", tdata->id);
|
||||
printf ("thread %d: starting\n", tdata->id);
|
||||
|
||||
for (i = 0; i < 10; ++i)
|
||||
{
|
||||
printf ("thread %d: hi there #%d\n", tdata->id, i);
|
||||
_moo_event_queue_push (tdata->event_id,
|
||||
g_strdup_printf ("thread %d: hi there #%d", tdata->id, i),
|
||||
g_free);
|
||||
g_usleep (g_random_int_range (10, 100) * 10000);
|
||||
printf ("thread %d: hi there #%d again\n", tdata->id, i);
|
||||
g_print ("thread %d: hi there #%d again\n", tdata->id, i);
|
||||
g_usleep (g_random_int_range (10, 100) * 1000);
|
||||
}
|
||||
|
||||
g_print ("thread %d: exiting\n", tdata->id);
|
||||
printf ("thread %d: exiting\n", tdata->id);
|
||||
|
||||
_moo_event_queue_disconnect (tdata->event_id);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define NTHREADS 100
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
guint i;
|
||||
GError *error = NULL;
|
||||
GThread *threads[NTHREADS];
|
||||
|
||||
g_thread_init (NULL);
|
||||
gdk_threads_init ();
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
moo_set_log_func_file ("testthreads2-log.txt");
|
||||
|
||||
thread_count = NTHREADS;
|
||||
for (i = 0; i < NTHREADS; ++i)
|
||||
{
|
||||
ThreadData *data = moo_new0 (ThreadData);
|
||||
data->id = i;
|
||||
data->event_id =
|
||||
_moo_event_queue_connect ((MooEventQueueCallback) callback, data,
|
||||
(GDestroyNotify) queue_notify);
|
||||
if (!(threads[i] = g_thread_create ((GThreadFunc) thread_main, data, FALSE, NULL)))
|
||||
g_error ("%s", error->message);
|
||||
}
|
||||
|
||||
gdk_threads_enter ();
|
||||
gtk_main ();
|
||||
gdk_threads_leave ();
|
||||
|
||||
return 0;
|
||||
}
|
6
tests/testthreads2.sh
Normal file
6
tests/testthreads2.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#! /bin/sh
|
||||
|
||||
rm -f testthreads2-log.txt
|
||||
echo "Running ./testthreads2"
|
||||
./testthreads2 || exit 1
|
||||
[ `wc -l < testthreads2-log.txt` = 3300 ] || exit 1
|
Loading…
x
Reference in New Issue
Block a user