aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-01-27 12:55:51 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2017-03-01 00:09:28 +0400
commit072bdb07c5ef8b0351f9973ab5bba9e76be978a9 (patch)
tree8906bc08d789c2860c340c753dff5e506628fee2 /tests
parent461a86202214c9c3daf3222a9a655206874bd970 (diff)
downloadqemu-072bdb07c5ef8b0351f9973ab5bba9e76be978a9.zip
qemu-072bdb07c5ef8b0351f9973ab5bba9e76be978a9.tar.gz
qemu-072bdb07c5ef8b0351f9973ab5bba9e76be978a9.tar.bz2
tests: fix ptimer leaks
Spotted by ASAN. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ptimer-test-stubs.c5
-rw-r--r--tests/ptimer-test.c122
2 files changed, 80 insertions, 47 deletions
diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c
index 21d4ebb..8a1b0a3 100644
--- a/tests/ptimer-test-stubs.c
+++ b/tests/ptimer-test-stubs.c
@@ -108,6 +108,11 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
return bh;
}
+void qemu_bh_delete(QEMUBH *bh)
+{
+ g_free(bh);
+}
+
void replay_bh_schedule_event(QEMUBH *bh)
{
bh->cb(bh->opaque);
diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c
index b36a476..5d1a2a8 100644
--- a/tests/ptimer-test.c
+++ b/tests/ptimer-test.c
@@ -73,6 +73,7 @@ static void check_set_count(gconstpointer arg)
ptimer_set_count(ptimer, 1000);
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
g_assert_false(triggered);
+ ptimer_free(ptimer);
}
static void check_set_limit(gconstpointer arg)
@@ -92,6 +93,7 @@ static void check_set_limit(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
g_assert_false(triggered);
+ ptimer_free(ptimer);
}
static void check_oneshot(gconstpointer arg)
@@ -194,6 +196,7 @@ static void check_oneshot(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_false(triggered);
+ ptimer_free(ptimer);
}
static void check_periodic(gconstpointer arg)
@@ -360,6 +363,7 @@ static void check_periodic(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
g_assert_false(triggered);
+ ptimer_free(ptimer);
}
static void check_on_the_fly_mode_change(gconstpointer arg)
@@ -406,6 +410,7 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_true(triggered);
+ ptimer_free(ptimer);
}
static void check_on_the_fly_period_change(gconstpointer arg)
@@ -438,6 +443,7 @@ static void check_on_the_fly_period_change(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_true(triggered);
+ ptimer_free(ptimer);
}
static void check_on_the_fly_freq_change(gconstpointer arg)
@@ -470,6 +476,7 @@ static void check_on_the_fly_freq_change(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
g_assert_true(triggered);
+ ptimer_free(ptimer);
}
static void check_run_with_period_0(gconstpointer arg)
@@ -487,6 +494,7 @@ static void check_run_with_period_0(gconstpointer arg)
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
g_assert_false(triggered);
+ ptimer_free(ptimer);
}
static void check_run_with_delta_0(gconstpointer arg)
@@ -591,6 +599,7 @@ static void check_run_with_delta_0(gconstpointer arg)
g_assert_true(triggered);
ptimer_stop(ptimer);
+ ptimer_free(ptimer);
}
static void check_periodic_with_load_0(gconstpointer arg)
@@ -649,6 +658,7 @@ static void check_periodic_with_load_0(gconstpointer arg)
}
ptimer_stop(ptimer);
+ ptimer_free(ptimer);
}
static void check_oneshot_with_load_0(gconstpointer arg)
@@ -682,14 +692,14 @@ static void check_oneshot_with_load_0(gconstpointer arg)
} else {
g_assert_false(triggered);
}
+
+ ptimer_free(ptimer);
}
static void add_ptimer_tests(uint8_t policy)
{
- uint8_t *ppolicy = g_malloc(1);
- char *policy_name = g_malloc0(256);
-
- *ppolicy = policy;
+ char policy_name[256] = "";
+ char *tmp;
if (policy == PTIMER_POLICY_DEFAULT) {
g_sprintf(policy_name, "default");
@@ -715,49 +725,67 @@ static void add_ptimer_tests(uint8_t policy)
g_strlcat(policy_name, "no_counter_rounddown,", 256);
}
- g_test_add_data_func(
- g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
- ppolicy, check_set_count);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
- ppolicy, check_set_limit);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
- ppolicy, check_oneshot);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
- ppolicy, check_periodic);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s", policy_name),
- ppolicy, check_on_the_fly_mode_change);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s", policy_name),
- ppolicy, check_on_the_fly_period_change);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s", policy_name),
- ppolicy, check_on_the_fly_freq_change);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/run_with_period_0 policy=%s", policy_name),
- ppolicy, check_run_with_period_0);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/run_with_delta_0 policy=%s", policy_name),
- ppolicy, check_run_with_delta_0);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s", policy_name),
- ppolicy, check_periodic_with_load_0);
-
- g_test_add_data_func(
- g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s", policy_name),
- ppolicy, check_oneshot_with_load_0);
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
+ g_memdup(&policy, 1), check_set_count, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
+ g_memdup(&policy, 1), check_set_limit, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
+ g_memdup(&policy, 1), check_oneshot, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
+ g_memdup(&policy, 1), check_periodic, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_on_the_fly_mode_change, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_on_the_fly_period_change, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_on_the_fly_freq_change, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_run_with_period_0, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_run_with_delta_0, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_periodic_with_load_0, g_free);
+ g_free(tmp);
+
+ g_test_add_data_func_full(
+ tmp = g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
+ policy_name),
+ g_memdup(&policy, 1), check_oneshot_with_load_0, g_free);
+ g_free(tmp);
}
static void add_all_ptimer_policies_comb_tests(void)