[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 3/3] tests/migration:fix unreachable path in stress test
From: |
Laurent Vivier |
Subject: |
Re: [PATCH v3 3/3] tests/migration:fix unreachable path in stress test |
Date: |
Fri, 4 Oct 2019 09:20:44 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 |
Le 04/10/2019 à 05:43, Mao Zhongyi a écrit :
> If stressone() or stress() exits it's because of a failure
> because the test runs forever otherwise, so change stressone
> type to void and stress should always return -1 to make the
> path of 'if (stress(ramsizeGB, ncpus) < 0)' can be reached.
>
> Signed-off-by: Mao Zhongyi <address@hidden>
> ---
> tests/migration/stress.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index debf34359f..b0df1323bb 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -167,7 +167,7 @@ static unsigned long long now(void)
> return (tv.tv_sec * 1000ull) + (tv.tv_usec / 1000ull);
> }
>
> -static int stressone(unsigned long long ramsizeMB)
> +static void stressone(unsigned long long ramsizeMB)
> {
> size_t pagesPerMB = 1024 * 1024 / PAGE_SIZE;
> g_autofree char *ram = g_malloc(ramsizeMB * 1024 * 1024);
> @@ -181,12 +181,12 @@ static int stressone(unsigned long long ramsizeMB)
> if (!ram) {
> fprintf(stderr, "%s (%05d): ERROR: cannot allocate %llu MB of RAM:
> %s\n",
> argv0, gettid(), ramsizeMB, strerror(errno));
> - return -1;
> + return;
> }
> if (!data) {
> fprintf(stderr, "%s (%d): ERROR: cannot allocate %d bytes of RAM:
> %s\n",
> argv0, gettid(), PAGE_SIZE, strerror(errno));
> - return -1;
> + return;
> }
Thanks to the g_malloc() you can remove this two "if () { }" blocks.
>
> /* We don't care about initial state, but we do want
> @@ -197,7 +197,7 @@ static int stressone(unsigned long long ramsizeMB)
> memset(ram, 0xfe, ramsizeMB * 1024 * 1024);
>
> if (random_bytes(data, PAGE_SIZE) < 0) {
> - return -1;
> + return;
> }
>
> before = now();
> @@ -250,7 +250,7 @@ static int stress(unsigned long long ramsizeGB, int ncpus)
you can change it to "void" too
>
> stressone(ramsizeMB);
>
> - return 0;
> + return -1;
> }
>
>
> @@ -348,6 +348,4 @@ int main(int argc, char **argv)
>
> if (stress(ramsizeGB, ncpus) < 0)
As it exits only on failure, you can remove the "if"
> exit_failure();
> -
> - exit_success();
and always use exit_failure().
> }
>