summaryrefslogtreecommitdiff
path: root/test/testout.c
blob: 547f9d8405c701f0356cf776b848b96afb5e3aad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * testout.c
 *
 * Display routines for the libsysfs testsuite
 *
 * Copyright (C) IBM Corp. 2004
 *
 *      This program is free software; you can redistribute it and/or modify it
 *      under the terms of the GNU General Public License as published by the
 *      Free Software Foundation version 2 of the License.
 *
 *      This program is distributed in the hope that it will be useful, but
 *      WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *      General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License along
 *      with this program; if not, write to the Free Software Foundation, Inc.,
 *      675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/**
 * Display routines for test functions
 */ 

#include <test-defs.h>

static void remove_end_newline(char *value)
{
        char *p = value + (strlen(value) - 1);

        if (p != NULL && *p == '\n')
                *p = '\0';
}

void show_device(struct sysfs_device *device)
{
	if (device != NULL)
		dbg_print("Device is \"%s\" at \"%s\"\n", 
				device->name, device->path);
}

void show_driver(struct sysfs_driver *driver)
{
	if (driver != NULL)
		dbg_print("Driver is \"%s\" at \"%s\"\n", 
				driver->name, driver->path);
}

void show_device_list(struct dlist *devlist)
{
	if (devlist != NULL) {
		struct sysfs_device *dev = NULL;
		
		dlist_for_each_data(devlist, dev, struct sysfs_device)
			show_device(dev);
	}
}

void show_driver_list(struct dlist *drvlist)
{
	if (drvlist != NULL) {
		struct sysfs_driver *drv = NULL;
		
		dlist_for_each_data(drvlist, drv, struct sysfs_driver)
			show_driver(drv);
	}
}

void show_root_device(struct sysfs_root_device *root)
{
	if (root != NULL)
		dbg_print("Device is \"%s\" at \"%s\"\n", 
				root->name, root->path);
}

void show_attribute(struct sysfs_attribute *attr)
{
	if (attr != NULL) {
		if (attr->value)
			remove_end_newline(attr->value);
		dbg_print("Attr \"%s\" at \"%s\" has a value \"%s\" \n",
				attr->name, attr->path, attr->value);
	}
}

void show_attribute_list(struct dlist *attrlist)
{
	if (attrlist != NULL) {
		struct sysfs_attribute *attr = NULL;
		
		dlist_for_each_data(attrlist, attr, struct sysfs_attribute)
			show_attribute(attr);
	}
}

void show_link(struct sysfs_link *ln)
{
	if (ln != NULL) 
		dbg_print("Link at \"%s\" points to \"%s\"\n",
				ln->path, ln->target);
}

void show_links_list(struct dlist *linklist)
{
	if (linklist != NULL) {
		struct sysfs_link *ln = NULL;
		
		dlist_for_each_data(linklist, ln, struct sysfs_link)
			show_link(ln);
	}
}

void show_dir(struct sysfs_directory *dir)
{
	if (dir != NULL)
		dbg_print("Directory \"%s\" is at \"%s\"\n",
				dir->name, dir->path);
}

void show_dir_list(struct dlist *dirlist)
{
	if (dirlist != NULL) {
		struct sysfs_directory *dir = NULL;

		dlist_for_each_data(dirlist, dir, struct sysfs_directory)
			show_dir(dir);
	}
}

void show_directory(struct sysfs_directory *dir)
{
	if (dir != NULL) {
		show_dir(dir);
		
		if (dir->attributes)
			show_attribute_list(dir->attributes);
		if (dir->links)
			show_links_list(dir->links);
		if (dir->subdirs)
			show_dir_list(dir->subdirs);
	}
}

void show_dir_tree(struct sysfs_directory *dir)
{
	if (dir != NULL) {
		struct sysfs_directory *subdir = NULL;

		if (dir->subdirs) {
			dlist_for_each_data(dir->subdirs, subdir,
						struct sysfs_directory) {
				show_dir(subdir);
				show_dir_tree(subdir);
			}
		}
	}
}
		
void show_class_device(struct sysfs_class_device *dev)
{
	if (dev != NULL)
		dbg_print("Class device \"%s\" belongs to the \"%s\" class\n",
				dev->name, dev->classname);
}

void show_class_device_list(struct dlist *devlist)
{
	if (devlist != NULL) {
		struct sysfs_class_device *dev = NULL;
		
		dlist_for_each_data(devlist, dev, struct sysfs_class_device)
			show_class_device(dev);
	}
}

void show_list(struct dlist *list)
{
	if (list != NULL) {
		char *name = NULL;
		
		dlist_for_each_data(list, name, char)
			dbg_print("%s\n", name);
	}
}