mirror of
https://github.com/systemd/systemd.git
synced 2025-05-27 21:05:55 +03:00
Merge pull request #27455 from yuwata/test-lib-sym
test: check all public functions are listed in .sym file
This commit is contained in:
commit
ecf82f74b6
@ -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'
|
||||
|
@ -667,7 +667,7 @@ _public_ int sd_notifyf(int unset_environment, const char *format, ...) {
|
||||
return sd_pid_notify(0, unset_environment, p);
|
||||
}
|
||||
|
||||
int sd_pid_notifyf_with_fds(
|
||||
_public_ int sd_pid_notifyf_with_fds(
|
||||
pid_t pid,
|
||||
int unset_environment,
|
||||
const int *fds, size_t n_fds,
|
||||
|
@ -1872,7 +1872,7 @@ _public_ int sd_event_add_exit(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_event_trim_memory(void) {
|
||||
_public_ int sd_event_trim_memory(void) {
|
||||
int r;
|
||||
|
||||
/* A default implementation of a memory pressure callback. Simply releases our own allocation caches
|
||||
|
@ -103,7 +103,7 @@ static sd_netlink_slot* netlink_slot_free(sd_netlink_slot *slot) {
|
||||
return mfree(slot);
|
||||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_netlink_slot, sd_netlink_slot, netlink_slot_free);
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_netlink_slot, sd_netlink_slot, netlink_slot_free);
|
||||
|
||||
sd_netlink *sd_netlink_slot_get_netlink(sd_netlink_slot *slot) {
|
||||
assert_return(slot, NULL);
|
||||
|
@ -481,7 +481,7 @@ static bool resolve_pid_changed(sd_resolve *r) {
|
||||
return r->original_pid != getpid_cached();
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_new(sd_resolve **ret) {
|
||||
int sd_resolve_new(sd_resolve **ret) {
|
||||
_cleanup_(sd_resolve_unrefp) sd_resolve *resolve = NULL;
|
||||
int i;
|
||||
|
||||
@ -517,7 +517,7 @@ _public_ int sd_resolve_new(sd_resolve **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_default(sd_resolve **ret) {
|
||||
int sd_resolve_default(sd_resolve **ret) {
|
||||
static thread_local sd_resolve *default_resolve = NULL;
|
||||
sd_resolve *e = NULL;
|
||||
int r;
|
||||
@ -542,7 +542,7 @@ _public_ int sd_resolve_default(sd_resolve **ret) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid) {
|
||||
int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid) {
|
||||
assert_return(resolve, -EINVAL);
|
||||
assert_return(tid, -EINVAL);
|
||||
assert_return(!resolve_pid_changed(resolve), -ECHILD);
|
||||
@ -601,23 +601,23 @@ static sd_resolve *resolve_free(sd_resolve *resolve) {
|
||||
return mfree(resolve);
|
||||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_resolve, sd_resolve, resolve_free);
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_resolve, sd_resolve, resolve_free);
|
||||
|
||||
_public_ int sd_resolve_get_fd(sd_resolve *resolve) {
|
||||
int sd_resolve_get_fd(sd_resolve *resolve) {
|
||||
assert_return(resolve, -EINVAL);
|
||||
assert_return(!resolve_pid_changed(resolve), -ECHILD);
|
||||
|
||||
return resolve->fds[RESPONSE_RECV_FD];
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_get_events(sd_resolve *resolve) {
|
||||
int sd_resolve_get_events(sd_resolve *resolve) {
|
||||
assert_return(resolve, -EINVAL);
|
||||
assert_return(!resolve_pid_changed(resolve), -ECHILD);
|
||||
|
||||
return resolve->n_queries > resolve->n_done ? POLLIN : 0;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *usec) {
|
||||
int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *usec) {
|
||||
assert_return(resolve, -EINVAL);
|
||||
assert_return(usec, -EINVAL);
|
||||
assert_return(!resolve_pid_changed(resolve), -ECHILD);
|
||||
@ -830,7 +830,7 @@ static int handle_response(sd_resolve *resolve, const Packet *packet, size_t len
|
||||
}
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_process(sd_resolve *resolve) {
|
||||
int sd_resolve_process(sd_resolve *resolve) {
|
||||
RESOLVE_DONT_DESTROY(resolve);
|
||||
|
||||
union {
|
||||
@ -863,7 +863,7 @@ _public_ int sd_resolve_process(sd_resolve *resolve) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec) {
|
||||
int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec) {
|
||||
int r;
|
||||
|
||||
assert_return(resolve, -EINVAL);
|
||||
@ -990,7 +990,7 @@ int resolve_getaddrinfo_with_destroy_callback(
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_getaddrinfo(
|
||||
int sd_resolve_getaddrinfo(
|
||||
sd_resolve *resolve,
|
||||
sd_resolve_query **ret_query,
|
||||
const char *node, const char *service,
|
||||
@ -1079,7 +1079,7 @@ int resolve_getnameinfo_with_destroy_callback(
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_getnameinfo(
|
||||
int sd_resolve_getnameinfo(
|
||||
sd_resolve *resolve,
|
||||
sd_resolve_query **ret_query,
|
||||
const struct sockaddr *sa, socklen_t salen,
|
||||
@ -1157,16 +1157,16 @@ static sd_resolve_query *resolve_query_free(sd_resolve_query *q) {
|
||||
return mfree(q);
|
||||
}
|
||||
|
||||
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_resolve_query, sd_resolve_query, resolve_query_free);
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_resolve_query, sd_resolve_query, resolve_query_free);
|
||||
|
||||
_public_ int sd_resolve_query_is_done(sd_resolve_query *q) {
|
||||
int sd_resolve_query_is_done(sd_resolve_query *q) {
|
||||
assert_return(q, -EINVAL);
|
||||
assert_return(!resolve_pid_changed(q->resolve), -ECHILD);
|
||||
|
||||
return q->done;
|
||||
}
|
||||
|
||||
_public_ void* sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata) {
|
||||
void* sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata) {
|
||||
void *ret;
|
||||
|
||||
assert_return(q, NULL);
|
||||
@ -1178,21 +1178,21 @@ _public_ void* sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata
|
||||
return ret;
|
||||
}
|
||||
|
||||
_public_ void* sd_resolve_query_get_userdata(sd_resolve_query *q) {
|
||||
void* sd_resolve_query_get_userdata(sd_resolve_query *q) {
|
||||
assert_return(q, NULL);
|
||||
assert_return(!resolve_pid_changed(q->resolve), NULL);
|
||||
|
||||
return q->userdata;
|
||||
}
|
||||
|
||||
_public_ sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q) {
|
||||
sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q) {
|
||||
assert_return(q, NULL);
|
||||
assert_return(!resolve_pid_changed(q->resolve), NULL);
|
||||
|
||||
return q->resolve;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_query_get_destroy_callback(sd_resolve_query *q, sd_resolve_destroy_t *destroy_callback) {
|
||||
int sd_resolve_query_get_destroy_callback(sd_resolve_query *q, sd_resolve_destroy_t *destroy_callback) {
|
||||
assert_return(q, -EINVAL);
|
||||
|
||||
if (destroy_callback)
|
||||
@ -1201,20 +1201,20 @@ _public_ int sd_resolve_query_get_destroy_callback(sd_resolve_query *q, sd_resol
|
||||
return !!q->destroy_callback;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_query_set_destroy_callback(sd_resolve_query *q, sd_resolve_destroy_t destroy_callback) {
|
||||
int sd_resolve_query_set_destroy_callback(sd_resolve_query *q, sd_resolve_destroy_t destroy_callback) {
|
||||
assert_return(q, -EINVAL);
|
||||
|
||||
q->destroy_callback = destroy_callback;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_query_get_floating(sd_resolve_query *q) {
|
||||
int sd_resolve_query_get_floating(sd_resolve_query *q) {
|
||||
assert_return(q, -EINVAL);
|
||||
|
||||
return q->floating;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_query_set_floating(sd_resolve_query *q, int b) {
|
||||
int sd_resolve_query_set_floating(sd_resolve_query *q, int b) {
|
||||
assert_return(q, -EINVAL);
|
||||
|
||||
if (q->floating == !!b)
|
||||
@ -1247,7 +1247,7 @@ static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userd
|
||||
return 1;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_attach_event(sd_resolve *resolve, sd_event *event, int64_t priority) {
|
||||
int sd_resolve_attach_event(sd_resolve *resolve, sd_event *event, int64_t priority) {
|
||||
int r;
|
||||
|
||||
assert_return(resolve, -EINVAL);
|
||||
@ -1278,7 +1278,7 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ int sd_resolve_detach_event(sd_resolve *resolve) {
|
||||
int sd_resolve_detach_event(sd_resolve *resolve) {
|
||||
assert_return(resolve, -EINVAL);
|
||||
|
||||
if (!resolve->event)
|
||||
@ -1289,7 +1289,7 @@ _public_ int sd_resolve_detach_event(sd_resolve *resolve) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
_public_ sd_event *sd_resolve_get_event(sd_resolve *resolve) {
|
||||
sd_event *sd_resolve_get_event(sd_resolve *resolve) {
|
||||
assert_return(resolve, NULL);
|
||||
|
||||
return resolve->event;
|
||||
|
@ -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',
|
||||
|
@ -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[] = {''')
|
||||
} symbols_from_sym[] = {''')
|
||||
|
||||
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
|
||||
with open(sys.argv[1], "r") as f:
|
||||
process_sym_file(f)
|
||||
|
||||
print(f'''}};
|
||||
print(''' {}
|
||||
}, symbols_from_source[] = {''')
|
||||
|
||||
int main(void) {{
|
||||
for (size_t i = 0; i < {count}; i++)
|
||||
printf("%p: %s\\n", symbols[i].symbol, symbols[i].name);
|
||||
return 0;
|
||||
}}''')
|
||||
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;
|
||||
}''')
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user