summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-29 06:56:40 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-05-01 08:40:18 +0200
commit4c1b6e699f5729f2f0d713ed233f1f66004998c8 (patch)
treef008220b5df08887d5712cfb0823ea221bfb7151 /src
parentlibsystemd: add missing _public_ attributes (diff)
downloadsystemd-4c1b6e699f5729f2f0d713ed233f1f66004998c8.tar.xz
systemd-4c1b6e699f5729f2f0d713ed233f1f66004998c8.zip
test: also test all _public_ functions are listed in .sym files
Co-authored-by: Frantisek Sumsal <frantisek@sumsal.cz>
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/meson.build4
-rw-r--r--src/libudev/meson.build6
-rwxr-xr-xsrc/test/generate-sym-test.py101
-rw-r--r--src/test/meson.build8
4 files changed, 88 insertions, 31 deletions
diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build
index 91887be831..aa42497080 100644
--- a/src/libsystemd/meson.build
+++ b/src/libsystemd/meson.build
@@ -126,8 +126,10 @@ libsystemd_static = static_library(
userspace],
build_by_default : false)
+libsystemd_dir_path = meson.current_source_dir()
+
libsystemd_sym = files('libsystemd.sym')
-libsystemd_sym_path = meson.current_source_dir() / 'libsystemd.sym'
+libsystemd_sym_path = libsystemd_dir_path / 'libsystemd.sym'
static_libsystemd = get_option('static-libsystemd')
static_libsystemd_pic = static_libsystemd == 'true' or static_libsystemd == 'pic'
diff --git a/src/libudev/meson.build b/src/libudev/meson.build
index 1c349cef6d..3787602a6b 100644
--- a/src/libudev/meson.build
+++ b/src/libudev/meson.build
@@ -15,11 +15,13 @@ libudev_sources = files(
libudev_includes = [includes, include_directories('.')]
+libudev_dir_path = meson.current_source_dir()
+
libudev_sym = files('libudev.sym')
-libudev_sym_path = meson.current_source_dir() / 'libudev.sym'
+libudev_sym_path = libudev_dir_path / 'libudev.sym'
install_headers('libudev.h')
-libudev_h_path = meson.current_source_dir() / 'libudev.h'
+libudev_h_path = libudev_dir_path / 'libudev.h'
libudev_basic = static_library(
'udev-basic',
diff --git a/src/test/generate-sym-test.py b/src/test/generate-sym-test.py
index 8ed4d26fd3..a2ad4547bf 100755
--- a/src/test/generate-sym-test.py
+++ b/src/test/generate-sym-test.py
@@ -1,36 +1,89 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
-import sys, re
+import os
+import re
+import sys
-print('#include <stdio.h>')
-for header in sys.argv[2:]:
+def process_sym_file(file):
+ for line in file:
+ m = re.search(r'^ +([a-zA-Z0-9_]+);', line)
+ if m:
+ if m[1] == 'sd_bus_object_vtable_format':
+ print(' {{"{0}", &{0}}},'.format(m[1]))
+ else:
+ print(' {{"{0}", {0}}},'.format(m[1]))
+
+def process_source_file(file):
+ for line in file:
+ # Functions
+ m = re.search(r'^_public_\s+(\S+\s+)+\**(\w+)\s*\(', line)
+ if m:
+ print(' {{ "{0}", {0} }},'.format(m[2]))
+ # Variables
+ m = re.search(r'^_public_\s+(\S+\s+)+\**(\w+)\s*=', line)
+ if m:
+ print(' {{ "{0}", &{0} }},'.format(m[2]))
+ # Functions defined through a macro
+ m = re.search(r'^DEFINE_PUBLIC_TRIVIAL_REF_FUNC\([^,]+,\s*(\w+)\s*\)', line)
+ if m:
+ print(' {{ "{0}_ref", {0}_ref }},'.format(m[1]))
+ m = re.search(r'^DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC\([^,]+,\s*(\w+)\s*,', line)
+ if m:
+ print(' {{ "{0}_unref", {0}_unref }},'.format(m[1]))
+ m = re.search(r"^DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC\([^,]+,\s*(\w+)\s*,", line)
+ if m:
+ print(' {{ "{0}_ref", {0}_ref }},'.format(m[1]))
+ print(' {{ "{0}_unref", {0}_unref }},'.format(m[1]))
+
+print('''/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <stdio.h>
+#include <stdlib.h>
+''')
+
+for header in sys.argv[3:]:
print('#include "{}"'.format(header.split('/')[-1]))
print('''
/* We want to check deprecated symbols too, without complaining */
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+''')
-const struct {
+print('''
+static const struct {
const char *name;
const void *symbol;
-} symbols[] = {''')
-
-count = 0
-for line in open(sys.argv[1]):
- match = re.search('^ +([a-zA-Z0-9_]+);', line)
- if match:
- s = match.group(1)
- if s == 'sd_bus_object_vtable_format':
- print(f' {{"{s}", &{s}}},')
- else:
- print(f' {{"{s}", {s}}},')
- count += 1
-
-print(f'''}};
-
-int main(void) {{
- for (size_t i = 0; i < {count}; i++)
- printf("%p: %s\\n", symbols[i].symbol, symbols[i].name);
- return 0;
-}}''')
+} symbols_from_sym[] = {''')
+
+with open(sys.argv[1], "r") as f:
+ process_sym_file(f)
+
+print(''' {}
+}, symbols_from_source[] = {''')
+
+for dirpath, _, filenames in os.walk(sys.argv[2]):
+ for filename in filenames:
+ with open(os.path.join(dirpath, filename), "r") as f:
+ process_source_file(f)
+
+print(''' {}
+};
+
+int main(void) {
+ size_t i, j;
+
+ puts("From symbol file:");
+ for (i = 0; symbols_from_sym[i].name; i++)
+ printf("%p: %s\\n", symbols_from_sym[i].symbol, symbols_from_sym[i].name);
+
+ puts("\\nFrom source files:");
+ for (j = 0; symbols_from_source[j].name; j++)
+ printf("%p: %s\\n", symbols_from_source[j].symbol, symbols_from_source[j].name);
+
+ puts("");
+ printf("Found %zu symbols from symbol file.\\n", i);
+ printf("Found %zu symbols from source files.\\n", j);
+
+ return i == j ? EXIT_SUCCESS : EXIT_FAILURE;
+}''')
diff --git a/src/test/meson.build b/src/test/meson.build
index 289967760e..8a5e47f004 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -21,17 +21,17 @@ generate_sym_test_py = find_program('generate-sym-test.py')
test_libsystemd_sym_c = custom_target(
'test-libsystemd-sym.c',
- input : [libsystemd_sym_path] + systemd_headers,
+ input : [libsystemd_sym_path] + systemd_headers + libsystemd_sources,
output : 'test-libsystemd-sym.c',
- command : [generate_sym_test_py, libsystemd_sym_path] + systemd_headers,
+ command : [generate_sym_test_py, libsystemd_sym_path, libsystemd_dir_path] + systemd_headers,
capture : true,
build_by_default : want_tests != 'false')
test_libudev_sym_c = custom_target(
'test-libudev-sym.c',
- input : [libudev_sym_path, libudev_h_path],
+ input : [libudev_sym_path, libudev_h_path] + libudev_sources,
output : 'test-libudev-sym.c',
- command : [generate_sym_test_py, '@INPUT0@', '@INPUT1@'],
+ command : [generate_sym_test_py, libudev_sym_path, libudev_dir_path, libudev_h_path],
capture : true,
build_by_default : want_tests != 'false')