Projects
openEuler:Mainline
libgudev
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 10
View file
_service:tar_scm:libgudev.spec
Changed
@@ -1,6 +1,6 @@ Name: libgudev -Version: 237 -Release: 2 +Version: 238 +Release: 1 Summary: Library that provides GObject bindings for libudev License: LGPLv2+ URL: https://wiki.gnome.org/Projects/libgudev @@ -62,6 +62,9 @@ %{_datadir}/gtk-doc/html/gudev/* %changelog +* Sat Jul 22 2022 zhouwenpei <zhouwenpei1@h-partners.com> - 238-1 +- update to 238 + * Tue Oct 25 2022 wangkerong <wangkerong@h-partners.com> - 237-2 - rebuild for next release
View file
_service:tar_scm:libgudev-238.tar.xz/.ci/fail_skipped_tests.py
Added
@@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +from lxml import etree +import sys + +def format_title(title): + """Put title in a box""" + box = { + 'tl': '╔', 'tr': '╗', 'bl': '╚', 'br': '╝', 'h': '═', 'v': '║', + } + hline = box'h' * (len(title) + 2) + + return '\n'.join( + f"{box'tl'}{hline}{box'tr'}", + f"{box'v'} {title} {box'v'}", + f"{box'bl'}{hline}{box'br'}", + ) + +tree = etree.parse(sys.argv1) +for suite in tree.xpath('/testsuites/testsuite'): + skipped = suite.get('skipped') + if int(skipped) != 0: + print(format_title('Tests were skipped when they should not have been. All the tests must be run in the CI'), + end='\n\n', flush=True) + sys.exit(1)
View file
_service:tar_scm:libgudev-238.tar.xz/.gitignore
Added
@@ -0,0 +1,39 @@ +*.a +*.cache +*.gir +*.html +*.la +*.lo +*.log +*.o +*.plist +*.pyc +*.stamp +*.swp +*.trs +*.typelib +*~ +.deps/ +.dirstamp +.libs/ +/*.gcda +/*.gcno +/*.tar.bz2 +/*.tar.gz +/*.tar.xz +/Makefile +/Makefile.in +/aclocal.m4 +/build-aux/ +/config.h +/config.h.in +/config.log +/config.status +/configure +/gtk-doc.make +/gudev/gudevenumtypes.h +/gudev/gudevenumtypes.c +/gudev-1.0.pc +/libtool +/m4/ +/stamp-*
View file
_service:tar_scm:libgudev-237.tar.xz/.gitlab-ci.yml -> _service:tar_scm:libgudev-238.tar.xz/.gitlab-ci.yml
Changed
@@ -37,6 +37,7 @@ - ninja -C build/ install - .ci/check-abi ${LAST_ABI_BREAK} $(git rev-parse HEAD) - ninja -C build/ test + - .ci/fail_skipped_tests.py build/meson-logs/testlog.junit.xml - ninja -C build/ dist reference:
View file
_service:tar_scm:libgudev-237.tar.xz/NEWS -> _service:tar_scm:libgudev-238.tar.xz/NEWS
Changed
@@ -1,5 +1,12 @@ libgudev - GObject bindings for libudev +CHANGES WITH 238: + * Fix newline stripping + * Add g_udev_device_get_current_tags() + * Add a number of tests, and devel docs + * Fix devhelp not being able to find the docs + * Skip locale test with locale isn't available + CHANGES WITH 237: * Fix reading double precision floats from sysfs attributes in locales that use comma as a separator
View file
_service:tar_scm:libgudev-237.tar.xz/docs/meson.build -> _service:tar_scm:libgudev-238.tar.xz/docs/meson.build
Changed
@@ -31,13 +31,13 @@ libgudev_reference_fixxref_args = - '--html-dir=@0@'.format(join_paths(gtkdocdir, 'html', package_string)), + '--html-dir=@0@'.format(join_paths(gtkdocdir, 'html', package_name)), '--extra-dir=@0@'.format(glib_docpath), '--extra-dir=@0@'.format(gobject_docpath), gnome.gtkdoc( - package_string, + package_name, main_xml: 'gudev-docs.xml', gobject_typesfile: files('gudev.types'), src_dir: libgudev_reference_source_folders,
View file
_service:tar_scm:libgudev-237.tar.xz/gudev/gudevdevice.c -> _service:tar_scm:libgudev-238.tar.xz/gudev/gudevdevice.c
Changed
@@ -76,9 +76,9 @@ gchar **property_keys; gchar **sysfs_attr_keys; gchar **tags; + gchar **current_tags; GHashTable *prop_strvs; GHashTable *sysfs_attr_strvs; - GHashTable *sysfs_attr; }; G_DEFINE_TYPE_WITH_CODE (GUdevDevice, g_udev_device, G_TYPE_OBJECT, G_ADD_PRIVATE(GUdevDevice)) @@ -92,6 +92,7 @@ g_strfreev (device->priv->property_keys); g_strfreev (device->priv->sysfs_attr_keys); g_strfreev (device->priv->tags); + g_strfreev (device->priv->current_tags); if (device->priv->udevice != NULL) udev_device_unref (device->priv->udevice); @@ -102,9 +103,6 @@ if (device->priv->sysfs_attr_strvs != NULL) g_hash_table_unref (device->priv->sysfs_attr_strvs); - if (device->priv->sysfs_attr != NULL) - g_hash_table_unref (device->priv->sysfs_attr); - if (G_OBJECT_CLASS (g_udev_device_parent_class)->finalize != NULL) (* G_OBJECT_CLASS (g_udev_device_parent_class)->finalize) (object); } @@ -123,6 +121,35 @@ device->priv = g_udev_device_get_instance_private (device); } +static void +fetch_get_tags (GUdevDevice *device) +{ + struct udev_list_entry *l; + GPtrArray *p; + + p = g_ptr_array_new (); + for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l)) + { + g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l))); + } + g_ptr_array_add (p, NULL); + device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE); +} + +static void +fetch_current_tags (GUdevDevice *device) +{ + struct udev_list_entry *l; + GPtrArray *p; + + p = g_ptr_array_new (); + for (l = udev_device_get_current_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l)) + { + g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l))); + } + g_ptr_array_add (p, NULL); + device->priv->current_tags = (gchar **) g_ptr_array_free (p, FALSE); +} GUdevDevice * _g_udev_device_new (struct udev_device *udevice) @@ -131,10 +158,9 @@ device = G_UDEV_DEVICE (g_object_new (G_UDEV_TYPE_DEVICE, NULL)); device->priv->udevice = udev_device_ref (udevice); - device->priv->sysfs_attr = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_free); + + fetch_get_tags (device); + fetch_current_tags (device); return device; } @@ -773,14 +799,8 @@ g_udev_device_get_sysfs_attr (GUdevDevice *device, const gchar *name) { - const char *attr; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL); g_return_val_if_fail (name != NULL, NULL); - - attr = g_hash_table_lookup (device->priv->sysfs_attr, name); - if (attr) - return attr; return udev_device_get_sysattr_value (device->priv->udevice, name); } @@ -1004,6 +1024,8 @@ * functions. * * Returns: %TRUE only if the value for @key exist. + * + * Since: 234 */ gboolean g_udev_device_has_sysfs_attr_uncached (GUdevDevice *device, @@ -1022,26 +1044,23 @@ * Look up the sysfs attribute with @name on @device. This function does * blocking I/O, and updates the sysfs attributes cache. * + * Before version 238 the uncached getters would not strip trailing newlines. + * * Returns: (nullable): The value of the sysfs attribute or %NULL if * there is no such attribute. Do not free this string, it is owned by * @device. + * + * Since: 234 */ const gchar * g_udev_device_get_sysfs_attr_uncached (GUdevDevice *device, const gchar *name) { - g_autofree char *path = NULL; - char *contents = NULL; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL); g_return_val_if_fail (name != NULL, NULL); - path = g_build_filename (udev_device_get_syspath (device->priv->udevice), name, NULL); - if (!g_file_get_contents (path, &contents, NULL, NULL)) - return NULL; - g_hash_table_insert (device->priv->sysfs_attr, g_strdup (name), contents); - - return contents; + udev_device_set_sysattr_value (device->priv->udevice, name, NULL); + return g_udev_device_get_sysfs_attr (device, name); } /** @@ -1053,27 +1072,22 @@ * using strtol(). This function does blocking I/O, and updates the sysfs * attributes cache. * + * Before version 238 the uncached getters would not strip trailing newlines. + * * Returns: The value of the sysfs attribute or 0 if there is no such * attribute. + * + * Since: 234 */ gint g_udev_device_get_sysfs_attr_as_int_uncached (GUdevDevice *device, const gchar *name) { - gint result; - const gchar *s; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0); g_return_val_if_fail (name != NULL, 0); - result = 0; - s = g_udev_device_get_sysfs_attr_uncached (device, name); - if (s == NULL) - goto out; - - result = strtol (s, NULL, 0); -out: - return result; + udev_device_set_sysattr_value (device->priv->udevice, name, NULL); + return g_udev_device_get_sysfs_attr_as_int (device, name); } /** @@ -1085,27 +1099,22 @@ * 64-bit integer using g_ascii_strtoull(). This function does blocking I/O, and * updates the sysfs attributes cache. * + * Before version 238 the uncached getters would not strip trailing newlines. + * * Returns: The value of the sysfs attribute or 0 if there is no such * attribute. + * + * Since: 234 */ guint64 g_udev_device_get_sysfs_attr_as_uint64_uncached (GUdevDevice *device, const gchar *name) { - guint64 result; - const gchar *s; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0); g_return_val_if_fail (name != NULL, 0); - result = 0; - s = g_udev_device_get_sysfs_attr_uncached (device, name); - if (s == NULL) - goto out; - - result = g_ascii_strtoull (s, NULL, 0); -out: - return result; + udev_device_set_sysattr_value (device->priv->udevice, name, NULL); + return g_udev_device_get_sysfs_attr_as_uint64 (device, name); } /** @@ -1117,27 +1126,22 @@ * precision floating point number using g_ascii_strtod(). This function does blocking * I/O, and updates the sysfs attributes cache. * + * Before version 238 the uncached getters would not strip trailing newlines. + * * Returns: The value of the sysfs attribute or 0.0 if there is no such * attribute. + * + * Since: 234 */ gdouble g_udev_device_get_sysfs_attr_as_double_uncached (GUdevDevice *device, const gchar *name) { - gdouble result; - const gchar *s; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0); g_return_val_if_fail (name != NULL, 0.0); - result = 0.0; - s = g_udev_device_get_sysfs_attr_uncached (device, name); - if (s == NULL) - goto out; - - result = g_ascii_strtod (s, NULL); -out: - return result; + udev_device_set_sysattr_value (device->priv->udevice, name, NULL); + return g_udev_device_get_sysfs_attr_as_double (device, name); } /** @@ -1150,36 +1154,22 @@ * on the string value against "1", "true", "Y" and "y". This function does * blocking I/O, and updates the sysfs attributes cache. * + * Before version 238 the uncached getters would not strip trailing newlines. + * * Returns: The value of the sysfs attribute or %FALSE if there is no such * attribute. + * + * Since: 234 */ gboolean g_udev_device_get_sysfs_attr_as_boolean_uncached (GUdevDevice *device, const gchar *name) { - gboolean result; - const gchar *raw; - g_autofree char *truncated = NULL; - const char *s; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE); g_return_val_if_fail (name != NULL, FALSE); - result = FALSE; - raw = g_udev_device_get_sysfs_attr_uncached (device, name); - if (raw == NULL) - goto out; - - truncated = truncate_at_linefeed (raw); - s = truncated ?: raw; - if (strcmp (s, "1") == 0 || - g_ascii_strcasecmp (s, "true") == 0 || - g_ascii_strcasecmp (s, "y") == 0) { - result = TRUE; - } - - out: - return result; + udev_device_set_sysattr_value (device->priv->udevice, name, NULL); + return g_udev_device_get_sysfs_attr_as_boolean (device, name); } /** @@ -1199,32 +1189,22 @@ * The value of the sysfs attribute split into tokens or %NULL if * there is no such attribute. This array is owned by @device and * should not be freed by the caller. + * + * Before version 238 the uncached getters would not strip trailing newlines. + * + * Since: 234 */ const gchar * const * g_udev_device_get_sysfs_attr_as_strv_uncached (GUdevDevice *device, const gchar *name) { - gchar **result; - const gchar *s; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL); g_return_val_if_fail (name != NULL, NULL); - result = NULL; - s = g_udev_device_get_sysfs_attr_uncached (device, name); - if (s == NULL) - goto out; + g_hash_table_remove (device->priv->sysfs_attr_strvs, name); - result = split_at_whitespace (s); - if (result == NULL) - goto out; - - if (device->priv->sysfs_attr_strvs == NULL) - device->priv->sysfs_attr_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev); - g_hash_table_insert (device->priv->sysfs_attr_strvs, g_strdup (name), result); - -out: - return (const gchar* const *) result; + udev_device_set_sysattr_value (device->priv->udevice, name, NULL); + return g_udev_device_get_sysfs_attr_as_strv (device, name); } /** @@ -1240,24 +1220,29 @@ const gchar* const * g_udev_device_get_tags (GUdevDevice *device) { - struct udev_list_entry *l; - GPtrArray *p; - g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL); - if (device->priv->tags != NULL) - goto out; + return (const gchar * const *) device->priv->tags; +} - p = g_ptr_array_new (); - for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l)) - { - g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l))); - } - g_ptr_array_add (p, NULL); - device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE); +/** + * g_udev_device_get_current_tags: + * @device: A #GUdevDevice. + * + * Gets all current tags for @device. + * + * https://www.freedesktop.org/software/systemd/man/udev_device_has_current_tag.html + * + * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of current tags. This array is owned by @device and should not be freed by the caller. + * + * Since: 238 + */ +const gchar* const * +g_udev_device_get_current_tags (GUdevDevice *device) +{ + g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL); - out: - return (const gchar * const *) device->priv->tags; + return (const gchar * const *) device->priv->current_tags; } /**
View file
_service:tar_scm:libgudev-237.tar.xz/gudev/gudevdevice.h -> _service:tar_scm:libgudev-238.tar.xz/gudev/gudevdevice.h
Changed
@@ -115,6 +115,7 @@ const gchar* const *g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device, const gchar *name); const gchar* const *g_udev_device_get_tags (GUdevDevice *device); +const gchar* const *g_udev_device_get_current_tags (GUdevDevice *device); gboolean g_udev_device_has_sysfs_attr_uncached (GUdevDevice *device, const gchar *key);
View file
_service:tar_scm:libgudev-237.tar.xz/gudev/meson.build -> _service:tar_scm:libgudev-238.tar.xz/gudev/meson.build
Changed
@@ -97,7 +97,7 @@ ) -if introspection_dep.found() +if gir_dep.found() libgudev_gir = gnome.generate_gir( libgudev, sources: libgudev_sources + libgudev_public_h,
View file
_service:tar_scm:libgudev-237.tar.xz/libgudev-1.0.sym -> _service:tar_scm:libgudev-238.tar.xz/libgudev-1.0.sym
Changed
@@ -44,6 +44,7 @@ g_udev_device_get_sysfs_attr_keys; g_udev_device_get_sysfs_path; g_udev_device_get_tags; + g_udev_device_get_current_tags; g_udev_device_get_type; g_udev_device_get_usec_since_initialized; g_udev_device_has_property;
View file
_service:tar_scm:libgudev-237.tar.xz/meson.build -> _service:tar_scm:libgudev-238.tar.xz/meson.build
Changed
@@ -1,5 +1,5 @@ project('libgudev', 'c', - version: '237', + version: '238', license: 'LGPLv2.1+', meson_version: '>= 0.53.0', default_options: @@ -41,10 +41,7 @@ cc = meson.get_compiler('c') glib_req = '>= 2.38.0' -libudev_req = '>= 199' -introspection_req = '>= 1.31.1' -vapigen_req = '>= 0.38.0' -gtk_doc_req = '>= 1.18' +libudev_req = '>= 251' glib_dep = dependency('glib-2.0', version: glib_req) gobject_dep = dependency('gobject-2.0', version: glib_req) @@ -58,20 +55,12 @@ required: get_option('tests') ) -introspection_dep = dependency( - 'gobject-introspection-1.0', version: introspection_req, - required: get_option('introspection') -) - -vapigen_dep = dependency( - 'vapigen', version: vapigen_req, - required: get_option('vapi') -) +gir_dep = find_program('g-ir-scanner', required: get_option('introspection')) +vapigen_dep = find_program('vapigen', required : get_option('vapi')) -gtk_doc_dep = dependency( - 'gtk-doc', version: gtk_doc_req, - required: get_option('gtk_doc') -) +if vapigen_dep.found() + assert(gir_dep.found(), 'vapi requires introspection') +endif # Configurations config_h = configuration_data() @@ -95,7 +84,7 @@ endif summary('Documentation', get_option('gtk_doc'), section: 'Build') -summary('Introspection', introspection_dep.found(), section: 'Build') +summary('Introspection', gir_dep.found(), section: 'Build') summary('Vala API', vapigen_dep.found(), section: 'Build') summary('Tests', umockdev_dep.found(), section: 'Build')
View file
_service:tar_scm:libgudev-237.tar.xz/tests/meson.build -> _service:tar_scm:libgudev-238.tar.xz/tests/meson.build
Changed
@@ -1,34 +1,38 @@ libgudev_tests = { + 'test-gudevdevice': { + 'dependencies': gio_dep, libgudev_dep, + 'link_with': libgudev, + 'sources': '../gudev/gudevdevice.c', + 'include_directories': include_directories('../'), + }, 'test-enumerator-filter': { - 'dependencies': gio_dep, umockdev_dep, + 'dependencies': libgudev_dep, gio_dep, umockdev_dep, 'environment': 'LD_PRELOAD=libumockdev-preload.so.0', }, 'test-sysfsattr': { - 'dependencies': gio_dep, umockdev_dep, + 'dependencies': libgudev_dep, gio_dep, umockdev_dep, 'environment': 'LD_PRELOAD=libumockdev-preload.so.0', }, 'test-double': { - 'dependencies': gio_dep, umockdev_dep, + 'dependencies': libgudev_dep, gio_dep, umockdev_dep, 'environment': 'LD_PRELOAD=libumockdev-preload.so.0', 'LC_NUMERIC=fr_FR.UTF-8', }, } -libgudev_tests_deps = - libgudev_dep, - - foreach test_name, test_extras: libgudev_tests test_sources = '@0@.c'.format(test_name) - test_deps = libgudev_tests_deps - test_env = - test_deps += test_extras.get('dependencies', ) - test_env += test_extras.get('environment', ) + test_sources += test_extras.get('sources', ) + test_deps = test_extras.get('dependencies', ) + test_env = test_extras.get('environment', ) + test_include = test_extras.get('include_directories', ) test_exe = executable( test_name, test_sources, dependencies: test_deps, + include_directories: test_include, + c_args: '-D_GUDEV_COMPILATION' ) test(
View file
_service:tar_scm:libgudev-237.tar.xz/tests/test-double.c -> _service:tar_scm:libgudev-238.tar.xz/tests/test-double.c
Changed
@@ -16,18 +16,32 @@ #include <gudev/gudev.h> +#define GNU_SKIP_RETURNCODE 77 + +typedef struct { + UMockdevTestbed *testbed; +} Fixture; + static void -test_double (void) +fixture_setup (Fixture *f, G_GNUC_UNUSED const void *data) { - /* create test bed */ - UMockdevTestbed *testbed = umockdev_testbed_new (); + f->testbed = umockdev_testbed_new (); - /* Relies on a test bed having been set up */ g_assert (umockdev_in_mock_environment ()); +} +static void +fixture_teardown (Fixture *f, G_GNUC_UNUSED const void *data) +{ + g_clear_object (&f->testbed); +} + +static void +test_double (Fixture *f, G_GNUC_UNUSED const void *data) +{ g_assert_cmpstr (nl_langinfo(RADIXCHAR), ==, ","); - umockdev_testbed_add_device (testbed, "platform", "dev1", NULL, + umockdev_testbed_add_device (f->testbed, "platform", "dev1", NULL, "in_accel_scale", "0.0000098", NULL, "ID_MODEL", "KoolGadget", "SCALE", "0.0000098", NULL); @@ -54,10 +68,17 @@ int main(int argc, char **argv) { setlocale (LC_ALL, NULL); - setlocale (LC_NUMERIC, "fr_FR.UTF-8"); + + /* Skip if locale is unavailable */ + if (setlocale (LC_NUMERIC, "fr_FR.UTF-8") == NULL) + return GNU_SKIP_RETURNCODE; + g_test_init (&argc, &argv, NULL); - g_test_add_func ("/gudev/double", test_double); + g_test_add ("/gudev/double", Fixture, NULL, + fixture_setup, + test_double, + fixture_teardown); return g_test_run (); }
View file
_service:tar_scm:libgudev-237.tar.xz/tests/test-enumerator-filter.c -> _service:tar_scm:libgudev-238.tar.xz/tests/test-enumerator-filter.c
Changed
@@ -20,25 +20,37 @@ #include <gudev/gudev.h> +typedef struct { + UMockdevTestbed *testbed; +} Fixture; + static void -test_enumerator_filter (void) +fixture_setup (Fixture *f, G_GNUC_UNUSED const void *data) { - /* create test bed */ - UMockdevTestbed *testbed = umockdev_testbed_new (); + f->testbed = umockdev_testbed_new (); - /* Relies on a test bed having been set up */ g_assert (umockdev_in_mock_environment ()); +} + +static void +fixture_teardown (Fixture *f, G_GNUC_UNUSED const void *data) +{ + g_clear_object (&f->testbed); +} +static void +test_enumerator_filter (Fixture *f, G_GNUC_UNUSED const void *data) +{ /* Add 2 devices in the USB subsystem, and one in the DRM subsystem */ - umockdev_testbed_add_device (testbed, "usb", "dev1", NULL, + umockdev_testbed_add_device (f->testbed, "usb", "dev1", NULL, "idVendor", "0815", "idProduct", "AFFE", NULL, "ID_MODEL", "KoolGadget", NULL); - umockdev_testbed_add_device (testbed, "usb", "dev2", NULL, + umockdev_testbed_add_device (f->testbed, "usb", "dev2", NULL, "idVendor", "0815", "idProduct", "AFFF", NULL, "ID_MODEL", "KoolGadget 2", NULL); - umockdev_testbed_add_device (testbed, "drm", "dev3", NULL, + umockdev_testbed_add_device (f->testbed, "drm", "dev3", NULL, "ID_FOR_SEAT", "drm-pci-0000_00_02_0", NULL, NULL); @@ -66,7 +78,10 @@ setlocale (LC_ALL, NULL); g_test_init (&argc, &argv, NULL); - g_test_add_func ("/gudev/enumerator_filter", test_enumerator_filter); + g_test_add ("/gudev/enumerator_filter", Fixture, NULL, + fixture_setup, + test_enumerator_filter, + fixture_teardown); return g_test_run (); }
View file
_service:tar_scm:libgudev-238.tar.xz/tests/test-gudevdevice.c
Added
@@ -0,0 +1,61 @@ +/* + * SPDX-FileCopyrightText: 2022 Red Hat Inc. + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * Author: Benjamin Berg <bberg@redhat.com> + */ + +#include <locale.h> +#include <unistd.h> +#include <stdio.h> +#include <glib.h> +#include <gio/gio.h> + +#include <libudev.h> +#include "gudev/gudev.h" +#include "gudev/gudevprivate.h" + +static void +test_tags () +{ + const char *expected_tags = { "tag1", "tag2", "tag3", NULL }; + const char *expected_current_tags = { "tag2", "tag3", NULL }; + struct udev *udev = NULL; + struct udev_device *udev_device = NULL; + g_autoptr(GUdevDevice) dev = NULL; + + /* Push device information into environment. */ + g_setenv ("DEVPATH", "/devices/dev1", TRUE); + g_setenv ("SUBSYSTEM", "subsystem", TRUE); + g_setenv ("ACTION", "add", TRUE); + g_setenv ("SEQNUM", "1", TRUE); + g_setenv ("TAGS", "tag1:tag2:tag3", TRUE); + g_setenv ("CURRENT_TAGS", "tag2:tag3", TRUE); + g_setenv ("UDEV_DATABASE_VERSION", "1", TRUE); + + udev = udev_new (); + udev_device = udev_device_new_from_environment (udev); + g_message ("error is: %d, %m", errno); + g_message ("tags list entry form udev device %p: %p", udev_device, udev_device_get_tags_list_entry (udev_device)); + + dev = _g_udev_device_new (udev_device); + + g_assert_nonnull (g_udev_device_get_tags (dev)); + g_assert_cmpstrv (expected_tags, g_udev_device_get_tags (dev)); + + g_assert_nonnull (g_udev_device_get_current_tags (dev)); + g_assert_cmpstrv (expected_current_tags, g_udev_device_get_current_tags (dev)); + + g_clear_pointer (&udev, udev_unref); + g_clear_pointer (&udev_device, udev_device_unref); +} + +int main(int argc, char **argv) +{ + setlocale (LC_ALL, NULL); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/gudev/tags", test_tags); + + return g_test_run (); +}
View file
_service:tar_scm:libgudev-237.tar.xz/tests/test-sysfsattr.c -> _service:tar_scm:libgudev-238.tar.xz/tests/test-sysfsattr.c
Changed
@@ -15,55 +15,123 @@ #include <gudev/gudev.h> +typedef struct { + UMockdevTestbed *testbed; +} Fixture; + static void -test_uncached_sysfs_attr (void) +fixture_setup (Fixture *f, G_GNUC_UNUSED const void *data) { - /* create test bed */ - UMockdevTestbed *testbed = umockdev_testbed_new (); + f->testbed = umockdev_testbed_new (); - /* Relies on a test bed having been set up */ g_assert (umockdev_in_mock_environment ()); +} - umockdev_testbed_add_device (testbed, "platform", "dev1", NULL, - "dytc_lapmode", "1", "console", "Y\n", NULL, - "ID_MODEL", "KoolGadget", NULL); - - /* Check the number of items in GUdevClient */ - const gchar *subsystems = { "platform", NULL}; - GUdevClient *client = g_udev_client_new (subsystems); +static GUdevDevice* +create_single_dev (Fixture *f, const char *device) +{ + g_autoptr(GError) error = NULL; + g_autoptr(GUdevClient) client = NULL; + g_autolist(GUdevDevice) devices; GUdevDevice *dev; - g_autofree char *lapmode_path = NULL; - g_autofree char *console_path = NULL; - FILE *sysfsfp; - GList *devices = g_udev_client_query_by_subsystem (client, NULL); + if (!umockdev_testbed_add_from_string (f->testbed, device, &error)) + g_error ("Failed to add test device: %s", error->message); + + client = g_udev_client_new (NULL); + + devices = g_udev_client_query_by_subsystem (client, NULL); g_assert_cmpint (g_list_length (devices), ==, 1); + dev = devices->data; - lapmode_path = g_build_filename (g_udev_device_get_sysfs_path (dev), "dytc_lapmode", NULL); + devices = g_list_delete_link (devices, devices); + + return dev; +} + +static void +fixture_teardown (Fixture *f, G_GNUC_UNUSED const void *data) +{ + g_clear_object (&f->testbed); +} + +static void +write_sysfs_attr (GUdevDevice *dev, const char *attr, const char *value) +{ + g_autofree char *path = NULL; + FILE *sysfsfp; + + path = g_build_filename (g_udev_device_get_sysfs_path (dev), attr, NULL); + sysfsfp = fopen (path, "w"); + fwrite (value, strlen(value), 1, sysfsfp); + fclose (sysfsfp); +} + +static void +test_uncached_sysfs_attr (Fixture *f, G_GNUC_UNUSED const void *data) +{ + g_autoptr(GUdevDevice) dev = NULL; + + dev = create_single_dev (f, "P: /devices/dev1\n" + "E: SUBSYSTEM=platform\n" + "A: dytc_lapmode=1\n" + "A: console=Y\\n\n" + "E: ID_MODEL=KoolGadget"); + /* First access */ g_assert_true (g_udev_device_get_sysfs_attr_as_boolean (dev, "dytc_lapmode")); - sysfsfp = fopen (lapmode_path, "w"); - fprintf (sysfsfp, "%s\n", "0"); - fclose (sysfsfp); + g_assert_cmpstr (g_udev_device_get_sysfs_attr (dev, "dytc_lapmode"), ==, "1"); + write_sysfs_attr (dev, "dytc_lapmode", "0\n"); /* This is cached */ g_assert_true (g_udev_device_get_sysfs_attr_as_boolean (dev, "dytc_lapmode")); /* This is uncached, and updates the cache */ g_assert_false (g_udev_device_get_sysfs_attr_as_boolean_uncached (dev, "dytc_lapmode")); g_assert_false (g_udev_device_get_sysfs_attr_as_boolean (dev, "dytc_lapmode")); + g_assert_cmpstr (g_udev_device_get_sysfs_attr (dev, "dytc_lapmode"), ==, "0"); /* Test N/Y and trailing linefeeds */ g_assert_true (g_udev_device_get_sysfs_attr_as_boolean (dev, "console")); - console_path = g_build_filename (g_udev_device_get_sysfs_path (dev), "console", NULL); - sysfsfp = fopen (console_path, "w"); - fprintf (sysfsfp, "%s\n", "N"); - fclose (sysfsfp); + write_sysfs_attr (dev, "console", "N\n"); g_assert_false (g_udev_device_get_sysfs_attr_as_boolean_uncached (dev, "console")); - sysfsfp = fopen (console_path, "w"); - fprintf (sysfsfp, "%s\n", "Y"); - fclose (sysfsfp); + write_sysfs_attr (dev, "console", "Y"); g_assert_true (g_udev_device_get_sysfs_attr_as_boolean_uncached (dev, "console")); +} + +static void +test_sysfs_attr_keys (Fixture *f, G_GNUC_UNUSED const void *data) +{ + const char *expected = { "console", "dytc_lapmode", "subsystem", "uevent", NULL }; + g_autoptr(GUdevDevice) dev = NULL; - g_list_free_full (devices, g_object_unref); + dev = create_single_dev (f, "P: /devices/dev1\n" + "E: SUBSYSTEM=platform\n" + "A: dytc_lapmode=1\n" + "A: console=Y\\n\n" + "E: ID_MODEL=KoolGadget"); + + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_keys (dev), expected); +} + +static void +test_sysfs_attr_as_strv (Fixture *f, G_GNUC_UNUSED const void *data) +{ + const char *expected = { "1", "2", "3", "4", "5", "6", NULL }; + const char *empty = { NULL }; + g_autoptr(GUdevDevice) dev = NULL; + + dev = create_single_dev (f, "P: /devices/dev1\n" + "E: SUBSYSTEM=platform\n" + "A: test=1\\n2 3\\r4\\t5 \\t\\n6\n" + "E: ID_MODEL=KoolGadget"); + + /* Reading gives the expected result, even after updating the file */ + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv (dev, "test"), expected); + write_sysfs_attr (dev, "test", "\n"); + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv (dev, "test"), expected); + + /* _uncached variant gets the new content and updates the cache */ + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv_uncached (dev, "test"), empty); + g_assert_cmpstrv (g_udev_device_get_sysfs_attr_as_strv (dev, "test"), empty); } int main(int argc, char **argv) @@ -71,7 +139,20 @@ setlocale (LC_ALL, NULL); g_test_init (&argc, &argv, NULL); - g_test_add_func ("/gudev/uncached_sysfs_attr", test_uncached_sysfs_attr); + g_test_add ("/gudev/uncached_sysfs_attr", Fixture, NULL, + fixture_setup, + test_uncached_sysfs_attr, + fixture_teardown); + + g_test_add ("/gudev/sysfs_attr_keys", Fixture, NULL, + fixture_setup, + test_sysfs_attr_keys, + fixture_teardown); + + g_test_add ("/gudev/sysfs_attr_as_strv", Fixture, NULL, + fixture_setup, + test_sysfs_attr_as_strv, + fixture_teardown); return g_test_run (); }
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2