diff mbox series

rt-tests: Support building with meson

Message ID 20220304231751.22856-1-richard@nod.at
State New
Headers show
Series rt-tests: Support building with meson | expand

Commit Message

Richard Weinberger March 4, 2022, 11:17 p.m. UTC
While rt-test's Makefile is not super complicated I still think
it can benefit from meson.
meson gracefully handles dependencies and Python installations.

To build and install using meson, run:
	meson builddir
	ninja -C builddir
	DESTDIR=/your/dest ninja -C builddir install

Android support is completely untested.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 README.markdown |   6 +++
 meson.build     | 135 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 141 insertions(+)
 create mode 100644 meson.build
diff mbox series

Patch

diff --git a/README.markdown b/README.markdown
index 3ab6ddf53c7e..8fbab9e75de0 100644
--- a/README.markdown
+++ b/README.markdown
@@ -9,6 +9,12 @@  This repository contains some programs that test various rt-linux features.
     sudo apt-get install build-essential libnuma-dev
     make
 
+### Compile and install with meson
+
+    meson builddir
+    ninja -C builddir
+    DESTDIR=/your/dest ninja -C builddir install
+
 ### Run tests
 
 To run one test thread per CPU or per CPU core, each thread on a separate
diff --git a/meson.build b/meson.build
new file mode 100644
index 000000000000..d7220090a423
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,135 @@ 
+project('rt-tests', 'c', version: '2.3')
+
+os_args = []
+want_andoid = false
+
+if target_machine.system() == 'android'
+	os_args += ['-DPTHREAD_BIONIC']
+	want_andoid = true
+endif
+
+add_global_arguments([
+	'-D_GNU_SOURCE',
+	'-Wno-nonnull',
+	'-DVERSION=@0@'.format(meson.project_version()),
+	os_args,
+        ],
+        language: 'c',
+)
+
+cc = meson.get_compiler('c')
+
+libdl_dep = cc.find_library('dl')
+librt_dep = cc.find_library('rt')
+
+thread_dep = dependency('threads')
+libnuma_dep = dependency('numa')
+
+base_inc = include_directories('src/include')
+
+pymod = import('python')
+pyinst = pymod.find_installation(required: false)
+
+rttest_lib = static_library(
+	'rtest',
+	[
+		'src/lib/rt-error.c',
+		'src/lib/rt-get_cpu.c',
+		'src/lib/rt-sched.c',
+		'src/lib/rt-utils.c',
+	],
+	include_directories: base_inc,
+)
+
+rttestnuma_lib = static_library(
+	'rtestnuma',
+	[
+		'src/lib/rt-numa.c',
+	],
+	include_directories: base_inc,
+)
+
+c_srcs = [
+	'src/cyclictest/cyclictest.c',
+	'src/hackbench/hackbench.c',
+]
+
+c_srcs_non_adroid = [
+	'src/oslat/oslat.c',
+	'src/pi_tests/pi_stress.c',
+	'src/pi_tests/pip_stress.c',
+	'src/pmqtest/pmqtest.c',
+	'src/ptsematest/ptsematest.c',
+	'src/queuelat/queuelat.c',
+	'src/rt-migrate-test/rt-migrate-test.c',
+	'src/sched_deadline/cyclicdeadline.c',
+	'src/sched_deadline/deadline_test.c',
+	'src/signaltest/signaltest.c',
+	'src/sigwaittest/sigwaittest.c',
+	'src/ssdd/ssdd.c',
+	'src/svsematest/svsematest.c',
+]
+
+if want_andoid == false
+	c_srcs += c_srcs_non_adroid
+endif
+
+py_srcs = [
+	'src/cyclictest/get_cyclictest_snapshot.py',
+	'src/hwlatdetect/hwlatdetect.py',
+]
+
+sh_srcs = [
+	'src/queuelat/determine_maximum_mpps.sh',
+]
+
+extra_link = {
+	'cyclictest': [rttestnuma_lib],
+	'oslat': [rttestnuma_lib],
+	'signaltest': [rttestnuma_lib],
+}
+
+extra_dep = {
+	'cyclictest': [libnuma_dep],
+	'oslat': [libnuma_dep],
+	'ptsematest': [libdl_dep],
+	'signaltest': [libnuma_dep],
+	'sigwaittest': [libnuma_dep],
+	'svsematest': [libnuma_dep],
+}
+
+foreach src: c_srcs
+	exe = src.split('/')[-1].split('.c')[0]
+	executable(
+		exe,
+		src,
+		include_directories: base_inc,
+		dependencies: [
+			libdl_dep,
+			librt_dep,
+			thread_dep,
+			extra_dep.get(exe, []),
+		],
+		link_with: [
+			rttest_lib,
+			extra_link.get(exe, []),
+		],
+		install: true,
+	)
+	install_man(src.split('.c')[0] + '.8')
+endforeach
+
+if pyinst.found()
+	pyinst.install_sources(py_srcs)
+	foreach src: py_srcs
+		install_man(src.split('.py')[0] + '.8')
+	endforeach
+endif
+
+install_data(sh_srcs,
+	install_dir: get_option('bindir'),
+	install_mode: 'rwxr-xr-x',
+)
+foreach src: sh_srcs
+	install_man(src.split('.sh')[0] + '.8')
+endforeach