Newer
Older
* Copyright © 2019-2023 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <steam-runtime-tools/steam-runtime-tools.h>
#include "steam-runtime-tools/utils-internal.h"
#include <steam-runtime-tools/glib-backports-internal.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <ftw.h>
#include "graphics-test-defines.h"
#include "fake-home.h"
#if defined(__i386__) || defined(__x86_64__)
static const char * const multiarch_tuples[] = { SRT_ABI_I386, SRT_ABI_X86_64 };
#elif defined(_SRT_MULTIARCH)
static const char * const multiarch_tuples[] = { _SRT_MULTIARCH };
#else
#warning Unknown architecture, assuming x86
static const char * const multiarch_tuples[] = { SRT_ABI_I386, SRT_ABI_X86_64 };
#endif
static gchar *fake_home_path;
static gchar *global_sysroots;
typedef struct
{
gchar *srcdir;
gchar *builddir;
const gchar *sysroots;
} Fixture;
typedef struct
{
int unused;
} Config;
static void
setup (Fixture *f,
gconstpointer context)
{
G_GNUC_UNUSED const Config *config = context;
f->srcdir = g_strdup (g_getenv ("G_TEST_SRCDIR"));
f->builddir = g_strdup (g_getenv ("G_TEST_BUILDDIR"));
if (f->srcdir == NULL)
f->srcdir = g_path_get_dirname (argv0);
if (f->builddir == NULL)
f->builddir = g_path_get_dirname (argv0);
f->sysroots = global_sysroots;
}
static void
teardown (Fixture *f,
gconstpointer context)
{
G_GNUC_UNUSED const Config *config = context;
g_free (f->srcdir);
g_free (f->builddir);
/* We expect that fake_home already cleaned this up, but just to be sure we
* do it too */
_srt_rm_rf (fake_home_path);
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
}
/*
* Test basic functionality of the SrtSystemInfo object.
*/
static void
test_object (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
gchar *expectations_in = NULL;
gchar *expectations = NULL;
int fd;
info = srt_system_info_new (NULL);
g_assert_nonnull (info);
g_object_get (info,
"expectations", &expectations,
NULL);
g_assert_cmpstr (expectations, ==, NULL);
/* We try it twice, to exercise the cached and non-cached cases */
#if defined(__x86_64__) && defined(__LP64__)
g_assert_true (srt_system_info_can_run (info, SRT_ABI_X86_64));
g_assert_true (srt_system_info_can_run (info, SRT_ABI_X86_64));
#endif
#if defined(__i386__)
g_assert_true (srt_system_info_can_run (info, SRT_ABI_I386));
g_assert_true (srt_system_info_can_run (info, SRT_ABI_I386));
#endif
g_assert_false (srt_system_info_can_run (info, "hal9000-linux-gnu"));
g_assert_false (srt_system_info_can_run (info, "hal9000-linux-gnu"));
/* This is a little bit tautologous - we're using the same check
* that the production code does. */
fd = open ("/dev/uinput", O_WRONLY | O_NONBLOCK);
if (fd >= 0)
{
g_assert_true (srt_system_info_can_write_to_uinput (info));
g_assert_true (srt_system_info_can_write_to_uinput (info));
close (fd);
}
else
{
g_assert_false (srt_system_info_can_write_to_uinput (info));
g_assert_false (srt_system_info_can_write_to_uinput (info));
}
g_object_unref (info);
expectations_in = g_build_filename (f->srcdir, "expectations", NULL);
info = srt_system_info_new (expectations_in);
g_assert_nonnull (info);
g_object_get (info,
"expectations", &expectations,
NULL);
g_assert_cmpstr (expectations, ==, expectations_in);
g_free (expectations_in);
g_free (expectations);
g_object_unref (info);
info = srt_system_info_new (NULL);
g_assert_nonnull (info);
srt_system_info_set_helpers_path (info, f->builddir);
g_assert_true (srt_system_info_can_run (info, "mock"));
/* The real helpers are not present here */
g_assert_false (srt_system_info_can_run (info, SRT_ABI_I386));
g_assert_false (srt_system_info_can_run (info, SRT_ABI_X86_64));
g_object_unref (info);
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
static void
test_libdl (Fixture *f,
gconstpointer context)
{
g_autoptr(SrtSystemInfo) info = NULL;
g_autofree gchar *libdl = NULL;
g_autoptr(GError) error = NULL;
info = srt_system_info_new (NULL);
g_assert_nonnull (info);
srt_system_info_set_helpers_path (info, f->builddir);
libdl = srt_system_info_dup_libdl_lib (info, "mock-good", &error);
g_assert_cmpstr (libdl, ==, "lib");
g_assert_no_error (error);
g_free (libdl);
/* Test cache */
libdl = srt_system_info_dup_libdl_lib (info, "mock-good", &error);
g_assert_cmpstr (libdl, ==, "lib");
g_assert_no_error (error);
g_free (libdl);
libdl = srt_system_info_dup_libdl_platform (info, "mock-good", &error);
g_assert_cmpstr (libdl, ==, "x86_64");
g_assert_no_error (error);
g_free (libdl);
/* Test cache */
libdl = srt_system_info_dup_libdl_platform (info, "mock-good", &error);
g_assert_cmpstr (libdl, ==, "x86_64");
g_assert_no_error (error);
g_free (libdl);
libdl = srt_system_info_dup_libdl_lib (info, "mock-bad", &error);
g_assert_cmpstr (libdl, ==, NULL);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
g_assert_cmpstr (error->message, ==, "Unable to find the library: "
"${ORIGIN}/i386-linux-gnu/${PLATFORM}/libidentify-lib.so: "
"cannot open shared object file: No such file or directory\n");
g_clear_error (&error);
libdl = srt_system_info_dup_libdl_platform (info, "mock-bad", &error);
g_assert_cmpstr (libdl, ==, NULL);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
g_assert_cmpstr (error->message, ==, "Unable to find the library: "
"${ORIGIN}/i386-linux-gnu/${PLATFORM}/libidentify-platform.so: "
"cannot open shared object file: No such file or directory\n");
}
static void
check_libraries_result (GList *libraries)
{
SrtLibrary *library = NULL;
const char * const *missing_symbols;
const char * const *misversioned_symbols;
const char * const *dependencies;
gboolean seen_libc;
GList *l;
g_assert_nonnull (libraries);
l = libraries;
/* Test first library. Alphabetical order is an API guarantee, so we know
* which one it should be. */
library = l->data;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libgio-2.0.so.0");
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
g_assert_cmpint (srt_library_get_issues (library), ==, SRT_LIBRARY_ISSUES_NONE);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
seen_libc = FALSE;
for (gsize i = 0; dependencies[i] != NULL; i++)
{
g_debug ("libgio-2.0.so.0 depends on %s", dependencies[i]);
if (strstr (dependencies[i], "/libc.so.") != NULL)
seen_libc = TRUE;
}
g_assert_true (seen_libc);
/* Test second library */
l = g_list_next (l);
library = l->data;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libglib-2.0.so.0");
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
g_assert_cmpint (srt_library_get_issues (library), ==, SRT_LIBRARY_ISSUES_NONE);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
seen_libc = FALSE;
for (gsize i = 0; dependencies[i] != NULL; i++)
{
g_debug ("libglib-2.0.so.0 depends on %s", dependencies[i]);
if (strstr (dependencies[i], "/libc.so.") != NULL)
seen_libc = TRUE;
}
g_assert_true (seen_libc);
/* Test third library */
l = g_list_next (l);
library = l->data;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libtheoraenc.so.1");
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
g_assert_cmpint (srt_library_get_issues (library), ==, SRT_LIBRARY_ISSUES_NONE);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
seen_libc = FALSE;
for (gsize i = 0; dependencies[i] != NULL; i++)
{
g_debug ("libtheoraenc.so.1 depends on %s", dependencies[i]);
if (strstr (dependencies[i], "/libc.so.") != NULL)
seen_libc = TRUE;
}
g_assert_true (seen_libc);
/* Test last library */
l = g_list_next (l);
library = l->data;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libz.so.1");
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
g_assert_cmpint (srt_library_get_issues (library), ==, SRT_LIBRARY_ISSUES_NONE);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
seen_libc = FALSE;
for (gsize i = 0; dependencies[i] != NULL; i++)
{
g_debug ("libz.so.1 depends on %s", dependencies[i]);
if (strstr (dependencies[i], "/libc.so.") != NULL)
seen_libc = TRUE;
}
g_assert_true (seen_libc);
g_assert_null (g_list_next (l));
}
/*
* Test if the expected libraries are available in the
* running system.
*/
static void
libraries_presence (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
gchar *expectations_in = NULL;
GList *libraries = NULL;
SrtLibraryIssues issues;
const char *multiarch_tuple = NULL;
#ifndef _SRT_MULTIARCH
g_test_skip ("Unsupported architecture");
return;
#else
multiarch_tuple = _SRT_MULTIARCH;
#endif
expectations_in = g_build_filename (f->srcdir, "expectations", NULL);
info = srt_system_info_new (expectations_in);
issues = srt_system_info_check_libraries (info,
multiarch_tuple,
&libraries);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_NONE);
check_libraries_result (libraries);
g_list_free_full (libraries, g_object_unref);
libraries = NULL;
/* Do the check again, this time using the cache */
issues = srt_system_info_check_libraries (info,
multiarch_tuple,
&libraries);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_NONE);
check_libraries_result (libraries);
g_list_free_full (libraries, g_object_unref);
g_free (expectations_in);
g_object_unref (info);
}
/*
* Check that the expectations can be auto-detected from the
* `STEAM_RUNTIME` environment variable.
*/
static void
auto_expectations (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
gchar *steam_runtime = NULL;
GList *libraries = NULL;
SrtLibraryIssues issues;
gchar **env;
const char *multiarch_tuple = NULL;
#ifndef _SRT_MULTIARCH
g_test_skip ("Unsupported architecture");
return;
#else
multiarch_tuple = _SRT_MULTIARCH;
#endif
env = g_get_environ ();
steam_runtime = g_build_filename (f->sysroots, "fake-steam-runtime", NULL);
env = g_environ_setenv (env, "STEAM_RUNTIME", steam_runtime, TRUE);
info = srt_system_info_new (NULL);
srt_system_info_set_environ (info, env);
issues = srt_system_info_check_libraries (info,
multiarch_tuple,
&libraries);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_NONE);
check_libraries_result (libraries);
g_list_free_full (libraries, g_object_unref);
g_object_unref (info);
g_strfreev (env);
g_free (steam_runtime);
}
static void
check_library_result (SrtLibrary *library)
{
const char * const *missing_symbols;
const char * const *misversioned_symbols;
const char * const *dependencies;
gboolean seen_libc;
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libz.so.1");
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
seen_libc = FALSE;
for (gsize i = 0; dependencies[i] != NULL; i++)
{
g_debug ("libz.so.1 depends on %s", dependencies[i]);
if (strstr (dependencies[i], "/libc.so.") != NULL)
seen_libc = TRUE;
}
g_assert_true (seen_libc);
}
/*
* Test if `libz.so.1` is available in the running system and
* if it has the expected symbols.
*/
static void
library_presence (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
gchar *expectations_in = NULL;
SrtLibrary *library = NULL;
SrtLibraryIssues issues;
const char *multiarch_tuple = NULL;
#ifndef _SRT_MULTIARCH
g_test_skip ("Unsupported architecture");
return;
#else
multiarch_tuple = _SRT_MULTIARCH;
#endif
expectations_in = g_build_filename (f->srcdir, "expectations", NULL);
info = srt_system_info_new (expectations_in);
issues = srt_system_info_check_library (info,
multiarch_tuple,
"libz.so.1",
&library);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_NONE);
check_library_result (library);
g_clear_pointer (&library, g_object_unref);
/* Do the check again, this time using the cache */
issues = srt_system_info_check_library (info,
multiarch_tuple,
"libz.so.1",
&library);
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_NONE);
check_library_result (library);
g_object_unref (library);
g_free (expectations_in);
g_object_unref (info);
}
static void
check_library_libz_missing_sym_result (SrtLibrary *library)
{
const char * const *missing_symbols;
const char * const *misversioned_symbols;
const char * const *dependencies;
gboolean seen_libc;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libz.so.1");
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
g_debug ("path to libz.so.1 is %s", srt_library_get_absolute_path (library));
g_assert_true (srt_library_get_absolute_path (library)[0] == '/');
g_assert_true (g_file_test (srt_library_get_absolute_path (library), G_FILE_TEST_EXISTS));
g_assert_cmpint (srt_library_get_issues (library) & SRT_LIBRARY_ISSUES_MISSING_SYMBOLS, !=, 0);
g_assert_cmpint (srt_library_get_issues (library) & SRT_LIBRARY_ISSUES_MISVERSIONED_SYMBOLS, !=, 0);
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, "missing@NotAvailable");
g_assert_cmpstr (missing_symbols[1], ==, NULL);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, "crc32@WRONG_VERSION");
g_assert_cmpstr (misversioned_symbols[1], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
seen_libc = FALSE;
for (gsize i = 0; dependencies[i] != NULL; i++)
{
g_debug ("libz.so.1 depends on %s", dependencies[i]);
if (strstr (dependencies[i], "/libc.so.") != NULL)
seen_libc = TRUE;
}
g_assert_true (seen_libc);
}
static void
check_missing_libraries_result (GList *libraries)
{
SrtLibrary *library = NULL;
const char * const *missing_symbols;
const char * const *misversioned_symbols;
const char * const *dependencies;
GList *l;
g_assert_nonnull (libraries);
l = libraries;
/* Test first library. Alphabetical order is an API guarantee, so we know
* which one it should be. */
library = l->data;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libgio-MISSING-2.0.so.0");
g_assert_cmpstr (srt_library_get_absolute_path (library), ==, NULL);
g_assert_cmpint (srt_library_get_issues (library), ==, SRT_LIBRARY_ISSUES_CANNOT_LOAD);
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], ==, NULL);
/* Test second library */
l = g_list_next (l);
library = l->data;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libglib-2.0.so.0");
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
g_debug ("path to libglib-2.0.so.0 is %s", srt_library_get_absolute_path (library));
g_assert_true (srt_library_get_absolute_path (library)[0] == '/');
g_assert_true (g_file_test (srt_library_get_absolute_path (library), G_FILE_TEST_EXISTS));
g_assert_cmpint (srt_library_get_issues (library), ==, SRT_LIBRARY_ISSUES_NONE);
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], !=, NULL);
/* Test last library */
l = g_list_next (l);
library = l->data;
check_library_libz_missing_sym_result (library);
}
/*
* Test libraries that are either not available or with missing and
* misversioned symbols.
*/
static void
libraries_missing (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
gchar *expectations_in = NULL;
GList *libraries = NULL;
SrtLibraryIssues issues;
const char *multiarch_tuple = NULL;
#ifndef _SRT_MULTIARCH
g_test_skip ("Unsupported architecture");
return;
#else
multiarch_tuple = _SRT_MULTIARCH;
#endif
expectations_in = g_build_filename (f->srcdir, "expectations_with_missings", NULL);
info = srt_system_info_new (expectations_in);
issues = srt_system_info_check_libraries (info,
multiarch_tuple,
&libraries);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISSING_SYMBOLS, !=, 0);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_CANNOT_LOAD, !=, 0);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISVERSIONED_SYMBOLS, !=, 0);
check_missing_libraries_result (libraries);
g_list_free_full (libraries, g_object_unref);
libraries = NULL;
/* Do the check again, this time using the cache */
issues = srt_system_info_check_libraries (info,
multiarch_tuple,
&libraries);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISSING_SYMBOLS, !=, 0);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_CANNOT_LOAD, !=, 0);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISVERSIONED_SYMBOLS, !=, 0);
check_missing_libraries_result (libraries);
g_list_free_full (libraries, g_object_unref);
g_free (expectations_in);
g_object_unref (info);
}
static void
check_library_missing_lib_result (SrtLibrary *library)
{
const char * const *missing_symbols;
const char * const *misversioned_symbols;
const char * const *dependencies;
g_assert_nonnull (library);
g_assert_cmpstr (srt_library_get_requested_name (library), ==, "libMISSING.so.62");
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
g_assert_cmpstr (srt_library_get_absolute_path (library), ==, NULL);
missing_symbols = srt_library_get_missing_symbols (library);
g_assert_nonnull (missing_symbols);
g_assert_cmpstr (missing_symbols[0], ==, NULL);
misversioned_symbols = srt_library_get_misversioned_symbols (library);
g_assert_nonnull (misversioned_symbols);
g_assert_cmpstr (misversioned_symbols[0], ==, NULL);
dependencies = srt_library_get_dependencies (library);
g_assert_nonnull (dependencies);
g_assert_cmpstr (dependencies[0], ==, NULL);
}
/*
* Test `libz.so.1` expecting missing and misversioned symbols.
* Then test the missing library `libMISSING.so.62`.
*/
static void
library_missing (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
gchar *expectations_in = NULL;
SrtLibrary *library = NULL;
SrtLibraryIssues issues;
const char *multiarch_tuple = NULL;
#ifndef _SRT_MULTIARCH
g_test_skip ("Unsupported architecture");
return;
#else
multiarch_tuple = _SRT_MULTIARCH;
#endif
expectations_in = g_build_filename (f->srcdir, "expectations_with_missings", NULL);
info = srt_system_info_new (expectations_in);
/* Check a present library that has a missing symbol */
issues = srt_system_info_check_library (info,
multiarch_tuple,
"libz.so.1",
&library);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISSING_SYMBOLS, !=, 0);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISVERSIONED_SYMBOLS, !=, 0);
check_library_libz_missing_sym_result (library);
g_clear_pointer (&library, g_object_unref);
/* Do the check again, this time using the cache */
issues = srt_system_info_check_library (info,
multiarch_tuple,
"libz.so.1",
&library);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISSING_SYMBOLS, !=, 0);
g_assert_cmpint (issues & SRT_LIBRARY_ISSUES_MISVERSIONED_SYMBOLS, !=, 0);
check_library_libz_missing_sym_result (library);
g_clear_pointer (&library, g_object_unref);
/* Check for a library that isn't listed in any of the .symbols files */
issues = srt_system_info_check_library (info,
multiarch_tuple,
"libMISSING.so.62",
&library);
g_assert_cmpint (issues, ==,
(SRT_LIBRARY_ISSUES_CANNOT_LOAD |
SRT_LIBRARY_ISSUES_UNKNOWN_EXPECTATIONS));
check_library_missing_lib_result (library);
g_clear_pointer (&library, g_object_unref);
/* Do the check again, this time using the cache */
issues = srt_system_info_check_library (info,
multiarch_tuple,
"libMISSING.so.62",
&library);
g_assert_cmpint (issues, ==,
(SRT_LIBRARY_ISSUES_CANNOT_LOAD |
SRT_LIBRARY_ISSUES_UNKNOWN_EXPECTATIONS));
check_library_missing_lib_result (library);
g_object_unref (library);
g_free (expectations_in);
g_object_unref (info);
}
/*
* Test libraries with the expectations folder set to NULL.
*/
static void
wrong_expectations (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
SrtLibraryIssues issues;
const char *multiarch_tuple = NULL;
#ifndef _SRT_MULTIARCH
g_test_skip ("Unsupported architecture");
return;
#else
multiarch_tuple = _SRT_MULTIARCH;
#endif
/* Set the expectations folder to one that does not contain the
* necessary files. We expect the library checks to fail. */
info = srt_system_info_new ("/dev");
issues = srt_system_info_check_libraries (info,
multiarch_tuple,
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_UNKNOWN_EXPECTATIONS);
issues = srt_system_info_check_library (info,
multiarch_tuple,
g_assert_cmpint (issues, ==, SRT_LIBRARY_ISSUES_UNKNOWN_EXPECTATIONS);
g_object_unref (info);
}
static void
multiarch_tuples_handling (Fixture *f,
gconstpointer context)
{
GStrv tuples_list;
SrtSystemInfo *info;
const gchar *multiarches[] = {"foo8000", "bar9000", NULL};
info = srt_system_info_new (NULL);
tuples_list = srt_system_info_dup_multiarch_tuples (info);
g_assert_cmpstr (srt_system_info_get_primary_multiarch_tuple (info), ==, tuples_list[0]);
#ifndef _SRT_MULTIARCH
g_assert_cmpstr (tuples_list[0], ==, "UNKNOWN");
#else
g_assert_cmpstr (tuples_list[0], ==, _SRT_MULTIARCH);
#endif
g_assert_cmpstr (tuples_list[1], ==, NULL);
g_strfreev (tuples_list);
srt_system_info_set_multiarch_tuples (info, multiarches);
tuples_list = srt_system_info_dup_multiarch_tuples (info);
g_assert_cmpstr (tuples_list[0], ==, multiarches[0]);
g_assert_cmpstr (tuples_list[1], ==, multiarches[1]);
g_assert_cmpstr (tuples_list[2], ==, multiarches[2]);
g_assert_cmpstr (srt_system_info_get_primary_multiarch_tuple (info), ==, multiarches[0]);
g_object_unref (info);
g_strfreev (tuples_list);
}
/* The filesystem used to run tests is not under our control, and on
* Docker-based CI it will often be overlayfs. */
static const SrtRuntimeIssues ignore_runtime_issues = (SRT_RUNTIME_ISSUES_ON_NON_UNIX_FILESYSTEM
| SRT_RUNTIME_ISSUES_ON_NETWORK_FILESYSTEM
| SRT_RUNTIME_ISSUES_ON_UNKNOWN_FILESYSTEM);
static void
steam_runtime (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
SrtRuntimeIssues runtime_issues;
SrtSteamIssues steam_issues;
SrtSteam *steam_details;
gchar *runtime_path = NULL;
gchar *installation_path = NULL;
gchar *bin32_path = NULL;
FakeHome *fake_home;
fake_home = fake_home_new (fake_home_path);
fake_home_create_structure (fake_home);
info = srt_system_info_new (NULL);
fake_home_apply_to_system_info (fake_home, info);
/* Check for runtime issues */
runtime_issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (runtime_issues, ==, SRT_RUNTIME_ISSUES_NONE);
runtime_path = srt_system_info_dup_runtime_path (info);
g_assert_cmpstr (runtime_path, ==, fake_home->runtime);
installation_path = srt_system_info_dup_steam_installation_path (info);
g_assert_cmpstr (installation_path, ==, fake_home->steam_install);
bin32_path = srt_system_info_dup_steam_bin32_path (info);
g_assert_cmpstr (bin32_path, ==, fake_home->ubuntu12_32);
g_free (runtime_path);
g_free (installation_path);
g_free (bin32_path);
/* Do the check again, this time using the cache */
runtime_issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (runtime_issues, ==, SRT_RUNTIME_ISSUES_NONE);
runtime_path = srt_system_info_dup_runtime_path (info);
g_assert_cmpstr (runtime_path, ==, fake_home->runtime);
installation_path = srt_system_info_dup_steam_installation_path (info);
g_assert_cmpstr (installation_path, ==, fake_home->steam_install);
bin32_path = srt_system_info_dup_steam_bin32_path (info);
g_assert_cmpstr (bin32_path, ==, fake_home->ubuntu12_32);
/* Check for Steam issues */
steam_issues = srt_system_info_get_steam_issues (info);
g_assert_cmpint (steam_issues, ==, SRT_STEAM_ISSUES_NONE);
steam_details = srt_system_info_get_steam_details (info);
steam_issues = srt_steam_get_issues (steam_details);
g_assert_cmpint (steam_issues, ==, SRT_STEAM_ISSUES_NONE);
g_object_unref (steam_details);
/* Do the check again, this time using the cache */
steam_issues = srt_system_info_get_steam_issues (info);
g_assert_cmpint (steam_issues, ==, SRT_STEAM_ISSUES_NONE);
steam_details = srt_system_info_get_steam_details (info);
steam_issues = srt_steam_get_issues (steam_details);
g_assert_cmpint (steam_issues, ==, SRT_STEAM_ISSUES_NONE);
fake_home_clean_up (fake_home);
g_object_unref (info);
g_object_unref (steam_details);
g_free (runtime_path);
g_free (installation_path);
g_free (bin32_path);
}
static void
steam_runtime_missing (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
SrtRuntimeIssues runtime_issues;
SrtSteamIssues steam_issues;
gchar *full_ld_path = NULL;
FakeHome *fake_home;
fake_home = fake_home_new (fake_home_path);
fake_home_create_structure (fake_home);
full_ld_path = g_strdup (g_environ_getenv (fake_home->env, "LD_LIBRARY_PATH"));
info = srt_system_info_new (NULL);
/* Unset LD_LIBRARY_PATH */
fake_home->env = g_environ_unsetenv (fake_home->env, "LD_LIBRARY_PATH");
fake_home_apply_to_system_info (fake_home, info);
runtime_issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (runtime_issues, ==, SRT_RUNTIME_ISSUES_NOT_IN_LD_PATH);
/* Re set LD_LIBRARY_PATH and remove a required folder from the runtime */
fake_home->env = g_environ_setenv (fake_home->env, "LD_LIBRARY_PATH", full_ld_path, TRUE);
fake_home_apply_to_system_info (fake_home, info);
g_assert_cmpint (g_rmdir (fake_home->amd64_usr_lib_64), ==, 0);
runtime_issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (runtime_issues & SRT_RUNTIME_ISSUES_NOT_RUNTIME, !=, 0);
g_assert_cmpint (runtime_issues & SRT_RUNTIME_ISSUES_NOT_IN_LD_PATH, !=, 0);
steam_issues = srt_system_info_get_steam_issues (info);
g_assert_cmpint (steam_issues, ==, SRT_STEAM_ISSUES_NONE);
/* Do the check again, this time using the cache */
runtime_issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (runtime_issues & SRT_RUNTIME_ISSUES_NOT_RUNTIME, !=, 0);
g_assert_cmpint (runtime_issues & SRT_RUNTIME_ISSUES_NOT_IN_LD_PATH, !=, 0);
steam_issues = srt_system_info_get_steam_issues (info);
g_assert_cmpint (steam_issues, ==, SRT_STEAM_ISSUES_NONE);
fake_home_clean_up (fake_home);
g_object_unref (info);
g_free (full_ld_path);
}
static void
steam_runtime_pinned (Fixture *f,
gconstpointer context)
{
SrtSystemInfo *info;
SrtRuntimeIssues issues;
gchar *full_ld_path = NULL;
gchar *ld_path = NULL;
FakeHome *fake_home;
fake_home = fake_home_new (fake_home_path);
fake_home_create_structure (fake_home);
full_ld_path = g_strdup (g_environ_getenv (fake_home->env, "LD_LIBRARY_PATH"));
info = srt_system_info_new (NULL);
/* Move the pinned libraries at the end of LD_LIBRARY_PATH */
ld_path = g_strjoin (":",
fake_home->i386_lib_i386,
fake_home->i386_lib,
fake_home->i386_usr_lib_i386,
fake_home->i386_usr_lib,
fake_home->amd64_lib_64,
fake_home->amd64_lib,
fake_home->amd64_usr_lib_64,
fake_home->amd64_usr_lib,
fake_home->pinned_32,
fake_home->pinned_64,
NULL);
fake_home->env = g_environ_setenv (fake_home->env, "LD_LIBRARY_PATH", ld_path, TRUE);
fake_home_apply_to_system_info (fake_home, info);
issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (SRT_RUNTIME_ISSUES_NOT_USING_NEWER_HOST_LIBRARIES, ==, issues);
g_free (ld_path);
/* Remove the pinned library folder */
g_assert_cmpint (g_rmdir (fake_home->pinned_32), ==, 0);
g_assert_cmpint (g_rmdir (fake_home->pinned_64), ==, 0);
fake_home->env = g_environ_setenv (fake_home->env, "LD_LIBRARY_PATH", full_ld_path, TRUE);
fake_home_apply_to_system_info (fake_home, info);
issues = srt_system_info_get_runtime_issues (info) & ~ignore_runtime_issues;
g_assert_cmpint (SRT_RUNTIME_ISSUES_NOT_USING_NEWER_HOST_LIBRARIES, ==, issues);
/* Remove pinned libraries from LD_LIBRARY_PATH */