qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH 4/5] tests/test-arm-mptimer: Don't leak string memory
Date: Tue, 4 Dec 2018 18:08:33 +0100	[thread overview]
Message-ID: <4485390f-5c05-d9f8-b43b-c8811519e638@redhat.com> (raw)
In-Reply-To: <20181204132952.2601-5-peter.maydell@linaro.org>

On 4/12/18 14:29, Peter Maydell wrote:
> The test-arm-mptimer setup creates a lot of test names using
> g_strdup_printf() and never frees them. This is entirely
> harmless since it's one-shot test code, but it clutters
> up the output from clang's LeakSanitizer. Refactor to
> use a helper function so we can free the memory.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  tests/test-arm-mptimer.c | 153 ++++++++++++++++++---------------------
>  1 file changed, 69 insertions(+), 84 deletions(-)
> 
> diff --git a/tests/test-arm-mptimer.c b/tests/test-arm-mptimer.c
> index cb8f2df9141..156a39f50dd 100644
> --- a/tests/test-arm-mptimer.c
> +++ b/tests/test-arm-mptimer.c
> @@ -991,10 +991,25 @@ static void test_timer_zero_load_nonscaled_periodic_to_prescaled_oneshot(void)
>      g_assert_cmpuint(timer_get_and_clr_int_sts(), ==, 0);
>  }
>  
> +/*
> + * Add a qtest test that comes in two versions: one with
> + * a timer scaler setting, and one with the timer nonscaled.
> + */
> +static void add_scaler_test(const char *str, bool scale,
> +                            void (*fn)(const void *))
> +{
> +    char *name;
> +    int *scaler = scale ? &scaled : &nonscaled;
> +
> +    name = g_strdup_printf("%s=%d", str, *scaler);
> +    qtest_add_data_func(name, scaler, fn);
> +    g_free(name);
> +}
> +
>  int main(int argc, char **argv)
>  {
> -    int *scaler = &nonscaled;
>      int ret;
> +    int scale;
>  
>      g_test_init(&argc, &argv, NULL);
>  
> @@ -1012,89 +1027,59 @@ int main(int argc, char **argv)
>      qtest_add_func("mptimer/prescaler", test_timer_prescaler);
>      qtest_add_func("mptimer/prescaler_on_the_fly", test_timer_prescaler_on_the_fly);
>  
> -tests_with_prescaler_arg:
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/oneshot scaler=%d", *scaler),
> -                        scaler, test_timer_oneshot);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/pause scaler=%d", *scaler),
> -                        scaler, test_timer_pause);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/reload scaler=%d", *scaler),
> -                        scaler, test_timer_reload);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/periodic scaler=%d", *scaler),
> -                        scaler, test_timer_periodic);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/oneshot_to_periodic scaler=%d", *scaler),
> -                        scaler, test_timer_oneshot_to_periodic);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/periodic_to_oneshot scaler=%d", *scaler),
> -                        scaler, test_timer_periodic_to_oneshot);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_oneshot_counter_to_0 scaler=%d", *scaler),
> -                        scaler, test_timer_set_oneshot_counter_to_0);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_periodic_counter_to_0 scaler=%d", *scaler),
> -                        scaler, test_timer_set_periodic_counter_to_0);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/noload_oneshot scaler=%d", *scaler),
> -                        scaler, test_timer_noload_oneshot);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/noload_periodic scaler=%d", *scaler),
> -                        scaler, test_timer_noload_periodic);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/zero_load_oneshot scaler=%d", *scaler),
> -                        scaler, test_timer_zero_load_oneshot);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/zero_load_periodic scaler=%d", *scaler),
> -                        scaler, test_timer_zero_load_periodic);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/zero_load_oneshot_to_nonzero scaler=%d", *scaler),
> -                        scaler, test_timer_zero_load_oneshot_to_nonzero);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/zero_load_periodic_to_nonzero scaler=%d", *scaler),
> -                        scaler, test_timer_zero_load_periodic_to_nonzero);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/nonzero_load_oneshot_to_zero scaler=%d", *scaler),
> -                        scaler, test_timer_nonzero_load_oneshot_to_zero);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/nonzero_load_periodic_to_zero scaler=%d", *scaler),
> -                        scaler, test_timer_nonzero_load_periodic_to_zero);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_periodic_counter_on_the_fly scaler=%d", *scaler),
> -                        scaler, test_timer_set_periodic_counter_on_the_fly);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/enable_and_set_counter scaler=%d", *scaler),
> -                        scaler, test_timer_enable_and_set_counter);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_counter_and_enable scaler=%d", *scaler),
> -                        scaler, test_timer_set_counter_and_enable);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/oneshot_with_counter_0_on_start scaler=%d", *scaler),
> -                        scaler, test_timer_oneshot_with_counter_0_on_start);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/periodic_with_counter_0_on_start scaler=%d", *scaler),
> -                        scaler, test_timer_periodic_with_counter_0_on_start);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/periodic_counter scaler=%d", *scaler),
> -                        scaler, test_periodic_counter);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_counter_periodic_with_zero_load scaler=%d", *scaler),
> -                        scaler, test_timer_set_counter_periodic_with_zero_load);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_oneshot_load_to_0 scaler=%d", *scaler),
> -                        scaler, test_timer_set_oneshot_load_to_0);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/set_periodic_load_to_0 scaler=%d", *scaler),
> -                        scaler, test_timer_set_periodic_load_to_0);
> -    qtest_add_data_func(
> -        g_strdup_printf("mptimer/zero_load_mode_switch scaler=%d", *scaler),
> -                        scaler, test_timer_zero_load_mode_switch);
> -
> -    if (scaler == &nonscaled) {
> -        scaler = &scaled;
> -        goto tests_with_prescaler_arg;
> +    for (scale = 0; scale < 2; scale++) {
> +        add_scaler_test("mptimer/oneshot scaler",
> +                        scale, test_timer_oneshot);
> +        add_scaler_test("mptimer/pause scaler",
> +                        scale, test_timer_pause);
> +        add_scaler_test("mptimer/reload scaler",
> +                        scale, test_timer_reload);
> +        add_scaler_test("mptimer/periodic scaler",
> +                        scale, test_timer_periodic);
> +        add_scaler_test("mptimer/oneshot_to_periodic scaler",
> +                        scale, test_timer_oneshot_to_periodic);
> +        add_scaler_test("mptimer/periodic_to_oneshot scaler",
> +                        scale, test_timer_periodic_to_oneshot);
> +        add_scaler_test("mptimer/set_oneshot_counter_to_0 scaler",
> +                        scale, test_timer_set_oneshot_counter_to_0);
> +        add_scaler_test("mptimer/set_periodic_counter_to_0 scaler",
> +                        scale, test_timer_set_periodic_counter_to_0);
> +        add_scaler_test("mptimer/noload_oneshot scaler",
> +                        scale, test_timer_noload_oneshot);
> +        add_scaler_test("mptimer/noload_periodic scaler",
> +                        scale, test_timer_noload_periodic);
> +        add_scaler_test("mptimer/zero_load_oneshot scaler",
> +                        scale, test_timer_zero_load_oneshot);
> +        add_scaler_test("mptimer/zero_load_periodic scaler",
> +                        scale, test_timer_zero_load_periodic);
> +        add_scaler_test("mptimer/zero_load_oneshot_to_nonzero scaler",
> +                        scale, test_timer_zero_load_oneshot_to_nonzero);
> +        add_scaler_test("mptimer/zero_load_periodic_to_nonzero scaler",
> +                        scale, test_timer_zero_load_periodic_to_nonzero);
> +        add_scaler_test("mptimer/nonzero_load_oneshot_to_zero scaler",
> +                        scale, test_timer_nonzero_load_oneshot_to_zero);
> +        add_scaler_test("mptimer/nonzero_load_periodic_to_zero scaler",
> +                        scale, test_timer_nonzero_load_periodic_to_zero);
> +        add_scaler_test("mptimer/set_periodic_counter_on_the_fly scaler",
> +                        scale, test_timer_set_periodic_counter_on_the_fly);
> +        add_scaler_test("mptimer/enable_and_set_counter scaler",
> +                        scale, test_timer_enable_and_set_counter);
> +        add_scaler_test("mptimer/set_counter_and_enable scaler",
> +                        scale, test_timer_set_counter_and_enable);
> +        add_scaler_test("mptimer/oneshot_with_counter_0_on_start scaler",
> +                        scale, test_timer_oneshot_with_counter_0_on_start);
> +        add_scaler_test("mptimer/periodic_with_counter_0_on_start scaler",
> +                        scale, test_timer_periodic_with_counter_0_on_start);
> +        add_scaler_test("mptimer/periodic_counter scaler",
> +                        scale, test_periodic_counter);
> +        add_scaler_test("mptimer/set_counter_periodic_with_zero_load scaler",
> +                        scale, test_timer_set_counter_periodic_with_zero_load);
> +        add_scaler_test("mptimer/set_oneshot_load_to_0 scaler",
> +                        scale, test_timer_set_oneshot_load_to_0);
> +        add_scaler_test("mptimer/set_periodic_load_to_0 scaler",
> +                        scale, test_timer_set_periodic_load_to_0);
> +        add_scaler_test("mptimer/zero_load_mode_switch scaler",
> +                        scale, test_timer_zero_load_mode_switch);
>      }
>  
>      qtest_start("-machine vexpress-a9");
> 

  parent reply	other threads:[~2018-12-04 17:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-04 13:29 [Qemu-devel] [PATCH 0/5] arm: five simple memory leak fixes Peter Maydell
2018-12-04 13:29 ` [Qemu-devel] [PATCH 1/5] target/arm: Free name string in ARMCPRegInfo hashtable entries Peter Maydell
2018-12-04 13:57   ` Richard Henderson
2018-12-04 14:25   ` Philippe Mathieu-Daudé
2018-12-04 13:29 ` [Qemu-devel] [PATCH 2/5] hw/arm/mps2-tz.c: Free mscname string in make_dma() Peter Maydell
2018-12-04 13:57   ` Richard Henderson
2018-12-04 14:26   ` Philippe Mathieu-Daudé
2018-12-04 13:29 ` [Qemu-devel] [PATCH 3/5] hw/sd/sdhci: Don't leak memory region in sdhci_sysbus_realize() Peter Maydell
2018-12-04 13:58   ` Richard Henderson
2018-12-04 14:29   ` Philippe Mathieu-Daudé
2018-12-04 13:29 ` [Qemu-devel] [PATCH 4/5] tests/test-arm-mptimer: Don't leak string memory Peter Maydell
2018-12-04 14:00   ` Richard Henderson
2018-12-04 17:08   ` Philippe Mathieu-Daudé [this message]
2018-12-04 13:29 ` [Qemu-devel] [PATCH 5/5] target/arm: Create timers in realize, not init Peter Maydell
2018-12-04 14:01   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4485390f-5c05-d9f8-b43b-c8811519e638@redhat.com \
    --to=philmd@redhat.com \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).