summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.pytest_cache/CACHEDIR.TAG4
-rw-r--r--test/.pytest_cache/README.md8
-rw-r--r--test/.pytest_cache/v/cache/lastfailed3
-rw-r--r--test/.pytest_cache/v/cache/nodeids3
-rw-r--r--test/.pytest_cache/v/cache/stepwise1
-rw-r--r--test/Makefile9
l---------test/_notes.py1
-rw-r--r--test/notes.c50
-rw-r--r--test/test.py15
9 files changed, 94 insertions, 0 deletions
diff --git a/test/.pytest_cache/CACHEDIR.TAG b/test/.pytest_cache/CACHEDIR.TAG
new file mode 100644
index 0000000..fce15ad
--- /dev/null
+++ b/test/.pytest_cache/CACHEDIR.TAG
@@ -0,0 +1,4 @@
+Signature: 8a477f597d28d172789f06886806bc55
+# This file is a cache directory tag created by pytest.
+# For information about cache directory tags, see:
+# https://bford.info/cachedir/spec.html
diff --git a/test/.pytest_cache/README.md b/test/.pytest_cache/README.md
new file mode 100644
index 0000000..b89018c
--- /dev/null
+++ b/test/.pytest_cache/README.md
@@ -0,0 +1,8 @@
+# pytest cache directory #
+
+This directory contains data from the pytest's cache plugin,
+which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
+
+**Do not** commit this to version control.
+
+See [the docs](https://docs.pytest.org/en/stable/how-to/cache.html) for more information.
diff --git a/test/.pytest_cache/v/cache/lastfailed b/test/.pytest_cache/v/cache/lastfailed
new file mode 100644
index 0000000..f974275
--- /dev/null
+++ b/test/.pytest_cache/v/cache/lastfailed
@@ -0,0 +1,3 @@
+{
+ "test.py::test_notes": true
+} \ No newline at end of file
diff --git a/test/.pytest_cache/v/cache/nodeids b/test/.pytest_cache/v/cache/nodeids
new file mode 100644
index 0000000..baac9f6
--- /dev/null
+++ b/test/.pytest_cache/v/cache/nodeids
@@ -0,0 +1,3 @@
+[
+ "test.py::test_notes"
+] \ No newline at end of file
diff --git a/test/.pytest_cache/v/cache/stepwise b/test/.pytest_cache/v/cache/stepwise
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/test/.pytest_cache/v/cache/stepwise
@@ -0,0 +1 @@
+[] \ No newline at end of file
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..b91a4ac
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,9 @@
+notes: notes.c
+ $(CC) -o $@ $+ $(CFLAGS) $(LDFLAGS) $(LDLIBS)
+
+check: notes
+ python3 -m pytest test.py
+
+clean:
+ rm -f notes
+ rm -rf __pycache__/
diff --git a/test/_notes.py b/test/_notes.py
new file mode 120000
index 0000000..88fcc3d
--- /dev/null
+++ b/test/_notes.py
@@ -0,0 +1 @@
+../dlopen-notes.py \ No newline at end of file
diff --git a/test/notes.c b/test/notes.c
new file mode 100644
index 0000000..5fa9dc1
--- /dev/null
+++ b/test/notes.c
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: CC0-1.0 */
+
+#include <stdint.h>
+
+#define XCONCATENATE(x, y) x ## y
+#define CONCATENATE(x, y) XCONCATENATE(x, y)
+#define UNIQ_T(x, uniq) CONCATENATE(__unique_prefix_, CONCATENATE(x, uniq))
+#define UNIQ __COUNTER__
+
+#define ELF_NOTE_DLOPEN_VENDOR "FDO"
+#define ELF_NOTE_DLOPEN_TYPE 0x407c0c0a
+
+#define _ELF_NOTE_DLOPEN(module, variable_name) \
+ __attribute__((used, section(".note.dlopen"))) _Alignas(sizeof(uint32_t)) static const struct { \
+ struct { \
+ uint32_t n_namesz, n_descsz, n_type; \
+ } nhdr; \
+ char name[sizeof(ELF_NOTE_DLOPEN_VENDOR)]; \
+ _Alignas(sizeof(uint32_t)) char dlopen_module[sizeof(module)]; \
+ } variable_name = { \
+ .nhdr = { \
+ .n_namesz = sizeof(ELF_NOTE_DLOPEN_VENDOR), \
+ .n_descsz = sizeof(module), \
+ .n_type = ELF_NOTE_DLOPEN_TYPE, \
+ }, \
+ .name = ELF_NOTE_DLOPEN_VENDOR, \
+ .dlopen_module = module, \
+ }
+
+#define _SONAME_ARRAY1(a) "[\""a"\"]"
+#define _SONAME_ARRAY2(a, b) "[\""a"\",\""b"\"]"
+#define _SONAME_ARRAY3(a, b, c) "[\""a"\",\""b"\",\""c"\"]"
+#define _SONAME_ARRAY4(a, b, c, d) "[\""a"\",\""b"\",\""c"\"",\""d"\"]"
+#define _SONAME_ARRAY5(a, b, c, d, e) "[\""a"\",\""b"\",\""c"\"",\""d"\",\""e"\"]"
+#define _SONAME_ARRAY_GET(_1,_2,_3,_4,_5,NAME,...) NAME
+#define _SONAME_ARRAY(...) _SONAME_ARRAY_GET(__VA_ARGS__, _SONAME_ARRAY5, _SONAME_ARRAY4, _SONAME_ARRAY3, _SONAME_ARRAY2, _SONAME_ARRAY1)(__VA_ARGS__)
+
+#define ELF_NOTE_DLOPEN(feature, description, priority, ...) \
+ _ELF_NOTE_DLOPEN("[{\"feature\":\"" feature "\",\"description\":\"" description "\",\"priority\":\"" priority "\",\"soname\":" _SONAME_ARRAY(__VA_ARGS__) "}]", UNIQ_T(s, UNIQ))
+
+#define ELF_NOTE_DLOPEN_DUAL(feature0, priority0, module0, feature1, priority1, module1) \
+ _ELF_NOTE_DLOPEN("[{\"feature\":\"" feature0 "\",\"priority\":\"" priority0 "\",\"soname\":[\"" module0 "\"]}, {\"feature\":\"" feature1 "\",\"priority\":\"" priority1 "\",\"soname\":[\"" module1 "\"]}]", UNIQ_T(s, UNIQ))
+
+int main(int argc, char **argv) {
+ ELF_NOTE_DLOPEN("fido2", "Support fido2 for encryption and authentication.", "required", "libfido2.so.1");
+ ELF_NOTE_DLOPEN("pcre2", "Support pcre2 for regex", "suggested", "libpcre2-8.so.0","libpcre2-8.so.1");
+ ELF_NOTE_DLOPEN("lz4", "Support lz4 decompression in journal and coredump files", "recommended", "liblz4.so.1");
+ ELF_NOTE_DLOPEN_DUAL("tpm", "recommended", "libtss2-mu.so.0", "tpm", "recommended", "libtss2-esys.so.0");
+ return 0;
+}
diff --git a/test/test.py b/test/test.py
new file mode 100644
index 0000000..462f476
--- /dev/null
+++ b/test/test.py
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: CC0-1.0
+
+from _notes import read_dlopen_notes, group_by_soname
+
+def test_notes():
+ expected = {
+ 'libfido2.so.1': 'required',
+ 'liblz4.so.1': 'recommended',
+ 'libpcre2-8.so.0': 'suggested',
+ 'libpcre2-8.so.1': 'suggested',
+ 'libtss2-esys.so.0': 'recommended',
+ 'libtss2-mu.so.0': 'recommended',
+ }
+ notes = [read_dlopen_notes('notes')]
+ assert group_by_soname(notes) == expected