commit d498196: [Minor] test: remove hard-coded build directory
Peter Wu
peter at lekensteyn.nl
Tue Jan 21 09:14:14 UTC 2020
Author: Peter Wu
Date: 2020-01-21 02:21:31 +0000
URL: https://github.com/rspamd/rspamd/commit/d498196712c209fdcbd92f65c0b47ff26fc6c009
[Minor] test: remove hard-coded build directory
* Reproducible build: avoid defining the BUILDROOT macro and avoid
embedding the build directory in the test image. Instead rely on the
test files being present next to the executable.
* I considered using g_test_build_filename, available since GLib 2.38
(available on all supported platforms, RHEL 7, Debian, Ubuntu, etc.),
but decided against it because it would require setting the
G_TEST_SRCDIR or G_TEST_BUILDDIR environment variables. Therefore this
patch simply parses argv0 directly.
---
config.h.in | 2 --
test/rspamd_lua_pcall_vs_resume_test.c | 8 ++++++--
test/rspamd_lua_test.c | 7 +++++--
test/rspamd_test_suite.c | 3 +++
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/config.h.in b/config.h.in
index e711af6d6..c2d73a0a9 100644
--- a/config.h.in
+++ b/config.h.in
@@ -248,8 +248,6 @@
#define MODULES_NUM ${RSPAMD_MODULES_NUM}
-#define BUILDROOT "${CMAKE_BINARY_DIR}"
-
/* sys/types */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
diff --git a/test/rspamd_lua_pcall_vs_resume_test.c b/test/rspamd_lua_pcall_vs_resume_test.c
index 6cb05fd38..eb945b92f 100644
--- a/test/rspamd_lua_pcall_vs_resume_test.c
+++ b/test/rspamd_lua_pcall_vs_resume_test.c
@@ -19,7 +19,8 @@
#include "lua/lua_thread_pool.h"
#include "unix-std.h"
-static const char *lua_src = BUILDROOT "/test/lua/pcall_test.lua";
+static const char *lua_src_name = "lua/pcall_test.lua";
+extern gchar *argv0_dirname;
extern struct rspamd_main *rspamd_main;
@@ -126,12 +127,15 @@ void
rspamd_lua_lua_pcall_vs_resume_test_func (void)
{
lua_State *L = rspamd_main->cfg->lua_state;
+ gchar *lua_src;
gdouble t1, reference;
+ lua_src = g_build_filename (argv0_dirname, lua_src_name, NULL);
if (luaL_dofile (L, lua_src) != 0) {
msg_err ("failed to load test file: %s ", lua_tostring (L, -1));
g_assert (0);
}
+ g_free (lua_src);
gint function_call = luaL_ref (L, LUA_REGISTRYINDEX);
@@ -148,4 +152,4 @@ rspamd_lua_lua_pcall_vs_resume_test_func (void)
t1 = test_resume_get_new_thread (function_call);
msg_notice ("resume+get [new] thread stat: ts: %1.5f, avg:%1.5f, slow=%1.2f", t1, t1/(gdouble)N, t1 / reference);
-}
\ No newline at end of file
+}
diff --git a/test/rspamd_lua_test.c b/test/rspamd_lua_test.c
index fc7979ee8..b014604b5 100644
--- a/test/rspamd_lua_test.c
+++ b/test/rspamd_lua_test.c
@@ -23,9 +23,10 @@
#include <glob.h>
#endif
-static const char *lua_src = BUILDROOT "/test/lua/tests.lua";
+static const char *lua_src_name = "lua/tests.lua";
extern gchar *lua_test;
extern gchar *lua_test_case;
+extern gchar *argv0_dirname;
extern struct rspamd_main *rspamd_main;
static int
@@ -59,7 +60,7 @@ void
rspamd_lua_test_func (void)
{
lua_State *L = (lua_State *)rspamd_main->cfg->lua_state;
- gchar *rp, rp_buf[PATH_MAX], path_buf[PATH_MAX], *tmp, *dir, *pattern;
+ gchar *lua_src, *rp, rp_buf[PATH_MAX], path_buf[PATH_MAX], *tmp, *dir, *pattern;
const gchar *old_path;
glob_t globbuf;
gint i, len;
@@ -75,11 +76,13 @@ rspamd_lua_test_func (void)
rspamd_printf ("Starting lua tests\n");
+ lua_src = g_build_filename (argv0_dirname, lua_src_name, NULL);
if ((rp = realpath (lua_src, rp_buf)) == NULL) {
msg_err ("cannot find path %s: %s",
lua_src, strerror (errno));
g_assert (0);
}
+ g_free (lua_src);
tmp = g_strdup (rp);
dir = dirname (tmp);
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index d7b660642..48645ca93 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -12,6 +12,7 @@ worker_t *workers[] = { NULL };
gchar *lua_test = NULL;
gchar *lua_test_case = NULL;
gboolean verbose = FALSE;
+gchar *argv0_dirname = NULL;
static GOptionEntry entries[] =
{
@@ -45,6 +46,8 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
+ argv0_dirname = g_path_get_dirname (argv[0]);
+
context = g_option_context_new ("- run rspamd test");
g_option_context_add_main_entries (context, entries, NULL);
More information about the Commits
mailing list