1 /*
2  * testout.c
3  *
4  * Display routines for the libsysfs testsuite
5  *
6  * Copyright (C) IBM Corp. 2004-2005
7  *
8  *      This program is free software; you can redistribute it and/or modify it
9  *      under the terms of the GNU General Public License as published by the
10  *      Free Software Foundation version 2 of the License.
11  *
12  *      This program is distributed in the hope that it will be useful, but
13  *      WITHOUT ANY WARRANTY; without even the implied warranty of
14  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *      General Public License for more details.
16  *
17  *      You should have received a copy of the GNU General Public License along
18  *      with this program; if not, write to the Free Software Foundation, Inc.,
19  *      675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 
23 /**
24  * Display routines for test functions
25  */
26 
27 #include <test-defs.h>
28 
remove_end_newline(char * value)29 static void remove_end_newline(char *value)
30 {
31         char *p = value + (strlen(value) - 1);
32 
33         if (p != NULL && *p == '\n')
34                 *p = '\0';
35 }
36 
show_device(struct sysfs_device * device)37 void show_device(struct sysfs_device *device)
38 {
39 	if (device != NULL)
40 		dbg_print("Device is \"%s\" at \"%s\"\n",
41 				device->name, device->path);
42 }
43 
show_driver(struct sysfs_driver * driver)44 void show_driver(struct sysfs_driver *driver)
45 {
46 	if (driver != NULL)
47 		dbg_print("Driver is \"%s\" at \"%s\"\n",
48 				driver->name, driver->path);
49 }
50 
show_device_list(struct dlist * devlist)51 void show_device_list(struct dlist *devlist)
52 {
53 	if (devlist != NULL) {
54 		struct sysfs_device *dev = NULL;
55 
56 		dlist_for_each_data(devlist, dev, struct sysfs_device)
57 			show_device(dev);
58 	}
59 }
60 
show_driver_list(struct dlist * drvlist)61 void show_driver_list(struct dlist *drvlist)
62 {
63 	if (drvlist != NULL) {
64 		struct sysfs_driver *drv = NULL;
65 
66 		dlist_for_each_data(drvlist, drv, struct sysfs_driver)
67 			show_driver(drv);
68 	}
69 }
70 
show_attribute(struct sysfs_attribute * attr)71 void show_attribute(struct sysfs_attribute *attr)
72 {
73 	if (attr != NULL) {
74 		if (attr->value)
75 			remove_end_newline(attr->value);
76 		dbg_print("Attr \"%s\" at \"%s\" has a value \"%s\" \n",
77 				attr->name, attr->path, attr->value);
78 	}
79 }
80 
show_attribute_list(struct dlist * attrlist)81 void show_attribute_list(struct dlist *attrlist)
82 {
83 	if (attrlist != NULL) {
84 		struct sysfs_attribute *attr = NULL;
85 
86 		dlist_for_each_data(attrlist, attr, struct sysfs_attribute)
87 			show_attribute(attr);
88 	}
89 }
90 
show_class_device(struct sysfs_class_device * dev)91 void show_class_device(struct sysfs_class_device *dev)
92 {
93 	if (dev != NULL)
94 		dbg_print("Class device \"%s\" belongs to the \"%s\" class\n",
95 				dev->name, dev->classname);
96 }
97 
show_class_device_list(struct dlist * devlist)98 void show_class_device_list(struct dlist *devlist)
99 {
100 	if (devlist != NULL) {
101 		struct sysfs_class_device *dev = NULL;
102 
103 		dlist_for_each_data(devlist, dev, struct sysfs_class_device)
104 			show_class_device(dev);
105 	}
106 }
107 
show_list(struct dlist * list)108 void show_list(struct dlist *list)
109 {
110 	if (list != NULL) {
111 		char *name = NULL;
112 
113 		dlist_for_each_data(list, name, char)
114 			dbg_print("%s\n", name);
115 	}
116 }
117 
show_parm_list(struct dlist * list)118 void show_parm_list(struct dlist *list)
119 {
120  	if (list != NULL) {
121   		char *name = NULL;
122 
123 		dlist_for_each_data(list, name, char)
124  			dbg_print("%s\n", name);
125   	}
126 }
127 
show_section_list(struct dlist * list)128 void show_section_list(struct dlist *list)
129 {
130    	if (list != NULL) {
131     		char *name = NULL;
132 
133      		dlist_for_each_data(list, name, char)
134       			dbg_print("%s\n", name);
135        	}
136 }
137 
show_module(struct sysfs_module * module)138 void show_module(struct sysfs_module *module)
139 {
140 	if (module) {
141 		dbg_print("Module name is %s, path is %s\n",
142 				module->name, module->path);
143  		show_attribute_list(module->attrlist);
144   		show_parm_list(module->parmlist);
145    		show_section_list(module->sections);
146     	}
147 }
148