build/tests: Automatically set ASAN_OPTIONS if preloading is required

If preloading a library is required asan doesn't work properly because
it requires to be the first loaded library to test everything, however
the behavior can be worked around using an ASAN_OPTIONS variable, so do
this to prevent the tests to fail completely

But instead of having to do it at test level, manage this at wider scope
This commit is contained in:
Marco Trevisan (Treviño) 2024-05-09 21:12:17 +02:00
parent c1027d7c22
commit acb1ee406e
5 changed files with 86 additions and 21 deletions

View File

@ -313,11 +313,6 @@ if host_machine.system() != 'windows'
}
if have_rtld_next and glib_build_shared
asan_env = {}
if 'address' in glib_sanitizers
asan_env = {'ASAN_OPTIONS': 'verify_asan_link_order=0'}
endif
slow_connect_preload_lib = shared_library('slow-connect-preload',
'slow-connect-preload.c',
name_prefix : '',
@ -332,11 +327,11 @@ if host_machine.system() != 'windows'
'depends' : slow_connect_preload_lib,
'env' : {
glib_exec_var_preload: slow_connect_preload_lib.full_path(),
} + asan_env,
},
'installed_tests_env' : {
} + asan_env,
glib_exec_var_preload: installed_tests_execdir /
fs.name(slow_connect_preload_lib.full_path()),
},
},
}
endif
@ -1114,6 +1109,15 @@ foreach test_name, extra_args : gio_tests
test_conf.set('program', test_name)
test_env_override = ''
if installed_tests_env != {}
if installed_tests_env.has_key(glib_exec_var_preload)
installed_tests_env += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
installed_tests_env.get('ASAN_OPTIONS', ''),
]),
}
endif
envs = []
foreach var, value : installed_tests_env
envs += '@0@=\'@1@\''.format(var, value)
@ -1149,7 +1153,17 @@ foreach test_name, extra_args : gio_tests
depends += test_extra_programs_targets[program]
endforeach
foreach var, value : extra_args.get('env', {})
local_test_env_args = extra_args.get('env', {})
if local_test_env_args.has_key(glib_exec_var_preload)
local_test_env_args += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
local_test_env_args.get('ASAN_OPTIONS', ''),
]),
}
endif
foreach var, value : local_test_env_args
local_test_env.append(var, value)
endforeach

View File

@ -21,7 +21,7 @@ gi_gen_env_variables = environment()
if 'address' in glib_sanitizers
gi_gen_env_variables.append(
'ASAN_OPTIONS', 'verify_asan_link_order=0', separator: ',')
'ASAN_OPTIONS', glib_exec_asan_option_ignore_preload, separator: ',')
endif
if host_system == 'windows'

View File

@ -105,6 +105,15 @@ foreach test_name, extra_args : girepository_tests
test_conf.set('program', test_name)
test_env_override = ''
if installed_tests_env != {}
if installed_tests_env.has_key(glib_exec_var_preload)
installed_tests_env += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
installed_tests_env.get('ASAN_OPTIONS', ''),
]),
}
endif
envs = []
foreach var, value : installed_tests_env
envs += '@0@=\'@1@\''.format(var, value)
@ -147,7 +156,17 @@ foreach test_name, extra_args : girepository_tests
endforeach
local_test_env = test_env
foreach var, value : extra_args.get('env', {})
local_test_env_args = extra_args.get('env', {})
if local_test_env_args.has_key(glib_exec_var_preload)
local_test_env_args += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
local_test_env_args.get('ASAN_OPTIONS', ''),
]),
}
endif
foreach var, value : local_test_env_args
local_test_env.append(var, value)
endforeach

View File

@ -266,20 +266,15 @@ else
install_tag : 'tests',
install: installed_tests_enabled)
asan_env = {}
if 'address' in glib_sanitizers
asan_env = {'ASAN_OPTIONS': 'verify_asan_link_order=0'}
endif
glib_tests += {
'gutils-user-database' : {
'depends' : getpwuid_preload,
'env' : {
glib_exec_var_preload: getpwuid_preload.full_path()
} + asan_env,
glib_exec_var_preload: getpwuid_preload.full_path(),
},
'installed_tests_env' : {
glib_exec_var_preload: installed_tests_execdir / fs.name(getpwuid_preload.full_path())
} + asan_env,
},
},
}
endif
@ -426,6 +421,15 @@ foreach test_name, extra_args : glib_tests
test_conf.set('program', test_name)
test_env_override = ''
if installed_tests_env != {}
if installed_tests_env.has_key(glib_exec_var_preload)
installed_tests_env += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
installed_tests_env.get('ASAN_OPTIONS', ''),
]),
}
endif
envs = []
foreach var, value : installed_tests_env
envs += '@0@=\'@1@\''.format(var, value)
@ -467,10 +471,20 @@ foreach test_name, extra_args : glib_tests
endforeach
local_test_env = test_env
foreach var, value : extra_args.get('env', {})
local_test_env_args = extra_args.get('env', {})
if local_test_env_args.has_key(glib_exec_var_preload)
local_test_env_args += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
local_test_env_args.get('ASAN_OPTIONS', ''),
]),
}
endif
foreach var, value : local_test_env_args
local_test_env.append(var, value)
endforeach
test(test_name, exe,
args: extra_args.get('args', []),
protocol : extra_args.get('protocol', test_protocol),
@ -515,7 +529,17 @@ foreach test_name, extra_args : python_tests
endif
local_test_env = test_env
foreach var, value : extra_args.get('env', {})
local_test_env_args = extra_args.get('env', {})
if local_test_env_args.has_key(glib_exec_var_preload)
local_test_env_args += {
'ASAN_OPTIONS': ','.join([
glib_exec_asan_option_ignore_preload,
local_test_env_args.get('ASAN_OPTIONS', ''),
]),
}
endif
foreach var, value : local_test_env_args
local_test_env.append(var, value)
endforeach

View File

@ -2677,6 +2677,14 @@ else
glib_exec_var_preload_separator = ' '
endif
glib_exec_asan_option_ignore_preload = ''
if 'address' in glib_sanitizers
# libasan needs to be the first in the preload list, and that we cant
# guarantee that, so we have to disable its link order checking when using
# LD_PRELOAD in tests.
glib_exec_asan_option_ignore_preload = 'verify_asan_link_order=false'
endif
pkg = import('pkgconfig')
windows = import('windows')
gnome = import('gnome')