[tracker/wip/sam/meson-functional-tests: 60/60] functional-tests: Fix configuration to work with Meson



commit 636268f8b0fd2a454fdc57b2d050aa4be0242384
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
    anything. The Autotools `make functional-test` target works the same as
    before.
    
    Instead of generating a Python source file that contains the build-time
    configuration, we write that to a .json file which is read when the
    common.utils.configuration module is imported. This controls the
    locations of the various things that the tests require, which allows us
    to support any kind fo build tree layout.
    
    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 implemented.

 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}      |   38 +++++++++----------
 tests/functional-tests/common/utils/helpers.py     |    5 +--
 tests/functional-tests/common/utils/system.py      |    4 +--
 tests/functional-tests/configuration.json.in       |    7 ++++
 tests/functional-tests/ipc/meson.build             |   30 ++++++++++-----
 tests/functional-tests/meson.build                 |   15 +++++---
 12 files changed, 82 insertions(+), 54 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..2e6e064 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'))
+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 b32b781..2f989d5 100644
--- a/tests/functional-tests/common/utils/Makefile.am
+++ b/tests/functional-tests/common/utils/Makefile.am
@@ -10,6 +10,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 74%
rename from tests/functional-tests/common/utils/configuration.py.in
rename to tests/functional-tests/common/utils/configuration.py
index bc4b114..1cb961c 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"
@@ -49,37 +58,26 @@ WRITEBACK_BUSNAME = "org.freedesktop.Tracker1.Writeback"
 
 DCONF_MINER_SCHEMA = "org.freedesktop.Tracker.Miner.Files"
 
+# Autoconf substitutes paths in the configuration.json file without
+# expanding variables, so we need to manually insert these.
 def expandvars (variable):
     # Note: the order matters!
     result = variable
-    for var, value in [("${datarootdir}", RAW_DATAROOT_DIR),
-                       ("${exec_prefix}", RAW_EXEC_PREFIX),
+    for var, value in [("${exec_prefix}", RAW_EXEC_PREFIX),
                        ("${prefix}", PREFIX)]:
         result = result.replace (var, value)
 
-
     return result
 
 
+PREFIX = config['PREFIX']
+RAW_EXEC_PREFIX = config['RAW_EXEC_PREFIX']
 
-PREFIX = "@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@"
+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 66debbd..b9c652f 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..c1e7c39
--- /dev/null
+++ b/tests/functional-tests/configuration.json.in
@@ -0,0 +1,7 @@
+{
+    "PREFIX": "@prefix@",
+    "RAW_EXEC_PREFIX": "@exec_prefix@",
+    "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/ipc/meson.build b/tests/functional-tests/ipc/meson.build
index c458ac8..5b88160 100644
--- a/tests/functional-tests/ipc/meson.build
+++ b/tests/functional-tests/ipc/meson.build
@@ -1,53 +1,63 @@
 insert_or_replace_test = executable('test-insert-or-replace',
   'test-insert-or-replace.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-insert-or-replace', insert_or_replace_test)
+test('functional-ipc-insert-or-replace', insert_or_replace_test,
+  env: test_env)
 
 busy_handling_test = executable('test-busy-handling',
   'test-busy-handling.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-busy-handling', busy_handling_test)
+test('functional-ipc-busy-handling', busy_handling_test,
+  env: test_env)
 
 direct_query_test = executable('test-direct-query',
   'test-direct-query.vala',
   'test-shared-query.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-direct-query', direct_query_test)
+test('functional-ipc-direct-query', direct_query_test,
+  env: test_env)
 
 bus_query_test = executable('test-bus-query',
   'test-bus-query.vala',
   'test-shared-query.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep, tracker_sparql_bus_dep])
-test('functional-ipc-bus-query', bus_query_test)
+test('functional-ipc-bus-query', bus_query_test,
+  env: test_env)
 
 default_update_test = executable('test-default-update',
   'test-default-update.vala',
   'test-shared-update.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-default-update', default_update_test)
+test('functional-ipc-default-update', default_update_test,
+  env: test_env)
 
 bus_update_test = executable('test-bus-update',
   'test-bus-update.vala',
   'test-shared-update.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep, tracker_sparql_bus_dep])
-test('functional-ipc-bus-update', bus_update_test)
+test('functional-ipc-bus-update', bus_update_test,
+  env: test_env)
 
 class_signal_test = executable('test-class-signal',
   'test-class-signal.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-class-signal', class_signal_test)
+test('functional-ipc-class-signal', class_signal_test,
+  env: test_env)
 
 class_signal_performance_test = executable('test-class-signal-performance',
   'test-class-signal-performance.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-class-signal-performance', class_signal_performance_test)
+test('functional-ipc-class-signal-performance', class_signal_performance_test,
+  env: test_env)
 
 class_signal_performance_batch_test = executable('test-class-signal-performance-batch',
   'test-class-signal-performance-batch.vala',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-class-signal-performance-batch', class_signal_performance_batch_test)
+test('functional-ipc-class-signal-performance-batch', class_signal_performance_batch_test,
+  env: test_env)
 
 update_array_performance_test = executable('test-update-array-performance',
   'test-update-array-performance.c',
   dependencies: [tracker_common_dep, tracker_sparql_dep])
-test('functional-ipc-update-array-performance', update_array_performance_test)
+test('functional-ipc-update-array-performance', update_array_performance_test,
+  env: test_env)
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index 7998f73..57de81f 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -1,5 +1,3 @@
-subdir('ipc')
-
 test_runner = find_program('test-runner.sh')
 
 config_json = configure_file(
@@ -33,15 +31,18 @@ functional_tests_with_test_data = [
   '13-threaded-store',
 ]
 
-tracker_top_build_dir = join_paths(meson.current_build_dir(), '..', '..')
-
-dconf_profile_full_path = join_paths(meson.current_source_dir(), 'trackertest')
 config_json_full_path = join_paths(meson.current_build_dir(), 'configuration.json')
+dconf_profile_full_path = join_paths(meson.current_source_dir(), 'trackertest')
+tracker_nepomuk_ontologies = join_paths(meson.current_source_dir(), '..', '..', 'src', 'ontologies', 
'nepomuk')
+tracker_stop_words_dir = join_paths(meson.current_source_dir(), '..', '..', 'src', 'libtracker-common', 
'stop-words')
+tracker_test_domain_ontology = join_paths(meson.current_source_dir(), '..', '..', 'src', 'tracker-store', 
'default.rule')
 
 test_env = environment()
 test_env.set('DCONF_PROFILE', dconf_profile_full_path)
-test_env.set('TRACKER_FUNCTIONAL_TEST_CONFIG', config_json_full_path)
+
 test_env.set('TRACKER_DB_ONTOLOGIES_DIR', tracker_nepomuk_ontologies)
+test_env.set('TRACKER_FUNCTIONAL_TEST_CONFIG', config_json_full_path)
+test_env.set('TRACKER_LANGUAGE_STOP_WORDS_DIR', tracker_stop_words_dir)
 test_env.set('TRACKER_TEST_DOMAIN_ONTOLOGY_RULE', tracker_test_domain_ontology)
 
 foreach t: functional_tests + functional_tests_with_test_data
@@ -52,3 +53,5 @@ foreach t: functional_tests + functional_tests_with_test_data
     # FIXME: these tests are all too slow
     timeout: 180)
 endforeach
+
+subdir('ipc')


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