aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio G. Cota <cota@braap.org>2018-08-15 17:08:37 -0400
committerRichard Henderson <richard.henderson@linaro.org>2018-09-26 08:55:54 -0700
commit922034e776420082e89c0f7679cb1568086a1071 (patch)
tree0124ffbd278d21874e2edebfe93f9958be5de615
parent69d55e9cc28dc2f1e2f2426d2a43f2d10db76f29 (diff)
downloadqemu-922034e776420082e89c0f7679cb1568086a1071.zip
qemu-922034e776420082e89c0f7679cb1568086a1071.tar.gz
qemu-922034e776420082e89c0f7679cb1568086a1071.tar.bz2
test-qht: test qht_iter_remove
Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Emilio G. Cota <cota@braap.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
-rw-r--r--tests/test-qht.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/tests/test-qht.c b/tests/test-qht.c
index dda6a06..283fb3d 100644
--- a/tests/test-qht.c
+++ b/tests/test-qht.c
@@ -108,6 +108,49 @@ static void iter_check(unsigned int count)
g_assert_cmpuint(curr, ==, count);
}
+static void sum_func(struct qht *ht, void *p, uint32_t hash, void *userp)
+{
+ uint32_t *sum = userp;
+ uint32_t a = *(uint32_t *)p;
+
+ *sum += a;
+}
+
+static void iter_sum_check(unsigned int expected)
+{
+ unsigned int sum = 0;
+
+ qht_iter(&ht, sum_func, &sum);
+ g_assert_cmpuint(sum, ==, expected);
+}
+
+static bool rm_mod_func(struct qht *ht, void *p, uint32_t hash, void *userp)
+{
+ uint32_t a = *(uint32_t *)p;
+ unsigned int mod = *(unsigned int *)userp;
+
+ return a % mod == 0;
+}
+
+static void iter_rm_mod(unsigned int mod)
+{
+ qht_iter_remove(&ht, rm_mod_func, &mod);
+}
+
+static void iter_rm_mod_check(unsigned int mod)
+{
+ unsigned int expected = 0;
+ unsigned int i;
+
+ for (i = 0; i < N; i++) {
+ if (i % mod == 0) {
+ continue;
+ }
+ expected += i;
+ }
+ iter_sum_check(expected);
+}
+
static void qht_do_test(unsigned int mode, size_t init_entries)
{
/* under KVM we might fetch stats from an uninitialized qht */
@@ -138,8 +181,11 @@ static void qht_do_test(unsigned int mode, size_t init_entries)
insert(10, 150);
check_n(N);
- rm(1, 2);
- check_n(N - 1);
+ qht_reset(&ht);
+ insert(0, N);
+ iter_rm_mod(10);
+ iter_rm_mod_check(10);
+ check_n(N * 9 / 10);
qht_reset_size(&ht, 0);
check_n(0);
check(0, N, false);