[PATCH v4 4/4] tests: check status qualifier

Dmitry V. Levin ldv at altlinux.org
Tue Jun 18 11:32:27 UTC 2019


On Sat, Jun 15, 2019 at 07:33:44PM +0200, Paul Chaignon wrote:
[...]
> diff --git a/tests/status-all.c b/tests/status-all.c
> new file mode 100644
> index 00000000..1b23c622
> --- /dev/null
> +++ b/tests/status-all.c
> @@ -0,0 +1,29 @@
> +/*
> + * Check status filtering for failed and successful syscalls.
> + *
> + * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "tests.h"
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	static const char sample_valid[] = ".";
> +	long rc = chdir(sample_valid);
> +	printf("chdir(\"%s\") = %s\n", sample_valid, sprintrc(rc));
> +
> +	static const char sample_invalid[] = "";
> +	rc = chdir(sample_invalid);
> +	printf("chdir(\"%s\")  = %s\n", sample_invalid, sprintrc(rc));
> +
> +	puts("+++ exited with 0 +++");
> +	return 0;
> +}
> diff --git a/tests/status-failed.c b/tests/status-failed.c
> new file mode 100644
> index 00000000..874d6576
> --- /dev/null
> +++ b/tests/status-failed.c
> @@ -0,0 +1,33 @@
> +/*
> + * Check status filtering for failed and successful syscalls.
> + *
> + * Copyright (c) 2019 Intel Corporation
> + * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "tests.h"
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	static const char sample_valid[] = ".";
> +	long rc = chdir(sample_valid);
> +	if (rc == -1)
> +		printf("chdir(\"%s\") = %s\n",
> +			sample_valid, sprintrc(rc));
> +
> +	static const char sample_invalid[] = "";
> +	rc = chdir(sample_invalid);
> +	if (rc == -1)
> +		printf("chdir(\"%s\") = %s\n",
> +			sample_invalid, sprintrc(rc));
> +
> +	puts("+++ exited with 0 +++");
> +	return 0;
> +}
> diff --git a/tests/status-successful.c b/tests/status-successful.c
> new file mode 100644
> index 00000000..826cf87d
> --- /dev/null
> +++ b/tests/status-successful.c
> @@ -0,0 +1,33 @@
> +/*
> + * Check status filtering for failed and successful syscalls.
> + *
> + * Copyright (c) 2019 Intel Corporation
> + * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "tests.h"
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +int
> +main(void)
> +{
> +	static const char sample_valid[] = ".";
> +	long rc = chdir(sample_valid);
> +	if (rc != -1)
> +		printf("chdir(\"%s\") = %s\n",
> +			sample_valid, sprintrc(rc));
> +
> +	static const char sample_invalid[] = "";
> +	rc = chdir(sample_invalid);
> +	if (rc != -1)
> +		printf("chdir(\"%s\") = %s\n",
> +			sample_invalid, sprintrc(rc));
> +
> +	puts("+++ exited with 0 +++");
> +	return 0;
> +}

I think this code duplication can be reduced by creating a common
function, e.g. test_status(bool print_successful, bool print_failed),
and invoking it in these tree tests.

Further de-duplication can be achieved using another helper function, e.g.
static void
test_status_chdir(const char *dir, bool print_successful, bool print_failed)
{
	long rc = chdir(dir);
	if (rc == -1 && print_failed ||
	    rc != -1 && print_successful)
		printf("chdir(\"%s\") = %s\n", dir, sprintrc(rc));
}


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20190618/a6286898/attachment.bin>


More information about the Strace-devel mailing list