tools/testing/selftests/net/tcp_ao/lib/ftrace.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_ao/lib/ftrace.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/tcp_ao/lib/ftrace.c
Extension
.c
Size
11911 bytes
Lines
544
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct test_ftracer {
	pthread_t tracer_thread;
	int	error;
	char	*instance_path;
	FILE	*trace_pipe;

	enum ftracer_op (*process_line)(const char *line);
	void (*destructor)(struct test_ftracer *tracer);
	bool (*expecting_more)(void);

	char	**saved_lines;
	size_t	saved_lines_size;
	size_t	next_line_ind;

	pthread_cond_t met_all_expected;
	pthread_mutex_t met_all_expected_lock;

	struct test_ftracer *next;
};

static struct test_ftracer *ftracers;
static pthread_mutex_t ftracers_lock = PTHREAD_MUTEX_INITIALIZER;

static int mount_ftrace(void)
{
	if (!mkdtemp(ftrace_path))
		test_error("Can't create temp dir");

	if (mount("tracefs", ftrace_path, "tracefs", 0, "rw"))
		return -errno;

	ftrace_mounted = true;

	return 0;
}

static void unmount_ftrace(void)
{
	if (ftrace_mounted && umount(ftrace_path))
		test_print("Failed on cleanup: can't unmount tracefs: %m");

	if (rmdir(ftrace_path))
		test_error("Failed on cleanup: can't remove ftrace dir %s",
			   ftrace_path);
}

struct opts_list_t {
	char *opt_name;
	struct opts_list_t *next;
};

static int disable_trace_options(const char *ftrace_path)
{
	struct opts_list_t *opts_list = NULL;
	char *fopts, *line = NULL;
	size_t buf_len = 0;
	ssize_t line_len;
	int ret = 0;
	FILE *opts;

	fopts = test_sprintf("%s/%s", ftrace_path, "trace_options");
	if (!fopts)
		return -ENOMEM;

	opts = fopen(fopts, "r+");
	if (!opts) {
		ret = -errno;
		goto out_free;
	}

	while ((line_len = getline(&line, &buf_len, opts)) != -1) {
		struct opts_list_t *tmp;

		if (!strncmp(line, "no", 2))
			continue;

		tmp = malloc(sizeof(*tmp));
		if (!tmp) {
			ret = -ENOMEM;
			goto out_free_opts_list;
		}
		tmp->next = opts_list;
		tmp->opt_name = test_sprintf("no%s", line);
		if (!tmp->opt_name) {
			ret = -ENOMEM;
			free(tmp);
			goto out_free_opts_list;
		}
		opts_list = tmp;
	}

Annotation

Implementation Notes