[tracker/wip/sam/functional-test-fixes: 4/4] functional-tests: Fix configuration to work with Meson



commit 09bb50f1da82deee197fe358df7f3ce6d5149557
Author: Sam Thursfield <sam afuera me uk>
Date:   Tue May 23 11:04:58 2017 +0100

    functional-tests: Fix configuration to work with Meson
    
    Previously the functional-test suite would test the installed version of
    Tracker, but would need to be run from a configured Tracker source+build tree.
    
    I have changed how things are configured and now with Meson the functional tests
    can be run completely from the build tree, without needing to install
    anythinng. The Autotools `make functional-test` target works the same as
    before, however.
    
    With the new setup it should also be possible to add a target that
    explicitly installs the functional tests, with a different
    configuration.json file such that they test the installed version of
    Tracker. That's not yet done, however.

 configure.ac                                       |    5 +++-
 meson.build                                        |   15 ++++++++++
 tests/functional-tests/17-ontology-changes.py      |    8 +-----
 tests/functional-tests/Makefile.am                 |    4 +++
 tests/functional-tests/common/utils/.gitignore     |    1 -
 tests/functional-tests/common/utils/Makefile.am    |    4 +--
 .../{configuration.py.in => configuration.py}      |   28 ++++++++++++--------
 tests/functional-tests/common/utils/helpers.py     |    5 +--
 tests/functional-tests/common/utils/system.py      |    4 +--
 tests/functional-tests/configuration.json.in       |    8 +++++
 tests/functional-tests/meson.build                 |   14 ++++++++++
 11 files changed, 67 insertions(+), 29 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2098e7a..fa88b4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -443,6 +443,9 @@ fi
 
 AM_CONDITIONAL(DIST_FUNCTIONAL_TESTS, test "x$enable_functional_tests" != "xno")
 
+AC_SUBST(FUNCTIONAL_TESTS_ONTOLOGIES_DIR, "${datadir}/tracker-tests/test-ontologies")
+AC_SUBST(FUNCTIONAL_TESTS_TRACKER_STORE_PATH, "${libexecdir}/tracker-store")
+
 ####################################################################
 # Check for gtk-doc and docbook-tools
 ####################################################################
