#include <libkmod.h>
#include <libudev.h>
#include <pthread.h>
+#include <regex.h>
#include <sys/time.h>
#include <sys/utsname.h>
#include <sys/types.h>
event_unlock();
}
+
+bool test_regex_match(const char *str, const char *pattern)
+{
+ char errbuf[128];
+ regex_t regex;
+ bool ret;
+ int rv;
+
+ rv = regcomp(®ex, pattern, REG_EXTENDED | REG_NEWLINE);
+ if (rv) {
+ regerror(rv, ®ex, errbuf, sizeof(errbuf));
+ die("unable to compile regex '%s': %s", pattern, errbuf);
+ }
+
+ rv = regexec(®ex, str, 0, 0, 0);
+ if (rv == REG_NOERROR) {
+ ret = true;
+ } else if (rv == REG_NOMATCH) {
+ ret = false;
+ } else {
+ regerror(rv, ®ex, errbuf, sizeof(errbuf));
+ die("unable to run a regex match: %s", errbuf);
+ }
+
+ regfree(®ex);
+
+ return ret;
+}
void test_free_chip_iter(struct gpiod_chip_iter **iter);
void test_free_chip_iter_noclose(struct gpiod_chip_iter **iter);
+bool test_regex_match(const char *str, const char *pattern);
+
#define TEST_ASSERT(statement) \
do { \
if (!(statement)) { \
#define TEST_ASSERT_NOTEQ(a1, a2) TEST_ASSERT(a1 != a2)
#define TEST_ASSERT_STR_EQ(s1, s2) TEST_ASSERT(strcmp(s1, s2) == 0)
#define TEST_ASSERT_STR_CONTAINS(s, p) TEST_ASSERT(strstr(s, p) != NULL)
+#define TEST_ASSERT_REGEX_MATCH(s, p) TEST_ASSERT(test_regex_match(s, p))
#endif /* __GPIOD_TEST_H__ */