summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-10-11 05:15:10 (GMT)
committerJason Evans <jasone@canonware.com>2016-10-11 05:15:10 (GMT)
commit5f11fb7d43795e9e2f5d72c8a43a042baaee9b63 (patch)
tree24e3b4aeb23578b483b46f9804d0a6545aac5a8b /test
parentee0c74b77a24dc4fdaad2c950bcf621b6fa54095 (diff)
downloadjemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.zip
jemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.tar.gz
jemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.tar.bz2
Do not advance decay epoch when time goes backwards.
Instead, move the epoch backward in time. Additionally, add nstime_monotonic() and use it in debug builds to assert that time only goes backward if nstime_update() is using a non-monotonic time source.
Diffstat (limited to 'test')
-rw-r--r--test/unit/decay.c13
-rw-r--r--test/unit/nstime.c9
2 files changed, 20 insertions, 2 deletions
diff --git a/test/unit/decay.c b/test/unit/decay.c
index 592935d..b465a5a 100644
--- a/test/unit/decay.c
+++ b/test/unit/decay.c
@@ -2,6 +2,7 @@
const char *malloc_conf = "purge:decay,decay_time:1,lg_tcache_max:0";
+static nstime_monotonic_t *nstime_monotonic_orig;
static nstime_update_t *nstime_update_orig;
static unsigned nupdates_mock;
@@ -9,6 +10,13 @@ static nstime_t time_mock;
static bool nonmonotonic_mock;
static bool
+nstime_monotonic_mock(void)
+{
+
+ return (false);
+}
+
+static bool
nstime_update_mock(nstime_t *time)
{
@@ -315,7 +323,9 @@ TEST_BEGIN(test_decay_nonmonotonic)
nstime_update(&time_mock);
nonmonotonic_mock = true;
+ nstime_monotonic_orig = nstime_monotonic;
nstime_update_orig = nstime_update;
+ nstime_monotonic = nstime_monotonic_mock;
nstime_update = nstime_update_mock;
for (i = 0; i < NPS; i++) {
@@ -339,8 +349,9 @@ TEST_BEGIN(test_decay_nonmonotonic)
config_stats ? 0 : ENOENT, "Unexpected mallctl result");
if (config_stats)
- assert_u64_gt(npurge1, npurge0, "Expected purging to occur");
+ assert_u64_eq(npurge0, npurge1, "Unexpected purging occurred");
+ nstime_monotonic = nstime_monotonic_orig;
nstime_update = nstime_update_orig;
#undef NPS
}
diff --git a/test/unit/nstime.c b/test/unit/nstime.c
index cd7d9a6..0368bc2 100644
--- a/test/unit/nstime.c
+++ b/test/unit/nstime.c
@@ -176,6 +176,13 @@ TEST_BEGIN(test_nstime_divide)
}
TEST_END
+TEST_BEGIN(test_nstime_monotonic)
+{
+
+ nstime_monotonic();
+}
+TEST_END
+
TEST_BEGIN(test_nstime_update)
{
nstime_t nst;
@@ -198,7 +205,6 @@ TEST_BEGIN(test_nstime_update)
assert_d_eq(nstime_compare(&nst, &nst0), 0,
"Time should not have been modified");
}
-
}
TEST_END
@@ -216,5 +222,6 @@ main(void)
test_nstime_imultiply,
test_nstime_idivide,
test_nstime_divide,
+ test_nstime_monotonic,
test_nstime_update));
}