2025-03-20 08:08:33 +01:00
|
|
|
mock_conf = configuration_data()
|
|
|
|
|
|
|
|
mock_conf.set(
|
|
|
|
'HAVE_GLIBC_IOCTL',
|
|
|
|
cc.compiles(
|
|
|
|
'''#include <sys/ioctl.h>
|
|
|
|
int ioctl(int fd, unsigned long request, ...);
|
|
|
|
''',
|
|
|
|
name: 'ioctl has glibc-style prototype'
|
|
|
|
),
|
|
|
|
description: 'Is ioctl the glibc interface (rather than POSIX)'
|
|
|
|
)
|
|
|
|
|
2025-02-16 10:12:19 +01:00
|
|
|
mock_ioctl = library(
|
|
|
|
'mock-ioctl',
|
|
|
|
['mock.c', 'util.c'],
|
2025-03-20 08:08:33 +01:00
|
|
|
dependencies: [dl_dep],
|
|
|
|
c_args: ['-DHAVE_GLIBC_IOCTL=' + (mock_conf.get('HAVE_GLIBC_IOCTL') ? '1' : '0')])
|
2025-02-16 10:12:19 +01:00
|
|
|
|
2025-02-16 10:16:49 +01:00
|
|
|
# Add mock-ioctl to the LD_PRELOAD path so it overrides libc.
|
|
|
|
# Append to LD_PRELOAD so existing libraries, e.g. libasan, are kept.
|
|
|
|
# If libasan isn't specified in the LD_PRELOAD path, ASAN warns about mock-ioctl
|
|
|
|
# being loaded first because its memory allocations might not get intercepted.
|
|
|
|
# But it appears this isn't a problem; ASAN errors in mock-ioctl are reported.
|
|
|
|
# This is likely because the executable still links with libasan before libc.
|
|
|
|
mock_ioctl_env = environment()
|
|
|
|
mock_ioctl_env.append('LD_PRELOAD', mock_ioctl.full_path())
|
|
|
|
mock_ioctl_env.set('ASAN_OPTIONS', 'verify_asan_link_order=0')
|
|
|
|
|
2025-02-16 10:50:54 +01:00
|
|
|
ana = executable(
|
|
|
|
'test-ana',
|
|
|
|
'ana.c',
|
|
|
|
dependencies: libnvme_dep,
|
|
|
|
include_directories: [incdir, internal_incdir],
|
|
|
|
link_with: mock_ioctl,
|
|
|
|
)
|
|
|
|
|
|
|
|
test('ana', ana, env: mock_ioctl_env)
|
|
|
|
|
2025-02-16 10:12:19 +01:00
|
|
|
discovery = executable(
|
|
|
|
'test-discovery',
|
|
|
|
'discovery.c',
|
|
|
|
dependencies: libnvme_dep,
|
|
|
|
include_directories: [incdir, internal_incdir],
|
|
|
|
link_with: mock_ioctl,
|
|
|
|
)
|
|
|
|
|
2025-02-16 10:16:49 +01:00
|
|
|
test('discovery', discovery, env: mock_ioctl_env)
|
2025-02-16 10:12:19 +01:00
|
|
|
|
|
|
|
features = executable(
|
|
|
|
'test-features',
|
|
|
|
'features.c',
|
|
|
|
dependencies: libnvme_dep,
|
|
|
|
link_with: mock_ioctl,
|
|
|
|
)
|
|
|
|
|
2025-02-16 10:16:49 +01:00
|
|
|
test('features', features, env: mock_ioctl_env)
|
2025-02-16 10:12:19 +01:00
|
|
|
|
|
|
|
identify = executable(
|
|
|
|
'test-identify',
|
|
|
|
'identify.c',
|
|
|
|
dependencies: libnvme_dep,
|
|
|
|
link_with: mock_ioctl,
|
|
|
|
)
|
|
|
|
|
2025-02-16 10:16:49 +01:00
|
|
|
test('identify', identify, env: mock_ioctl_env)
|