@@ -936,9 +939,9 @@ AC_CONFIG_FILES([
        tests/libtracker-fts/prefix/Makefile
        tests/libtracker-sparql/Makefile
        tests/functional-tests/Makefile
+       tests/functional-tests/configuration.json
        tests/functional-tests/ipc/Makefile
        tests/functional-tests/common/Makefile
-       tests/functional-tests/common/utils/configuration.py
        tests/functional-tests/common/utils/Makefile
        tests/functional-tests/unittest2/Makefile
        tests/functional-tests/test-ontologies/Makefile
diff --git a/meson.build b/meson.build
index 17173b2..778a638 100644
--- a/meson.build
+++ b/meson.build
@@ -223,6 +223,8 @@ conf.set('TRACKER_BINARY_AGE', 100 * tracker_minor_version + tracker_micro_versi
 
 # Config that goes in some other generated files (.desktop, .pc, etc)
 conf.set('exec_prefix', get_option('prefix'))
+conf.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
+conf.set('datadir', join_paths(get_option('prefix'), get_option('datadir')))
 conf.set('includedir', join_paths(get_option('prefix'), get_option('includedir')))
 conf.set('libdir', join_paths(get_option('prefix'), get_option('libdir')))
 conf.set('libexecdir', join_paths(get_option('prefix'), get_option('libexecdir')))
@@ -230,6 +232,19 @@ conf.set('prefix', get_option('prefix'))
 conf.set('TRACKER_API_VERSION', tracker_api_version)
 conf.set('VERSION', meson.project_version())
 
+# Configure functional tests to run completely from source tree.
+conf.set('FUNCTIONAL_TESTS_ONTOLOGIES_DIR', join_paths(meson.current_source_dir(), 'tests', 
'functional-tests', 'test-ontologies-data'))
+conf.set('FUNCTIONAL_TESTS_TRACKER_STORE_PATH', join_paths(meson.current_build_dir(), 'src', 
'tracker-store', 'tracker-store'))
+
+# This is set in an awkward way for compatibility with Autoconf. Switch it
+# to a normal boolean once we get rid of the Autotools build system. It's
+# only used in tests/functional-tests/common/utils/configuration.py.in.
+if get_option('journal')
+    conf.set('DISABLE_JOURNAL_TRUE', '')
+else
+    conf.set('DISABLE_JOURNAL_TRUE', 'false')
+endif
+
 configure_file(input: 'config.h.meson.in',
                output: 'config.h',
                configuration: conf)
diff --git a/tests/functional-tests/17-ontology-changes.py b/tests/functional-tests/17-ontology-changes.py
index 8665a5d..b5c1471 100755
--- a/tests/functional-tests/17-ontology-changes.py
+++ b/tests/functional-tests/17-ontology-changes.py
@@ -62,13 +62,7 @@ class OntologyChangeTestTemplate (ut.TestCase):
     """
         
     def get_ontology_dir (self, param):
-        local = os.path.join (os.getcwd (), "test-ontologies", param)
-        if (os.path.exists (local)):
-            # Use local directory if available
-            return local
-        else:
-            return os.path.join (cfg.DATADIR, "tracker-tests",
-                                    "test-ontologies", param)
+        return os.path.join(cfg.TEST_ONTOLOGIES_DIR, param)
 
     def setUp (self):
         self.system = TrackerSystemAbstraction ()
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index db62255..ddad7e0 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -8,6 +8,7 @@ SUBDIRS = \
 configdir = $(datadir)/tracker-tests
 
 config_DATA = \
+       configuration.json \
        trackertest
 
 config_SCRIPTS = \
@@ -51,16 +52,19 @@ TEST_RUNNER = $(top_srcdir)/tests/functional-tests/test-runner.sh
 
 functional-test: ${standard_tests}
        for test in ${standard_tests} ; do \
+               export 
TRACKER_FUNCTIONAL_TEST_CONFIG=$(top_builddir)/tests/functional-tests/configuration.json ; \
                $(TEST_RUNNER) python $(top_srcdir)/tests/functional-tests/$$test; \
        done
 
 functional-test-slow: ${slow_tests}
        @for test in ${slow_tests} ; do \
+               export 
TRACKER_FUNCTIONAL_TEST_CONFIG=$(top_builddir)/tests/functional-tests/configuration.json \
                $(TEST_RUNNER) python $(top_srcdir)/tests/functional-tests/$$test; \
        done
 
 EXTRA_DIST = \
        $(config_SCRIPTS) \
        $(config_DATA) \
+       configuration.json.in \
        test-runner.sh \
        meson.build
diff --git a/tests/functional-tests/common/utils/Makefile.am b/tests/functional-tests/common/utils/Makefile.am
index c330275..c39a766 100644
--- a/tests/functional-tests/common/utils/Makefile.am
+++ b/tests/functional-tests/common/utils/Makefile.am
@@ -13,6 +13,4 @@ utils_SCRIPTS =                                        \
        options.py                                     \
        system.py
 
-EXTRA_DIST =                                           \
-       configuration.py.in                            \
-       $(utils_SCRIPTS)
+EXTRA_DIST = $(utils_SCRIPTS)
diff --git a/tests/functional-tests/common/utils/configuration.py.in 
b/tests/functional-tests/common/utils/configuration.py
similarity index 78%
rename from tests/functional-tests/common/utils/configuration.py.in
rename to tests/functional-tests/common/utils/configuration.py
index 6bc3b1b..497a789 100644
--- a/tests/functional-tests/common/utils/configuration.py.in
+++ b/tests/functional-tests/common/utils/configuration.py
@@ -20,8 +20,17 @@
 
 "Constants describing Tracker D-Bus services"
 
+import json
 import os
 
+if 'TRACKER_FUNCTIONAL_TEST_CONFIG' not in os.environ:
+    raise RuntimeError("The TRACKER_FUNCTIONAL_TEST_CONFIG environment "
+                       "variable must be set to point to the location of "
+                       "the generated configuration.json file.")
+
+with open(os.environ['TRACKER_FUNCTIONAL_TEST_CONFIG']) as f:
+    config = json.load(f)
+
 TRACKER_BUSNAME = 'org.freedesktop.Tracker1'
 TRACKER_OBJ_PATH = '/org/freedesktop/Tracker1/Resources'
 RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
@@ -32,7 +41,7 @@ MINER_IFACE = "org.freedesktop.Tracker1.Miner"
 MINERFS_INDEX_OBJ_PATH = "/org/freedesktop/Tracker1/Miner/Files/Index"
 MINER_INDEX_IFACE = "org.freedesktop.Tracker1.Miner.Files.Index"
 
-TRACKER_BACKUP_OBJ_PATH = "/org/freedesktop/Tracker1/Backup"                                            
+TRACKER_BACKUP_OBJ_PATH = "/org/freedesktop/Tracker1/Backup"
 BACKUP_IFACE = "org.freedesktop.Tracker1.Backup"
 
 TRACKER_STATS_OBJ_PATH = "/org/freedesktop/Tracker1/Statistics"
@@ -62,24 +71,21 @@ def expandvars (variable):
 
 
 
-PREFIX = "@prefix@"
+PREFIX = config['PREFIX']
 #
 # This raw variables are set by autotools without translating vars:
 #   E.G. bindir='${exec_prefix}/bin
 #
 # So we do the translation by hand in the expandvars function
 #
-RAW_EXEC_PREFIX = "@exec_prefix@"
-RAW_EXEC_DIR = "@libexecdir@"
-RAW_DATA_DIR = "@datadir@"
-RAW_DATAROOT_DIR = "@datarootdir@"
-RAW_BINDIR = "@bindir@"
+RAW_EXEC_PREFIX = config['RAW_EXEC_PREFIX']
+RAW_DATAROOT_DIR = config['RAW_DATAROOT_DIR']
+
+TEST_ONTOLOGIES_DIR = os.path.normpath(expandvars(config['TEST_ONTOLOGIES_DIR']))
 
-EXEC_PREFIX = os.path.normpath (expandvars (RAW_EXEC_DIR))
-DATADIR = os.path.normpath (expandvars (RAW_DATA_DIR))
-BINDIR = os.path.normpath (expandvars (RAW_BINDIR))
+TRACKER_STORE_PATH = os.path.normpath(expandvars(config['TRACKER_STORE_PATH']))
 
-disableJournal = ("@DISABLE_JOURNAL_TRUE@" == "")
+disableJournal = (len(config['disableJournal']) != 0)
 
 TEST_TMP_DIR = os.path.join (os.environ["HOME"], "tracker-tests")
 
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index d085e26..8667347 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -78,9 +78,7 @@ class Helper:
         sys.excepthook = new_hook
 
     def _start_process (self):
-        path = getattr (self,
-                        "PROCESS_PATH",
-                        os.path.join (cfg.EXEC_PREFIX, self.PROCESS_NAME))
+        path = self.PROCESS_PATH
         flags = getattr (self,
                          "FLAGS",
                          [])
@@ -212,6 +210,7 @@ class StoreHelper (Helper):
     """
 
     PROCESS_NAME = "tracker-store"
+    PROCESS_PATH = cfg.TRACKER_STORE_PATH
     BUS_NAME = cfg.TRACKER_BUSNAME
 
     graph_updated_handler_id = 0
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index bf8433d..b61c482 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -19,9 +19,7 @@ import helpers
 TEST_ENV_DIRS =  { "XDG_DATA_HOME" : os.path.join (cfg.TEST_TMP_DIR, "data"),
                    "XDG_CACHE_HOME": os.path.join (cfg.TEST_TMP_DIR, "cache")}
 
-TEST_ENV_VARS = {  "LC_COLLATE": "en_GB.utf8",
-                   "DCONF_PROFILE": os.path.join (cfg.DATADIR, "tracker-tests",
-                                                  "trackertest") }
+TEST_ENV_VARS = {  "LC_COLLATE": "en_GB.utf8" }
 
 EXTRA_DIRS = [os.path.join (cfg.TEST_TMP_DIR, "data", "tracker"),
               os.path.join (cfg.TEST_TMP_DIR, "cache", "tracker")]
diff --git a/tests/functional-tests/configuration.json.in b/tests/functional-tests/configuration.json.in
new file mode 100644
index 0000000..06a5be1
--- /dev/null
+++ b/tests/functional-tests/configuration.json.in
@@ -0,0 +1,8 @@
+{
+    "PREFIX": "@prefix@",
+    "RAW_EXEC_PREFIX": "@exec_prefix@",
+    "RAW_DATAROOT_DIR": "@datarootdir@",
+    "TEST_ONTOLOGIES_DIR": "@FUNCTIONAL_TESTS_ONTOLOGIES_DIR@",
+    "TRACKER_STORE_PATH": "@FUNCTIONAL_TESTS_TRACKER_STORE_PATH@",
+    "disableJournal": "@DISABLE_JOURNAL_TRUE@"
+}
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index 8261e14..b37fbd0 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -23,9 +23,23 @@ functional_tests = [
   '200-backup-restore',
 ]
 
+config_json = configure_file(
+  input: 'configuration.json.in',
+  output: 'configuration.json',
+  configuration: conf
+)
+
+dconf_profile_full_path = join_paths(meson.current_source_dir(), 'trackertest')
+config_json_full_path = join_paths(meson.current_build_dir(), 'configuration.json')
+
+test_env = environment()
+test_env.set('DCONF_PROFILE', dconf_profile_full_path)
+test_env.set('TRACKER_FUNCTIONAL_TEST_CONFIG', config_json_full_path)
+
 foreach t: functional_tests
   test('functional-' + t, test_runner,
     args: './' + t + '.py',
+    env: test_env,
     workdir: meson.current_source_dir(),
     # FIXME: these tests are all too slow
     timeout: 180)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]