Merge pull request #10218 from keszybz/export-sd-device-hwdb

Export functions in sd-device and sd-hwdb
This commit is contained in:
Yu Watanabe 2018-10-01 19:45:55 +02:00 committed by GitHub
commit 5c434af721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 154 additions and 2 deletions

View File

@ -576,4 +576,76 @@ global:
sd_bus_message_readv;
sd_bus_set_method_call_timeout;
sd_bus_get_method_call_timeout;
sd_device_ref;
sd_device_unref;
sd_device_new_from_syspath;
sd_device_new_from_devnum;
sd_device_new_from_subsystem_sysname;
sd_device_new_from_device_id;
sd_device_get_parent;
sd_device_get_parent_with_subsystem_devtype;
sd_device_get_syspath;
sd_device_get_subsystem;
sd_device_get_devtype;
sd_device_get_devnum;
sd_device_get_ifindex;
sd_device_get_driver;
sd_device_get_devpath;
sd_device_get_devname;
sd_device_get_sysname;
sd_device_get_sysnum;
sd_device_get_is_initialized;
sd_device_get_usec_since_initialized;
sd_device_get_tag_first;
sd_device_get_tag_next;
sd_device_get_devlink_first;
sd_device_get_devlink_next;
sd_device_get_property_first;
sd_device_get_property_next;
sd_device_get_sysattr_first;
sd_device_get_sysattr_next;
sd_device_has_tag;
sd_device_get_property_value;
sd_device_get_sysattr_value;
sd_device_set_sysattr_value;
sd_device_enumerator_new;
sd_device_enumerator_ref;
sd_device_enumerator_unref;
sd_device_enumerator_get_device_first;
sd_device_enumerator_get_device_next;
sd_device_enumerator_get_subsystem_first;
sd_device_enumerator_get_subsystem_next;
sd_device_enumerator_add_match_subsystem;
sd_device_enumerator_add_match_sysattr;
sd_device_enumerator_add_match_property;
sd_device_enumerator_add_match_sysname;
sd_device_enumerator_add_match_tag;
sd_device_enumerator_add_match_parent;
sd_device_enumerator_allow_uninitialized;
sd_device_unrefp;
sd_device_enumerator_unrefp;
sd_hwdb_ref;
sd_hwdb_unref;
sd_hwdb_new;
sd_hwdb_get;
sd_hwdb_seek;
sd_hwdb_enumerate;
sd_hwdb_unrefp;
} LIBSYSTEMD_239;

View File

@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdbool.h>
char* setup_fake_runtime_dir(void);
const char* get_testdata_dir(void);
const char* get_catalog_dir(void);

View File

@ -5,7 +5,9 @@ _systemd_headers = '''
sd-bus-protocol.h
sd-bus-vtable.h
sd-daemon.h
sd-device.h
sd-event.h
sd-hwdb.h
sd-id128.h
sd-journal.h
sd-login.h
@ -15,8 +17,6 @@ _systemd_headers = '''
# https://github.com/mesonbuild/meson/issues/1633
systemd_headers = files(_systemd_headers)
# sd-device.h
# sd-hwdb.h
# sd-dhcp6-client.h
# sd-dhcp6-lease.h
# sd-dhcp-client.h

View File

@ -661,6 +661,10 @@ tests += [
[['src/test/test-bus-util.c'],
[],
[]],
[['src/test/test-sd-hwdb.c'],
[],
[]],
]
############################################################

74
src/test/test-sd-hwdb.c Normal file
View File

@ -0,0 +1,74 @@
#include "sd-hwdb.h"
#include "alloc-util.h"
#include "errno.h"
#include "tests.h"
static int test_failed_enumerate(void) {
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb;
const char *key, *value;
int r;
log_info("/* %s */", __func__);
r = sd_hwdb_new(&hwdb);
if (r == -ENOENT)
return r;
assert_se(r == 0);
assert_se(sd_hwdb_seek(hwdb, "no-such-modalias-should-exist") == 0);
assert_se(sd_hwdb_enumerate(hwdb, &key, &value) == 0);
assert_se(sd_hwdb_enumerate(hwdb, &key, NULL) == -EINVAL);
assert_se(sd_hwdb_enumerate(hwdb, NULL, &value) == -EINVAL);
return 0;
}
#define DELL_MODALIAS \
"evdev:atkbd:dmi:bvnXXX:bvrYYY:bdZZZ:svnDellXXX:pnYYY"
static void test_basic_enumerate(void) {
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb;
const char *key, *value;
size_t len1 = 0, len2 = 0;
int r;
log_info("/* %s */", __func__);
assert_se(sd_hwdb_new(&hwdb) == 0);
assert_se(sd_hwdb_seek(hwdb, DELL_MODALIAS) == 0);
for (;;) {
r = sd_hwdb_enumerate(hwdb, &key, &value);
assert(IN_SET(r, 0, 1));
if (r == 0)
break;
assert(key);
assert(value);
log_debug("A: \"%s\"\"%s\"", key, value);
len1 += strlen(key) + strlen(value);
}
SD_HWDB_FOREACH_PROPERTY(hwdb, DELL_MODALIAS, key, value) {
log_debug("B: \"%s\"\"%s\"", key, value);
len2 += strlen(key) + strlen(value);
}
assert_se(len1 == len2);
}
int main(int argc, char *argv[]) {
int r;
test_setup_logging(LOG_DEBUG);
r = test_failed_enumerate();
if (r < 0)
return log_tests_skipped_errno(r, "cannot open hwdb");
test_basic_enumerate();
return 0;
}