mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-24 11:10:05 +01:00
test: sort-of autodetect whether we need root privileges
It's not really autodetection, we just declare the test suites that need root privs. But this way we can generically check for it from the main() that we re-use across tests. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
83ce8eb5be
commit
b642eddc31
6 changed files with 22 additions and 9 deletions
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <libevdev/libevdev.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
|
|
@ -31,17 +32,24 @@
|
|||
struct libevdev_test {
|
||||
const char *name;
|
||||
Suite* (*setup)(void);
|
||||
bool needs_root_privileges;
|
||||
} __attribute__((aligned(16)));
|
||||
|
||||
#define TEST_SUITE(name) \
|
||||
#define _TEST_SUITE(name, root_privs) \
|
||||
static Suite* (name##_setup)(void); \
|
||||
static const struct libevdev_test _test \
|
||||
__attribute__((used)) \
|
||||
__attribute__((section ("test_section"))) = { \
|
||||
#name, name##_setup \
|
||||
#name, name##_setup, root_privs \
|
||||
}; \
|
||||
static Suite* (name##_setup)(void)
|
||||
|
||||
#define TEST_SUITE(name) \
|
||||
_TEST_SUITE(name, false)
|
||||
|
||||
#define TEST_SUITE_ROOT_PRIVILEGES(name) \
|
||||
_TEST_SUITE(name, true)
|
||||
|
||||
#define TEST_DEVICE_NAME "libevdev test device"
|
||||
|
||||
#include "test-common-uinput.h"
|
||||
|
|
|
|||
|
|
@ -2140,7 +2140,7 @@ START_TEST(test_event_mt_value_setters_current_slot)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
TEST_SUITE(libevdev_events)
|
||||
TEST_SUITE_ROOT_PRIVILEGES(libevdev_events)
|
||||
{
|
||||
Suite *s = suite_create("libevdev event tests");
|
||||
|
||||
|
|
|
|||
|
|
@ -1142,7 +1142,7 @@ START_TEST(test_led_same)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
TEST_SUITE(has_events)
|
||||
TEST_SUITE_ROOT_PRIVILEGES(has_events)
|
||||
{
|
||||
Suite *s = suite_create("libevdev_has_event tests");
|
||||
|
||||
|
|
|
|||
|
|
@ -683,7 +683,7 @@ START_TEST(test_clock_id_events)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
TEST_SUITE(libevdev_init_test)
|
||||
TEST_SUITE_ROOT_PRIVILEGES(libevdev_init_test)
|
||||
{
|
||||
Suite *s = suite_create("libevdev init tests");
|
||||
|
||||
|
|
|
|||
|
|
@ -68,9 +68,14 @@ int main(void)
|
|||
const struct rlimit corelimit = {0, 0};
|
||||
int failed;
|
||||
|
||||
if (getuid() != 0) {
|
||||
fprintf(stderr, "This test needs to run as root\n");
|
||||
return 77;
|
||||
for (t = &__start_test_section; t < &__stop_test_section; t++) {
|
||||
if (t->needs_root_privileges) {
|
||||
if (getuid() != 0) {
|
||||
fprintf(stderr, "This test needs to run as root\n");
|
||||
return 77;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_debugger_attached())
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ START_TEST(test_uinput_properties)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
TEST_SUITE(uinput_suite)
|
||||
TEST_SUITE_ROOT_PRIVILEGES(uinput_suite)
|
||||
{
|
||||
Suite *s = suite_create("libevdev uinput device tests");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue