[PATCH libevdev] Actually filter by log priority
David Herrmann
dh.herrmann at gmail.com
Wed Feb 12 15:39:02 CET 2014
Hi
On Wed, Feb 12, 2014 at 6:07 AM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> If a message is higher than the current priority, filter it. And add a few
> tests that the priority is handled the way it should.
Reviewed-by: David Herrmann <dh.herrmann at gmail.com>
Thanks
David
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> libevdev/libevdev.c | 2 +-
> test/test-libevdev-init.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 77 insertions(+), 1 deletion(-)
>
> diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
> index cf532e3..142d6ad 100644
> --- a/libevdev/libevdev.c
> +++ b/libevdev/libevdev.c
> @@ -122,7 +122,7 @@ log_msg(enum libevdev_log_priority priority,
> {
> va_list args;
>
> - if (!log_data.handler)
> + if (!log_data.handler || priority > log_data.priority)
> return;
>
> va_start(args, format);
> diff --git a/test/test-libevdev-init.c b/test/test-libevdev-init.c
> index 6be3d74..c2c90a5 100644
> --- a/test/test-libevdev-init.c
> +++ b/test/test-libevdev-init.c
> @@ -120,6 +120,8 @@ START_TEST(test_log_init)
> {
> struct libevdev *dev = NULL;
>
> + libevdev_set_log_priority(LIBEVDEV_LOG_DEBUG);
> +
> libevdev_set_log_function(logfunc, NULL);
> libevdev_set_log_function(NULL, NULL);
>
> @@ -144,6 +146,77 @@ START_TEST(test_log_init)
> libevdev_free(dev);
>
> libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
> +
> + log_fn_called = 0;
> +}
> +END_TEST
> +
> +START_TEST(test_log_default_priority)
> +{
> + ck_assert_int_eq(libevdev_get_log_priority(), LIBEVDEV_LOG_INFO);
> +}
> +END_TEST
> +
> +START_TEST(test_log_set_get_priority)
> +{
> + enum libevdev_log_priority pri;
> +
> + pri = LIBEVDEV_LOG_DEBUG;
> + libevdev_set_log_priority(pri);
> + ck_assert_int_eq(libevdev_get_log_priority(), pri);
> +
> + pri = LIBEVDEV_LOG_INFO;
> + libevdev_set_log_priority(pri);
> + ck_assert_int_eq(libevdev_get_log_priority(), pri);
> +
> + pri = LIBEVDEV_LOG_ERROR;
> + libevdev_set_log_priority(pri);
> + ck_assert_int_eq(libevdev_get_log_priority(), pri);
> +
> + /* debug and above is clamped */
> + pri = LIBEVDEV_LOG_DEBUG + 1;
> + libevdev_set_log_priority(pri);
> + ck_assert_int_eq(libevdev_get_log_priority(), LIBEVDEV_LOG_DEBUG);
> +
> + /* error and below is not clamped, we need this for another test */
> + pri = LIBEVDEV_LOG_ERROR - 1;
> + libevdev_set_log_priority(pri);
> + ck_assert_int_eq(libevdev_get_log_priority(), pri);
> +}
> +END_TEST
> +
> +START_TEST(test_log_priority)
> +{
> + struct libevdev *dev = NULL;
> +
> + libevdev_set_log_function(logfunc, logdata);
> +
> + dev = libevdev_new();
> + ck_assert(dev != NULL);
> +
> + libevdev_set_log_priority(LIBEVDEV_LOG_DEBUG);
> + libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, NULL);
> + ck_assert_int_eq(log_fn_called, 1);
> +
> + libevdev_set_log_priority(LIBEVDEV_LOG_INFO);
> + libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, NULL);
> + ck_assert_int_eq(log_fn_called, 2);
> +
> + libevdev_set_log_priority(LIBEVDEV_LOG_ERROR);
> + libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, NULL);
> + ck_assert_int_eq(log_fn_called, 3);
> +
> + /* we don't have any log msgs > ERROR at the moment, so test it by
> + setting an invalid priority. */
> + libevdev_set_log_priority(LIBEVDEV_LOG_ERROR - 1);
> + libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, NULL);
> + ck_assert_int_eq(log_fn_called, 3);
> +
> + libevdev_free(dev);
> +
> + libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
> +
> + log_fn_called = 0;
> }
> END_TEST
>
> @@ -390,6 +463,9 @@ libevdev_init_test(void)
>
> tc = tcase_create("log init");
> tcase_add_test(tc, test_log_init);
> + tcase_add_test(tc, test_log_priority);
> + tcase_add_test(tc, test_log_set_get_priority);
> + tcase_add_test(tc, test_log_default_priority);
> tcase_add_test(tc, test_log_data);
> suite_add_tcase(s, tc);
>
> --
> 1.8.4.2
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools
More information about the Input-tools
mailing list