[pkg-fso-commits] [SCM] Automatic Display Manager branch, bug540201, updated. debian/0.6-1-38-g11bdc2d
Enrico Zini
enrico at enricozini.org
Wed Jul 6 08:38:17 UTC 2011
The following commit has been merged in the bug540201 branch:
commit 11bdc2dc6420801c24bc51f5fa376d017975c978
Author: Enrico Zini <enrico at enricozini.org>
Date: Wed Jul 6 10:38:12 2011 +0200
Collected common test code in a test module
diff --git a/Makefile.am b/Makefile.am
index fac0a4e..a59bba1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,9 +6,10 @@ ACLOCAL_AMFLAGS = -I m4
sbin_PROGRAMS = nodm
-dist_noinst_HEADERS = common.h dm.h log.h xserver.h xsession.h xsession-child.h
+dist_noinst_HEADERS = common.h dm.h log.h test.h xserver.h xsession.h xsession-child.h
libsources = common.c log.c xsession-child.c xserver.c xsession.c dm.c
+testlibsources = $(libsources) test.c
AM_CPPFLAGS = $(X11_CFLAGS)
AM_LDFLAGS = $(PAM_LIBS) $(X11_LIBS)
@@ -25,11 +26,11 @@ man_MANS = nodm.8
TESTS = test-internals test-xstart test-xsession
check_PROGRAMS = test-internals test-xstart test-xsession
-test_xstart_SOURCES = $(libsources) test-xstart.c
+test_xstart_SOURCES = $(testlibsources) test-xstart.c
-test_xsession_SOURCES = $(libsources) test-xsession.c
+test_xsession_SOURCES = $(testlibsources) test-xsession.c
-test_internals_SOURCES = $(libsources) test-internals.c
+test_internals_SOURCES = $(testlibsources) test-internals.c
EXTRA_DIST = test_nodm TODO nodm-man-extras autogen.sh
diff --git a/log.c b/log.c
index b0564ae..4d55046 100644
--- a/log.c
+++ b/log.c
@@ -53,7 +53,7 @@ void log_info(const char* fmt, ...)
if (config->info_to_stderr)
{
- fprintf(stderr, "%s: ", config->program_name);
+ fprintf(stderr, "%s:", config->program_name);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
@@ -74,7 +74,7 @@ void log_warn(const char* fmt, ...)
if (config->log_to_stderr)
{
- fprintf(stderr, "%s: ", config->program_name);
+ fprintf(stderr, "%s:", config->program_name);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
@@ -95,7 +95,7 @@ void log_err(const char* fmt, ...)
if (config->log_to_stderr)
{
- fprintf(stderr, "%s: ", config->program_name);
+ fprintf(stderr, "%s:", config->program_name);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
diff --git a/test-internals.c b/test-internals.c
index ebb3ff0..f82a2d8 100644
--- a/test-internals.c
+++ b/test-internals.c
@@ -21,30 +21,14 @@
#include "log.h"
#include "common.h"
#include "dm.h"
+#include "test.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-void ensure_equals(const char* a, const char* b)
-{
- if (a == NULL && b == NULL)
- return;
- if (a == NULL || b == NULL || strcmp(a, b) != 0)
- {
- log_warn("strings differ: \"%s\" != \"%s\"", a, b);
- exit(1);
- }
-}
-
int main(int argc, char* argv[])
{
- struct log_config cfg = {
- .program_name = "test-internals",
- .log_to_syslog = false,
- .log_to_stderr = true,
- .info_to_stderr = true,
- };
- log_start(&cfg);
+ test_start("test-internals");
// Test getenv_with_default
setenv("FOO", "foo", 1);
@@ -114,6 +98,5 @@ int main(int argc, char* argv[])
ensure_equals(s.srv.argv[3], NULL);
nodm_display_manager_cleanup(&s);
- log_end();
- return 0;
+ test_ok();
}
diff --git a/test-xsession.c b/test-xsession.c
index b42b4bc..cfe9f86 100644
--- a/test-xsession.c
+++ b/test-xsession.c
@@ -21,6 +21,7 @@
#include "log.h"
#include "common.h"
#include "dm.h"
+#include "test.h"
#include <stdio.h>
#include <stdlib.h>
@@ -31,55 +32,27 @@ int test_session(struct nodm_xsession_child* s)
int main(int argc, char* argv[])
{
- struct log_config cfg = {
- .program_name = "test-xsession",
- .log_to_syslog = false,
- .log_to_stderr = true,
- .info_to_stderr = true,
- };
- log_start(&cfg);
+ test_start("test-xsession");
//const char* xcmdline = "/usr/bin/Xnest :1";
setenv("NODM_SESSION", "/bin/true", 1);
setenv("NODM_USER", getenv_with_default("USER", "root"), 1);
- int res;
-
struct nodm_display_manager dm;
nodm_display_manager_init(&dm);
// configure display manager for testing
- res = nodm_display_manager_parse_xcmdline(&dm, "/usr/bin/Xnest :1 -geometry 1x1+0+0");
- if (res != E_SUCCESS)
- {
- fprintf(stderr, "nodm_display_manager_parse_xcmdline return code: %d\n", res);
- goto cleanup;
- }
+ ensure_succeeds(nodm_display_manager_parse_xcmdline(&dm, "/usr/bin/Xnest :1 -geometry 1x1+0+0"));
dm.session.conf_use_pam = false;
dm.session.conf_cleanup_xse = false;
dm.session.conf_run_as[0] = 0;
dm.session.child_body = test_session;
- res = nodm_display_manager_start(&dm);
- if (res != E_SUCCESS)
- {
- fprintf(stderr, "nodm_display_manager_start return code: %d\n", res);
- goto cleanup;
- }
+ ensure_succeeds(nodm_display_manager_start(&dm));
- res = nodm_display_manager_wait(&dm);
- if (res != E_SUCCESS)
- {
- fprintf(stderr, "nodm_display_manager_wait return code: %d\n", res);
- goto cleanup;
- }
+ ensure_succeeds(nodm_display_manager_wait(&dm));
- res = nodm_display_manager_stop(&dm);
- if (res != E_SUCCESS)
- {
- fprintf(stderr, "nodm_display_manager_stop return code: %d\n", res);
- goto cleanup;
- }
+ ensure_succeeds(nodm_display_manager_stop(&dm));
// TODO:
// - test a wrong xserver command line (dying X server)
@@ -88,9 +61,5 @@ int main(int argc, char* argv[])
nodm_display_manager_cleanup(&dm);
-cleanup:
- if (res != E_SUCCESS)
- fprintf(stderr, "Error: %s\n", nodm_strerror(res));
- log_end();
- return res;
+ test_ok();
}
diff --git a/test-xstart.c b/test-xstart.c
index 7a32323..c75ee2a 100644
--- a/test-xstart.c
+++ b/test-xstart.c
@@ -20,18 +20,13 @@
#include "log.h"
#include "xserver.h"
+#include "test.h"
#include "common.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
- struct log_config cfg = {
- .program_name = "test-xstart",
- .log_to_syslog = false,
- .log_to_stderr = true,
- .info_to_stderr = true,
- };
- log_start(&cfg);
+ test_start("test-xstart");
struct nodm_xserver srv;
nodm_xserver_init(&srv);
@@ -54,6 +49,5 @@ int main(int argc, char* argv[])
return res;
}
- log_end();
- return E_SUCCESS;
+ test_ok();
}
diff --git a/test-xstart.c b/test.c
similarity index 52%
copy from test-xstart.c
copy to test.c
index 7a32323..94996ea 100644
--- a/test-xstart.c
+++ b/test.c
@@ -1,5 +1,5 @@
/*
- * test-xstart - test that we are able to start X
+ * test - nodm test utilities
*
* Copyright 2011 Enrico Zini <enrico at enricozini.org>
*
@@ -18,42 +18,49 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "log.h"
-#include "xserver.h"
+#include "test.h"
#include "common.h"
+#include <string.h>
#include <stdio.h>
-int main(int argc, char* argv[])
+void test_start(const char* testname)
{
- struct log_config cfg = {
- .program_name = "test-xstart",
- .log_to_syslog = false,
- .log_to_stderr = true,
- .info_to_stderr = true,
- };
+ static struct log_config cfg;
+ cfg.program_name = testname,
+ cfg.log_to_syslog = false,
+ cfg.log_to_stderr = true,
+ cfg.info_to_stderr = true,
log_start(&cfg);
+}
- struct nodm_xserver srv;
- nodm_xserver_init(&srv);
+void test_fail()
+{
+ log_end();
+ exit(1);
+}
- const char* server_argv[] = { "/usr/bin/Xnest", ":1", "-geometry", "1x1+0+0", NULL };
- srv.argv = server_argv;
- srv.name = ":1";
+void test_ok()
+{
+ log_end();
+ exit(0);
+}
- int res = nodm_xserver_start(&srv);
- if (res != E_SUCCESS)
+void ensure_equals(const char* a, const char* b)
+{
+ if (a == NULL && b == NULL)
+ return;
+ if (a == NULL || b == NULL || strcmp(a, b) != 0)
{
- fprintf(stderr, "nodm_xserver_start return code: %d\n", res);
- return res;
+ log_warn("strings differ: \"%s\" != \"%s\"", a, b);
+ test_fail();
}
+}
- res = nodm_xserver_stop(&srv);
- if (res != E_SUCCESS)
+void _ensure_succeeds(int code, const char* file, int line, const char* desc)
+{
+ if (code != E_SUCCESS)
{
- fprintf(stderr, "nodm_xserver_stop return code: %d\n", res);
- return res;
+ log_err("%s:%d:%s failed with code %d (%s)", file, line, desc, code, nodm_strerror(code));
+ test_fail();
}
-
- log_end();
- return E_SUCCESS;
}
diff --git a/test.h b/test.h
new file mode 100644
index 0000000..30b7d41
--- /dev/null
+++ b/test.h
@@ -0,0 +1,42 @@
+/*
+ * test - nodm test utilities
+ *
+ * Copyright 2011 Enrico Zini <enrico at enricozini.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NODM_TEST_H
+#define NODM_TEST_H
+
+#include "log.h"
+#include <stdlib.h>
+
+/// Setup the logging system for a test script
+void test_start(const char* testname);
+
+/// exit() the program reporting a test failure
+void test_fail() __attribute__((noreturn));
+
+/// exit() the program reporting a success
+void test_ok() __attribute__((noreturn));
+
+/// Ensure that two strings are the same
+void ensure_equals(const char* a, const char* b);
+
+#define ensure_succeeds(val) _ensure_succeeds((val), __FILE__, __LINE__, #val)
+void _ensure_succeeds(int code, const char* file, int line, const char* desc);
+
+#endif
--
Automatic Display Manager
More information about the pkg-fso-commits
mailing list