]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
util: Add time-related functions from testsuite
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 3 Jun 2022 21:50:43 +0000 (14:50 -0700)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Mon, 27 Jun 2022 06:23:46 +0000 (23:23 -0700)
This will be useful in future not only to testsuite, but also to tools
and library.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/util.c
shared/util.h
testsuite/testsuite.c

index b487b5f5d44b196bfadc3354daea5949861537e5..aeb171f18ed42879cf8dc8b66f857fa58f9db0d9 100644 (file)
@@ -466,6 +466,16 @@ unsigned long long ts_usec(const struct timespec *ts)
               (unsigned long long) ts->tv_nsec / NSEC_PER_USEC;
 }
 
+unsigned long long now_usec(void)
+{
+       struct timespec ts;
+
+       if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+               return 0;
+
+       return ts_usec(&ts);
+}
+
 unsigned long long stat_mstamp(const struct stat *st)
 {
 #ifdef HAVE_STRUCT_STAT_ST_MTIM
index c6a31dfb205ab162730db8ba2fd051b09aa4faf7..734a5234774fb7cf0d3c5aa68dcafc0a1435c5d6 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <time.h>
 
 #include <shared/macro.h>
 
@@ -42,7 +43,14 @@ char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull(
 int mkdir_p(const char *path, int len, mode_t mode);
 int mkdir_parents(const char *path, mode_t mode);
 unsigned long long stat_mstamp(const struct stat *st);
+
+/* time-related functions
+ * ************************************************************************ */
+#define USEC_PER_SEC   1000000ULL
+#define USEC_PER_MSEC  1000ULL
+
 unsigned long long ts_usec(const struct timespec *ts);
+unsigned long long now_usec(void);
 
 /* endianess and alignments                                                 */
 /* ************************************************************************ */
index 05df5538079a309212110522bf0a9f687ca7d215..6a2d29672ab3e29c63c2506107138ed0be5efb16 100644 (file)
@@ -51,6 +51,7 @@ static const struct option options[] = {
 };
 
 #define OVERRIDE_LIBDIR ABS_TOP_BUILDDIR "/testsuite/.libs/"
+#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC
 
 struct _env_config {
        const char *key;
@@ -62,19 +63,6 @@ struct _env_config {
        [TC_DELETE_MODULE_RETCODES] = { S_TC_DELETE_MODULE_RETCODES, OVERRIDE_LIBDIR "delete_module.so" },
 };
 
-#define USEC_PER_SEC  1000000ULL
-#define USEC_PER_MSEC  1000ULL
-#define TEST_TIMEOUT_USEC 2 * USEC_PER_SEC
-static unsigned long long now_usec(void)
-{
-       struct timespec ts;
-
-       if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
-               return 0;
-
-       return ts_usec(&ts);
-}
-
 static void help(void)
 {
        const struct option *itr;