[Intel-gfx] [i-g-t PATCH v2 3/4] Convert shell script tests to C version

Chris Wilson chris at chris-wilson.co.uk
Mon May 29 13:00:27 UTC 2017


On Mon, May 29, 2017 at 03:08:09PM +0300, Abdiel Janulgue wrote:
> diff --git a/tests/debugfs.c b/tests/debugfs.c
> new file mode 100644
> index 0000000..fb33f9f
> --- /dev/null
> +++ b/tests/debugfs.c
> @@ -0,0 +1,97 @@
> +/*
> + * Copyright © 2017 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +#include "igt.h"
> +#include "igt_sysfs.h"
> +#include <fcntl.h>
> +#include <sys/types.h>
> +#include <dirent.h>
> +
> +igt_main
> +{
> +	int fd = -1, debugfs;
> +	igt_skip_on_simulation();
> +
> +	igt_fixture {
> +		fd = drm_open_driver_master(DRIVER_INTEL);
> +		igt_require_gem(fd);
> +		debugfs = igt_debugfs_dir(fd);
> +	}
> +
> +	igt_subtest_group {

What's the group for? It's very lonely.

> +		igt_subtest("emon_crash") {
> +			int i;
> +			/*
> +			 * This check if we can crash the kernel with
> +			 * segmentation-fault by reading
> +			 * /sys/kernel/debug/dri/0/i915_emon_status too quickly
> +			 */
> +			for (i = 0; i < 1; i++) {
> +				char *buf = igt_sysfs_get(debugfs,
> +							  "i915_emon_status");
> +				free(buf);
> +			}

This is covered by the later test to read it once. And if frequent
rereads is a trigger, apply it to all.

> +
> +			/* If we got here, we haven't crashed */
> +			igt_success();
> +		}
> +
> +		igt_subtest("wedged") {
> +			char *error;
> +			int dev;
> +
> +			/* wedge the hw to check the error_state reading */
> +			igt_sysfs_write(debugfs, "i915_error_state", "", 1);
> +
> +			dev = igt_debugfs_open(fd, "i915_wedged", O_WRONLY);
> +			igt_ignore_warn(write(dev, "1\n", 2));
> +			close(dev);
> +			/*
> +			 * Reading i915_error_state file explodes on a
> +			 * broken kernel
> +			 */
> +			error = igt_sysfs_get(debugfs, "i915_error_state");
> +			igt_assert(error);
> +			free(error);
> +			/* If we got here, we haven't crashed */
> +			igt_success();

This is drv_hangman/basic.

> +		}
> +
> +		igt_subtest("drv_reader") {
> +			struct dirent *dirent;
> +			DIR *dir;
> +
> +			igt_assert((dir = fdopendir(debugfs)) != NULL);
> +			while ((dirent = readdir(dir))) {
> +				char *buf = igt_sysfs_get(debugfs, dirent->d_name);
> +				free(buf);
> +			}
> +		}

Needs to descend through the debugfs directory.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the Intel-gfx mailing list