[glib-networking/wip/laney/fix-tls-installed-tests] tls/tests: Fix to work as installed tests



commit 88754760531f6ca663e368406c159c4ed8cca315
Author: Iain Lane <iainl gnome org>
Date:   Fri Dec 20 10:35:11 2019 +0000

    tls/tests: Fix to work as installed tests
    
    The `mock-pkcs11.so` module wasn't being installed so the tests couldn't
    find it - similarly for the dummy certificates used by the testsuite.
    
    We need to use `g_test_build_filename` to find files, so that they can
    be found at build and installed test time.

 tls/tests/certificate.c |  4 +++-
 tls/tests/connection.c  |  3 ++-
 tls/tests/meson.build   | 12 ++++++++++--
 tls/tests/mock-pkcs11.c | 10 +++++-----
 4 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/tls/tests/certificate.c b/tls/tests/certificate.c
index f6ec4af..24da260 100644
--- a/tls/tests/certificate.c
+++ b/tls/tests/certificate.c
@@ -593,7 +593,9 @@ main (int   argc,
   g_assert (g_ascii_strcasecmp (G_OBJECT_TYPE_NAME (g_tls_backend_get_default ()), "GTlsBackend" BACKEND) == 
0);
 
 #ifdef BACKEND_IS_GNUTLS
-  module_path = g_build_filename (g_getenv ("G_TEST_BUILDDIR"), "mock-pkcs11.so", NULL);
+  module_path = g_test_build_filename (G_TEST_BUILT, "mock-pkcs11.so", NULL);
+  g_assert_true (g_file_test (module_path, G_FILE_TEST_EXISTS));
+
   g_assert (gnutls_pkcs11_init (GNUTLS_PKCS11_FLAG_MANUAL, NULL) == GNUTLS_E_SUCCESS);
   g_assert (gnutls_pkcs11_add_provider (module_path, NULL) == GNUTLS_E_SUCCESS);
   g_free (module_path);
diff --git a/tls/tests/connection.c b/tls/tests/connection.c
index 76c7fc0..6bb4585 100644
--- a/tls/tests/connection.c
+++ b/tls/tests/connection.c
@@ -2548,7 +2548,8 @@ main (int   argc,
   g_assert_true (g_ascii_strcasecmp (G_OBJECT_TYPE_NAME (g_tls_backend_get_default ()), "GTlsBackend" 
BACKEND) == 0);
 
 #ifdef BACKEND_IS_GNUTLS
-  module_path = g_build_filename (g_getenv ("G_TEST_BUILDDIR"), "mock-pkcs11.so", NULL);
+  module_path = g_test_build_filename (G_TEST_BUILT, "mock-pkcs11.so", NULL);
+  g_assert_true (g_file_test (module_path, G_FILE_TEST_EXISTS));
 
   /* This just adds extra logging which is useful for debugging */
   spy_path = g_getenv ("PKCS11SPY_PATH");
diff --git a/tls/tests/meson.build b/tls/tests/meson.build
index ac5d88a..e35875e 100644
--- a/tls/tests/meson.build
+++ b/tls/tests/meson.build
@@ -29,12 +29,18 @@ if backends.contains('gnutls')
     dependencies: [
       gio_dep,
       gnutls_dep,
-    ]
+    ],
+    install: enable_installed_tests,
+    install_dir: installed_tests_execdir
   )
 else
   mock_pkcs11_module = []
 endif
 
+if enable_installed_tests
+  install_subdir('files', install_dir: installed_tests_execdir)
+endif
+
 test_programs = [
   ['certificate', [], deps, [], [mock_pkcs11_module]],
   ['file-database', [], deps, [], []],
@@ -85,7 +91,9 @@ foreach backend: backends
     )
 
     test_envs = envs + [
-      'GIO_MODULE_DIR=' + join_paths(meson.build_root(), 'tls', backend)
+      'GIO_MODULE_DIR=' + join_paths(meson.build_root(), 'tls', backend),
+      'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
+      'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir())
     ]
 
     # FIXME: OpenSSL tests are disabled until we fix https://gitlab.gnome.org/GNOME/glib-networking/issues/54
diff --git a/tls/tests/mock-pkcs11.c b/tls/tests/mock-pkcs11.c
index 706986e..a1a5a53 100644
--- a/tls/tests/mock-pkcs11.c
+++ b/tls/tests/mock-pkcs11.c
@@ -283,7 +283,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs)
         IGNORE(pInitArgs);
 
         // client.pem
-        path = g_build_filename(g_getenv("G_TEST_SRCDIR"), "files", "client.pem", NULL);
+        path = g_test_build_filename(G_TEST_DIST, "files", "client.pem", NULL);
         status = gnutls_load_file(path, &data);
         g_debug("Loading %s - %s", path, gnutls_strerror(status));
         g_assert(status == GNUTLS_E_SUCCESS);
@@ -298,7 +298,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs)
         g_free(path);
 
         // client-key.pem
-        path = g_build_filename(g_getenv("G_TEST_SRCDIR"), "files", "client-key.pem", NULL);
+        path = g_test_build_filename(G_TEST_DIST, "files", "client-key.pem", NULL);
         status = gnutls_load_file(path, &data);
         g_debug("Loading %s - %s", path, gnutls_strerror(status));
         g_assert(status == GNUTLS_E_SUCCESS);
@@ -313,7 +313,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs)
         g_free(path);
 
         // client2-key.pem
-        path = g_build_filename(g_getenv("G_TEST_SRCDIR"), "files", "client2-key.pem", NULL);
+        path = g_test_build_filename(G_TEST_DIST, "files", "client2-key.pem", NULL);
         status = gnutls_load_file(path, &data);
         g_debug("Loading %s - %s", path, gnutls_strerror(status));
         g_assert(status == GNUTLS_E_SUCCESS);
@@ -328,7 +328,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(CK_VOID_PTR pInitArgs)
         g_free(path);
 
         // client2.pem
-        path = g_build_filename(g_getenv("G_TEST_SRCDIR"), "files", "client2.pem", NULL);
+        path = g_test_build_filename(G_TEST_DIST, "files", "client2.pem", NULL);
         status = gnutls_load_file(path, &data);
         g_debug("Loading %s - %s", path, gnutls_strerror(status));
         g_assert(status == GNUTLS_E_SUCCESS);
@@ -3048,4 +3048,4 @@ CK_DEFINE_FUNCTION(CK_RV, C_InteractiveLogin)(CK_SESSION_HANDLE hSession)
         }
 
         return rv;
-}
\ No newline at end of file
+}


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