summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-12-12 05:18:59 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-12-12 07:04:28 +0100
commit0b39dc23ba2d8d3e99f5dc30c3da5d0f6baf10d7 (patch)
tree266e843722bffb45aca811c26dd71adb92882274 /src/test
parenttest: modernize generate-sym-test.py (diff)
downloadsystemd-0b39dc23ba2d8d3e99f5dc30c3da5d0f6baf10d7.tar.xz
systemd-0b39dc23ba2d8d3e99f5dc30c3da5d0f6baf10d7.zip
test: also generate list of symbols from header files
To make the generated tests able to detect issues like #35554.
Diffstat (limited to 'src/test')
-rwxr-xr-xsrc/test/generate-sym-test.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/generate-sym-test.py b/src/test/generate-sym-test.py
index 24223aa7b0..7b5ded936c 100755
--- a/src/test/generate-sym-test.py
+++ b/src/test/generate-sym-test.py
@@ -19,6 +19,47 @@ def process_sym_file(file: IO[str]) -> None:
print(f' {{ "{m[1]}", {m[1]} }},')
+def process_header_file(file: IO[str]) -> None:
+ for line in file:
+ if (
+ line.startswith('#')
+ or line.startswith('typedef')
+ or line.startswith('extern "C"')
+ or line.startswith('__extension__')
+ or line.startswith('/*')
+ or ' __inline__ ' in line
+ or re.search(r'^\s+', line)
+ ):
+ continue
+
+ m = re.search(r'^(.*)\s*__attribute__', line)
+ if m:
+ line = m[1]
+
+ m = re.search(r'^(.*)\s*_sd_printf_', line)
+ if m:
+ line = m[1]
+
+ # Functions
+ m = re.search(r'^(\S+\s+)+\**(\w+)\s*\(', line)
+ if m:
+ print(f' {{ "{m[2]}", {m[2]} }},')
+ continue
+
+ # Variables
+ m = re.search(r'^extern\s', line)
+ if m:
+ n = line.split()[-1].rstrip(';')
+ print(f' {{ "{n}", &{n} }},')
+ continue
+
+ # Functions defined by macro
+ m = re.search(r'_SD_DEFINE_POINTER_CLEANUP_FUNC\(\w+,\s*(\w+)\)', line)
+ if m:
+ print(f' {{ "{m[1]}", {m[1]} }},')
+ continue
+
+
def process_source_file(file: IO[str]) -> None:
for line in file:
# Functions
@@ -84,6 +125,13 @@ with open(sys.argv[1], 'r') as f:
process_sym_file(f)
print(""" {}
+}, symbols_from_header[] = {""")
+
+for header in sys.argv[3:]:
+ with open(header, 'r') as f:
+ process_header_file(f)
+
+print(""" {}
}, symbols_from_source[] = {""")
for dirpath, _, filenames in sorted(os.walk(sys.argv[2])):
@@ -104,37 +152,63 @@ static int sort_callback(const void *a, const void *b) {
int main(void) {
size_t size = sizeof(symbols_from_sym[0]),
n_sym = sizeof(symbols_from_sym)/sizeof(symbols_from_sym[0]) - 1,
+ n_header = sizeof(symbols_from_header)/sizeof(symbols_from_header[0]) - 1,
n_source = sizeof(symbols_from_source)/sizeof(symbols_from_source[0]) - 1;
qsort(symbols_from_sym, n_sym, size, sort_callback);
+ qsort(symbols_from_header, n_header, size, sort_callback);
qsort(symbols_from_source, n_source, size, sort_callback);
puts("From symbol file:");
for (size_t i = 0; i < n_sym; i++)
printf("%p: %s\\n", symbols_from_sym[i].symbol, symbols_from_sym[i].name);
+ puts("\\nFrom header files:");
+ for (size_t i = 0; i < n_header; i++)
+ printf("%p: %s\\n", symbols_from_header[i].symbol, symbols_from_header[i].name);
+
puts("\\nFrom source files:");
for (size_t i = 0; i < n_source; i++)
printf("%p: %s\\n", symbols_from_source[i].symbol, symbols_from_source[i].name);
puts("");
printf("Found %zu symbols from symbol file.\\n", n_sym);
+ printf("Found %zu symbols from header files.\\n", n_header);
printf("Found %zu symbols from source files.\\n", n_source);
unsigned n_error = 0;
for (size_t i = 0; i < n_sym; i++) {
+ if (!bsearch(symbols_from_sym+i, symbols_from_header, n_header, size, sort_callback)) {
+ printf("Found in symbol file, but not in headers: %s\\n", symbols_from_sym[i].name);
+ n_error++;
+ }
if (!bsearch(symbols_from_sym+i, symbols_from_source, n_source, size, sort_callback)) {
printf("Found in symbol file, but not in sources: %s\\n", symbols_from_sym[i].name);
n_error++;
}
}
+ for (size_t i = 0; i < n_header; i++) {
+ if (!bsearch(symbols_from_header+i, symbols_from_sym, n_sym, size, sort_callback)) {
+ printf("Found in header file, but not in symbol file: %s\\n", symbols_from_header[i].name);
+ n_error++;
+ }
+ if (!bsearch(symbols_from_header+i, symbols_from_source, n_source, size, sort_callback)) {
+ printf("Found in header file, but not in sources: %s\\n", symbols_from_header[i].name);
+ n_error++;
+ }
+ }
+
for (size_t i = 0; i < n_source; i++) {
if (!bsearch(symbols_from_source+i, symbols_from_sym, n_sym, size, sort_callback)) {
printf("Found in source file, but not in symbol file: %s\\n", symbols_from_source[i].name);
n_error++;
}
+ if (!bsearch(symbols_from_source+i, symbols_from_header, n_header, size, sort_callback)) {
+ printf("Found in source file, but not in header: %s\\n", symbols_from_source[i].name);
+ n_error++;
+ }
}
return n_error == 0 ? EXIT_SUCCESS : EXIT_FAILURE;