diff options
author | Alan Brault <alan.brault@incruentatus.net> | 2010-12-06 19:51:27 -0500 |
---|---|---|
committer | Alan Brault <alan.brault@incruentatus.net> | 2010-12-06 19:51:27 -0500 |
commit | 5cd0319f34e5f7bcfd867d4a3a3d2707727b4757 (patch) | |
tree | 1680e6e6d1c3d8fa0d9a2062ed4599b961b174d1 /sysfsutils/test | |
parent | 4507e17c12b952c02160ec30a16df66b8c9cf10d (diff) | |
download | NetNuke2-5cd0319f34e5f7bcfd867d4a3a3d2707727b4757.tar.gz |
Bundle sysfsutils for portability reasons
Diffstat (limited to 'sysfsutils/test')
-rw-r--r-- | sysfsutils/test/CVS/Entries | 20 | ||||
-rw-r--r-- | sysfsutils/test/CVS/Repository | 1 | ||||
-rw-r--r-- | sysfsutils/test/CVS/Root | 1 | ||||
-rw-r--r-- | sysfsutils/test/CVS/Tag | 1 | ||||
-rw-r--r-- | sysfsutils/test/GPL | 272 | ||||
-rw-r--r-- | sysfsutils/test/Makefile.am | 16 | ||||
-rw-r--r-- | sysfsutils/test/Makefile.in | 494 | ||||
-rwxr-xr-x | sysfsutils/test/create-test | 42 | ||||
-rw-r--r-- | sysfsutils/test/dlist_test.c | 329 | ||||
-rw-r--r-- | sysfsutils/test/get_device.c | 58 | ||||
-rw-r--r-- | sysfsutils/test/get_driver.c | 86 | ||||
-rw-r--r-- | sysfsutils/test/get_module.c | 71 | ||||
-rw-r--r-- | sysfsutils/test/libsysfs.conf | 87 | ||||
-rw-r--r-- | sysfsutils/test/test-defs.h | 125 | ||||
-rw-r--r-- | sysfsutils/test/test.c | 327 | ||||
-rw-r--r-- | sysfsutils/test/test_attr.c | 318 | ||||
-rw-r--r-- | sysfsutils/test/test_bus.c | 460 | ||||
-rw-r--r-- | sysfsutils/test/test_class.c | 799 | ||||
-rw-r--r-- | sysfsutils/test/test_device.c | 459 | ||||
-rw-r--r-- | sysfsutils/test/test_driver.c | 478 | ||||
-rw-r--r-- | sysfsutils/test/test_module.c | 711 | ||||
-rw-r--r-- | sysfsutils/test/test_utils.c | 628 | ||||
-rw-r--r-- | sysfsutils/test/testout.c | 147 |
23 files changed, 5930 insertions, 0 deletions
diff --git a/sysfsutils/test/CVS/Entries b/sysfsutils/test/CVS/Entries new file mode 100644 index 0000000..ea94151 --- /dev/null +++ b/sysfsutils/test/CVS/Entries @@ -0,0 +1,20 @@ +/GPL/1.2/Wed Apr 6 20:57:12 2005//Tsysfsutils-2_1_0 +/Makefile.am/1.3.2.4.4.1/Wed Aug 23 07:37:02 2006//Tsysfsutils-2_1_0 +/Makefile.in/1.3.2.4/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/create-test/1.2.2.1/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/dlist_test.c/1.3.2.3/Fri Nov 25 14:06:05 2005//Tsysfsutils-2_1_0 +/get_device.c/1.2.2.3/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/get_driver.c/1.2.2.3/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/get_module.c/1.1.2.1/Tue May 3 22:29:10 2005//Tsysfsutils-2_1_0 +/libsysfs.conf/1.2.2.2/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/test-defs.h/1.2.2.4/Mon Aug 7 05:08:02 2006//Tsysfsutils-2_1_0 +/test.c/1.2.2.4/Mon Aug 7 05:08:02 2006//Tsysfsutils-2_1_0 +/test_attr.c/1.1.2.1/Mon Nov 28 10:25:27 2005//Tsysfsutils-2_1_0 +/test_bus.c/1.2.2.3/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/test_class.c/1.2.2.3/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +/test_device.c/1.1.2.1/Mon Nov 28 10:25:27 2005//Tsysfsutils-2_1_0 +/test_driver.c/1.2.2.4/Mon Dec 5 07:06:03 2005//Tsysfsutils-2_1_0 +/test_module.c/1.1.2.2/Mon Dec 5 07:06:03 2005//Tsysfsutils-2_1_0 +/test_utils.c/1.2.2.4/Mon Aug 7 05:08:02 2006//Tsysfsutils-2_1_0 +/testout.c/1.2.2.3/Mon Nov 28 10:22:10 2005//Tsysfsutils-2_1_0 +D diff --git a/sysfsutils/test/CVS/Repository b/sysfsutils/test/CVS/Repository new file mode 100644 index 0000000..3d63d49 --- /dev/null +++ b/sysfsutils/test/CVS/Repository @@ -0,0 +1 @@ +sysfsutils/test diff --git a/sysfsutils/test/CVS/Root b/sysfsutils/test/CVS/Root new file mode 100644 index 0000000..d5dff2a --- /dev/null +++ b/sysfsutils/test/CVS/Root @@ -0,0 +1 @@ +:ext:mohanltc@linux-diag.cvs.sourceforge.net:/cvsroot/linux-diag diff --git a/sysfsutils/test/CVS/Tag b/sysfsutils/test/CVS/Tag new file mode 100644 index 0000000..450247d --- /dev/null +++ b/sysfsutils/test/CVS/Tag @@ -0,0 +1 @@ +Tsysfsutils-2_1_0 diff --git a/sysfsutils/test/GPL b/sysfsutils/test/GPL new file mode 100644 index 0000000..cde4efd --- /dev/null +++ b/sysfsutils/test/GPL @@ -0,0 +1,272 @@ + + The GNU General Public License (GPL) + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your freedom to + share and change it. By contrast, the GNU General Public License is + intended to guarantee your freedom to share and change free software--to + make sure the software is free for all its users. This General Public + License applies to most of the Free Software Foundation's software and to + any other program whose authors commit to using it. (Some other Free + Software Foundation software is covered by the GNU Library General Public + License instead.) You can apply it to your programs, too. + + When we speak of free software, we are referring to freedom, not price. + Our General Public Licenses are designed to make sure that you have the + freedom to distribute copies of free software (and charge for this service + if you wish), that you receive source code or can get it if you want it, + that you can change the software or use pieces of it in new free programs; + and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid anyone to + deny you these rights or to ask you to surrender the rights. These + restrictions translate to certain responsibilities for you if you + distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether gratis or + for a fee, you must give the recipients all the rights that you have. You + must make sure that they, too, receive or can get the source code. And you + must show them these terms so they know their rights. + + We protect your rights with two steps: (1) copyright the software, and (2) + offer you this license which gives you legal permission to copy, + distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain that + everyone understands that there is no warranty for this free software. If + the software is modified by someone else and passed on, we want its + recipients to know that what they have is not the original, so that any + problems introduced by others will not reflect on the original authors' + reputations. + + Finally, any free program is threatened constantly by software patents. We + wish to avoid the danger that redistributors of a free program will + individually obtain patent licenses, in effect making the program + proprietary. To prevent this, we have made it clear that any patent must + be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and + modification follow. + + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains a + notice placed by the copyright holder saying it may be distributed under + the terms of this General Public License. The "Program", below, refers to + any such program or work, and a "work based on the Program" means either + the Program or any derivative work under copyright law: that is to say, a + work containing the Program or a portion of it, either verbatim or with + modifications and/or translated into another language. (Hereinafter, + translation is included without limitation in the term "modification".) + Each licensee is addressed as "you". + + Activities other than copying, distribution and modification are not + covered by this License; they are outside its scope. The act of running + the Program is not restricted, and the output from the Program is covered + only if its contents constitute a work based on the Program (independent + of having been made by running the Program). Whether that is true depends + on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's source + code as you receive it, in any medium, provided that you conspicuously and + appropriately publish on each copy an appropriate copyright notice and + disclaimer of warranty; keep intact all the notices that refer to this + License and to the absence of any warranty; and give any other recipients + of the Program a copy of this License along with the Program. + + You may charge a fee for the physical act of transferring a copy, and you + may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion of it, + thus forming a work based on the Program, and copy and distribute such + modifications or work under the terms of Section 1 above, provided that + you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating + that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole + or in part contains or is derived from the Program or any part thereof, + to be licensed as a whole at no charge to all third parties under the + terms of this License. + + c) If the modified program normally reads commands interactively when + run, you must cause it, when started running for such interactive use in + the most ordinary way, to print or display an announcement including an + appropriate copyright notice and a notice that there is no warranty (or + else, saying that you provide a warranty) and that users may + redistribute the program under these conditions, and telling the user + how to view a copy of this License. (Exception: if the Program itself is + interactive but does not normally print such an announcement, your work + based on the Program is not required to print an announcement.) + + These requirements apply to the modified work as a whole. If identifiable + sections of that work are not derived from the Program, and can be + reasonably considered independent and separate works in themselves, then + this License, and its terms, do not apply to those sections when you + distribute them as separate works. But when you distribute the same + sections as part of a whole which is a work based on the Program, the + distribution of the whole must be on the terms of this License, whose + permissions for other licensees extend to the entire whole, and thus to + each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your + rights to work written entirely by you; rather, the intent is to exercise + the right to control the distribution of derivative or collective works + based on the Program. + + In addition, mere aggregation of another work not based on the Program + with the Program (or with a work based on the Program) on a volume of a + storage or distribution medium does not bring the other work under the + scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, under + Section 2) in object code or executable form under the terms of Sections 1 + and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source + code, which must be distributed under the terms of Sections 1 and 2 + above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to + give any third party, for a charge no more than your cost of physically + performing source distribution, a complete machine-readable copy of the + corresponding source code, to be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to + distribute corresponding source code. (This alternative is allowed only + for noncommercial distribution and only if you received the program in + object code or executable form with such an offer, in accord with + Subsection b above.) + + The source code for a work means the preferred form of the work for making + modifications to it. For an executable work, complete source code means + all the source code for all modules it contains, plus any associated + interface definition files, plus the scripts used to control compilation + and installation of the executable. However, as a special exception, the + source code distributed need not include anything that is normally + distributed (in either source or binary form) with the major components + (compiler, kernel, and so on) of the operating system on which the + executable runs, unless that component itself accompanies the executable. + + If distribution of executable or object code is made by offering access to + copy from a designated place, then offering equivalent access to copy the + source code from the same place counts as distribution of the source code, + even though third parties are not compelled to copy the source along with + the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program except + as expressly provided under this License. Any attempt otherwise to copy, + modify, sublicense or distribute the Program is void, and will + automatically terminate your rights under this License. However, parties + who have received copies, or rights, from you under this License will not + have their licenses terminated so long as such parties remain in full + compliance. + + 5. You are not required to accept this License, since you have not signed + it. However, nothing else grants you permission to modify or distribute + the Program or its derivative works. These actions are prohibited by law + if you do not accept this License. Therefore, by modifying or distributing + the Program (or any work based on the Program), you indicate your + acceptance of this License to do so, and all its terms and conditions for + copying, distributing or modifying the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the + Program), the recipient automatically receives a license from the original + licensor to copy, distribute or modify the Program subject to these terms + and conditions. You may not impose any further restrictions on the + recipients' exercise of the rights granted herein. You are not responsible + for enforcing compliance by third parties to this License. + + 7. If, as a consequence of a court judgment or allegation of patent + infringement or for any other reason (not limited to patent issues), + conditions are imposed on you (whether by court order, agreement or + otherwise) that contradict the conditions of this License, they do not + excuse you from the conditions of this License. If you cannot distribute + so as to satisfy simultaneously your obligations under this License and + any other pertinent obligations, then as a consequence you may not + distribute the Program at all. For example, if a patent license would not + permit royalty-free redistribution of the Program by all those who receive + copies directly or indirectly through you, then the only way you could + satisfy both it and this License would be to refrain entirely from + distribution of the Program. + + If any portion of this section is held invalid or unenforceable under any + particular circumstance, the balance of the section is intended to apply + and the section as a whole is intended to apply in other circumstances. + + It is not the purpose of this section to induce you to infringe any + patents or other property right claims or to contest validity of any such + claims; this section has the sole purpose of protecting the integrity of + the free software distribution system, which is implemented by public + license practices. Many people have made generous contributions to the + wide range of software distributed through that system in reliance on + consistent application of that system; it is up to the author/donor to + decide if he or she is willing to distribute software through any other + system and a licensee cannot impose that choice. + + This section is intended to make thoroughly clear what is believed to be a + consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in certain + countries either by patents or by copyrighted interfaces, the original + copyright holder who places the Program under this License may add an + explicit geographical distribution limitation excluding those countries, + so that distribution is permitted only in or among countries not thus + excluded. In such case, this License incorporates the limitation as if + written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions of + the General Public License from time to time. Such new versions will be + similar in spirit to the present version, but may differ in detail to + address new problems or concerns. + + Each version is given a distinguishing version number. If the Program + specifies a version number of this License which applies to it and "any + later version", you have the option of following the terms and conditions + either of that version or of any later version published by the Free + Software Foundation. If the Program does not specify a version number of + this License, you may choose any version ever published by the Free + Software Foundation. + + 10. If you wish to incorporate parts of the Program into other free + programs whose distribution conditions are different, write to the author + to ask for permission. For software which is copyrighted by the Free + Software Foundation, write to the Free Software Foundation; we sometimes + make exceptions for this. Our decision will be guided by the two goals of + preserving the free status of all derivatives of our free software and of + promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY + FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN + OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES + PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED + OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS + TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE + PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, + REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING + WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR + REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, + INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES + ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT + LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES + SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE + WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + diff --git a/sysfsutils/test/Makefile.am b/sysfsutils/test/Makefile.am new file mode 100644 index 0000000..953f2df --- /dev/null +++ b/sysfsutils/test/Makefile.am @@ -0,0 +1,16 @@ +bin_PROGRAMS = dlist_test get_device get_driver get_module +BUILT_SOURCES = test.h +CLEANFILES = test.h +test.h: + ./create-test +get_device_SOURCES = get_device.c +get_driver_SOURCES = get_driver.c +get_module_SOURCES = get_module.c +testlibsysfs_SOURCES = test.c test_attr.c test_bus.c test_class.c \ + test_device.c test_driver.c test_module.c test_utils.c \ + testout.c test-defs.h libsysfs.conf create-test +INCLUDES = -I../include +LDADD = ../lib/libsysfs.la +EXTRA_CFLAGS = @EXTRA_CLFAGS@ +AM_CFLAGS = -Wall -W -Wstrict-prototypes $(EXTRA_CLFAGS) + diff --git a/sysfsutils/test/Makefile.in b/sysfsutils/test/Makefile.in new file mode 100644 index 0000000..6ac3a16 --- /dev/null +++ b/sysfsutils/test/Makefile.in @@ -0,0 +1,494 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +bin_PROGRAMS = dlist_test$(EXEEXT) get_device$(EXEEXT) \ + get_driver$(EXEEXT) get_module$(EXEEXT) +subdir = test +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/klibc.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(bin_PROGRAMS) +dlist_test_SOURCES = dlist_test.c +dlist_test_OBJECTS = dlist_test.$(OBJEXT) +dlist_test_LDADD = $(LDADD) +dlist_test_DEPENDENCIES = ../lib/libsysfs.la +am_get_device_OBJECTS = get_device.$(OBJEXT) +get_device_OBJECTS = $(am_get_device_OBJECTS) +get_device_LDADD = $(LDADD) +get_device_DEPENDENCIES = ../lib/libsysfs.la +am_get_driver_OBJECTS = get_driver.$(OBJEXT) +get_driver_OBJECTS = $(am_get_driver_OBJECTS) +get_driver_LDADD = $(LDADD) +get_driver_DEPENDENCIES = ../lib/libsysfs.la +am_get_module_OBJECTS = get_module.$(OBJEXT) +get_module_OBJECTS = $(am_get_module_OBJECTS) +get_module_LDADD = $(LDADD) +get_module_DEPENDENCIES = ../lib/libsysfs.la +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = dlist_test.c $(get_device_SOURCES) $(get_driver_SOURCES) \ + $(get_module_SOURCES) +DIST_SOURCES = dlist_test.c $(get_device_SOURCES) \ + $(get_driver_SOURCES) $(get_module_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CLFAGS@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KLCC = @KLCC@ +KLIBC = @KLIBC@ +KLIBC_FALSE = @KLIBC_FALSE@ +KLIBC_TRUE = @KLIBC_TRUE@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +BUILT_SOURCES = test.h +CLEANFILES = test.h +get_device_SOURCES = get_device.c +get_driver_SOURCES = get_driver.c +get_module_SOURCES = get_module.c +testlibsysfs_SOURCES = test.c test_attr.c test_bus.c test_class.c \ + test_device.c test_driver.c test_module.c test_utils.c \ + testout.c test-defs.h libsysfs.conf create-test + +INCLUDES = -I../include +LDADD = ../lib/libsysfs.la +AM_CFLAGS = -Wall -W -Wstrict-prototypes $(EXTRA_CLFAGS) +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu test/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu test/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + || test -f $$p1 \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ + rm -f "$(DESTDIR)$(bindir)/$$f"; \ + done + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +dlist_test$(EXEEXT): $(dlist_test_OBJECTS) $(dlist_test_DEPENDENCIES) + @rm -f dlist_test$(EXEEXT) + $(LINK) $(dlist_test_LDFLAGS) $(dlist_test_OBJECTS) $(dlist_test_LDADD) $(LIBS) +get_device$(EXEEXT): $(get_device_OBJECTS) $(get_device_DEPENDENCIES) + @rm -f get_device$(EXEEXT) + $(LINK) $(get_device_LDFLAGS) $(get_device_OBJECTS) $(get_device_LDADD) $(LIBS) +get_driver$(EXEEXT): $(get_driver_OBJECTS) $(get_driver_DEPENDENCIES) + @rm -f get_driver$(EXEEXT) + $(LINK) $(get_driver_LDFLAGS) $(get_driver_OBJECTS) $(get_driver_LDADD) $(LIBS) +get_module$(EXEEXT): $(get_module_OBJECTS) $(get_module_DEPENDENCIES) + @rm -f get_module$(EXEEXT) + $(LINK) $(get_module_LDFLAGS) $(get_module_OBJECTS) $(get_module_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dlist_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_device.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_driver.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_module.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: install-binPROGRAMS + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-binPROGRAMS uninstall-info-am + +test.h: + ./create-test +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/sysfsutils/test/create-test b/sysfsutils/test/create-test new file mode 100755 index 0000000..78ce1a2 --- /dev/null +++ b/sysfsutils/test/create-test @@ -0,0 +1,42 @@ +#! /bin/sh + +rm -f test.h + +conf_file=./libsysfs.conf + +. $conf_file + +echo "#define val_dir_path \"$VALID_DIRECTORY_PATH\"" > test.h +echo "#define val_link_path \"$VALID_LINK_PATH\"" >> test.h +echo "#define val_file_path \"$VALID_FILE_PATH\"" >> test.h +echo "#define val_subdir_link_name \"$VALID_SUBDIR_LINK_NAME\"" >> test.h +echo "#define val_subdir_name \"$VALID_SUBDIR_NAME\"" >> test.h +echo "#define val_subsys \"$VALID_SUBSYSTEM\"" >> test.h +echo "#define val_bus_name \"$VALID_BUS_NAME\"" >> test.h +echo "#define val_bus_attr \"$VALID_BUS_ATTR\"" >> test.h +echo "#define val_root_name \"$VALID_ROOT_NAME\"" >> test.h +echo "#define val_root_dev_path \"$VALID_ROOT_PATH\"" >> test.h +echo "#define val_bus_id \"$VALID_BUS_ID\"" >> test.h +echo "#define val_dev_path \"$VALID_DEVICE_PATH\"" >> test.h +echo "#define val_dev_attr \"$VALID_DEVICE_ATTR\"" >> test.h +echo "#define val_class \"$VALID_CLASS\"" >> test.h +echo "#define val_class_dev \"$VALID_CLASS_DEVICE\"" >> test.h +echo "#define val_class_dev_path \"$VALID_CLASS_DEVICE_PATH\"" >> test.h +echo "#define val_class_dev_attr \"$VALID_CLASS_DEV_ATTR\"" >> test.h +echo "#define val_block_class_dev_path \"$VALID_BLOCK_DEV_PATH\"" >> test.h +echo "#define val_drv_name \"$VALID_DRIVER\"" >> test.h +echo "#define val_drv_path \"$VALID_DRIVER_PATH\"" >> test.h +echo "#define val_drv_bus_name \"$VALID_DRIVER_BUS\"" >> test.h +echo "#define val_drv_dev_name \"$VALID_DRIVER_DEVICE\"" >> test.h +echo "#define val_drv_attr_name \"$VALID_DRIVER_ATTR\"" >> test.h +echo "#define val_drv1_name \"$VALID_DRIVER1\"" >> test.h +echo "#define val_drv1_path \"$VALID_DRIVER1_PATH\"" >> test.h +echo "#define val_drv1_bus_name \"$VALID_DRIVER1_BUS\"" >> test.h +echo "#define val_write_attr_path \"$VALID_WRITE_ATTR_PATH\"" >> test.h +echo "#define val_mod_path \"$VALID_MODULE_PATH\"" >> test.h +echo "#define val_mod_name \"$VALID_MODULE\"" >> test.h +echo "#define val_mod_attr_name \"$VALID_MODULE_ATTRIBUTE\"" >> test.h +echo "#define val_mod_param \"$VALID_MODULE_PARAM\"" >> test.h +echo "#define val_mod_section \"$VALID_MODULE_SECTION\"" >> test.h + + diff --git a/sysfsutils/test/dlist_test.c b/sysfsutils/test/dlist_test.c new file mode 100644 index 0000000..d36f5f6 --- /dev/null +++ b/sysfsutils/test/dlist_test.c @@ -0,0 +1,329 @@ +/* + * dlist_test.c + * + * Copyright (C) 2003 Eric J Bohm + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +/* Double linked list implementation tester. + */ +#include "dlist.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +// create some dlists put nodes in and out +// use dump +// try list with del_func and without +// use insert, unshift, push +// use pop push mark +// use prev next + +typedef struct simple { + char label[80]; + int number; +} Simple; + + +typedef struct complex { + int cnumber; + Simple *sthing; +} Complex; + +void complex_silly_multiply_by_two( void *a); +int complex_equal(void *a, void *b); +int complex_less(void *a, void *b); +int complex_greater(void *a, void *b); +int complex_comp(void *a, void *b); +void simple_dump(Dlist *); +void simple_dump_rev(Dlist *); +void complex_dump(Dlist *); +void complex_dump_rev(Dlist *); +void complex_out(void *); +void complex_del(void *); +Complex *complex_maker(int,int,char *); +int complex_filter(void *a); + +Simple *simple_maker(int ,char *); + +int main (int argc,char *argv[]) +{ + Dlist *list; + Simple *s1,*s2,*s3,*stemp; + Complex *c1,*c2,*c3, *c4, *ctemp, *cfound; + while(1) + { + s1=simple_maker(1,"one"); + s2=simple_maker(2,"two"); + s3=simple_maker(3,"three"); + if((list=dlist_new(sizeof(Simple)))==NULL) + { + fprintf(stderr,"ERR dlist_new fail\n"); + return(2); + } + dlist_push(list,s1); + dlist_push(list,s2); + dlist_push(list,s3); + printf("count is %ld\n",list->count); + simple_dump(list); + simple_dump_rev(list); + stemp=dlist_pop(list); + printf("popped %s\n",stemp->label); + simple_dump(list); + printf("pushed\n"); + dlist_push(list,s3); + simple_dump(list); + stemp=dlist_shift(list); + printf("shifted %s\n",stemp->label); + simple_dump(list); + printf("unshifted\n"); + dlist_unshift(list,stemp); + simple_dump(list); + dlist_destroy(list); + c1=complex_maker(1,1,"one"); + c2=complex_maker(2,2,"two"); + c3=complex_maker(3,3,"three"); + if((list=dlist_new_with_delete(sizeof(Complex),complex_del))==NULL) + { + fprintf(stderr,"ERR dlist_new fail\n"); + return(2); + } + if(dlist_insert_sorted(list,c1,complex_less)==NULL) + { + fprintf(stderr,"ERR dlist_insert fail\n"); + return(2); + } + printf("sorted insert 1\n"); + if(dlist_insert_sorted(list,c3,complex_less)==NULL) + { + fprintf(stderr,"ERR dlist_insert fail\n"); + return(2); + } + if(dlist_insert_sorted(list,c2,complex_less)==NULL) + { + fprintf(stderr,"ERR dlist_insert fail\n"); + return(2); + } + printf("sorted insert 2\n"); + printf("ascending sorted output\n"); + complex_dump(list); + dlist_transform(list,complex_silly_multiply_by_two); + printf("transform multi by 2 output\n"); + complex_dump(list); + ctemp=complex_maker(6,6,"three"); + if((cfound=(Complex *) dlist_find_custom(list,ctemp,complex_equal))!=NULL) + + { + printf("found %d as %d in list\n",ctemp->cnumber,cfound->cnumber); + } else { + printf("ERROR find failed on %d \n",ctemp->cnumber); + return(3); + } + complex_del(ctemp); + dlist_destroy(list); + c1=complex_maker(1,1,"one"); + c2=complex_maker(2,2,"two"); + c3=complex_maker(3,3,"three"); + if((list=dlist_new_with_delete(sizeof(Complex),complex_del))==NULL) + { + fprintf(stderr,"ERR dlist_new fail\n"); + return(2); + } + if(dlist_insert_sorted(list,c1,complex_greater)==NULL) + { + fprintf(stderr,"ERR dlist_insert fail\n"); + return(2); + } + printf("greater sorted insert 1\n"); + if(dlist_insert_sorted(list,c3,complex_greater)==NULL) + { + fprintf(stderr,"ERR dlist_insert fail\n"); + return(2); + } + printf("greater sorted insert 3\n"); + if(dlist_insert_sorted(list,c2,complex_greater)==NULL) + { + fprintf(stderr,"ERR dlist_insert fail\n"); + return(2); + } + printf("greater sorted insert 2\n"); + printf("descending sorted output using transform\n"); + dlist_transform(list,complex_out); + dlist_destroy(list); + c1=complex_maker(1,1,"one"); + c2=complex_maker(2,2,"two"); + c3=complex_maker(3,3,"three"); + c4=complex_maker(4,4,"four"); + if((list=dlist_new_with_delete(sizeof(Complex),complex_del))==NULL) + { + fprintf(stderr,"ERR dlist_new fail\n"); + return(2); + } + dlist_push(list,c2); + dlist_push(list,c1); + dlist_push(list,c4); + dlist_push(list,c3); + printf("unsorted custom\n"); + complex_dump(list); + printf("unsorted custom reversed\n"); + complex_dump_rev(list); + dlist_sort_custom(list,complex_comp); + printf("custom sorted output\n"); + complex_dump(list); + + dlist_filter_sort(list, complex_filter, complex_comp); + printf("custom filtered and sorted output\n"); + complex_dump(list); + dlist_destroy(list); + } + return(0); +} + +void simple_dump (Dlist *list) +{ + Simple *thisone; + printf("count %ld \n",list->count); + dlist_for_each_data(list,thisone,Simple) + { + printf("label %s number %d \n",thisone->label,thisone->number); + } + +} +void simple_dump_rev (Dlist *list) +{ + Simple *thisone; + printf("rev count %ld \n",list->count); + dlist_for_each_data_rev(list,thisone,Simple) + { + printf("label %s number %d \n",thisone->label,thisone->number); + } +} + +Simple * simple_maker(int snumber,char *label) +{ + Simple *stemp; + if((stemp=malloc(sizeof(Simple)))==NULL) + { + fprintf(stderr,"ERR malloc fail\n"); + return(NULL); + } + stemp->number=snumber; + strcpy(stemp->label,label); + return(stemp); +} + +Complex * complex_maker(int cnumber, int snumber, char* label) +{ + Complex *ctemp; + if((ctemp=malloc(sizeof(Complex)))==NULL) + { + fprintf(stderr,"ERR malloc fail\n"); + return(NULL); + } + ctemp->cnumber=cnumber; + ctemp->sthing=simple_maker(snumber,label); + return(ctemp); +} + +void complex_out(void *data) +{ + Complex *thisone=(Complex *)data; + printf("cnumber %d label %s number %d \n",thisone->cnumber,thisone->sthing->label,thisone->sthing->number); +} + +/** + * return 1 if a==b, else 0 + */ +int complex_equal(void *a, void *b) +{ + if((((Complex *)a)->cnumber==((Complex *)b)->cnumber) + && (((Complex *)a)->sthing->number== + ((Complex *)b)->sthing->number) + && strcmp(((Complex *)a)->sthing->label, + ((Complex *)b)->sthing->label)==0) + return(1); + return(0); +} + +/** for sorting + * return 1 if a<b, else 0 + */ +int complex_less(void *a, void *b) +{ + return( ((Complex *)a)->cnumber < ((Complex *)b)->cnumber ); +} + +/** for sorting + * return 1 if a>b, else 0 + */ +int complex_greater(void *a, void *b) +{ + return( ((Complex *)a)->cnumber > ((Complex *)b)->cnumber ); +} + +int complex_comp(void *a, void *b) +{ + return( ((Complex *)a)->cnumber - ((Complex *)b)->cnumber ); +} + +void complex_silly_multiply_by_two( void *a) +{ + ((Complex *)a)->cnumber=((Complex *)a)->cnumber*2; + ((Complex *)a)->sthing->number=((Complex *)a)->sthing->number*2; +} + +void complex_dump (Dlist *list) +{ + Complex *thisone; + dlist_start(list); + printf("count %ld \n",list->count); + dlist_for_each_data(list,thisone,Complex) + { + printf("cnumber %d label %s number %d \n",thisone->cnumber,thisone->sthing->label,thisone->sthing->number); + } + +} + +void complex_dump_rev (Dlist *list) +{ + Complex *thisone; + dlist_start(list); + printf("count %ld \n",list->count); + dlist_for_each_data_rev(list,thisone,Complex) + { + printf("cnumber %d label %s number %d \n",thisone->cnumber,thisone->sthing->label,thisone->sthing->number); + } + +} + +void complex_del (void *item) +{ + Complex *corpse=item; + printf("freeing complex\n"); + free(corpse->sthing); + free(corpse); +} + +int complex_filter(void *a) +{ + Complex *c = (Complex *)a; + + if (c->cnumber >= 2 && c->cnumber <= 3) + return 1; + else + return 0; +} diff --git a/sysfsutils/test/get_device.c b/sysfsutils/test/get_device.c new file mode 100644 index 0000000..4af1b8e --- /dev/null +++ b/sysfsutils/test/get_device.c @@ -0,0 +1,58 @@ +/* + * get_device.c + * + * Utility to get details of a given device + * + * Copyright (C) IBM Corp. 2003-2005 + * + * 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. + * + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "libsysfs.h" + +static void print_usage(void) +{ + fprintf(stdout, "Usage: get_device [bus] [device]\n"); +} + +int main(int argc, char *argv[]) +{ + struct sysfs_device *device = NULL; + + if (argc != 3) { + print_usage(); + return 1; + } + + device = sysfs_open_device(argv[1], argv[2]); + if (device == NULL) { + fprintf(stdout, "Device \"%s\" not found on bus \"%s\"\n", + argv[2], argv[1]); + return 1; + } + fprintf(stdout, "device is on bus %s, using driver %s\n", + device->bus, device->driver_name); + + struct sysfs_device *parent = sysfs_get_device_parent(device); + if (parent) + fprintf(stdout, "parent is %s\n", parent->name); + else + fprintf(stdout, "no parent\n"); + return 0; +} + diff --git a/sysfsutils/test/get_driver.c b/sysfsutils/test/get_driver.c new file mode 100644 index 0000000..51c6522 --- /dev/null +++ b/sysfsutils/test/get_driver.c @@ -0,0 +1,86 @@ +/* + * get_driver.c + * + * Utility to get details of the given driver + * + * Copyright (C) IBM Corp. 2003-2005 + * + * 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. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "libsysfs.h" + +static void print_usage(void) +{ + fprintf(stdout, "Usage: get_driver [bus] [driver]\n"); +} + +int main(int argc, char *argv[]) +{ + char *bus = NULL, path[SYSFS_PATH_MAX]; + struct sysfs_driver *driver = NULL; + struct sysfs_device *device = NULL; + struct dlist *devlist = NULL; + struct sysfs_attribute *attr = NULL; + + if (argc != 3) { + print_usage(); + return 1; + } + + memset(path, 0, SYSFS_PATH_MAX); + if ((sysfs_get_mnt_path(path, SYSFS_PATH_MAX)) != 0) { + fprintf(stdout, "Sysfs not mounted?\n"); + return 1; + } + strcat(path, "/"); + strcat(path, SYSFS_BUS_NAME); + strcat(path, "/"); + strcat(path, argv[1]); + strcat(path, "/"); + strcat(path, SYSFS_DRIVERS_NAME); + strcat(path, "/"); + strcat(path, argv[2]); + driver = sysfs_open_driver_path(path); + if (driver == NULL) { + fprintf(stdout, "Driver %s not found\n", argv[1]); + free(bus); + return 1; + } + devlist = sysfs_get_driver_devices(driver); + if (devlist != NULL) { + fprintf(stdout, "%s is used by:\n", argv[2]); + dlist_for_each_data(devlist, device, struct sysfs_device) + fprintf(stdout, "\t\t%s\n", device->bus_id); + } else + fprintf(stdout, "%s is presently not used by any device\n", + argv[2]); + + fprintf(stdout, "driver %s is on bus %s\n", driver->name, driver->bus); + + struct sysfs_module *module = sysfs_get_driver_module(driver); + if (module) + fprintf(stdout, "%s is using the module %s\n", + driver->name, module->name); + + sysfs_close_driver(driver); + free(bus); + return 0; +} + diff --git a/sysfsutils/test/get_module.c b/sysfsutils/test/get_module.c new file mode 100644 index 0000000..9dd64ad --- /dev/null +++ b/sysfsutils/test/get_module.c @@ -0,0 +1,71 @@ +/* + * get_module.c + * + * Utility to get details of a given module + * + * Copyright (C) IBM Corp. 2003-2005 + * + * 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. + * + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "libsysfs.h" + +static void print_usage(void) +{ + fprintf(stdout, "Usage: get_module [name]\n"); +} + +int main(int argc, char *argv[]) +{ + struct sysfs_module *module = NULL; + struct sysfs_attribute *attr = NULL; + struct dlist *attrlist = NULL; + + if (argc != 2) { + print_usage(); + return 1; + } + module = sysfs_open_module(argv[1]); + if (module == NULL) { + fprintf(stdout, "Module \"%s\" not found\n", argv[1]); + return 1; + } + + attrlist = sysfs_get_module_attributes(module); + if (attrlist != NULL) { + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + fprintf(stdout, "\n"); + + attrlist = sysfs_get_module_parms(module); + if (attrlist != NULL) { + fprintf(stdout, "Parameters:\n"); + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + attrlist = sysfs_get_module_sections(module); + if (attrlist != NULL) { + fprintf(stdout, "Sections:\n"); + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + + sysfs_close_module(module); + return 0; +} diff --git a/sysfsutils/test/libsysfs.conf b/sysfsutils/test/libsysfs.conf new file mode 100644 index 0000000..bda70b9 --- /dev/null +++ b/sysfsutils/test/libsysfs.conf @@ -0,0 +1,87 @@ +# The config file for libsysfs testsuite +# All values in this file are in relation to the sysfs filesystem only +# +# Values defined here will be used to dynamically build a header file that +# gets used while compiling the testsuite. + +# NOTE NOTE NOTE: If you change values in this file, please make sure that +# you run "make clean" and "make" (in the "test" directory) for the changes +# to take effect. + + +# A valid directory path under sysfs +# A valid link name under a subidirectory of VALID_DIRECTORY_PATH... eg., if +# the VALID_DIRECTORY_PATH is /sys/bus/pci, then enter a pci device name for +# VALID SUBDIR_LINK_NAME +VALID_DIRECTORY_PATH=/sys/bus/pci +VALID_SUBDIR_LINK_NAME=0000:00:00.0 + +# A valid link path under sysfs - enter the absolute path to a soft-link here +VALID_LINK_PATH=/sys/block/sda/device + +# Absolute path to a regular (readable) attribute (a normal file) under sysfs +VALID_FILE_PATH=/sys/block/sda/dev + +# A valid subsystem name - an entry under /sys +VALID_SUBSYSTEM=bus + +# A valid bus name supported on this system +# A device belonging to the bus +# Absolute path to the device +# A valid attribute defined for this device +VALID_BUS_NAME=pci +VALID_BUS_ID=0000:00:00.0 +VALID_DEVICE_PATH=/sys/devices/pci0000:00/0000:00:00.0 +VALID_DEVICE_ATTR=vendor + +# A valid attribute exported under VALID_BUS_NAME +# NOTE: As of now, no buses export attributes, change this to a valid value +# when one becomes avaliable +VALID_BUS_ATTR=online + +# A valid directory under /sys/devices +# Its absolute path +# A valid subdirectory under VALID_ROOT_PATH +VALID_ROOT_NAME=pci0000:00 +VALID_ROOT_PATH=/sys/devices/pci0000:00 +VALID_SUBDIR_NAME=0000:00:00.0 + +# A valid class - directory under /sys/class +# A valid class_device belonging to the class - a dir under VALID_CLASS +# Abslolute path to the VALID_CLASS_DEVICE +# A valid attribute defined for the VALID_CLASS_DEVICE +VALID_CLASS=net +VALID_CLASS_DEVICE=eth0 +VALID_CLASS_DEVICE_PATH=/sys/class/net/eth0 +VALID_CLASS_DEV_ATTR=type + +# A valid directory path under /sys/block/xxx - preferably a partition +VALID_BLOCK_DEV_PATH=/sys/block/hda/hda1 + +# A valid driver (preferably a driver that exports readable attributes) +# The absolute path to the driver +# The bus the driver is registered on +# A device that is using it and +# A valid attribute corresponding to the driver +VALID_DRIVER=e100 +VALID_DRIVER_PATH=/sys/bus/pci/drivers/e100 +VALID_DRIVER_BUS=pci +VALID_DRIVER_DEVICE=0000:02:08.0 +VALID_DRIVER_ATTR=new_id + +# Another valid driver - but one that is not being used by any device +# Absolute path to the driver +# The bus the driver is registered +VALID_DRIVER1=usbfs +VALID_DRIVER1_PATH=/sys/bus/usb/drivers/usbfs +VALID_DRIVER1_BUS=usb + +# Path to a writable attribute - make sure that the tester has permission to +# "write" to the file at VALID_WRITE_ATTR_PATH +VALID_WRITE_ATTR_PATH=/sys/class/net/eth0/tx_queue_len + +VALID_MODULE_PATH=/sys/module/usbcore +VALID_MODULE=usbcore +VALID_MODULE_ATTRIBUTE=refcnt +VALID_MODULE_PARAM=blinkenlights +VALID_MODULE_SECTION=__versions diff --git a/sysfsutils/test/test-defs.h b/sysfsutils/test/test-defs.h new file mode 100644 index 0000000..b22909a --- /dev/null +++ b/sysfsutils/test/test-defs.h @@ -0,0 +1,125 @@ +/* + * test.h + * + * Generic defines/declarations for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +#ifndef _TESTER_H_ +#define _TESTER_H_ + +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <dirent.h> + +#include "libsysfs.h" +#include "dlist.h" +#include "test.h" + +#define val_drv1_dev_name "dummy1" +#define val_drv1_attr_name "dummy2" +#define inval_name "invalid_name" +#define inval_path "/sys/invalid/path" +#define FUNC_TABLE_SIZE (sizeof(func_table)/sizeof(int)) + +FILE *my_stdout; + +#define dbg_print(format, arg...) fprintf(my_stdout, format, ## arg) + +/** + * list of display functions + */ +extern void show_device(struct sysfs_device *device); +extern void show_driver(struct sysfs_driver *driver); +extern void show_device_list(struct dlist *devlist); +extern void show_driver_list(struct dlist *drvlist); +extern void show_attribute(struct sysfs_attribute *attr); +extern void show_attribute_list(struct dlist *list); +extern void show_links_list(struct dlist *linklist); +extern void show_dir_list(struct dlist *dirlist); +extern void show_class_device(struct sysfs_class_device *dev); +extern void show_class_device_list(struct dlist *devlist); +extern void show_list(struct dlist *list); +extern void show_parm_list(struct dlist *list); +extern void show_section_list(struct dlist *list); +extern void show_module(struct sysfs_module *module); + +/** + * list of test functions..... + */ +extern int test_sysfs_get_mnt_path(int flag); +extern int test_sysfs_remove_trailing_slash(int flag); +extern int test_sysfs_get_name_from_path(int flag); +extern int test_sysfs_path_is_dir(int flag); +extern int test_sysfs_path_is_link(int flag); +extern int test_sysfs_path_is_file(int flag); +extern int test_sysfs_get_link(int flag); +extern int test_sysfs_open_directory_list(int flag); +extern int test_sysfs_open_link_list(int flag); +extern int test_sysfs_close_list(int flag); +extern int test_sysfs_close_attribute(int flag); +extern int test_sysfs_open_attribute(int flag); +extern int test_sysfs_read_attribute(int flag); +extern int test_sysfs_write_attribute(int flag); +extern int test_sysfs_close_driver(int flag); +extern int test_sysfs_open_driver(int flag); +extern int test_sysfs_open_driver_path(int flag); +extern int test_sysfs_get_driver_attr(int flag); +extern int test_sysfs_get_driver_attributes(int flag); +extern int test_sysfs_get_driver_devices(int flag); +extern int test_sysfs_get_driver_module(int flag); +extern int test_sysfs_close_device(int flag); +extern int test_sysfs_open_device(int flag); +extern int test_sysfs_get_device_parent(int flag); +extern int test_sysfs_open_device_path(int flag); +extern int test_sysfs_get_device_attr(int flag); +extern int test_sysfs_get_device_attributes(int flag); +extern int test_sysfs_close_bus(int flag); +extern int test_sysfs_open_bus(int flag); +extern int test_sysfs_get_bus_device(int flag); +extern int test_sysfs_get_bus_driver(int flag); +extern int test_sysfs_get_bus_drivers(int flag); +extern int test_sysfs_get_bus_devices(int flag); +extern int test_sysfs_close_class_device(int flag); +extern int test_sysfs_open_class_device_path(int flag); +extern int test_sysfs_open_class_device(int flag); +extern int test_sysfs_get_classdev_device(int flag); +extern int test_sysfs_get_classdev_parent(int flag); +extern int test_sysfs_close_class(int flag); +extern int test_sysfs_open_class(int flag); +extern int test_sysfs_get_class_devices(int flag); +extern int test_sysfs_get_class_device(int flag); +extern int test_sysfs_get_classdev_attributes(int flag); +extern int test_sysfs_get_classdev_attr(int flag); +extern int test_sysfs_open_classdev_attr(int flag); +extern int test_sysfs_close_module(int flag); +extern int test_sysfs_open_module_path(int flag); +extern int test_sysfs_open_module(int flag); +extern int test_sysfs_get_module_attr(int flag); +extern int test_sysfs_get_module_attributes(int flag); +extern int test_sysfs_get_module_parms(int flag); +extern int test_sysfs_get_module_sections(int flag); +extern int test_sysfs_get_module_parm(int flag); +extern int test_sysfs_get_module_section(int flag); + +#endif /* _TESTER_H_ */ diff --git a/sysfsutils/test/test.c b/sysfsutils/test/test.c new file mode 100644 index 0000000..2e8f201 --- /dev/null +++ b/sysfsutils/test/test.c @@ -0,0 +1,327 @@ +/* + * test.c + * + * Main program for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + * this doesn't do much, just loops throug to call each function. + */ + +#include "test-defs.h" +#include <errno.h> + +/*************************************************/ +char *function_name[] = { + "sysfs_get_mnt_path", + "sysfs_remove_trailing_slash", + "sysfs_get_name_from_path", + "sysfs_path_is_dir", + "sysfs_path_is_link", + "sysfs_path_is_file", + "sysfs_get_link", + "sysfs_close_list", + "sysfs_open_directory_list", + "sysfs_open_link_list", + "sysfs_close_attribute", + "sysfs_open_attribute", + "sysfs_read_attribute", + "sysfs_write_attribute", + "sysfs_close_driver", + "sysfs_open_driver", + "sysfs_open_driver_path", + "sysfs_get_driver_attr", + "sysfs_get_driver_attributes", + "sysfs_get_driver_devices", + "sysfs_close_device", + "sysfs_open_device", + "sysfs_get_device_parent", + "sysfs_open_device_path", + "sysfs_get_device_attr", + "sysfs_get_device_attributes", + "sysfs_close_bus", + "sysfs_open_bus", + "sysfs_get_bus_device", + "sysfs_get_bus_driver", + "sysfs_get_bus_drivers", + "sysfs_get_bus_devices", + "sysfs_close_class_device", + "sysfs_open_class_device_path", + "sysfs_open_class_device", + "sysfs_get_classdev_device", + "sysfs_get_classdev_parent", + "sysfs_close_class", + "sysfs_open_class", + "sysfs_get_class_devices", + "sysfs_get_class_device", + "sysfs_get_classdev_attributes", + "sysfs_get_classdev_attr", + "sysfs_close_module", + "sysfs_open_module_path", + "sysfs_open_module", + "sysfs_get_module_attr", + "sysfs_get_module_attributes", + "sysfs_get_module_parms", + "sysfs_get_module_sections", + "sysfs_get_module_parm", + "sysfs_get_module_section", +}; + +int (*func_table[])(int) = { + test_sysfs_get_mnt_path, + test_sysfs_remove_trailing_slash, + test_sysfs_get_name_from_path, + test_sysfs_path_is_dir, + test_sysfs_path_is_link, + test_sysfs_path_is_file, + test_sysfs_get_link, + test_sysfs_close_list, + test_sysfs_open_directory_list, + test_sysfs_open_link_list, + test_sysfs_close_attribute, + test_sysfs_open_attribute, + test_sysfs_read_attribute, + test_sysfs_write_attribute, + test_sysfs_close_driver, + test_sysfs_open_driver, + test_sysfs_open_driver_path, + test_sysfs_get_driver_attr, + test_sysfs_get_driver_attributes, + test_sysfs_get_driver_devices, + test_sysfs_close_device, + test_sysfs_open_device, + test_sysfs_get_device_parent, + test_sysfs_open_device_path, + test_sysfs_get_device_attr, + test_sysfs_get_device_attributes, + test_sysfs_close_bus, + test_sysfs_open_bus, + test_sysfs_get_bus_device, + test_sysfs_get_bus_driver, + test_sysfs_get_bus_drivers, + test_sysfs_get_bus_devices, + test_sysfs_close_class_device, + test_sysfs_open_class_device_path, + test_sysfs_open_class_device, + test_sysfs_get_classdev_device, + test_sysfs_get_classdev_parent, + test_sysfs_close_class, + test_sysfs_open_class, + test_sysfs_get_class_devices, + test_sysfs_get_class_device, + test_sysfs_get_classdev_attributes, + test_sysfs_get_classdev_attr, + test_sysfs_close_module, + test_sysfs_open_module_path, + test_sysfs_open_module, + test_sysfs_get_module_attr, + test_sysfs_get_module_attributes, + test_sysfs_get_module_parms, + test_sysfs_get_module_sections, + test_sysfs_get_module_parm, + test_sysfs_get_module_section, +}; + +char *dir_paths[] = { + val_dir_path, + val_root_dev_path, + val_class_dev_path, + val_block_class_dev_path, + val_drv_path, + val_drv1_path, + NULL +}; + +char *file_paths[] = { + val_file_path, + val_write_attr_path, + NULL +}; + +char *link_paths[] = { + val_link_path, + NULL +}; + +static int path_is_dir(const char *path) +{ + struct stat astats; + + if ((lstat(path, &astats)) != 0) + goto direrr; + + if (S_ISDIR(astats.st_mode)) + return 0; + +direrr: + fprintf(stdout, "Config error: %s not a directory\n", path); + return 1; +} + +static int path_is_file(const char *path) +{ + struct stat astats; + + if ((lstat(path, &astats)) != 0) + goto fileerr; + + if (S_ISREG(astats.st_mode)) + return 0; + +fileerr: + fprintf(stdout, "Config error: %s not a file\n", path); + return 1; +} + +static int path_is_link(const char *path) +{ + struct stat astats; + + if ((lstat(path, &astats)) != 0) + goto linkerr; + + if (S_ISLNK(astats.st_mode)) + return 0; + +linkerr: + fprintf(stdout, "Config error: %s not a link\n", path); + return 1; +} + +/* + * Check validity of the test.h file entries + */ +static int check_header(void) +{ + char *var_path = NULL; + char path1[SYSFS_PATH_MAX]; + int i = 0; + + for (i = 0; dir_paths[i] != NULL; i++) { + var_path = dir_paths[i]; + if (path_is_dir(var_path) != 0) + return 1; + } + + for (i = 0; file_paths[i] != NULL; i++) { + var_path = file_paths[i]; + if (path_is_file(var_path) != 0) + return 1; + } + + for (i = 0; link_paths[i] != NULL; i++) { + var_path = link_paths[i]; + if (path_is_link(var_path) != 0) + return 1; + } + + memset(path1, 0, SYSFS_PATH_MAX); + strcpy(path1, val_root_dev_path); + strcat(path1, "/"); + strcat(path1, val_subdir_name); + if (path_is_dir(path1) != 0) + return 1; + + memset(path1, 0, SYSFS_PATH_MAX); + strcpy(path1, val_drv_path); + strcat(path1, "/"); + strcat(path1, val_drv_dev_name); + if (path_is_link(path1) != 0) + return 1; + + memset(path1, 0, SYSFS_PATH_MAX); + strcpy(path1, val_dir_path); + strcat(path1, "/devices"); + strcat(path1, "/"); + strcat(path1, val_subdir_link_name); + if (path_is_link(path1) != 0) + return 1; + + memset(path1, 0, SYSFS_PATH_MAX); + strcpy(path1, val_class_dev_path); + strcat(path1, "/"); + strcat(path1, val_class_dev_attr); + if (path_is_file(path1) != 0) + return 1; + + memset(path1, 0, SYSFS_PATH_MAX); + strcpy(path1, val_dev_path); + strcat(path1, "/"); + strcat(path1, val_dev_attr); + if (path_is_file(path1) != 0) + return 1; + + memset(path1, 0, SYSFS_PATH_MAX); + strcpy(path1, val_drv_path); + strcat(path1, "/"); + strcat(path1, val_drv_attr_name); + if (path_is_file(path1) != 0) + return 1; + + return 0; +} + +static void usage(void) +{ + fprintf(stdout, "testlibsysfs <no-of-times> [log-file]\n"); + fprintf(stdout, "\t eg: testlibsysfs 3 /home/user/test.log\n"); +} + +int main(int argc, char *argv[]) +{ + char std_out[] = "/dev/stdout"; + char *file_name = NULL; + int i = 0, j = 0, k = 0, num = 1; + + if (argc == 3) { + file_name = argv[2]; + } else { + file_name = std_out; + } + my_stdout = fopen(file_name,"w"); + if (argc < 2) { + usage(); + return 0; + } else + num = strtol(argv[1], NULL, 0); + + if (check_header() != 0) + return 1; + + dbg_print("\nTest running %d times\n", num); + + for (k = 0; k < num ; k++) { + dbg_print("\nThis is the %d test run\n", k+1); + + for (i = 0; i < FUNC_TABLE_SIZE; i++) { +dbg_print("\n**************************************************************\n"); + dbg_print("TESTING: %s, function no: %d\n\n", + function_name[i], i); + for (j = 0; ; j++) { + fflush(my_stdout); + if (func_table[i](j) == -1) + break; + } +dbg_print("**************************************************************\n"); + } + } + + fclose(my_stdout); + return 0; +} diff --git a/sysfsutils/test/test_attr.c b/sysfsutils/test/test_attr.c new file mode 100644 index 0000000..689a0e8 --- /dev/null +++ b/sysfsutils/test/test_attr.c @@ -0,0 +1,318 @@ +/* + * test_dir.c + * + * Tests for directory related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + *************************************************************************** + * this will test the directory related functions provided by libsysfs. + * + * extern void sysfs_close_attribute(struct sysfs_attribute *sysattr); + * extern struct sysfs_attribute *sysfs_open_attribute + * (const char *path); + * extern int sysfs_read_attribute(struct sysfs_attribute *sysattr); + * extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, + * const char *new_value, size_t len); + **************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * extern void sysfs_close_attribute(struct sysfs_attribute *sysattr); + * + * flag: + * 0: sysattr -> valid + * 1: sysattr -> NULL + */ +int test_sysfs_close_attribute(int flag) +{ + struct sysfs_attribute *sysattr = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_file_path; + sysattr = sysfs_open_attribute(path); + if (sysattr == NULL) { + dbg_print("%s: Error opening attribute at %s\n", + __FUNCTION__, val_file_path); + return 0; + } + break; + case 1: + sysattr = NULL; + break; + default: + return -1; + } + sysfs_close_attribute(sysattr); + + dbg_print("%s: returns void\n", __FUNCTION__); + + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_open_attribute + * (const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_open_attribute(int flag) +{ + char *path = NULL; + struct sysfs_attribute *sysattr = NULL; + + switch (flag) { + case 0: + path = val_file_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + sysattr = sysfs_open_attribute(path); + + switch (flag) { + case 0: + if (sysattr == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Attrib name = %s, at %s\n\n", + sysattr->name, sysattr->path); + } + break; + case 1: + case 2: + if (sysattr != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + + } + if (sysattr != NULL) { + sysfs_close_attribute(sysattr); + sysattr = NULL; + } + + return 0; +} + +/** + * extern int sysfs_read_attribute(struct sysfs_attribute *sysattr); + * + * flag: + * 0: sysattr -> valid + * 1: sysattr -> NULL + */ +int test_sysfs_read_attribute(int flag) +{ + struct sysfs_attribute *sysattr = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysattr = sysfs_open_attribute(val_file_path); + if (sysattr == NULL) { + dbg_print("%s: failed opening attribute at %s\n", + __FUNCTION__, val_file_path); + return 0; + } + break; + case 1: + sysattr = NULL; + break; + default: + return -1; + } + ret = sysfs_read_attribute(sysattr); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(sysattr); + dbg_print("\n"); + } + break; + case 1: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (sysattr != NULL) + sysfs_close_attribute(sysattr); + + return 0; +} + +/** + * extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, + * const char *new_value, size_t len); + * + * flag: + * 0: sysattr -> valid, new_value -> valid, len -> valid; + * 1: sysattr -> valid, new_value -> invalid, len -> invalid; + * 2: sysattr -> valid, new_value -> NULL, len -> invalid; + * 3: sysattr -> NULL, new_value -> valid, len -> valid; + * 4: sysattr -> NULL, new_value -> invalid, len -> invalid; + * 5: sysattr -> NULL, new_value -> NULL, len -> invalid; + */ +int test_sysfs_write_attribute(int flag) +{ + struct sysfs_attribute *sysattr = NULL; + char *new_value = NULL; + size_t len = 0; + int ret = 0; + + switch (flag) { + case 0: + sysattr = sysfs_open_attribute(val_write_attr_path); + if (sysattr == NULL) { + dbg_print("%s: failed opening attribute at %s\n", + __FUNCTION__, val_write_attr_path); + return 0; + } + if (sysfs_read_attribute(sysattr) != 0) { + dbg_print("%s: failed reading attribute at %s\n", + __FUNCTION__, val_write_attr_path); + return 0; + } + new_value = calloc(1, sysattr->len + 1); + strncpy(new_value, sysattr->value, sysattr->len); + len = sysattr->len; + break; + case 1: + sysattr = sysfs_open_attribute(val_write_attr_path); + if (sysattr == NULL) { + dbg_print("%s: failed opening attribute at %s\n", + __FUNCTION__, val_write_attr_path); + return 0; + } + new_value = calloc(1, SYSFS_PATH_MAX); + strncpy(new_value, "this should not get copied in the attrib", + SYSFS_PATH_MAX); + len = SYSFS_PATH_MAX; + break; + case 2: + sysattr = sysfs_open_attribute(val_write_attr_path); + if (sysattr == NULL) { + dbg_print("%s: failed opening attribute at %s\n", + __FUNCTION__, val_write_attr_path); + return 0; + } + new_value = NULL; + len = SYSFS_PATH_MAX; + break; + case 3: + sysattr = sysfs_open_attribute(val_write_attr_path); + if (sysattr == NULL) { + dbg_print("%s: failed opening attribute at %s\n", + __FUNCTION__, val_write_attr_path); + return 0; + } + new_value = calloc(1, sysattr->len + 1); + strncpy(new_value, sysattr->value, sysattr->len); + len = sysattr->len; + sysfs_close_attribute(sysattr); + sysattr = NULL; + break; + case 4: + sysattr = NULL; + new_value = calloc(1, SYSFS_PATH_MAX); + strncpy(new_value, "this should not get copied in the attrib", + SYSFS_PATH_MAX); + len = SYSFS_PATH_MAX; + break; + case 5: + sysattr = NULL; + new_value = NULL; + len = SYSFS_PATH_MAX; + break; + default: + return -1; + } + ret = sysfs_write_attribute(sysattr, new_value, len); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Attribute at %s now has value %s\n\n", + sysattr->path, sysattr->value); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (sysattr != NULL) { + sysfs_close_attribute(sysattr); + sysattr = NULL; + } + if (new_value != NULL) + free(new_value); + + return 0; +} diff --git a/sysfsutils/test/test_bus.c b/sysfsutils/test/test_bus.c new file mode 100644 index 0000000..46036f5 --- /dev/null +++ b/sysfsutils/test/test_bus.c @@ -0,0 +1,460 @@ +/* + * test_bus.c + * + * Tests for bus related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + ****************************************************************************** + * this will test the bus related functions provided by libsysfs. + * + * extern void sysfs_close_bus(struct sysfs_bus *bus); + * extern struct sysfs_bus *sysfs_open_bus(const char *name); + * extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus, + * char *id); + * extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus, + * char *drvname); + * extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus); + * extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus); + ****************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * extern void sysfs_close_bus(struct sysfs_bus *bus); + * + * flags: + * 0 -> bus -> valid + * 1 -> bus -> null. + */ +int test_sysfs_close_bus(int flag) +{ + struct sysfs_bus *bus = NULL; + char *bus_name = NULL; + + switch (flag) { + case 0: + bus_name = val_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + break; + case 1: + bus = NULL; + break; + default: + return -1; + } + sysfs_close_bus(bus); + + dbg_print("%s: returns void\n", __FUNCTION__); + return 0; +} + +/** + * extern struct sysfs_bus *sysfs_open_bus(const char *name); + * + * flag: + * 0 - name -> valid + * 1 - name -> invalid + * 2 - name -> null + */ +int test_sysfs_open_bus(int flag) +{ + struct sysfs_bus *bus = NULL; + char *name = NULL; + + switch (flag) { + case 0: + name = val_bus_name; + break; + case 1: + name = inval_name; + break; + case 2: + name = NULL; + break; + default: + return -1; + } + bus = sysfs_open_bus(name); + + switch (flag) { + case 0: + if (bus == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Bus = %s, path = %s\n\n", + bus->name, bus->path); + } + break; + case 1: + case 2: + if (bus != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + } + if (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus, + * char *id); + * + * flag: + * 0 : bus -> valid, id -> valid + * 1 : bus -> valid, id -> invalid + * 2 : bus -> valid, id -> NULL + * 3 : bus -> NULL, id -> valid + * 4 : bus -> NULL, id -> invalid + * 5 : bus -> NULL, id -> NULL + */ +int test_sysfs_get_bus_device(int flag) +{ + struct sysfs_bus *bus = NULL; + struct sysfs_device *dev = NULL; + char *bus_name = NULL; + char *id = NULL; + + switch(flag) { + case 0: + bus_name = val_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + id = val_bus_id; + break; + case 1: + bus_name = val_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + id = inval_name; + break; + case 2: + bus_name = val_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + id = NULL; + break; + case 3: + bus = NULL; + id = val_bus_id; + break; + case 4: + bus = NULL; + id = inval_name; + break; + case 5: + bus = NULL; + id = NULL; + break; + default: + return -1; + } + dev = sysfs_get_bus_device(bus, id); + + switch (flag) { + case 0: + if (dev == NULL) { + if (errno == 0) + dbg_print("%s: Device %s not on bus %s\n", + __FUNCTION__, id, bus_name); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device(dev); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (dev != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus, + * char *drvname); + * + * flag: + * 0 : bus -> valid, drvname -> valid + * 1 : bus -> valid, drvname -> invalid + * 2 : bus -> valid, drvname -> NULL + * 3 : bus -> NULL, drvname -> valid + * 4 : bus -> NULL, drvname -> invalid + * 5 : bus -> NULL, drvname -> NULL + */ +int test_sysfs_get_bus_driver(int flag) +{ + struct sysfs_bus *bus = NULL; + struct sysfs_driver *drv = NULL; + char *drvname = NULL; + char *bus_name = NULL; + + switch(flag) { + case 0: + bus_name = val_drv_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + drvname = val_drv_name; + break; + case 1: + bus_name = val_drv_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + drvname = inval_name; + break; + case 2: + bus_name = val_drv_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + drvname = NULL; + break; + case 3: + bus = NULL; + drvname = val_drv_name; + break; + case 4: + bus = NULL; + drvname = inval_name; + break; + case 5: + bus = NULL; + drvname = NULL; + break; + default: + return -1; + } + drv = sysfs_get_bus_driver(bus, drvname); + + switch (flag) { + case 0: + if (drv == NULL) { + if (errno == 0) + dbg_print("%s: Driver %s not on bus %s\n", + __FUNCTION__, drvname, bus_name); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_driver(drv); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (drv != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus); + * + * flag: + * 0 : bus -> valid + * 1 : bus -> NULL + */ +int test_sysfs_get_bus_drivers(int flag) +{ + struct sysfs_bus *bus = NULL; + struct dlist *list = NULL; + char *bus_name = NULL; + + switch (flag) { + case 0: + bus_name = val_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + break; + case 1: + bus = NULL; + break; + default: + return -1; + } + list = sysfs_get_bus_drivers(bus); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: No drivers registered with bus %s\n", + __FUNCTION__, bus_name); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_driver_list(list); + dbg_print("\n"); + } + break; + case 1: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + } + if (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus); + * + * flag: + * 0 : bus -> valid + * 1 : bus -> NULL + */ +int test_sysfs_get_bus_devices(int flag) +{ + struct sysfs_bus *bus = NULL; + struct dlist *list = NULL; + char *bus_name = NULL; + + switch (flag) { + case 0: + bus_name = val_bus_name; + bus = sysfs_open_bus(bus_name); + if (bus == NULL) { + dbg_print("%s: sysfs_open_bus() failed\n",__FUNCTION__); + return 0; + } + break; + case 1: + bus = NULL; + break; + default: + return -1; + } + list = sysfs_get_bus_devices(bus); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: No devices registered with bus %s\n", + __FUNCTION__, bus_name); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device_list(list); + dbg_print("\n"); + } + break; + case 1: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + } + if (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} diff --git a/sysfsutils/test/test_class.c b/sysfsutils/test/test_class.c new file mode 100644 index 0000000..c071ab1 --- /dev/null +++ b/sysfsutils/test/test_class.c @@ -0,0 +1,799 @@ +/* + * test_class.c + * + * Tests for class related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + *************************************************************************** + * this will test the class related functions provided by libsysfs. + * + * extern void sysfs_close_class_device(struct sysfs_class_device *dev); + * extern struct sysfs_class_device *sysfs_open_class_device_path + * (const char *path); + * extern struct sysfs_class_device *sysfs_open_class_device + * (const char *classname, const char *name); + * extern struct sysfs_device *sysfs_get_classdev_device + * (struct sysfs_class_device *clsdev); + * extern struct sysfs_class_device *sysfs_get_classdev_parent + * (struct sysfs_class_device *clsdev); + * extern void sysfs_close_class(struct sysfs_class *cls); + * extern struct sysfs_class *sysfs_open_class(const char *name); + * extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls); + * extern struct sysfs_class_device *sysfs_get_class_device + * (struct sysfs_class *cls, char *name); + * extern struct dlist *sysfs_get_classdev_attributes + * (struct sysfs_class_device *cdev); + * extern struct sysfs_attribute *sysfs_get_classdev_attr + * (struct sysfs_class_device *clsdev, const char *name); + ***************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * this test the function: + * extern void sysfs_close_class_device(struct sysfs_class_device *dev); + * this has no return, + * + * flag: + * 0: dev -> valid + * 1: dev -> NULL + */ +int test_sysfs_close_class_device(int flag) +{ + struct sysfs_class_device *dev = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_class_dev_path; + dev = sysfs_open_class_device_path(path); + if (dev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + break; + case 1: + dev = NULL; + break; + default: + return -1; + } + sysfs_close_class_device(dev); + + dbg_print("%s: returns void\n", __FUNCTION__); + return 0; +} + +/** + * extern struct sysfs_class_device *sysfs_open_class_device_path + * (const char *path); + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_open_class_device_path(int flag) +{ + struct sysfs_class_device *dev = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_class_dev_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + dev = sysfs_open_class_device_path(path); + + switch (flag) { + case 0: + if (dev == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_class_device(dev); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (dev != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + + } + if (dev != NULL) + sysfs_close_class_device(dev); + + return 0; +} + +/** + * extern struct sysfs_class_device *sysfs_open_class_device + * (const char *class, const char *name); + * + * flag: + * 0: class -> valid , name -> valid + * 1: class -> valid , name -> invalid + * 2: class -> valid , name -> NULL + * 3: class -> invalid , name -> valid + * 4: class -> invalid , name -> invalid + * 5: class -> invalid , name -> NULL + * 6: class -> NULL valid , name -> valid + * 7: class -> NULL , name -> invalid + * 8: class -> NULL , name -> NULL + */ +int test_sysfs_open_class_device(int flag) +{ + struct sysfs_class_device *clsdev = NULL; + char *name = NULL; + char *class = NULL; + + switch(flag) { + case 0: + class = val_class; + name = val_class_dev; + break; + case 1: + class = val_class; + name = inval_name; + break; + case 2: + class = val_class; + name = NULL; + break; + case 3: + class = inval_name; + name = val_class_dev; + break; + case 4: + class = inval_name; + name = inval_name; + break; + case 5: + class = inval_name; + name = NULL; + break; + case 6: + class = NULL; + name = val_class_dev; + break; + case 7: + class = NULL; + name = inval_name; + break; + case 8: + class = NULL; + name = NULL; + break; + default: + return -1; + } + clsdev = sysfs_open_class_device(class, name); + + switch(flag) { + case 0: + if (clsdev == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_class_device(clsdev); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + if (clsdev != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (clsdev != NULL) + sysfs_close_class_device(clsdev); + + return 0; +} + +/** + * extern struct sysfs_device *sysfs_get_classdev_device + * (struct sysfs_class_device *clsdev); + * + * flag: + * 0: clsdev -> valid + * 1: clsdev -> NULL + */ +int test_sysfs_get_classdev_device(int flag) +{ + struct sysfs_class_device *clsdev = NULL; + struct sysfs_device *dev = NULL; + char *path = NULL; + + switch(flag) { + case 0: + path = val_class_dev_path; + clsdev = sysfs_open_class_device_path(path); + if (clsdev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + break; + case 1: + clsdev = NULL; + break; + default: + return -1; + } + dev = sysfs_get_classdev_device(clsdev); + + switch (flag) { + case 0: + if (dev == NULL) { + if (errno == 0) + dbg_print("%s: Class device at %s does not have a device symlink\n", + __FUNCTION__, path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device(dev); + dbg_print("\n"); + } + break; + case 1: + if (dev != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (clsdev != NULL) + sysfs_close_class_device(clsdev); + + return 0; +} + +/** + * extern struct sysfs_class_device *sysfs_get_classdev_parent + * (struct sysfs_class_device *clsdev); + * flag: + * 0: clsdev -> valid + * 1: clsdev -> NULL + */ +int test_sysfs_get_classdev_parent(int flag) +{ + struct sysfs_class_device *clsdev = NULL; + struct sysfs_class_device *parent = NULL; + char *path = NULL; + + switch(flag) { + case 0: + path = val_block_class_dev_path; + clsdev = sysfs_open_class_device_path(path); + if (clsdev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + break; + case 1: + clsdev = NULL; + break; + default: + return -1; + } + parent = sysfs_get_classdev_parent(clsdev); + + switch (flag) { + case 0: + if (parent == NULL) { + if (errno == 0) + dbg_print("%s: Class device at %s does not have a parent\n", + __FUNCTION__, path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_class_device(parent); + dbg_print("\n"); + } + break; + case 1: + if (parent != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (clsdev != NULL) + sysfs_close_class_device(clsdev); + + return 0; +} + +/** + * extern void sysfs_close_class(struct sysfs_class *cls); + * + * flag: + * 0: cls -> valid + * 1: cls -> NULL + */ +int test_sysfs_close_class(int flag) +{ + struct sysfs_class *cls = NULL; + char *class = NULL; + + switch(flag) { + case 0: + class = val_class; + cls = sysfs_open_class(class); + if (cls == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, class); + return 0; + } + break; + case 1: + cls = NULL; + break; + default: + return -1; + } + sysfs_close_class(cls); + dbg_print("%s: returns void\n", __FUNCTION__); + + return 0; +} + +/** + * extern struct sysfs_class *sysfs_open_class(const char *name); + * + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + */ +int test_sysfs_open_class(int flag) +{ + struct sysfs_class *cls = NULL; + char *name = NULL; + + switch(flag) { + case 0: + name = val_class; + break; + case 1: + name = inval_name; + break; + case 2: + name = NULL; + break; + default: + return -1; + } + cls = sysfs_open_class(name); + + switch(flag) { + case 0: + if (cls == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Class %s is at %s\n\n", + cls->name, cls->path); + } + break; + case 1: + case 2: + if (cls != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (cls != NULL) + sysfs_close_class(cls); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls); + * + * flag: + * 0: cls -> valid + * 1: cls -> NULL + */ +int test_sysfs_get_class_devices(int flag) +{ + struct sysfs_class *cls = NULL; + struct dlist *list = NULL; + char *class = NULL; + + switch(flag) { + case 0: + class = val_class; + cls = sysfs_open_class(class); + if (cls == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, class); + return 0; + } + break; + case 1: + cls = NULL; + break; + default: + return -1; + } + list = sysfs_get_class_devices(cls); + + switch(flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: Class %s does not have devices\n", + __FUNCTION__, val_class); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_class_device_list(list); + dbg_print("\n"); + } + break; + case 1: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (cls != NULL) + sysfs_close_class(cls); + + return 0; +} + +/** + * extern struct sysfs_class_device *sysfs_get_class_device + * (struct sysfs_class *class, char *name); + * + * flag: + * 0: class -> valid, name -> valid + * 1: class -> valid, name -> invalid + * 2: class -> valid, name -> NULL + * 3: class -> NULL, name -> valid + * 4: class -> NULL, name -> invalid + * 5: class -> NULL, name -> NULL + */ +int test_sysfs_get_class_device(int flag) +{ + struct sysfs_class_device *clsdev = NULL; + struct sysfs_class *class = NULL; + char *name = NULL; + + switch(flag) { + case 0: + class = sysfs_open_class(val_class); + if (class == NULL) { + dbg_print("%s: failed opening class %s\n", + __FUNCTION__, val_class); + return 0; + } + name = val_class_dev; + break; + case 1: + class = sysfs_open_class(val_class); + if (class == NULL) { + dbg_print("%s: failed opening class %s\n", + __FUNCTION__, val_class); + return 0; + } + name = inval_name; + break; + case 2: + class = sysfs_open_class(val_class); + if (class == NULL) { + dbg_print("%s: failed opening class %s\n", + __FUNCTION__, val_class); + return 0; + } + name = NULL; + break; + case 3: + class = NULL; + name = val_class_dev; + break; + case 4: + class = NULL; + name = inval_name; + break; + case 5: + class = NULL; + name = NULL; + break; + default: + return -1; + } + clsdev = sysfs_get_class_device(class, name); + + switch(flag) { + case 0: + if (clsdev == NULL) { + if (errno == 0) + dbg_print("%s: Class device %s does not belong to the %s class\n", + __FUNCTION__, val_class_dev, val_class); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_class_device(clsdev); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (clsdev != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (class) + sysfs_close_class(class); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_classdev_attributes + * (struct sysfs_class_device *cdev); + * flag: + * 0: cdev -> valid + * 1: cdev -> NULL + */ +int test_sysfs_get_classdev_attributes(int flag) +{ + struct dlist *list = NULL; + struct sysfs_class_device *cdev = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_class_dev_path; + cdev = sysfs_open_class_device_path(path); + if (cdev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + break; + case 1: + cdev = NULL; + break; + default: + return -1; + } + list = sysfs_get_classdev_attributes(cdev); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: Class device at %s does not export attributes\n", + __FUNCTION__, path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute_list(list); + dbg_print("\n"); + } + break; + case 1: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (cdev != NULL) + sysfs_close_class_device(cdev); + + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_get_classdev_attr + * (struct sysfs_class_device *clsdev, const char *name); + * + * flag: + * 0: clsdev -> valid, name -> valid + * 1: clsdev -> valid, name -> invalid + * 2: clsdev -> valid, name -> NULL + * 3: clsdev -> NULL, name -> valid + * 4: clsdev -> NULL, name -> invalid + * 5: clsdev -> NULL, name -> NULL + */ +int test_sysfs_get_classdev_attr(int flag) +{ + struct sysfs_attribute *attr = NULL; + struct sysfs_class_device *clsdev = NULL; + char *name = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_class_dev_path; + clsdev = sysfs_open_class_device_path(path); + if (clsdev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + name = val_class_dev_attr; + break; + case 1: + path = val_class_dev_path; + clsdev = sysfs_open_class_device_path(path); + if (clsdev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + name = inval_name; + break; + case 2: + path = val_class_dev_path; + clsdev = sysfs_open_class_device_path(path); + if (clsdev == NULL) { + dbg_print("%s: failed opening class device at %s\n", + __FUNCTION__, path); + return 0; + } + name = NULL; + break; + case 3: + clsdev = NULL; + name = val_class_dev_attr; + break; + case 4: + clsdev = NULL; + name = inval_name; + break; + case 5: + clsdev = NULL; + name = NULL; + break; + default: + return -1; + } + attr = sysfs_get_classdev_attr(clsdev, name); + + switch (flag) { + case 0: + if (attr == NULL) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support READ\n", + __FUNCTION__, name); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for class device at %s\n", + __FUNCTION__, name, path); + else if (errno == 0) + dbg_print("%s: class device at %s does not export attributes\n", + __FUNCTION__, path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (attr != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + + } + if (clsdev != NULL) + sysfs_close_class_device(clsdev); + + return 0; +} diff --git a/sysfsutils/test/test_device.c b/sysfsutils/test/test_device.c new file mode 100644 index 0000000..47000f2 --- /dev/null +++ b/sysfsutils/test/test_device.c @@ -0,0 +1,459 @@ +/* + * test_root.c + * + * Tests for device/root device related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + ****************************************************************************** + * this will test the device/root device related functions provided by libsysfs + * + * extern void sysfs_close_device(struct sysfs_device *dev); + * extern struct sysfs_device *sysfs_open_device + * (const char *bus, const char *bus_id); + * extern struct sysfs_device *sysfs_get_device_parent + * (struct sysfs_device *dev); + * extern struct sysfs_device *sysfs_open_device_path + * (const char *path); + * extern struct sysfs_attribute *sysfs_get_device_attr + * (struct sysfs_device *dev, const char *name); + * extern struct dlist *sysfs_get_device_attributes + * (struct sysfs_device *device); + ****************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * extern void sysfs_close_device(struct sysfs_device *dev); + * + * flag: + * 0: dev -> valid + * 1: dev -> NULL + */ +int test_sysfs_close_device(int flag) +{ + struct sysfs_device *dev = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_dev_path; + dev = sysfs_open_device_path(path); + if (dev == NULL) { + dbg_print("%s: failed to open device at %s\n", + __FUNCTION__, path); + return 0; + } + break; + case 1: + dev = NULL; + break; + default: + return -1; + } + sysfs_close_device(dev); + + dbg_print("%s: returns void\n", __FUNCTION__); + return 0; +} + +/** + * extern struct sysfs_device *sysfs_open_device + * (const char *bus, const char *bus_id); + * + * flag: + * 0: bus -> valid, bus_id -> valid + * 1: bus -> valid, bus_id -> invalid + * 2: bus -> valid, bus_id -> invalid + * 3: bus -> invalid, bus_id -> valid + * 4: bus -> invalid, bus_id -> invalid + * 5: bus -> invalid, bus_id -> invalid + * 6: bus -> NULL, bus_id -> valid + * 7: bus -> NULL, bus_id -> invalid + * 8: bus -> NULL, bus_id -> invalid + */ +int test_sysfs_open_device(int flag) +{ + struct sysfs_device *dev = NULL; + char *bus = NULL; + char *bus_id = NULL; + + switch (flag) { + case 0: + bus = val_bus_name; + bus_id = val_bus_id; + break; + case 1: + bus = val_bus_name; + bus_id = inval_name; + break; + case 2: + bus = val_bus_name; + bus_id = NULL; + break; + case 3: + bus = inval_name; + bus_id = val_bus_id; + break; + case 4: + bus = inval_name; + bus_id = inval_name; + break; + case 5: + bus = inval_name; + bus_id = NULL; + break; + case 6: + bus = NULL; + bus_id = val_bus_id; + break; + case 7: + bus = NULL; + bus_id = inval_name; + break; + case 8: + bus = NULL; + bus_id = NULL; + break; + default: + return -1; + } + dev = sysfs_open_device(bus, bus_id); + + switch (flag) { + case 0: + if (dev == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device(dev); + dbg_print("\n"); + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + if (dev == NULL) + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + break; + } + + if (dev != NULL) + sysfs_close_device(dev); + return 0; +} + +/** + * extern struct sysfs_device *sysfs_get_device_parent + * (struct sysfs_device *dev); + * + * flag: + * 0: dev -> valid + * 1: dev -> NULL + */ +int test_sysfs_get_device_parent(int flag) +{ + struct sysfs_device *pdev = NULL; + struct sysfs_device *dev = NULL; + char *dev_path = NULL; + + switch (flag) { + case 0: + dev_path = val_dev_path; + dev = sysfs_open_device_path(dev_path); + if (dev == NULL) { + dbg_print("%s: failed to open device at %s\n", + __FUNCTION__, dev_path); + return 0; + } + break; + case 1: + dev = NULL; + break; + default: + return -1; + } + pdev = sysfs_get_device_parent(dev); + + switch (flag) { + case 0: + if (pdev == NULL) { + if (errno == 0) + dbg_print("%s: Device at %s does not have a parent\n", + __FUNCTION__, dev_path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device(pdev); + dbg_print("\n"); + } + break; + case 1: + if (pdev == NULL) + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + default: + break; + } + if (dev != NULL) { + sysfs_close_device(dev); + } + return 0; +} + +/** + * extern struct sysfs_device *sysfs_open_device_path + * (const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + * + */ +int test_sysfs_open_device_path(int flag) +{ + struct sysfs_device *dev = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_dev_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + dev = sysfs_open_device_path(path); + + switch (flag) { + case 0: + if (dev == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device(dev); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (dev == NULL) + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + default: + break; + } + if (dev != NULL) + sysfs_close_device(dev); + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_get_device_attr + * (struct sysfs_device *dev, const char *name); + * + * flag: + * 0: dev -> valid, name -> valid + * 1: dev -> valid, name -> invalid + * 2: dev -> valid, name -> NULL + * 3: dev -> NULL, name -> valid + * 4: dev -> NULL, name -> invalid + * 5: dev -> NULL, name -> NULL + */ +int test_sysfs_get_device_attr(int flag) +{ + struct sysfs_device *dev = NULL; + char *name = NULL; + char *path = NULL; + struct sysfs_attribute *attr = NULL; + + switch (flag) { + case 0: + path = val_dev_path; + dev = sysfs_open_device_path(path); + if (dev == NULL) { + dbg_print("%s: failed to open device at %s\n", + __FUNCTION__, path); + return 0; + } + name = val_dev_attr; + break; + case 1: + dev = sysfs_open_device_path(path); + name = inval_name; + break; + case 2: + dev = sysfs_open_device_path(path); + name = NULL; + break; + case 3: + dev = NULL; + name = val_dev_attr; + break; + case 4: + dev = NULL; + name = inval_name; + break; + case 5: + dev = NULL; + name = NULL; + break; + default: + return -1; + } + attr = sysfs_get_device_attr(dev, name); + + switch (flag) { + case 0: + if (attr == NULL) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support READ\n", + __FUNCTION__, name); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for device at %s\n", + __FUNCTION__, name, path); + else if (errno == 0) + dbg_print("%s: device at %s does not export attributes\n", + __FUNCTION__, path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (attr != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + if (errno == EINVAL) + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } + default: + break; + } + + if (dev != NULL) + sysfs_close_device(dev); + return 0; +} + +/** + * extern struct dlist *sysfs_get_device_attributes + * (struct sysfs_device *device); + * + * flag: + * 0: device -> valid + * 1: device -> NULL + */ +int test_sysfs_get_device_attributes(int flag) +{ + struct sysfs_device *device = NULL; + struct dlist *list = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_dev_path; + device = sysfs_open_device_path(path); + if (device == NULL) { + dbg_print("%s: failed to open device at %s\n", + __FUNCTION__, path); + return 0; + } + break; + case 1: + device = NULL; + break; + default: + return -1; + } + list = sysfs_get_device_attributes(device); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: device at %s does not export attributes\n", + __FUNCTION__, path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute_list(list); + dbg_print("\n"); + } + break; + case 1: + if (errno != EINVAL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (device != NULL) + sysfs_close_device(device); + return 0; +} diff --git a/sysfsutils/test/test_driver.c b/sysfsutils/test/test_driver.c new file mode 100644 index 0000000..66e1ca6 --- /dev/null +++ b/sysfsutils/test/test_driver.c @@ -0,0 +1,478 @@ +/* + * test_driver.c + * + * Tests for driver related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + ****************************************************************************** + * this will test the driver related functions provided by libsysfs. + * + * extern void sysfs_close_driver(struct sysfs_driver *driver); + * extern struct sysfs_driver *sysfs_open_driver + * (const char *bus_name, const char *drv_name); + * extern struct sysfs_driver *sysfs_open_driver_path + * (const char *path); + * extern struct sysfs_attribute *sysfs_get_driver_attr + * (struct sysfs_driver *drv, const char *name); + * extern struct dlist *sysfs_get_driver_attributes + * (struct sysfs_driver *driver); + * extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver); + ****************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * extern void sysfs_close_driver(struct sysfs_driver *driver); + * + * flag: + * 0: driver -> valid + * 1: driver -> NULL + */ +int test_sysfs_close_driver(int flag) +{ + struct sysfs_driver *driver = NULL; + + switch (flag) { + case 0: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) + return 0; + break; + case 1: + driver = NULL; + break; + default: + return -1; + } + sysfs_close_driver(driver); + + dbg_print("%s: returns void\n", __FUNCTION__); + return 0; +} + +/** + * extern struct sysfs_driver *sysfs_open_driver_path + * (const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_open_driver_path(int flag) +{ + struct sysfs_driver *driver = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_drv_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + driver = sysfs_open_driver_path(path); + + switch (flag) { + case 0: + if (driver == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_driver(driver); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (driver != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (driver != NULL) + sysfs_close_driver(driver); + + return 0; +} + +/** + * extern struct sysfs_driver *sysfs_open_driver + * (const char *bus_name, const char *drv_name); + * + * flag: + * 0: path -> valid, name -> valid + * 1: path -> valid, name -> invalid + * 2: path -> valid, name -> NULL + * 3: path -> invalid, name -> valid + * 4: path -> invalid, name -> invalid + * 5: path -> invalid, name -> NULL + * 6: path -> NULL, name -> valid + * 7: path -> NULL, name -> invalid + * 8: path -> NULL, name -> NULL + */ +int test_sysfs_open_driver(int flag) +{ + struct sysfs_driver *driver = NULL; + char *bus_name = NULL; + char *drv_name = NULL; + + switch (flag) { + case 0: + bus_name = val_drv_bus_name; + drv_name = val_drv_name; + dbg_print("bus_name = %s, drv_name = %s\n", bus_name, drv_name); + break; + case 1: + bus_name = val_drv_bus_name; + drv_name = inval_name; + break; + case 2: + bus_name = val_drv_bus_name; + drv_name = NULL; + break; + case 3: + bus_name = inval_name; + drv_name = val_drv_name; + break; + case 4: + bus_name = inval_name; + drv_name = inval_name; + break; + case 5: + bus_name = inval_name; + drv_name = NULL; + break; + case 6: + bus_name = NULL; + drv_name = val_drv_name; + break; + case 7: + bus_name = NULL; + drv_name = inval_name; + break; + case 8: + bus_name = NULL; + drv_name = NULL; + break; + + default: + return -1; + } + driver = sysfs_open_driver(bus_name, drv_name); + switch (flag) { + case 0: + if (driver == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_driver(driver); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (driver != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (driver != NULL) + sysfs_close_driver(driver); + + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_get_driver_attr + * (struct sysfs_driver *drv, const char *name); + * + * flag: + * 0: drv -> valid, name -> valid + * 1: drv -> valid, name -> invalid + * 2: drv -> valid, name -> NULL + * 3: drv -> NULL, name -> valid + * 4: drv -> NULL, name -> invalid + * 5: drv -> NULL, name -> NULL + */ +int test_sysfs_get_driver_attr(int flag) +{ + char *name = NULL; + char *attrname = NULL; + struct sysfs_driver *drv = NULL; + struct sysfs_attribute *attr = NULL; + + switch (flag) { + case 0: + name = val_drv_path; + drv = sysfs_open_driver_path(name); + if (drv == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, name); + return 0; + } + attrname = val_drv_attr_name; + break; + case 1: + name = val_drv_path; + drv = sysfs_open_driver_path(name); + if (drv == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, name); + return 0; + } + attrname = inval_name; + break; + case 2: + name = val_drv_path; + drv = sysfs_open_driver_path(name); + if (drv == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, name); + return 0; + } + attrname = NULL; + break; + case 3: + drv = NULL; + attrname = val_drv_attr_name; + break; + case 4: + drv = NULL; + attrname = inval_name; + break; + case 5: + drv = NULL; + attrname = NULL; + break; + default: + return -1; + } + + attr = sysfs_get_driver_attr(drv, attrname); + switch (flag) { + case 0: + if (attr == NULL) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support READ\n", + __FUNCTION__, attrname); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for driver at %s\n", + __FUNCTION__, attrname, name); + else if (errno == 0) + dbg_print("%s: driver at %s does not export attributes\n", + __FUNCTION__, val_drv_path); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (attr != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (drv != NULL) + sysfs_close_driver(drv); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_driver_attributes + * (struct sysfs_driver *driver); + * + * flag: + * 0: driver -> valid + * 1: driver -> NULL + */ +int test_sysfs_get_driver_attributes(int flag) +{ + struct sysfs_driver *driver = NULL; + struct dlist *list = NULL; + char *drv = NULL; + + switch (flag) { + case 0: + drv = val_drv_path; + driver = sysfs_open_driver_path(drv); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + break; + case 1: + driver = NULL; + break; + case 2: + drv = val_drv1_path; + driver = sysfs_open_driver_path(drv); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv1_path); + return 0; + } + break; + default: + return -1; + } + list = sysfs_get_driver_attributes(driver); + + switch (flag) { + case 0: + case 2: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: No attributes are defined for the driver at %s\n", + __FUNCTION__, drv); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute_list(list); + dbg_print("\n"); + } + break; + case 1: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (driver != NULL) + sysfs_close_driver(driver); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver); + * + * flag: + * 0: driver -> valid + * 1: driver -> NULL + */ +int test_sysfs_get_driver_devices(int flag) +{ + struct sysfs_driver *driver = NULL; + struct dlist *list = NULL; + char *drv = NULL; + + switch (flag) { + case 0: + drv = val_drv_path; + driver = sysfs_open_driver_path(drv); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + break; + case 1: + driver = NULL; + break; + case 2: + drv = val_drv1_path; + driver = sysfs_open_driver_path(drv); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv1_path); + return 0; + } + break; + default: + return -1; + } + errno = 0; + list = sysfs_get_driver_devices(driver); + + switch (flag) { + case 0: + case 2: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: No devices are using the driver at %s\n", + __FUNCTION__, drv); + else + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_device_list(list); + dbg_print("\n"); + } + break; + case 1: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + if (driver != NULL) + sysfs_close_driver(driver); + + return 0; +} diff --git a/sysfsutils/test/test_module.c b/sysfsutils/test/test_module.c new file mode 100644 index 0000000..b4e6523 --- /dev/null +++ b/sysfsutils/test/test_module.c @@ -0,0 +1,711 @@ +/* + * sysfs_module.c + * + * Generic module utility functions for libsysfs + * + * Copyright (C) IBM Corp. 2003-2005 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/** + *************************************************************************** + * this will test the module related functions provided by libsysfs. + * + * extern void sysfs_close_module(struct sysfs_module *module); + * extern struct sysfs_module *sysfs_open_module_path(const char *path); + * extern struct sysfs_module *sysfs_open_module(const char *name); + * extern struct dlist *sysfs_get_module_attributes + * (struct sysfs_module *module); + * extern struct sysfs_attribute *sysfs_get_module_attr + * (struct sysfs_module *module, const char *name); + * extern struct dlist *sysfs_get_module_parms(struct sysfs_module *module); + * extern struct dlist *sysfs_get_module_sections(struct sysfs_module *module); + * extern struct sysfs_attribute *sysfs_get_module_parm + * (struct sysfs_module *module, const char *parm); + * extern struct sysfs_attribute *sysfs_get_module_section + * (struct sysfs_module *module, const char *section); + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * sysfs_close_module: closes a module. + * @module: sysfs_module device to close. + * flag: + * 0: path -> valid + * 1: path -> NULL + */ +int test_sysfs_close_module(int flag) +{ + struct sysfs_module *module; + + switch (flag) { + case 0: + module = sysfs_open_module_path(val_mod_path); + if (module == NULL) + return 0; + break; + case 1: + module = NULL; + break; + default: + return -1; + } + sysfs_close_module(module); + + dbg_print("%s: returns void\n",__FUNCTION__); + return 0; +} + +/** + * sysfs_open_module_path: Opens and populates the module struct + * @path: path to module. + * returns struct sysfs_module with success and NULL with error. + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_open_module_path(int flag) +{ + struct sysfs_module *module = NULL; + char *path = NULL; + + switch (flag) { + case 0: + path = val_mod_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + + module = sysfs_open_module_path(path); + + switch (flag) { + case 0: + if (module == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_module(module); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (module != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + + if (module!= NULL) + sysfs_close_module(module); + + return 0; +} + +/** + * sysfs_open_module: opens specific module on a system + * returns sysfs_module structure with success or NULL with error. + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + */ +int test_sysfs_open_module(int flag) +{ + struct sysfs_module *module = NULL; + char *modname = NULL; + + switch (flag) { + case 0: + modname = val_mod_name; + break; + case 1: + modname = inval_name; + break; + case 2: + modname = NULL; + break; + default: + return -1; + } + + module = sysfs_open_module(modname); + + switch (flag) { + case 0: + if (module == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_module(module); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (module) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} + +/** + * sysfs_get_module_attr: searches module's attributes by name + * @module: module to look through + * @name: attribute name to get + * returns sysfs_attribute reference with success or NULL with error + * flag: + * 0: name -> valid, attrname -> valid + * 1: name -> valid, attrname -> invalid + * 2: name -> valid, attrname -> NULL + */ +int test_sysfs_get_module_attr(int flag) +{ + char *name, *attrname; + struct sysfs_attribute *attr; + struct sysfs_module *module; + + switch (flag) { + case 0: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + attrname = val_mod_attr_name; + break; + case 1: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + attrname = inval_name; + break; + case 2: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + attrname = NULL; + break; + default: + return -1; + } + + attr = sysfs_get_module_attr(module,attrname); + + switch (flag) { + case 0: + if(!attr) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support " + "READ\n", __FUNCTION__, attrname); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for " + "module at %s\n", __FUNCTION__, + attrname, name); + else if (errno == 0) + dbg_print("%s: module at %s does not export " + "attributes\n", __FUNCTION__, val_drv_path); + else + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + + case 1: + case 2: + if (attr) + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + dbg_print("******************\n"); + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} + +/** + * sysfs_get_module_attributes: returns a dlist of attributes for + * the requested sysfs_module + * @cdev: sysfs_module for which attributes are needed + * returns a dlist of attributes if exists, NULL otherwise + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + */ +int test_sysfs_get_module_attributes(int flag) +{ + struct dlist *list; + struct sysfs_module *module; + char *name; + + switch (flag) { + case 0: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + break; + case 1: + name = inval_name; + module = sysfs_open_module_path(name); + if (!module) { + return 0; + } + break; + case 2: + name = NULL; + module = sysfs_open_module_path(name); + if (!module) { + return 0; + } + default: + return -1; + } + + list = sysfs_get_module_attributes(module); + + switch (flag) { + case 0: + if (!list) { + if (errno == 0) + dbg_print("%s: No attributes are defined for " + "the module at %s\n", __FUNCTION__, name); + else + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute_list(list); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} + +/** + * sysfs_get_module_parms: Get modules list of parameters + * @module: sysfs_module whose parmameter list is required + * Returns dlist of parameters on SUCCESS and NULL on error + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + */ +int test_sysfs_get_module_parms(int flag) +{ + struct dlist *params; + char *name; + struct sysfs_module *module; + switch (flag) { + case 0: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + break; + case 1: + name = inval_name; + module = sysfs_open_module_path(name); + if (!module) { + return 0; + } + break; + case 2: + name = NULL; + module = sysfs_open_module_path(name); + if (!module) { + return 0; + } + break; + default: + return -1; + } + + params = sysfs_get_module_parms(module); + + switch (flag) { + case 0: + if (!params) { + if (errno == 0) + dbg_print("%s: No parameters are passed for " + "the module at %s\n", __FUNCTION__, name); + else + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_parm_list(params); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (params) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} + +/** + * sysfs_get_module_sections: Get the set of sections for this module + * @module: sysfs_module whose list of sections is required + * Returns dlist of sections on SUCCESS and NULL on error + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + */ +int test_sysfs_get_module_sections(int flag) +{ + struct dlist *sections; + char *name; + struct sysfs_module *module; + + switch (flag) { + case 0: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + break; + case 1: + name = inval_name; + module = sysfs_open_module_path(name); + if (!module) { + return 0; + } + break; + case 2: + name = NULL; + module = sysfs_open_module_path(name); + if (!module) { + return 0; + } + break; + default: + return -1; + } + + sections = sysfs_get_module_sections(module); + + switch (flag) { + case 0: + if (!sections) { + if (errno == 0) + dbg_print("%s: No sections for the module at " + "%s\n", __FUNCTION__, name); + else + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_section_list(sections); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (sections) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} + +/** + * sysfs_get_module_parm: + * @module: sysfs_module to look through + * @parm: name of the parameter to look for + * Returns sysfs_attribute * on SUCCESS and NULL on error + * flag: + * 0: name -> valid, paramname -> valid + * 1: name -> valid, paramname -> invalid + * 2: name -> valid, paramname -> NULL + */ +int test_sysfs_get_module_parm(int flag) +{ + char *name, *paramname; + struct sysfs_attribute *attr; + struct sysfs_module *module; + + switch (flag) { + case 0: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + paramname = val_mod_param; + break; + case 1: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + paramname = inval_name; + break; + case 2: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + paramname = NULL; + break; + default: + return -1; + } + + attr = sysfs_get_module_parm(module,paramname); + + switch (flag) { + case 0: + if(!attr) { + if (errno == EACCES) + dbg_print("%s: parameter %s not used by module" + , __FUNCTION__, paramname); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for " + "module at %s\n", __FUNCTION__, + paramname, name); + else if (errno == 0) + dbg_print("%s: module at %s does not use " + "parameter\n", __FUNCTION__, val_mod_path); + else + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + + case 1: + case 2: + if (attr) + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} + +/** + * sysfs_get_module_section + * @module: sysfs_module to look through + * @section: name of the section to look for + * Returns sysfs_attribute * on SUCCESS and NULL on error + * flag: + * 0: name -> valid, sectname -> valid + * 1: name -> valid, sectname -> invalid + * 2: name -> valid, sectname -> NULL + */ +int test_sysfs_get_module_section(int flag) +{ + char *name, *sectname; + struct sysfs_attribute *attr; + struct sysfs_module *module; + + switch (flag) { + case 0: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + sectname = val_mod_section; + break; + case 1: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + sectname = inval_name; + break; + case 2: + name = val_mod_path; + module = sysfs_open_module_path(name); + if (!module) { + dbg_print("%s: failed opening module at %s\n", + __FUNCTION__, name); + return 0; + } + sectname = NULL; + break; + default: + return -1; + } + + attr = sysfs_get_module_section(module,sectname); + + switch (flag) { + case 0: + if(!attr) { + if (errno == EACCES) + dbg_print("%s: section %s not used by module" + , __FUNCTION__, sectname); + else if (errno == ENOENT) + dbg_print("%s: section %s not defined for " + "module at %s\n", __FUNCTION__, + sectname, name); + else if (errno == 0) + dbg_print("%s: module at %s does not use " + "section\n", __FUNCTION__, val_mod_path); + else + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + } else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + + case 1: + case 2: + if (attr) + dbg_print("%s: FAILED with flag = %d errno = " + "%d\n", __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + default: + break; + } + + if (module) + sysfs_close_module(module); + return 0; +} diff --git a/sysfsutils/test/test_utils.c b/sysfsutils/test/test_utils.c new file mode 100644 index 0000000..f935140 --- /dev/null +++ b/sysfsutils/test/test_utils.c @@ -0,0 +1,628 @@ +/* + * test_utils.c + * + * Tests for utility functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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. + * + */ + +/** + *************************************************************************** + * this will test the utility functions provided by libsysfs. + * + * extern int sysfs_get_mnt_path(char *mnt_path, size_t len); + * extern int sysfs_remove_trailing_slash(char *path); + * extern int sysfs_get_name_from_path(const char *path, + * char *name, size_t len); + * extern int sysfs_path_is_dir(const char *path); + * extern int sysfs_path_is_link(const char *path); + * extern int sysfs_path_is_file(const char *path); + * extern int sysfs_get_link(const char *path, char *target, size_t len); + * extern struct dlist *sysfs_open_directory_list(char *name); + * extern struct dlist *sysfs_open_link_list(char *name); + * extern void sysfs_close_list(struct dlist *list); + ***************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * extern int sysfs_get_mnt_path(char *mnt_path, size_t len); + * + * flag: + * 0: mnt_path -> valid, len -> valid + * 1: mnt_path -> valid, len -> 0 + * 2: mnt_path -> NULL, len -> valid + * 3: mnt_path -> NULL, len -> NULL + */ +int test_sysfs_get_mnt_path(int flag) +{ + char *mnt_path = NULL; + size_t len = 0; + int ret = 0; + + switch (flag) { + case 0: + mnt_path = calloc(1, SYSFS_PATH_MAX); + len = SYSFS_PATH_MAX; + break; + case 1: + mnt_path = calloc(1, SYSFS_PATH_MAX); + len = 0; + break; + case 2: + mnt_path = NULL; + len = SYSFS_PATH_MAX; + break; + case 3: + mnt_path = NULL; + len = 0; + break; + default: + return -1; + } + ret = sysfs_get_mnt_path(mnt_path, len); + + switch (flag) { + case 0: + if (ret) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("sysfs is mounted at \"%s\"\n\n", mnt_path); + } + break; + case 1: + case 2: + case 3: + if (!ret) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (mnt_path != NULL) { + free(mnt_path); + mnt_path = NULL; + } + + return 0; +} + +/** + * extern int sysfs_remove_trailing_slash(char *path); + * + * flag: + * 0: path -> valid + * 1: path -> NULL + */ +int test_sysfs_remove_trailing_slash(int flag) +{ + char *path = NULL; + int ret = 0; + + switch (flag) { + case 0: + path = calloc(1, SYSFS_PATH_MAX); + strcpy(path, "/some/path/is/this/"); + break; + case 1: + path = NULL; + break; + default: + return -1; + } + ret = sysfs_remove_trailing_slash(path); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Path now is \"%s\"\n\n", path); + } + break; + case 1: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + + if (path != NULL) { + free(path); + path = NULL; + } + + return 0; +} + +/** + * extern int sysfs_get_name_from_path(const char *path, + * char *name, size_t len); + * + * flag: + * 0: path -> valid, name -> valid, len -> valid + * 1: path -> valid, name -> NULL, len -> invalid + * 2: path -> NULL, name -> valid, len -> valid + * 3: path -> NULL, name -> NULL, len -> invalid + */ +int test_sysfs_get_name_from_path(int flag) +{ + char *path = NULL; + char *name = NULL; + size_t len = SYSFS_NAME_LEN; + int ret = 0; + + switch (flag) { + case 0: + path = val_dir_path; + name = calloc(1, SYSFS_NAME_LEN); + break; + case 1: + path = val_dir_path; + name = NULL; + break; + case 2: + path = NULL; + name = calloc(1, SYSFS_NAME_LEN); + break; + case 3: + path = NULL; + name = NULL; + break; + default: + return -1; + } + ret = sysfs_get_name_from_path(path, name, len); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Name extracted from \"%s\" is \"%s\"\n\n", + path, name); + } + break; + case 1: + case 2: + case 3: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (name != NULL) { + free(name); + name = NULL; + } + + return 0; +} + +/** + * extern int sysfs_path_is_dir(const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_path_is_dir(int flag) +{ + char *path = NULL; + int ret = 0; + + switch (flag) { + case 0: + path = val_dir_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + ret = sysfs_path_is_dir(path); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Path \"%s\" points to a directory\n\n", + path); + } + break; + case 1: + case 2: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + break; + } + + return 0; +} + +/** + * extern int sysfs_path_is_link(const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_path_is_link(int flag) +{ + char *path = NULL; + int ret = 0; + + switch (flag) { + case 0: + path = val_link_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + ret = sysfs_path_is_link(path); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Path \"%s\" points to a link\n\n", + path); + } + break; + case 1: + case 2: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + break; + } + + return 0; +} + +/** + * extern int sysfs_path_is_file(const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_path_is_file(int flag) +{ + char *path = NULL; + int ret = 0; + + switch (flag) { + case 0: + path = val_file_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + ret = sysfs_path_is_file(path); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Path \"%s\" points to a file\n\n", + path); + } + break; + case 1: + case 2: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + break; + } + return 0; +} + +/** + * extern int sysfs_get_link(const char *path, + * char *target, size_t len); + * + * flag: + * 0: path -> valid, target -> valid + * 1: path -> valid, target -> NULL + * 2: path -> NULL, target -> valid + * 3: path -> NULL, target -> NULL + */ +int test_sysfs_get_link(int flag) +{ + char *path = NULL; + char *target = NULL; + size_t len = SYSFS_PATH_MAX; + int ret = 0; + + switch (flag) { + case 0: + path = val_link_path; + target = calloc(1, SYSFS_PATH_MAX); + break; + case 1: + path = val_link_path; + target = NULL; + break; + case 2: + path = NULL; + target = calloc(1, SYSFS_PATH_MAX); + break; + case 3: + path = NULL; + target = NULL; + break; + default: + return -1; + } + ret = sysfs_get_link(path, target, len); + + switch (flag) { + case 0: + if (ret != 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + dbg_print("Link at \"%s\" points to \"%s\"\n\n", + path, target); + } + break; + case 1: + case 2: + case 3: + if (ret == 0) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + return 0; + break; + } + if (target != NULL) { + free(target); + target = NULL; + } + + return 0; +} + +/** + * extern struct dlist *sysfs_open_directory_list(char *name); + * + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + * + */ +int test_sysfs_open_directory_list(int flag) +{ + char *path = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + path = val_dir_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + list = sysfs_open_directory_list(path); + + switch (flag) { + case 0: + if (list == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_list(list); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (list != NULL) { + sysfs_close_list(list); + list = NULL; + } + + return 0; +} + +/** + * extern struct dlist *sysfs_open_link_list(char *name); + * + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + * + */ +int test_sysfs_open_link_list(int flag) +{ + char *path = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + path = val_link_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + list = sysfs_open_link_list(path); + + switch (flag) { + case 0: + if (list == NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else { + dbg_print("%s: SUCCEEDED with flag = %d\n\n", + __FUNCTION__, flag); + show_list(list); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (list != NULL) + dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); + else + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + break; + default: + break; + } + if (list != NULL) { + sysfs_close_list(list); + list = NULL; + } + + return 0; +} +/** + * extern void sysfs_close_list(struct dlist *list); + * + * flag: + * 0: list -> valid + * 1: list -> NULL + */ +int test_sysfs_close_list(int flag) +{ + struct dlist *list = NULL; + + switch (flag) { + case 0: + list = NULL; + break; + default: + return -1; + } + sysfs_close_list(list); + + dbg_print("%s: returns void\n", __FUNCTION__); + + return 0; +} diff --git a/sysfsutils/test/testout.c b/sysfsutils/test/testout.c new file mode 100644 index 0000000..8deb351 --- /dev/null +++ b/sysfsutils/test/testout.c @@ -0,0 +1,147 @@ +/* + * testout.c + * + * Display routines for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004-2005 + * + * 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_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_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); + } +} + +void show_parm_list(struct dlist *list) +{ + if (list != NULL) { + char *name = NULL; + + dlist_for_each_data(list, name, char) + dbg_print("%s\n", name); + } +} + +void show_section_list(struct dlist *list) +{ + if (list != NULL) { + char *name = NULL; + + dlist_for_each_data(list, name, char) + dbg_print("%s\n", name); + } +} + +void show_module(struct sysfs_module *module) +{ + if (module) { + dbg_print("Module name is %s, path is %s\n", + module->name, module->path); + show_attribute_list(module->attrlist); + show_parm_list(module->parmlist); + show_section_list(module->sections); + } +} |