]> git.ipfire.org Git - thirdparty/kmod.git/blobdiff - testsuite/test-util.c
treewide: add some static const notations
[thirdparty/kmod.git] / testsuite / test-util.c
index 5e25e587d69bdc4e0dd8f00f37bfb3405f770e3f..e3243e8bc6a2c6935310d2ba5e475149edda36dd 100644 (file)
@@ -31,7 +31,7 @@
 
 static int alias_1(const struct test *t)
 {
-       static const char *input[] = {
+       static const char *const input[] = {
                "test1234",
                "test[abcfoobar]2211",
                "bar[aaa][bbbb]sss",
@@ -42,7 +42,7 @@ static int alias_1(const struct test *t)
 
        char buf[PATH_MAX];
        size_t len;
-       const char **alias;
+       const char *const *alias;
 
        for (alias = input; *alias != NULL; alias++) {
                int ret;
@@ -156,6 +156,9 @@ static int test_path_ends_with_kmod_ext(const struct test *t)
 #endif
 #ifdef ENABLE_XZ
                { "/bla.ko.xz", true },
+#endif
+#ifdef ENABLE_ZSTD
+               { "/bla.ko.zst", true },
 #endif
                { "/bla.ko.x", false },
                { "/bla.ko.", false },
@@ -226,4 +229,45 @@ DEFINE_TEST(test_addu64_overflow,
        );
 
 
+static int test_backoff_time(const struct test *t)
+{
+       unsigned long long delta = 0;
+
+       /* Check exponential increments */
+       get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+       assert_return(delta == 1, EXIT_FAILURE);
+       get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+       assert_return(delta == 2, EXIT_FAILURE);
+       get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+       assert_return(delta == 4, EXIT_FAILURE);
+       get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta);
+       assert_return(delta == 8, EXIT_FAILURE);
+
+       {
+               unsigned long long t0, tend;
+
+               /* Check tail */
+               delta = 4;
+               tend = now_msec() + 3;
+               t0 = tend - 10;
+               get_backoff_delta_msec(t0, tend, &delta);
+               assert_return(delta == 2, EXIT_FAILURE);
+               tend = now_msec() + 1;
+               t0 = tend - 9;
+               get_backoff_delta_msec(t0, tend, &delta);
+               assert_return(delta == 1, EXIT_FAILURE);
+               tend = now_msec();
+               t0 = tend - 10;
+               get_backoff_delta_msec(t0, tend, &delta);
+               assert_return(delta == 0, EXIT_FAILURE);
+       }
+
+       return EXIT_SUCCESS;
+}
+DEFINE_TEST(test_backoff_time,
+       .description = "check implementation of get_backoff_delta_msec()",
+       .need_spawn = false,
+       );
+
+
 TESTSUITE_MAIN();