diff options
author | stekloff <stekloff> | 2005-04-06 20:57:01 +0000 |
---|---|---|
committer | stekloff <stekloff> | 2005-04-06 20:57:01 +0000 |
commit | dd8c511d725f816bc64592028ff178616fcde607 (patch) | |
tree | 55250e02ac67ceeb3c2bac3b1e29a78c22be1ac2 /test | |
parent | 855a337e54321d9aa2b97c38ffa4787d3105257c (diff) | |
download | sysfsutils-master.tar.gz |
Diffstat (limited to 'test')
-rw-r--r-- | test/GPL | 272 | ||||
-rw-r--r-- | test/Makefile.am | 20 | ||||
-rw-r--r-- | test/Makefile.in | 455 | ||||
-rwxr-xr-x | test/create-test | 36 | ||||
-rw-r--r-- | test/dlist_test.c | 313 | ||||
-rw-r--r-- | test/get_bus_devices_list.c | 54 | ||||
-rw-r--r-- | test/get_class_dev.c | 72 | ||||
-rw-r--r-- | test/get_classdev_parent.c | 78 | ||||
-rw-r--r-- | test/get_device.c | 63 | ||||
-rw-r--r-- | test/get_driver.c | 85 | ||||
-rw-r--r-- | test/libsysfs.conf | 82 | ||||
-rw-r--r-- | test/test-defs.h | 155 | ||||
-rw-r--r-- | test/test.c | 385 | ||||
-rw-r--r-- | test/test_bus.c | 777 | ||||
-rw-r--r-- | test/test_class.c | 1158 | ||||
-rw-r--r-- | test/test_dir.c | 1763 | ||||
-rw-r--r-- | test/test_driver.c | 1009 | ||||
-rw-r--r-- | test/test_root.c | 936 | ||||
-rw-r--r-- | test/test_utils.c | 654 | ||||
-rw-r--r-- | test/testout.c | 187 | ||||
-rw-r--r-- | test/write_attr.c | 61 |
21 files changed, 8615 insertions, 0 deletions
diff --git a/test/GPL b/test/GPL new file mode 100644 index 0000000..cde4efd --- /dev/null +++ b/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/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..e33528c --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,20 @@ +bin_PROGRAMS = dlist_test get_class_dev get_device get_driver write_attr \ + get_bus_devices_list get_classdev_parent testlibsysfs +BUILT_SOURCES = test.h +CLEANFILES = test.h +test.h: + ./create-test +dlist_test_SOURCES = dlist_test.c +get_class_dev_SOURCES = get_class_dev.c +get_device_SOURCES = get_device.c +get_driver_SOURCES = get_driver.c +get_bus_devices_list_SOURCES = get_bus_devices_list.c +write_attr_SOURCES = write_attr.c +get_classdev_parent_SOURCES = get_classdev_parent.c +testlibsysfs_SOURCES = test.c test_bus.c test_class.c test_dir.c test_driver.c \ + test_root.c test_utils.c testout.c test-defs.h \ + libsysfs.conf create-test +INCLUDES = -I../include +LDADD = ../lib/libsysfs.la +CFLAGS = -Wall -Wshadow -W -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls + diff --git a/test/Makefile.in b/test/Makefile.in new file mode 100644 index 0000000..4ab200e --- /dev/null +++ b/test/Makefile.in @@ -0,0 +1,455 @@ +# Makefile.in generated by automake 1.6.3 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 +# 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@ +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ + +EXEEXT = @EXEEXT@ +OBJEXT = @OBJEXT@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +AMTAR = @AMTAR@ +AS = @AS@ +AWK = @AWK@ +CC = @CC@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +OBJDUMP = @OBJDUMP@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +VERSION = @VERSION@ +am__include = @am__include@ +am__quote = @am__quote@ +install_sh = @install_sh@ +bin_PROGRAMS = dlist_test get_class_dev get_device get_driver write_attr \ + get_bus_devices_list get_classdev_parent testlibsysfs + +BUILT_SOURCES = test.h +CLEANFILES = test.h +dlist_test_SOURCES = dlist_test.c +get_class_dev_SOURCES = get_class_dev.c +get_device_SOURCES = get_device.c +get_driver_SOURCES = get_driver.c +get_bus_devices_list_SOURCES = get_bus_devices_list.c +write_attr_SOURCES = write_attr.c +get_classdev_parent_SOURCES = get_classdev_parent.c +testlibsysfs_SOURCES = test.c test_bus.c test_class.c test_dir.c test_driver.c \ + test_root.c test_utils.c testout.c test-defs.h \ + libsysfs.conf create-test + +INCLUDES = -I../include +LDADD = ../lib/libsysfs.la +CFLAGS = -Wall -Wshadow -W -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls +subdir = test +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +bin_PROGRAMS = dlist_test$(EXEEXT) get_class_dev$(EXEEXT) \ + get_device$(EXEEXT) get_driver$(EXEEXT) write_attr$(EXEEXT) \ + get_bus_devices_list$(EXEEXT) get_classdev_parent$(EXEEXT) \ + testlibsysfs$(EXEEXT) +PROGRAMS = $(bin_PROGRAMS) + +am_dlist_test_OBJECTS = dlist_test.$(OBJEXT) +dlist_test_OBJECTS = $(am_dlist_test_OBJECTS) +dlist_test_LDADD = $(LDADD) +dlist_test_DEPENDENCIES = ../lib/libsysfs.la +dlist_test_LDFLAGS = +am_get_bus_devices_list_OBJECTS = get_bus_devices_list.$(OBJEXT) +get_bus_devices_list_OBJECTS = $(am_get_bus_devices_list_OBJECTS) +get_bus_devices_list_LDADD = $(LDADD) +get_bus_devices_list_DEPENDENCIES = ../lib/libsysfs.la +get_bus_devices_list_LDFLAGS = +am_get_class_dev_OBJECTS = get_class_dev.$(OBJEXT) +get_class_dev_OBJECTS = $(am_get_class_dev_OBJECTS) +get_class_dev_LDADD = $(LDADD) +get_class_dev_DEPENDENCIES = ../lib/libsysfs.la +get_class_dev_LDFLAGS = +am_get_classdev_parent_OBJECTS = get_classdev_parent.$(OBJEXT) +get_classdev_parent_OBJECTS = $(am_get_classdev_parent_OBJECTS) +get_classdev_parent_LDADD = $(LDADD) +get_classdev_parent_DEPENDENCIES = ../lib/libsysfs.la +get_classdev_parent_LDFLAGS = +am_get_device_OBJECTS = get_device.$(OBJEXT) +get_device_OBJECTS = $(am_get_device_OBJECTS) +get_device_LDADD = $(LDADD) +get_device_DEPENDENCIES = ../lib/libsysfs.la +get_device_LDFLAGS = +am_get_driver_OBJECTS = get_driver.$(OBJEXT) +get_driver_OBJECTS = $(am_get_driver_OBJECTS) +get_driver_LDADD = $(LDADD) +get_driver_DEPENDENCIES = ../lib/libsysfs.la +get_driver_LDFLAGS = +am_testlibsysfs_OBJECTS = test.$(OBJEXT) test_bus.$(OBJEXT) \ + test_class.$(OBJEXT) test_dir.$(OBJEXT) test_driver.$(OBJEXT) \ + test_root.$(OBJEXT) test_utils.$(OBJEXT) testout.$(OBJEXT) +testlibsysfs_OBJECTS = $(am_testlibsysfs_OBJECTS) +testlibsysfs_LDADD = $(LDADD) +testlibsysfs_DEPENDENCIES = ../lib/libsysfs.la +testlibsysfs_LDFLAGS = +am_write_attr_OBJECTS = write_attr.$(OBJEXT) +write_attr_OBJECTS = $(am_write_attr_OBJECTS) +write_attr_LDADD = $(LDADD) +write_attr_DEPENDENCIES = ../lib/libsysfs.la +write_attr_LDFLAGS = + +DEFS = @DEFS@ +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/dlist_test.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/get_bus_devices_list.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/get_class_dev.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/get_classdev_parent.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/get_device.Po ./$(DEPDIR)/get_driver.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/test.Po ./$(DEPDIR)/test_bus.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/test_class.Po ./$(DEPDIR)/test_dir.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/test_driver.Po ./$(DEPDIR)/test_root.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/test_utils.Po ./$(DEPDIR)/testout.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/write_attr.Po +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ + $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +DIST_SOURCES = $(dlist_test_SOURCES) $(get_bus_devices_list_SOURCES) \ + $(get_class_dev_SOURCES) $(get_classdev_parent_SOURCES) \ + $(get_device_SOURCES) $(get_driver_SOURCES) \ + $(testlibsysfs_SOURCES) $(write_attr_SOURCES) +DIST_COMMON = Makefile.am Makefile.in +SOURCES = $(dlist_test_SOURCES) $(get_bus_devices_list_SOURCES) $(get_class_dev_SOURCES) $(get_classdev_parent_SOURCES) $(get_device_SOURCES) $(get_driver_SOURCES) $(testlibsysfs_SOURCES) $(write_attr_SOURCES) + +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu test/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(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; \ + 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_bus_devices_list$(EXEEXT): $(get_bus_devices_list_OBJECTS) $(get_bus_devices_list_DEPENDENCIES) + @rm -f get_bus_devices_list$(EXEEXT) + $(LINK) $(get_bus_devices_list_LDFLAGS) $(get_bus_devices_list_OBJECTS) $(get_bus_devices_list_LDADD) $(LIBS) +get_class_dev$(EXEEXT): $(get_class_dev_OBJECTS) $(get_class_dev_DEPENDENCIES) + @rm -f get_class_dev$(EXEEXT) + $(LINK) $(get_class_dev_LDFLAGS) $(get_class_dev_OBJECTS) $(get_class_dev_LDADD) $(LIBS) +get_classdev_parent$(EXEEXT): $(get_classdev_parent_OBJECTS) $(get_classdev_parent_DEPENDENCIES) + @rm -f get_classdev_parent$(EXEEXT) + $(LINK) $(get_classdev_parent_LDFLAGS) $(get_classdev_parent_OBJECTS) $(get_classdev_parent_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) +testlibsysfs$(EXEEXT): $(testlibsysfs_OBJECTS) $(testlibsysfs_DEPENDENCIES) + @rm -f testlibsysfs$(EXEEXT) + $(LINK) $(testlibsysfs_LDFLAGS) $(testlibsysfs_OBJECTS) $(testlibsysfs_LDADD) $(LIBS) +write_attr$(EXEEXT): $(write_attr_OBJECTS) $(write_attr_DEPENDENCIES) + @rm -f write_attr$(EXEEXT) + $(LINK) $(write_attr_LDFLAGS) $(write_attr_OBJECTS) $(write_attr_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) core *.core + +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_bus_devices_list.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_class_dev.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/get_classdev_parent.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)/test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_bus.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_class.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dir.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_driver.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_root.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_utils.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testout.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write_attr.Po@am__quote@ + +distclean-depend: + -rm -rf ./$(DEPDIR) + +.c.o: +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< + +.c.obj: +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(COMPILE) -c `cygpath -w $<` + +.c.lo: +@AMDEP_TRUE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + $(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$< +CCDEPMODE = @CCDEPMODE@ + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ETAGS = etags +ETAGSFLAGS = + +tags: TAGS + +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: $(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 "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_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 +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @list='$(DISTFILES)'; for file in $$list; do \ + 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"; \ + $(mkinstalldirs) "$(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: check-am +all-am: Makefile $(PROGRAMS) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(bindir) + +install: 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_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: + -rm -f Makefile $(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 + +distclean-am: clean-am distclean-compile distclean-depend \ + distclean-generic distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-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 + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +uninstall-am: uninstall-binPROGRAMS uninstall-info-am + +.PHONY: GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool distclean distclean-compile \ + distclean-depend distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-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 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/test/create-test b/test/create-test new file mode 100755 index 0000000..2d1fb85 --- /dev/null +++ b/test/create-test @@ -0,0 +1,36 @@ +#! /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 + diff --git a/test/dlist_test.c b/test/dlist_test.c new file mode 100644 index 0000000..ddd0ae8 --- /dev/null +++ b/test/dlist_test.c @@ -0,0 +1,313 @@ +/* + * 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 <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 *); + +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_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); +} diff --git a/test/get_bus_devices_list.c b/test/get_bus_devices_list.c new file mode 100644 index 0000000..b828ef0 --- /dev/null +++ b/test/get_bus_devices_list.c @@ -0,0 +1,54 @@ +/* + * get_bus_devices_list.c + * + * Utility to get the list of devices on a given bus + * + * Copyright (C) IBM Corp. 2003 + * + * 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_bus_devices_list [bus]\n"); +} + +int main(int argc, char *argv[]) +{ + struct dlist *name = NULL; + char *cur = NULL; + + if (argc != 2) { + print_usage(); + return 1; + } + name = sysfs_open_bus_devices_list(argv[1]); + if (name != NULL) { + fprintf(stdout, "Devices on bus \"%s\":\n", argv[1]); + dlist_for_each_data(name, cur, char) { + fprintf(stdout, "\t%s\n", cur); + } + } else + fprintf(stdout, "Bus \"%s\" not found\n", argv[1]); + sysfs_close_list(name); + + return 0; +} + diff --git a/test/get_class_dev.c b/test/get_class_dev.c new file mode 100644 index 0000000..0cb9437 --- /dev/null +++ b/test/get_class_dev.c @@ -0,0 +1,72 @@ +/* + * get_class_dev.c + * + * Utility to find the class a given device is on + * + * Copyright (C) IBM Corp. 2003 + * + * 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_class_dev [class name] [class_device]\n"); +} + +int main(int argc, char *argv[]) +{ + struct sysfs_class_device *cdev = NULL; + struct sysfs_attribute *attr = NULL; + struct dlist *attrlist = NULL; + struct sysfs_device *device = NULL; + struct sysfs_driver *driver = NULL; + + if (argc != 3) { + print_usage(); + return 1; + } + + cdev = sysfs_open_class_device(argv[1], argv[2]); + if (cdev == NULL) { + fprintf(stdout, "Device \"%s\" not found\n", argv[2]); + return 1; + } + + fprintf(stdout, "Class device \"%s\"\n", cdev->name); + + attrlist = sysfs_get_classdev_attributes(cdev); + if (attrlist != NULL) { + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + fprintf(stdout, "\n"); + + device = sysfs_get_classdev_device(cdev); + if (device) + fprintf(stdout, "\tDevice : \"%s\"\n", cdev->sysdevice->bus_id); + driver = sysfs_get_classdev_driver(cdev); + if (driver) + fprintf(stdout, "\tDriver : \"%s\"\n", cdev->driver->name); + + sysfs_close_class_device(cdev); + return 0; +} + diff --git a/test/get_classdev_parent.c b/test/get_classdev_parent.c new file mode 100644 index 0000000..56be44d --- /dev/null +++ b/test/get_classdev_parent.c @@ -0,0 +1,78 @@ +/* + * get_classdev_parent.c + * + * Utility to get a given class device as well as its parent if available + * + * Copyright (C) IBM Corp. 2003 + * + * 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" + +int main(int argc, char *argv[]) +{ + struct sysfs_class_device *cdev = NULL, *parent = NULL; + struct sysfs_attribute *attr = NULL; + struct dlist *attrlist = NULL; + struct sysfs_device *device = NULL; + struct sysfs_driver *driver = NULL; + + /* FIXME: edit this path to any valid path on your system to test */ + cdev = sysfs_open_class_device_path("/sys/block/sda/sda1"); + if (cdev == NULL) { + fprintf(stdout, "Class device not found\n"); + return 1; + } + + fprintf(stdout, "Class device \"%s\"\n", cdev->name); + + attrlist = sysfs_get_classdev_attributes(cdev); + if (attrlist != NULL) { + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + fprintf(stdout, "\n"); + + device = sysfs_get_classdev_device(cdev); + if (device) + fprintf(stdout, "\tDevice : \"%s\"\n", cdev->sysdevice->bus_id); + driver = sysfs_get_classdev_driver(cdev); + if (driver) + fprintf(stdout, "\tDriver : \"%s\"\n", cdev->driver->name); + + parent = sysfs_get_classdev_parent(cdev); + if (parent != NULL) { + fprintf(stdout, "Device \"%s\"'s parent is \"%s\"\n", + cdev->name, parent->name); + attrlist = sysfs_get_classdev_attributes(parent); + if (attrlist != NULL) { + dlist_for_each_data(attrlist, attr, + struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + fprintf(stdout, "\n"); + } else + fprintf(stdout, "No parent device found\n"); + + sysfs_close_class_device(cdev); + return 0; +} + diff --git a/test/get_device.c b/test/get_device.c new file mode 100644 index 0000000..a2e72ca --- /dev/null +++ b/test/get_device.c @@ -0,0 +1,63 @@ +/* + * get_device.c + * + * Utility to get details of a given device + * + * Copyright (C) IBM Corp. 2003 + * + * 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; + struct sysfs_attribute *attr = NULL; + struct dlist *attrlist = 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; + } + + attrlist = sysfs_get_device_attributes(device); + if (attrlist != NULL) { + dlist_for_each_data(attrlist, attr, + struct sysfs_attribute) + fprintf(stdout, "\t%-20s : %s", + attr->name, attr->value); + } + fprintf(stdout, "\n"); + + sysfs_close_device(device); + return 0; +} + diff --git a/test/get_driver.c b/test/get_driver.c new file mode 100644 index 0000000..0a808a6 --- /dev/null +++ b/test/get_driver.c @@ -0,0 +1,85 @@ +/* + * get_driver.c + * + * Utility to get details of the given driver + * + * Copyright (C) IBM Corp. 2003 + * + * 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 [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; + + if (argc != 2) { + print_usage(); + return 1; + } + + memset(path, 0, SYSFS_PATH_MAX); + bus = (char *)calloc(1, SYSFS_NAME_LEN); + if ((sysfs_find_driver_bus(argv[1], bus, SYSFS_NAME_LEN)) < 0) { + fprintf(stdout, "Driver %s not found\n", argv[1]); + free(bus); + return 1; + } + fprintf(stdout, "Driver %s is a member of bus %s\n", argv[1], bus); + + 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, bus); + strcat(path, "/"); + strcat(path, SYSFS_DRIVERS_NAME); + strcat(path, "/"); + strcat(path, argv[1]); + driver = sysfs_open_driver_path(path); + if (driver == NULL) { + fprintf(stdout, "Device %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[1]); + 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[1]); + + sysfs_close_driver(driver); + free(bus); + return 0; +} + diff --git a/test/libsysfs.conf b/test/libsysfs.conf new file mode 100644 index 0000000..e5bca81 --- /dev/null +++ b/test/libsysfs.conf @@ -0,0 +1,82 @@ +# 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/sda/sda1 + +# 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=3c59x +VALID_DRIVER_PATH=/sys/bus/pci/drivers/3c59x +VALID_DRIVER_BUS=pci +VALID_DRIVER_DEVICE=0000:01:0a.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 + diff --git a/test/test-defs.h b/test/test-defs.h new file mode 100644 index 0000000..b9996a3 --- /dev/null +++ b/test/test-defs.h @@ -0,0 +1,155 @@ +/* + * test.h + * + * Generic defines/declarations for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#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 <mntent.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 81 + +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_root_device(struct sysfs_root_device *root); +extern void show_attribute(struct sysfs_attribute *attr); +extern void show_attribute_list(struct dlist *list); +extern void show_link(struct sysfs_link *ln); +extern void show_links_list(struct dlist *linklist); +extern void show_dir(struct sysfs_directory *dir); +extern void show_dir_list(struct dlist *dirlist); +extern void show_directory(struct sysfs_directory *dir); +extern void show_dir_tree(struct sysfs_directory *dir); +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); + +/** + * 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_subsystem_list(int flag); +extern int test_sysfs_open_bus_devices_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_read_attribute_value(int flag); +extern int test_sysfs_write_attribute(int flag); +extern int test_sysfs_get_value_from_attributes(int flag); +extern int test_sysfs_refresh_dir_attributes(int flag); +extern int test_sysfs_refresh_dir_links(int flag); +extern int test_sysfs_refresh_dir_subdirs(int flag); +extern int test_sysfs_close_directory(int flag); +extern int test_sysfs_open_directory(int flag); +extern int test_sysfs_read_dir_attributes(int flag); +extern int test_sysfs_read_dir_links(int flag); +extern int test_sysfs_read_dir_subdirs(int flag); +extern int test_sysfs_read_directory(int flag); +extern int test_sysfs_read_all_subdirs(int flag); +extern int test_sysfs_get_subdirectory(int flag); +extern int test_sysfs_close_link(int flag); +extern int test_sysfs_open_link(int flag); +extern int test_sysfs_get_directory_link(int flag); +extern int test_sysfs_get_subdirectory_link(int flag); +extern int test_sysfs_get_directory_attribute(int flag); +extern int test_sysfs_get_dir_attributes(int flag); +extern int test_sysfs_get_dir_links(int flag); +extern int test_sysfs_get_dir_subdirs(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_refresh_driver_devices(int flag); +extern int test_sysfs_get_driver_links(int flag); +extern int test_sysfs_get_driver_device(int flag); +extern int test_sysfs_refresh_driver_attributes(int flag); +extern int test_sysfs_open_driver_attr(int flag); +extern int test_sysfs_close_root_device(int flag); +extern int test_sysfs_open_root_device(int flag); +extern int test_sysfs_get_root_devices(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_refresh_device_attributes(int flag); +extern int test_sysfs_open_device_attr(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_get_bus_attributes(int flag); +extern int test_sysfs_refresh_bus_attributes(int flag); +extern int test_sysfs_get_bus_attribute(int flag); +extern int test_sysfs_find_driver_bus(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_driver(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_refresh_classdev_attributes(int flag); +extern int test_sysfs_get_classdev_attr(int flag); +extern int test_sysfs_open_classdev_attr(int flag); + +#endif /* _TESTER_H_ */ diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..0f845c9 --- /dev/null +++ b/test/test.c @@ -0,0 +1,385 @@ +/* + * test.c + * + * Main program for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + * 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_open_subsystem_list", + "sysfs_open_bus_devices_list", + "sysfs_close_list", + "sysfs_close_attribute", + "sysfs_open_attribute", + "sysfs_read_attribute", + "sysfs_read_attribute_value", + "sysfs_write_attribute", + "sysfs_get_value_from_attributes", + "sysfs_refresh_dir_attributes", + "sysfs_refresh_dir_links", + "sysfs_refresh_dir_subdirs", + "sysfs_close_directory", + "sysfs_open_directory", + "sysfs_read_dir_attributes", + "sysfs_read_dir_links", + "sysfs_read_dir_subdirs", + "sysfs_read_directory", + "sysfs_read_all_subdirs", + "sysfs_get_subdirectory", + "sysfs_close_link", + "sysfs_open_link", + "sysfs_get_directory_link", + "sysfs_get_subdirectory_link", + "sysfs_get_directory_attribute", + "sysfs_get_dir_attributes", + "sysfs_get_dir_links", + "sysfs_get_dir_subdirs", + "sysfs_close_driver", + "sysfs_open_driver", + "sysfs_open_driver_path", + "sysfs_get_driver_attr", + "sysfs_get_driver_attributes", + "sysfs_get_driver_devices", + "sysfs_refresh_driver_devices", + "sysfs_get_driver_links", + "sysfs_get_driver_device", + "sysfs_refresh_driver_attributes", + "sysfs_open_driver_attr", + "sysfs_close_root_device", + "sysfs_open_root_device", + "sysfs_get_root_devices", + "sysfs_close_device", + "sysfs_open_device", + "sysfs_get_device_parent", + "sysfs_open_device_path", + "sysfs_get_device_attr", + "sysfs_get_device_attributes", + "sysfs_refresh_device_attributes", + "sysfs_open_device_attr", + "sysfs_close_bus", + "sysfs_open_bus", + "sysfs_get_bus_device", + "sysfs_get_bus_driver", + "sysfs_get_bus_drivers", + "sysfs_get_bus_devices", + "sysfs_get_bus_attributes", + "sysfs_refresh_bus_attributes", + "sysfs_get_bus_attribute", + "sysfs_find_driver_bus", + "sysfs_close_class_device", + "sysfs_open_class_device_path", + "sysfs_open_class_device", + "sysfs_get_classdev_device", + "sysfs_get_classdev_driver", + "sysfs_get_classdev_parent", + "sysfs_close_class", + "sysfs_open_class", + "sysfs_get_class_devices", + "sysfs_get_class_device", + "sysfs_get_classdev_attributes", + "sysfs_refresh_classdev_attributes", + "sysfs_get_classdev_attr", + "sysfs_open_classdev_attr", +}; + +int (*func_table[81])(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_open_subsystem_list, + test_sysfs_open_bus_devices_list, + test_sysfs_close_list, + test_sysfs_close_attribute, + test_sysfs_open_attribute, + test_sysfs_read_attribute, + test_sysfs_read_attribute_value, + test_sysfs_write_attribute, + test_sysfs_get_value_from_attributes, + test_sysfs_refresh_dir_attributes, + test_sysfs_refresh_dir_links, + test_sysfs_refresh_dir_subdirs, + test_sysfs_close_directory, + test_sysfs_open_directory, + test_sysfs_read_dir_attributes, + test_sysfs_read_dir_links, + test_sysfs_read_dir_subdirs, + test_sysfs_read_directory, + test_sysfs_read_all_subdirs, + test_sysfs_get_subdirectory, + test_sysfs_close_link, + test_sysfs_open_link, + test_sysfs_get_directory_link, + test_sysfs_get_subdirectory_link, + test_sysfs_get_directory_attribute, + test_sysfs_get_dir_attributes, + test_sysfs_get_dir_links, + test_sysfs_get_dir_subdirs, + 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_refresh_driver_devices, + test_sysfs_get_driver_links, + test_sysfs_get_driver_device, + test_sysfs_refresh_driver_attributes, + test_sysfs_open_driver_attr, + test_sysfs_close_root_device, + test_sysfs_open_root_device, + test_sysfs_get_root_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_refresh_device_attributes, + test_sysfs_open_device_attr, + 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_get_bus_attributes, + test_sysfs_refresh_bus_attributes, + test_sysfs_get_bus_attribute, + test_sysfs_find_driver_bus, + 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_driver, + 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_refresh_classdev_attributes, + test_sysfs_get_classdev_attr, + test_sysfs_open_classdev_attr, +}; + +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/test/test_bus.c b/test/test_bus.c new file mode 100644 index 0000000..aaca5a6 --- /dev/null +++ b/test/test_bus.c @@ -0,0 +1,777 @@ +/* + * test_bus.c + * + * Tests for bus related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + ****************************************************************************** + * 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); + * extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus); + * extern struct dlist *sysfs_refresh_bus_attributes(struct sysfs_bus *bus); + * extern struct sysfs_attribute *sysfs_get_bus_attribute + * (struct sysfs_bus *bus, + * char *attrname); + * extern int sysfs_find_driver_bus(const char *driver, + * char *busname, size_t bsize); + ****************************************************************************** + */ + +#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; +} + +/** + * extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus); + * + * flag: + * 0 : bus -> valid + * 1 : bus -> NULL + */ +int test_sysfs_get_bus_attributes(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_attributes(bus); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) { + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + dbg_print("since no buses have attribs as of now\n"); + } else + 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; + 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 (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern struct dlist *sysfs_refresh_bus_attributes(struct sysfs_bus *bus); + * + * flag: + * 0 : bus -> valid + * 1 : bus -> NULL + */ +int test_sysfs_refresh_bus_attributes(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_refresh_bus_attributes(bus); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) { + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + dbg_print("since no buses have attribs as of now\n"); + } else + 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; + 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 (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_get_bus_attribute + * (struct sysfs_bus *bus, + * char *attrname); + * flag: + * 0 : bus -> valid, attrname -> valid + * 1 : bus -> valid, attrname -> invalid + * 2 : bus -> valid, attrname -> NULL + * 3 : bus -> NULL, attrname -> valid + * 4 : bus -> NULL, attrname -> invalid + * 5 : bus -> NULL, attrname -> NULL + * + */ +int test_sysfs_get_bus_attribute(int flag) +{ + struct sysfs_attribute *attr = NULL; + struct sysfs_bus *bus = NULL; + char *attrname = 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; + } + attrname = val_bus_attr; + 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; + } + attrname = 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; + } + attrname = NULL; + break; + case 3: + bus = NULL; + attrname = val_bus_attr; + break; + case 4: + bus = NULL; + attrname = inval_name; + break; + case 5: + bus = NULL; + attrname = NULL; + break; + default: + return -1; + } + + attr = sysfs_get_bus_attribute(bus, attrname); + switch (flag) { + case 0: + if (attr == NULL) { + if (errno == 0) { + dbg_print("%s: SUCCEEDED with flag = %d\n", + __FUNCTION__, flag); + + dbg_print("since no buses have attribs as of now\n"); + } else + 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; + 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); + break; + default: + break; + } + + if (bus != NULL) + sysfs_close_bus(bus); + + return 0; +} + +/** + * extern int sysfs_find_driver_bus(const char *driver, + * char *busname, size_t bsize); + * + * flag: + * 0: driver -> valid, busname -> valid, size ->valid. + * 1: driver -> valid, busname -> NULL, size ->valid. + * 2: driver -> invalid, busname -> valid, size ->valid. + * 3: driver -> invalid, busname -> NULL, size ->valid. + * 4: driver -> NULL, busname -> valid, size ->valid. + * 5: driver -> NULL, busname -> NULL, size ->valid. + */ +int test_sysfs_find_driver_bus(int flag) +{ + char *driver = NULL; + char *busname = NULL; + char bus_name_buf[SYSFS_NAME_LEN]; + size_t bsize = SYSFS_NAME_LEN; + int ret = 0; + + switch (flag) { + case 0: + driver = val_drv_name; + busname = bus_name_buf; + break; + case 1: + driver = val_drv_name; + busname = NULL; + break; + case 2: + driver = inval_name; + busname = bus_name_buf; + break; + case 3: + driver = inval_name; + busname = NULL; + break; + case 4: + driver = NULL; + busname = bus_name_buf; + break; + case 5: + driver = NULL; + busname = NULL; + break; + default: + return -1; + } + ret = sysfs_find_driver_bus(driver, busname, bsize); + + 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", + __FUNCTION__, flag); + dbg_print("%s:\nDriver %s is on bus %s\n\n", + __FUNCTION__, driver, busname); + } + 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); + default: + break; + } + + return 0; +} + diff --git a/test/test_class.c b/test/test_class.c new file mode 100644 index 0000000..2f6ef72 --- /dev/null +++ b/test/test_class.c @@ -0,0 +1,1158 @@ +/* + * test_class.c + * + * Tests for class related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + *************************************************************************** + * 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_driver *sysfs_get_classdev_driver + * (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 dlist *sysfs_refresh_classdev_attributes + * (struct sysfs_class_device *cdev); + * extern struct sysfs_attribute *sysfs_get_classdev_attr + * (struct sysfs_class_device *clsdev, const char *name); + * extern struct sysfs_attribute *sysfs_open_classdev_attr + * (const char *classname, + * const char *dev, const char *attrib); + ***************************************************************************** + */ + +#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_driver *sysfs_get_classdev_driver + * (struct sysfs_class_device *clsdev); + * + * flag: + * 0: clsdev -> valid + * 1: clsdev -> NULL + */ +int test_sysfs_get_classdev_driver(int flag) +{ + struct sysfs_class_device *clsdev = NULL; + struct sysfs_driver *drv = 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; + + } + drv = sysfs_get_classdev_driver(clsdev); + + switch (flag) { + case 0: + if (drv == NULL) { + if (errno == 0) + dbg_print("%s: Class device at %s does not have a driver 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_driver(drv); + dbg_print("\n"); + } + break; + case 1: + 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 (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 dlist *sysfs_refresh_classdev_attributes + * (struct sysfs_class_device *cdev); + * + * flag: + * 0: cdev -> valid + * 1: cdev -> NULL + */ +int test_sysfs_refresh_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_refresh_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; +} + +/** + * extern struct sysfs_attribute *sysfs_open_classdev_attr + * (const char *classname, + * const char *dev, + * const char *attrib); + * flag: + * 0: classname -> valid, dev -> valid, attrib -> valid + * 1: classname -> valid, dev -> valid, attrib -> invalid + * 2: classname -> valid, dev -> valid, attrib -> NULL + * 3: classname -> valid, dev -> invalid, attrib -> valid + * 4: classname -> valid, dev -> invalid, attrib -> invalid + * 5: classname -> valid, dev -> invalid, attrib -> NULL + * 6: classname -> valid, dev -> NULL , attrib -> valid + * 7: classname -> valid, dev -> NULL , attrib -> invalid + * 8: classname -> valid, dev -> NULL , attrib -> NULL + * 9: classname -> invalid, dev -> valid, attrib -> valid + * 10: classname -> invalid, dev -> valid, attrib -> invalid + * 11: classname -> invalid, dev -> valid, attrib -> NULL + * 12: classname -> invalid, dev -> invalid, attrib -> valid + * 13: classname -> invalid, dev -> invalid, attrib -> invalid + * 14: classname -> invalid, dev -> invalid, attrib -> NULL + * 15: classname -> invalid, dev -> NULL , attrib -> valid + * 16: classname -> invalid, dev -> NULL , attrib -> invalid + * 17: classname -> invalid, dev -> NULL , attrib -> NULL + * 18: classname -> NULL, dev -> valid, attrib -> valid + * 19: classname -> NULL, dev -> valid, attrib -> invalid + * 20: classname -> NULL, dev -> valid, attrib -> NULL + * 21: classname -> NULL, dev -> invalid, attrib -> valid + * 22: classname -> NULL, dev -> invalid, attrib -> invalid + * 23: classname -> NULL, dev -> invalid, attrib -> NULL + * 24: classname -> NULL, dev -> NULL , attrib -> valid + * 25 classname -> NULL, dev -> NULL , attrib -> invalid + * 26: classname -> NULL, dev -> NULL , attrib -> NULL + */ +int test_sysfs_open_classdev_attr(int flag) +{ + struct sysfs_attribute *attr = NULL; + char *classname = NULL; + char *dev = NULL; + char *attrib = NULL; + + switch (flag) { + case 0: + classname = val_class; + dev = val_class_dev; + attrib = val_class_dev_attr; + break; + case 1: + classname = val_class; + dev = val_class_dev; + attrib = inval_name; + break; + case 2: + classname = val_class; + dev = val_class_dev; + attrib = NULL; + break; + case 3: + classname = val_class; + dev= inval_name; + attrib = val_class_dev_attr; + break; + case 4: + classname = val_class; + dev= inval_name; + attrib = inval_name; + break; + case 5: + classname = val_class; + dev= inval_name; + attrib = NULL; + break; + case 6: + classname = val_class; + dev = NULL; + attrib = val_class_dev_attr; + break; + case 7: + classname = val_class; + dev = NULL; + attrib = inval_name; + break; + case 8: + classname = val_class; + dev = NULL; + attrib = NULL; + break; + case 9: + classname = inval_name; + dev = val_class_dev; + attrib = val_class_dev_attr; + break; + case 10: + classname = inval_name; + dev = val_class_dev; + attrib = inval_name; + break; + case 11: + classname = inval_name; + dev = val_class_dev; + attrib = NULL; + break; + case 12: + classname = inval_name; + dev= inval_name; + attrib = val_class_dev_attr; + break; + case 13: + classname = inval_name; + dev= inval_name; + attrib = inval_name; + break; + case 14: + classname = inval_name; + dev= inval_name; + attrib = NULL; + break; + case 15: + classname = inval_name; + dev = NULL; + attrib = val_class_dev_attr; + break; + case 16: + classname = inval_name; + dev = NULL; + attrib = inval_name; + break; + case 17: + classname = inval_name; + dev = NULL; + attrib = NULL; + break; + case 18: + classname = NULL; + dev = val_class_dev; + attrib = val_class_dev_attr; + break; + case 19: + classname = NULL; + dev = val_class_dev; + attrib = inval_name; + break; + case 20: + classname = NULL; + dev = val_class_dev; + attrib = NULL; + break; + case 21: + classname = NULL; + dev= inval_name; + attrib = val_class_dev_attr; + break; + case 22: + classname = NULL; + dev= inval_name; + attrib = inval_name; + break; + case 23: + classname = NULL; + dev= inval_name; + attrib = NULL; + break; + case 24: + classname = NULL; + dev = NULL; + attrib = val_class_dev_attr; + break; + case 25: + classname = NULL; + dev = NULL; + attrib = inval_name; + break; + case 27: + classname = NULL; + dev = NULL; + attrib = NULL; + break; + default: + return -1; + } + attr = sysfs_open_classdev_attr(classname, dev, attrib); + + switch (flag) { + case 0: + if (attr == NULL) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support READ\n", + __FUNCTION__, attrib); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for class device %s\n", + __FUNCTION__, attrib, dev); + else if (errno == 0) + dbg_print("%s: class device %s does not export attributes\n", + __FUNCTION__, dev); + 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; + default: + 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); + break; + + } + if (attr != NULL) + sysfs_close_attribute(attr); + + return 0; +} diff --git a/test/test_dir.c b/test/test_dir.c new file mode 100644 index 0000000..a6cdc41 --- /dev/null +++ b/test/test_dir.c @@ -0,0 +1,1763 @@ +/* + * test_dir.c + * + * Tests for directory related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + *************************************************************************** + * 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_read_attribute_value(const char *attrpath, + * char *value, size_t vsize); + * extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, + * const char *new_value, size_t len); + * extern char *sysfs_get_value_from_attributes(struct dlist *attr, + * const char * name); + * extern int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir); + * extern int sysfs_refresh_dir_links(struct sysfs_directory *sysdir); + * extern int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir); + * extern void sysfs_close_directory(struct sysfs_directory *sysdir); + * extern struct sysfs_directory *sysfs_open_directory + * (const char *path); + * extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir); + * extern int sysfs_read_dir_links(struct sysfs_directory *sysdir); + * extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir); + * extern int sysfs_read_directory(struct sysfs_directory *sysdir); + * extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir); + * extern struct sysfs_directory *sysfs_get_subdirectory + * (struct sysfs_directory *dir, char *subname); + * extern void sysfs_close_link(struct sysfs_link *ln); + * extern struct sysfs_link *sysfs_open_link(const char *lnpath); + * extern struct sysfs_link *sysfs_get_directory_link + * (struct sysfs_directory *dir, char *linkname); + * extern struct sysfs_link *sysfs_get_subdirectory_link + * (struct sysfs_directory *dir, char *linkname); + * extern struct sysfs_attribute *sysfs_get_directory_attribute + * (struct sysfs_directory *dir, char *attrname); + * extern struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir); + * extern struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir); + * extern struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir); + **************************************************************************** + */ + +#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_read_attribute_value(const char *attrpath, + * char *value, size_t vsize); + * + * flag: + * 0: attrpath -> valid, value -> valid + * 1: attrpath -> valid, value -> NULL + * 2: attrpath -> NULL, value -> valid + * 3: attrpath -> NULL, value -> NULL + */ +int test_sysfs_read_attribute_value(int flag) +{ + char *attrpath = NULL; + char *value = NULL; + size_t vsize = SYSFS_PATH_MAX; + int ret = 0; + + switch (flag) { + case 0: + attrpath = val_file_path; + value = calloc(1, SYSFS_PATH_MAX); + break; + case 1: + attrpath = val_file_path; + value = NULL; + break; + case 2: + attrpath = NULL; + value = calloc(1, SYSFS_PATH_MAX); + break; + case 3: + attrpath = NULL; + value = NULL; + break; + default: + return -1; + } + ret = sysfs_read_attribute_value(attrpath, value, vsize); + + 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 has value %s\n\n", + attrpath, value); + } + 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 (value != NULL) + free(value); + + 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; +} + +/** + * extern char *sysfs_get_value_from_attributes(struct dlist *attr, + * const char * name); + * + * flag: + * 0: attr -> valid, name -> valid + * 1: attr -> valid, name -> invalid + * 2: attr -> valid, name -> NULL + * 3: attr -> NULL, name -> valid + * 4: attr -> NULL, name -> invalid + * 5: attr -> NULL, name -> NULL + */ +int test_sysfs_get_value_from_attributes(int flag) +{ + struct dlist *attrlist = NULL; + struct sysfs_device *device = NULL; + char *name = NULL; + char *val = 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 opening device at %s\n", + __FUNCTION__, path); + return 0; + } + attrlist = sysfs_get_device_attributes(device); + if (attrlist == NULL) { + dbg_print("%s: failed getting attribs for device %s\n", + __FUNCTION__, device->name); + sysfs_close_device(device); + return 0; + } + name = val_dev_attr; + break; + case 1: + path = val_dev_path; + device = sysfs_open_device_path(path); + if (device == NULL) { + dbg_print("%s: failed opening device at %s\n", + __FUNCTION__, path); + return 0; + } + attrlist = sysfs_get_device_attributes(device); + if (attrlist == NULL) { + dbg_print("%s: failed getting attribs for device %s\n", + __FUNCTION__, device->name); + sysfs_close_device(device); + return 0; + } + name = inval_name; + break; + case 2: + path = val_dev_path; + device = sysfs_open_device_path(path); + if (device == NULL) { + dbg_print("%s: failed opening device at %s\n", + __FUNCTION__, path); + return 0; + } + attrlist = sysfs_get_device_attributes(device); + if (attrlist == NULL) { + dbg_print("%s: failed getting attribs for device %s\n", + __FUNCTION__, device->name); + sysfs_close_device(device); + return 0; + } + name = NULL; + break; + case 3: + attrlist = NULL; + name = val_dev_attr; + break; + case 4: + attrlist = NULL; + name = inval_name; + break; + case 5: + attrlist = NULL; + name = NULL; + break; + default: + return -1; + } + val = sysfs_get_value_from_attributes(attrlist, name); + + switch (flag) { + case 0: + if (val == 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("Attribute %s has value %s\n\n", + name, val); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (val != 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 (device != NULL) { + sysfs_close_device(device); + device = NULL; + } + return 0; +} + +/** + * extern int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_refresh_dir_attributes(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_dev_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dev_path); + return 0; + } + if (sysfs_read_dir_attributes(sysdir) != 0) { + dbg_print("%s: failed to read attribs under %s\n", + __FUNCTION__, sysdir->path); + sysfs_close_directory(sysdir); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_refresh_dir_attributes(sysdir); + + 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_list(sysdir->attributes); + 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 (sysdir != NULL) { + sysfs_close_directory(sysdir); + sysdir = NULL; + } + return 0; +} + +/** + * extern int sysfs_refresh_dir_links(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_refresh_dir_links(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_drv_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + if (sysfs_read_dir_links(sysdir) != 0) { + dbg_print("%s: failed to read links under %s\n", + __FUNCTION__, sysdir->path); + sysfs_close_directory(sysdir); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_refresh_dir_links(sysdir); + + 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_links_list(sysdir->links); + 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 (sysdir != NULL) { + sysfs_close_directory(sysdir); + sysdir = NULL; + } + return 0; +} + +/** + * extern int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_refresh_dir_subdirs(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_root_dev_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_root_dev_path); + return 0; + } + if (sysfs_read_dir_subdirs(sysdir) != 0) { + dbg_print("%s: failed to read subdirs under at %s\n", + __FUNCTION__, sysdir->path); + sysfs_close_directory(sysdir); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_refresh_dir_subdirs(sysdir); + + 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_dir_list(sysdir->subdirs); + 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 (sysdir != NULL) { + sysfs_close_directory(sysdir); + sysdir = NULL; + } + return 0; +} + +/** + * extern void sysfs_close_directory(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> invalid + * 2: sysdir -> NULL + */ +int test_sysfs_close_directory(int flag) +{ + struct sysfs_directory *sysdir = NULL; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_dir_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + break; + case 1: + sysdir = calloc(1, sizeof(struct sysfs_directory)); + break; + case 2: + sysdir = NULL; + break; + default: + return -1; + } + + sysfs_close_directory(sysdir); + dbg_print("%s: returns void\n", __FUNCTION__); + + return 0; +} + +/** + * extern struct sysfs_directory *sysfs_open_directory + * (const char *path); + * + * flag: + * 0: path -> valid + * 1: path -> invalid + * 2: path -> NULL + */ +int test_sysfs_open_directory(int flag) +{ + char *path = NULL; + struct sysfs_directory *dir = NULL; + + switch (flag) { + case 0: + path = val_dir_path; + break; + case 1: + path = inval_path; + break; + case 2: + path = NULL; + break; + default: + return -1; + } + dir = sysfs_open_directory(path); + + switch (flag) { + case 0: + if (dir == 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("Directory is %s at %s\n\n", + dir->name, dir->path); + } + break; + case 1: + case 2: + if (dir != 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 (dir != NULL) + sysfs_close_directory(dir); + return 0; +} + +/** + * extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_read_dir_attributes(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_dev_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dev_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_read_dir_attributes(sysdir); + + 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_list(sysdir->attributes); + 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 (sysdir != NULL) + sysfs_close_directory(sysdir); + return 0; +} + +/** + * extern int sysfs_read_dir_links(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_read_dir_links(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_drv_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_read_dir_links(sysdir); + + 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_links_list(sysdir->links); + 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 (sysdir != NULL) + sysfs_close_directory(sysdir); + return 0; +} + +/** + * extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_read_dir_subdirs(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_dir_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + + ret = sysfs_read_dir_subdirs(sysdir); + + 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_dir_list(sysdir->subdirs); + 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 (sysdir != NULL) + sysfs_close_directory(sysdir); + return 0; +} + +/** + * extern int sysfs_read_directory(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULL + */ +int test_sysfs_read_directory(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_drv_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_read_directory(sysdir); + + 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_directory(sysdir); + 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 (flag == 1) { + free(sysdir); + sysdir = NULL; + } + + if (sysdir != NULL) + sysfs_close_directory(sysdir); + return 0; +} + +/** + * extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir); + * + * flag: + * 0: sysdir -> valid + * 1: sysdir -> NULLd + */ +int test_sysfs_read_all_subdirs(int flag) +{ + struct sysfs_directory *sysdir = NULL; + int ret = 0; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_root_dev_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_root_dev_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + ret = sysfs_read_all_subdirs(sysdir); + + 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_dir_tree(sysdir); + 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 (sysdir != NULL) + sysfs_close_directory(sysdir); + + return 0; +} + +/** + * extern struct sysfs_directory *sysfs_get_subdirectory + * (struct sysfs_directory *dir, char *subname); + * + * flag: + * 0: dir -> valid, subname -> valid + * 1: dir -> valid, subname -> invalid + * 2: dir -> valid, subname -> NULL + * 3: dir -> NULL, subname -> valid + * 4: dir -> NULL, subname -> invalid + * 5: dir -> NULL, subname -> NULL + */ +int test_sysfs_get_subdirectory(int flag) +{ + struct sysfs_directory *dir = NULL, *subdir = NULL; + char *subname = NULL; + + switch (flag) { + case 0: + dir = sysfs_open_directory(val_root_dev_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_root_dev_path); + return 0; + } + subname = val_subdir_name; + break; + case 1: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + subname = inval_name; + break; + case 2: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + subname = NULL; + break; + case 3: + dir = NULL; + subname = val_subdir_name; + break; + case 4: + dir = NULL; + subname = inval_name; + break; + case 5: + dir = NULL; + subname = NULL; + break; + default: + return -1; + } + subdir = sysfs_get_subdirectory(dir, subname); + + switch (flag) { + case 0: + if (subdir == 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_dir(subdir); + dbg_print("\n"); + } + break; + default: + if (subdir != 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; + } + + if (dir != NULL) { + sysfs_close_directory(dir); + dir = NULL; + } + return 0; +} + +/** + * extern void sysfs_close_link(struct sysfs_link *ln); + * + * flag: + * 0: ln -> valid + * 1: ln -> NULL + */ +int test_sysfs_close_link(int flag) +{ + struct sysfs_link *ln = NULL; + + switch (flag) { + case 0: + ln = sysfs_open_link(val_link_path); + if (ln == NULL) + return 0; + break; + case 1: + ln = NULL; + break; + default: + return -1; + } + + sysfs_close_link(ln); + dbg_print("%s: returns void\n", __FUNCTION__); + + return 0; +} + +/** + * extern struct sysfs_link *sysfs_open_link(const char *lnpath); + * + * flag: + * 0: lnpath -> valid; + * 1: lnpath -> invalid; + * 2: lnpath -> NULL; + */ +int test_sysfs_open_link(int flag) +{ + char *lnpath = NULL; + struct sysfs_link *ln = NULL; + + switch (flag) { + case 0: + lnpath = val_link_path; + break; + case 1: + lnpath = inval_path; + break; + case 2: + lnpath = NULL; + break; + default: + return -1; + } + ln = sysfs_open_link(lnpath); + + switch (flag) { + case 0: + if (ln == 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_link(ln); + dbg_print("\n"); + } + break; + default: + if (ln != 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; + } + + if (ln != NULL) + sysfs_close_link(ln); + + return 0; +} + +/** + * extern struct sysfs_link *sysfs_get_directory_link + * (struct sysfs_directory *dir, char *linkname); + * + * flag: + * 0: dir -> valid, linkname -> valid + * 1: dir -> valid, linkname -> invalid + * 2: dir -> valid, linkname -> NULL + * 3: dir -> NULL, linkname -> valid + * 4: dir -> NULL, linkname -> invalid + * 5: dir -> NULL, linkname -> NULL + */ +int test_sysfs_get_directory_link(int flag) +{ + struct sysfs_directory *dir = NULL; + struct sysfs_link *ln = NULL; + char *linkname = NULL; + + switch (flag) { + case 0: + dir = sysfs_open_directory(val_drv_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + linkname = val_drv_dev_name; + break; + case 1: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + linkname = inval_name; + break; + case 2: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + linkname = NULL; + break; + case 3: + dir = NULL; + linkname = val_drv_dev_name; + break; + case 4: + dir = NULL; + linkname = inval_name; + break; + case 5: + dir = NULL; + linkname = NULL; + break; + default: + return -1; + } + ln = sysfs_get_directory_link(dir, linkname); + + switch (flag) { + case 0: + if (ln == 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_link(ln); + dbg_print("\n"); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (ln != 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 (dir != NULL) + sysfs_close_directory(dir); + + return 0; +} + +/** + * extern struct sysfs_link *sysfs_get_subdirectory_link + * (struct sysfs_directory *dir, char *linkname); + * + * flag: + * 0: dir -> valid, linkname -> valid + * 1: dir -> valid, linkname -> invalid + * 2: dir -> valid, linkname -> NULL + * 3: dir -> NULL, linkname -> valid + * 4: dir -> NULL, linkname -> invalid + * 5: dir -> NULL, linkname -> NULL + */ +int test_sysfs_get_subdirectory_link(int flag) +{ + struct sysfs_directory *dir = NULL; + struct sysfs_link *ln = NULL; + char *linkname = NULL; + + switch (flag) { + case 0: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + linkname = val_subdir_link_name; + break; + case 1: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + linkname = inval_name; + break; + case 2: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + linkname = NULL; + break; + case 3: + dir = NULL; + linkname = val_subdir_link_name; + break; + case 4: + dir = NULL; + linkname = inval_name; + break; + case 5: + dir = NULL; + linkname = NULL; + break; + default: + return -1; + } + ln = sysfs_get_subdirectory_link(dir, linkname); + + switch (flag) { + case 0: + if (ln == 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_link(ln); + dbg_print("\n"); + } + break; + default: + if (ln != 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; + } + + if (dir != NULL) + sysfs_close_directory(dir); + + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_get_directory_attribute + * (struct sysfs_directory *dir, char *attrname); + * + * flag: + * 0: dir -> valid, attrname -> valid + * 1: dir -> valid, attrname -> invalid + * 2: dir -> valid, attrname -> NULL + * 3: dir -> NULL, attrname -> valid + * 4: dir -> NULL, attrname -> invalid + * 5: dir -> NULL, attrname -> NULL + */ +int test_sysfs_get_directory_attribute(int flag) +{ + struct sysfs_directory *dir = NULL; + struct sysfs_attribute *attr = NULL; + char *attrname = NULL; + + switch (flag) { + case 0: + dir = sysfs_open_directory(val_dev_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dev_path); + return 0; + } + attrname = val_dev_attr; + break; + case 1: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + attrname = inval_name; + break; + case 2: + dir = sysfs_open_directory(val_dir_path); + if (dir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + attrname = NULL; + break; + case 3: + dir = NULL; + attrname = val_dev_attr; + break; + case 4: + dir = NULL; + attrname = inval_name; + break; + case 5: + dir = NULL; + attrname = NULL; + break; + default: + return -1; + } + attr = sysfs_get_directory_attribute(dir, attrname); + + switch (flag) { + case 0: + 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\n", + __FUNCTION__, flag); + show_attribute(attr); + dbg_print("\n"); + } + break; + default: + 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); + break; + } + + if (dir != NULL) + sysfs_close_directory(dir); + return 0; +} + +/** + * extern struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir); + * + * flag: + * 0: dir -> valid + * 1: dir -> valid + */ +int test_sysfs_get_dir_attributes(int flag) +{ + struct sysfs_directory *sysdir = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_dev_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dev_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + list = sysfs_get_dir_attributes(sysdir); + + 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_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); + break; + default: + break; + } + + if (sysdir != NULL) + sysfs_close_directory(sysdir); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir); + * + * flag: + * 0: dir -> valid + * 1: dir -> valid + * + */ +int test_sysfs_get_dir_links(int flag) +{ + struct sysfs_directory *sysdir = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_class_dev_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_class_dev_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + list = sysfs_get_dir_links(sysdir); + + 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_links_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 (sysdir != NULL) + sysfs_close_directory(sysdir); + + return 0; +} + +/** + * extern struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir); + * + * flag: + * 0: dir -> valid + * 1: dir -> valid + */ +int test_sysfs_get_dir_subdirs(int flag) +{ + struct sysfs_directory *sysdir = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + sysdir = sysfs_open_directory(val_dir_path); + if (sysdir == NULL) { + dbg_print("%s: failed opening directory at %s\n", + __FUNCTION__, val_dir_path); + return 0; + } + break; + case 1: + sysdir = NULL; + break; + default: + return -1; + } + list = sysfs_get_dir_subdirs(sysdir); + + 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_dir_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 (sysdir != NULL) + sysfs_close_directory(sysdir); + + return 0; +} diff --git a/test/test_driver.c b/test/test_driver.c new file mode 100644 index 0000000..2c7fafa --- /dev/null +++ b/test/test_driver.c @@ -0,0 +1,1009 @@ +/* + * test_driver.c + * + * Tests for driver related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + ****************************************************************************** + * 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); + * extern struct dlist *sysfs_refresh_driver_devices + * (struct sysfs_driver *driver); + * extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver); + * extern struct sysfs_device *sysfs_get_driver_device + * (struct sysfs_driver *driver, const char *name); + * extern struct dlist *sysfs_refresh_driver_attributes + * (struct sysfs_driver *driver); + * extern struct sysfs_attribute *sysfs_open_driver_attr + * (const char *bus, const char *drv, + * const char *attrib); + * + ****************************************************************************** + */ + +#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; + } + 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; +} + +/** + * extern struct dlist *sysfs_refresh_driver_devices + * (struct sysfs_driver *driver); + * + * flag: + * 0: driver -> valid + * 1: driver -> NULL + */ +int test_sysfs_refresh_driver_devices(int flag) +{ + struct sysfs_driver *driver = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + list = sysfs_get_driver_devices(driver); + if (list == NULL) { + dbg_print("%s: Error getting driver devices for %s\n", + __FUNCTION__, driver->name); + sysfs_close_driver(driver); + return 0; + } + break; + case 1: + driver = NULL; + break; + default: + return -1; + } + list = sysfs_refresh_driver_devices(driver); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: No devices are using the driver at %s\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_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; +} + +/** + * extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver); + * + * flag: + * 0: driver -> valid + * 1: driver -> NULL + */ +int test_sysfs_get_driver_links(int flag) +{ + struct sysfs_driver *driver = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + break; + case 1: + driver = NULL; + break; + default: + return -1; + } + list = sysfs_get_driver_links(driver); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: Driver at %s does not have any links\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_links_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 sysfs_device *sysfs_get_driver_device + * (struct sysfs_driver *driver, const char *name); + * + * flag: + * 0: driver -> valid, name -> valid + * 1: driver -> valid, name -> invalid + * 2: driver -> valid, name -> NULL + * 3: driver -> NULL, name -> valid + * 4: driver -> NULL, name -> invalid + * 5: driver -> NULL, name -> NULL + */ +int test_sysfs_get_driver_device(int flag) +{ + struct sysfs_driver *driver = NULL; + struct sysfs_device *dev = NULL; + char *name = NULL; + + switch (flag) { + case 0: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + name = val_drv_dev_name; + break; + case 1: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + name = inval_name; + break; + case 2: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + name = NULL; + break; + case 3: + driver = NULL; + name = val_drv_dev_name; + break; + case 4: + driver = NULL; + name = inval_name; + break; + case 5: + driver = NULL; + name = NULL; + break; + default: + return -1; + } + dev = sysfs_get_driver_device(driver, name); + + switch (flag) { + case 0: + if (dev == NULL) { + if (errno == 0) + dbg_print("%s: Device with name %s does not use the driver at %s\n", + __FUNCTION__, name, 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_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); + default: + break; + + } + if (driver != NULL) + sysfs_close_driver(driver); + + return 0; +} + +/** + * extern struct dlist *sysfs_refresh_driver_attributes + * (struct sysfs_driver *driver); + * flag: + * 0: driver -> valid + * 1: driver -> NULL + */ +int test_sysfs_refresh_driver_attributes(int flag) +{ + struct sysfs_driver *driver = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + driver = sysfs_open_driver_path(val_drv_path); + if (driver == NULL) { + dbg_print("%s: failed opening driver at %s\n", + __FUNCTION__, val_drv_path); + return 0; + } + break; + case 1: + driver = NULL; + break; + default: + return -1; + } + list = sysfs_refresh_driver_attributes(driver); + + switch (flag) { + case 0: + if (list == NULL) { + 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_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 sysfs_attribute *sysfs_open_driver_attr + * (const char *bus, const char *drv, + * const char *attrib); + * + * flag: + * 0: bus -> valid, drv -> valid, attrib -> valid + * 1: bus -> valid, drv -> valid, attrib -> invalid + * 2: bus -> valid, drv -> valid, attrib -> NULL + * 3: bus -> valid, drv -> invalid, attrib -> valid + * 4: bus -> valid, drv -> invalid, attrib -> invalid + * 5: bus -> valid, drv -> invalid, attrib -> NULL + * 6: bus -> valid, drv -> NULL, attrib -> valid + * 7: bus -> valid, drv -> NULL, attrib -> invalid + * 8: bus -> valid, drv -> NULL, attrib -> NULL + * 9: bus -> invalid, drv -> valid, attrib -> valid + * 10: bus -> invalid, drv -> valid, attrib -> invalid + * 11: bus -> invalid, drv -> valid, attrib -> NULL + * 12: bus -> invalid, drv -> invalid, attrib -> valid + * 13: bus -> invalid, drv -> invalid, attrib -> invalid + * 14: bus -> invalid, drv -> invalid, attrib -> NULL + * 15: bus -> invalid, drv -> NULL, attrib -> valid + * 16: bus -> invalid, drv -> NULL, attrib -> invalid + * 17: bus -> invalid, drv -> NULL, attrib -> NULL + * 18: bus -> NULL, drv -> valid, attrib -> valid + * 19: bus -> NULL, drv -> valid, attrib -> invalid + * 20: bus -> NULL, drv -> valid, attrib -> NULL + * 21: bus -> NULL, drv -> invalid, attrib -> valid + * 22: bus -> NULL, drv -> invalid, attrib -> invalid + * 23: bus -> NULL, drv -> invalid, attrib -> NULL + * 24: bus -> NULL, drv -> NULL, attrib -> valid + * 25: bus -> NULL, drv -> NULL, attrib -> invalid + * 26: bus -> NULL, drv -> NULL, attrib -> NULL + */ +int test_sysfs_open_driver_attr(int flag) +{ + + char *bus = NULL; + char *drv = NULL; + char *attrib = NULL; + struct sysfs_attribute *attr = NULL; + + switch (flag) { + case 0: + bus = val_drv_bus_name; + drv = val_drv_name; + attrib = val_drv_attr_name; + break; + case 1: + bus = val_drv_bus_name; + drv = val_drv_name; + attrib = inval_name; + break; + case 2: + bus = val_drv_bus_name; + drv = val_drv_name; + attrib = NULL; + break; + case 3: + bus = val_drv_bus_name; + drv = inval_name; + attrib = val_drv_attr_name; + break; + case 4: + bus = val_drv_bus_name; + drv = inval_name; + attrib = inval_name; + break; + case 5: + bus = val_drv_bus_name; + drv = inval_name; + attrib = NULL; + break; + case 6: + bus = val_drv_bus_name; + drv = NULL; + attrib = val_drv_attr_name; + break; + case 7: + bus = val_drv_bus_name; + drv = NULL; + attrib = inval_name; + break; + case 8: + bus = val_drv_bus_name; + drv = NULL; + attrib = NULL; + break; + case 9: + bus = inval_name; + drv = val_drv_name; + attrib = val_drv_attr_name; + break; + case 10: + bus = inval_name; + drv = val_drv_name; + attrib = inval_name; + break; + case 11: + bus = inval_name; + drv = val_drv_name; + attrib = NULL; + break; + case 12: + bus = inval_name; + drv = inval_name; + attrib = val_drv_attr_name; + break; + case 13: + bus = inval_name; + drv = inval_name; + attrib = inval_name; + break; + case 14: + bus = inval_name; + drv = inval_name; + attrib = NULL; + break; + case 15: + bus = inval_name; + drv = NULL; + attrib = val_drv_attr_name; + break; + case 16: + bus = inval_name; + drv = NULL; + attrib = inval_name; + break; + case 17: + bus = inval_name; + drv = NULL; + attrib = NULL; + break; + case 18: + bus = NULL; + drv = val_drv_name; + attrib = val_drv_attr_name; + break; + case 19: + bus = NULL; + drv = val_drv_name; + attrib = inval_name; + break; + case 20: + bus = NULL; + drv = val_drv_name; + attrib = NULL; + break; + case 21: + bus = NULL; + drv = inval_name; + attrib = val_drv_attr_name; + break; + case 22: + bus = NULL; + drv = inval_name; + attrib = inval_name; + break; + case 23: + bus = NULL; + drv = inval_name; + attrib = NULL; + break; + case 24: + bus = NULL; + drv = NULL; + attrib = val_drv_attr_name; + break; + case 25: + bus = NULL; + drv = NULL; + attrib = inval_name; + break; + case 26: + bus = NULL; + drv = NULL; + attrib = NULL; + break; + case 27: + bus = val_drv1_bus_name; + drv = val_drv1_name; + attrib = val_drv1_attr_name; + break; + default: + return -1; + } + attr = sysfs_open_driver_attr(bus, drv, attrib); + + switch (flag) { + case 0: + case 27: + if (attr == NULL) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support READ\n", + __FUNCTION__, attrib); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for driver %s\n", + __FUNCTION__, attrib, 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(attr); + dbg_print("\n"); + } + break; + default: + 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); + break; + + } + if (attr != NULL) + sysfs_close_attribute(attr); + + return 0; +} diff --git a/test/test_root.c b/test/test_root.c new file mode 100644 index 0000000..122b36d --- /dev/null +++ b/test/test_root.c @@ -0,0 +1,936 @@ +/* + * test_root.c + * + * Tests for device/root device related functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + ****************************************************************************** + * this will test the device/root device related functions provided by libsysfs + * + * extern void sysfs_close_root_device(struct sysfs_root_device *root); + * extern struct sysfs_root_device *sysfs_open_root_device + * (const char *name); + * extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root); + * 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); + * extern struct dlist *sysfs_refresh_device_attributes + * (struct sysfs_device *device); + * extern struct sysfs_attribute *sysfs_open_device_attr + * (const char *bus, + * const char *bus_id, + * const char *attrib); + * + ****************************************************************************** + */ + +#include "test-defs.h" +#include <errno.h> + +/** + * extern void sysfs_close_root_device(struct sysfs_root_device *root); + * + * flag: + * 0: root -> valid + * 1: root -> NULL + */ +int test_sysfs_close_root_device(int flag) +{ + struct sysfs_root_device *root = NULL; + char *root_name = NULL; + + switch (flag) { + case 0: + root_name = val_root_name; + root = sysfs_open_root_device(root_name); + if (root == NULL) { + dbg_print("%s: failed to open root device %s\n", + __FUNCTION__, root_name); + return 0; + } + break; + case 1: + root = NULL; + break; + default: + return -1; + + } + sysfs_close_root_device(root); + + dbg_print("%s: returns void\n", __FUNCTION__); + return 0; +} + +/** + * extern struct sysfs_root_device *sysfs_open_root_device + * (const char *name); + * + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + */ +int test_sysfs_open_root_device(int flag) +{ + struct sysfs_root_device *root = NULL; + char *name = NULL; + + switch (flag) { + case 0: + name = val_root_name; + break; + case 1: + name = inval_name; + break; + case 2: + name = NULL; + break; + default: + return -1; + } + root = sysfs_open_root_device(name); + + switch (flag) { + case 0: + if (root == 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_root_device(root); + dbg_print("\n"); + } + break; + case 1: + case 2: + if (root != 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 (root != NULL) + sysfs_close_root_device(root); + return 0; +} + +/** + * extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root); + * + * flag: + * 0: root -> valid + * 1: root -> NULL + */ +int test_sysfs_get_root_devices(int flag) +{ + struct sysfs_root_device *root = NULL; + struct dlist *list = NULL; + char *root_name = NULL; + + switch (flag) { + case 0: + root_name = val_root_name; + root = sysfs_open_root_device(root_name); + if (root == NULL) { + dbg_print("%s: failed to open root device %s\n", + __FUNCTION__, root_name); + return 0; + } + break; + case 1: + root = NULL; + break; + default: + return -1; + + } + list = sysfs_get_root_devices(root); + + switch (flag) { + case 0: + if (list == NULL) { + if (errno == 0) + dbg_print("%s: Root device %s does not have any devices under it\n", + __FUNCTION__, root_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 + 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 (root != NULL) + sysfs_close_root_device(root); + + return 0; +} + +/** + * 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; +} + +/** + * extern struct dlist *sysfs_refresh_device_attributes + * (struct sysfs_device *device); + * + * flag: + * 0: device -> valid + * 1: device -> NULL + * + */ +int test_sysfs_refresh_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; + } + list = sysfs_get_device_attributes(device); + if (list == NULL) { + dbg_print("%s: failed to get device attribs for %s\n", + __FUNCTION__, device->name); + sysfs_close_device(device); + return 0; + } + break; + case 1: + device = NULL; + break; + default: + return -1; + } + list = sysfs_refresh_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 (list != 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 (device != NULL) + sysfs_close_device(device); + return 0; +} + +/** + * extern struct sysfs_attribute *sysfs_open_device_attr + * (const char *bus, + * const char *bus_id, + * const char *attrib); + * + * flag: + * 0: bus -> valid, bus_id -> valid, attrib -> valid + * 1: bus -> valid, bus_id -> valid, attrib -> invalid + * 2: bus -> valid, bus_id -> valid, attrib -> NULL + * 3: bus -> valid, bus_id -> invalid, attrib -> valid + * 4: bus -> valid, bus_id -> invalid, attrib -> invalid + * 5: bus -> valid, bus_id -> invalid, attrib -> NULL + * 6: bus -> valid, bus_id -> NULL, attrib -> valid + * 7: bus -> valid, bus_id -> NULL, attrib -> invalid + * 8: bus -> valid, bus_id -> NULL, attrib -> NULL + * 9: bus -> invalid, bus_id -> valid, attrib -> valid + * 10: bus -> invalid, bus_id -> valid, attrib -> invalid + * 11: bus -> invalid, bus_id -> valid, attrib -> NULL + * 12: bus -> invalid, bus_id -> invalid, attrib -> valid + * 13: bus -> invalid, bus_id -> invalid, attrib -> invalid + * 14: bus -> invalid, bus_id -> invalid, attrib -> NULL + * 15: bus -> invalid, bus_id -> NULL, attrib -> valid + * 16: bus -> invalid, bus_id -> NULL, attrib -> invalid + * 17: bus -> invalid, bus_id -> NULL, attrib -> NULL + * 18: bus -> NULL, bus_id -> valid, attrib -> valid + * 19: bus -> NULL, bus_id -> valid, attrib -> invalid + * 20: bus -> NULL, bus_id -> valid, attrib -> NULL + * 21: bus -> NULL, bus_id -> invalid, attrib -> valid + * 22: bus -> NULL, bus_id -> invalid, attrib -> invalid + * 23: bus -> NULL, bus_id -> invalid, attrib -> NULL + * 24: bus -> NULL, bus_id -> NULL, attrib -> valid + * 25: bus -> NULL, bus_id -> NULL, attrib -> invalid + * 26: bus -> NULL, bus_id -> NULL, attrib -> NULL + */ +int test_sysfs_open_device_attr(int flag) +{ + + char *bus = NULL; + char *bus_id = NULL; + char *attrib = NULL; + struct sysfs_attribute *attr = NULL; + + switch (flag) { + case 0: + bus = val_bus_name; + bus_id = val_bus_id; + attrib = val_dev_attr; + break; + case 1: + bus = val_bus_name; + bus_id = val_bus_id; + attrib = inval_name; + break; + case 2: + bus = val_bus_name; + bus_id = val_bus_id; + attrib = NULL; + break; + case 3: + bus = val_bus_name; + bus_id = inval_name; + attrib = val_dev_attr; + break; + case 4: + bus = val_bus_name; + bus_id = inval_name; + attrib = inval_name; + break; + case 5: + bus = val_bus_name; + bus_id = inval_name; + attrib = NULL; + break; + case 6: + bus = val_bus_name; + bus_id = NULL; + attrib = val_dev_attr; + break; + case 7: + bus = val_bus_name; + bus_id = NULL; + attrib = inval_name; + break; + case 8: + bus = val_bus_name; + bus_id = NULL; + attrib = NULL; + break; + case 9: + bus = inval_name; + bus_id = val_bus_id; + attrib = val_dev_attr; + break; + case 10: + bus = inval_name; + bus_id = val_bus_id; + attrib = inval_name; + break; + case 11: + bus = inval_name; + bus_id = val_bus_id; + attrib = NULL; + break; + case 12: + bus = inval_name; + bus_id = inval_name; + attrib = val_dev_attr; + break; + case 13: + bus = inval_name; + bus_id = inval_name; + attrib = inval_name; + break; + case 14: + bus = inval_name; + bus_id = inval_name; + attrib = NULL; + break; + case 15: + bus = inval_name; + bus_id = NULL; + attrib = val_dev_attr; + break; + case 16: + bus = inval_name; + bus_id = NULL; + attrib = inval_name; + break; + case 17: + bus = inval_name; + bus_id = NULL; + attrib = NULL; + break; + case 18: + bus = NULL; + bus_id = val_bus_id; + attrib = val_dev_attr; + break; + case 19: + bus = NULL; + bus_id = val_bus_id; + attrib = inval_name; + break; + case 20: + bus = NULL; + bus_id = val_bus_id; + attrib = NULL; + break; + case 21: + bus = NULL; + bus_id = inval_name; + attrib = val_dev_attr; + break; + case 22: + bus = NULL; + bus_id = inval_name; + attrib = inval_name; + break; + case 23: + bus = NULL; + bus_id = inval_name; + attrib = NULL; + break; + case 24: + bus = NULL; + bus_id = NULL; + attrib = val_dev_attr; + break; + case 25: + bus = NULL; + bus_id = NULL; + attrib = inval_name; + break; + case 26: + bus = NULL; + bus_id = NULL; + attrib = NULL; + break; + default: + return -1; + } + attr = sysfs_open_device_attr(bus, bus_id, attrib); + + switch (flag) { + case 0: + if (attr == NULL) { + if (errno == EACCES) + dbg_print("%s: attribute %s does not support READ\n", + __FUNCTION__, attrib); + else if (errno == ENOENT) + dbg_print("%s: attribute %s not defined for device %s\n", + __FUNCTION__, attrib, bus_id); + else if (errno == 0) + dbg_print("%s: device %s does not export attributes\n", + __FUNCTION__, bus_id); + 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; + default: + 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); + break; + + } + if (attr != NULL) + sysfs_close_attribute(attr); + return 0; +} diff --git a/test/test_utils.c b/test/test_utils.c new file mode 100644 index 0000000..56746be --- /dev/null +++ b/test/test_utils.c @@ -0,0 +1,654 @@ +/* + * test_utils.c + * + * Tests for utility functions for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + *************************************************************************** + * 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_subsystem_list(char *name); + * extern struct dlist *sysfs_open_bus_devices_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 -> invalid + * 2: mnt_path -> valid, len -> 0 + * 3: mnt_path -> NULL, len -> valid + * 4: mnt_path -> NULL, len -> invalid + * 5: 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 = 1; + break; + case 2: + mnt_path = calloc(1, SYSFS_PATH_MAX); + len = 0; + break; + case 3: + mnt_path = NULL; + len = 0; + break; + case 4: + mnt_path = NULL; + len = 12; + break; + case 5: + mnt_path = NULL; + len = 0; + break; + default: + return -1; + } + ret = sysfs_get_mnt_path(mnt_path, 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("sysfs is mounted at \"%s\"\n\n", mnt_path); + } + break; + case 1: + case 2: + case 3: + case 4: + case 5: + if (ret != -1) + 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_subsystem_list(char *name); + * + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + * + */ +int test_sysfs_open_subsystem_list(int flag) +{ + char *name = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + name = val_subsys; + break; + case 1: + name = inval_name; + break; + case 2: + name = NULL; + break; + default: + return -1; + } + list = sysfs_open_subsystem_list(name); + + 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_bus_devices_list(char *name); + * + * flag: + * 0: name -> valid + * 1: name -> invalid + * 2: name -> NULL + * + */ +int test_sysfs_open_bus_devices_list(int flag) +{ + char *name = NULL; + struct dlist *list = NULL; + + switch (flag) { + case 0: + name = val_bus_name; + break; + case 1: + name = inval_name; + break; + case 2: + name = NULL; + break; + default: + return -1; + } + list = sysfs_open_bus_devices_list(name); + + 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 = sysfs_open_subsystem_list("bus"); + if (list == NULL) { + dbg_print("%s: failed to open the bus list\n", + __FUNCTION__); + return 0; + } + break; + case 1: + list = NULL; + break; + default: + return -1; + } + sysfs_close_list(list); + + dbg_print("%s: returns void\n", __FUNCTION__); + + return 0; +} diff --git a/test/testout.c b/test/testout.c new file mode 100644 index 0000000..547f9d8 --- /dev/null +++ b/test/testout.c @@ -0,0 +1,187 @@ +/* + * testout.c + * + * Display routines for the libsysfs testsuite + * + * Copyright (C) IBM Corp. 2004 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/** + * Display routines for test functions + */ + +#include <test-defs.h> + +static void remove_end_newline(char *value) +{ + char *p = value + (strlen(value) - 1); + + if (p != NULL && *p == '\n') + *p = '\0'; +} + +void show_device(struct sysfs_device *device) +{ + if (device != NULL) + dbg_print("Device is \"%s\" at \"%s\"\n", + device->name, device->path); +} + +void show_driver(struct sysfs_driver *driver) +{ + if (driver != NULL) + dbg_print("Driver is \"%s\" at \"%s\"\n", + driver->name, driver->path); +} + +void show_device_list(struct dlist *devlist) +{ + if (devlist != NULL) { + struct sysfs_device *dev = NULL; + + dlist_for_each_data(devlist, dev, struct sysfs_device) + show_device(dev); + } +} + +void show_driver_list(struct dlist *drvlist) +{ + if (drvlist != NULL) { + struct sysfs_driver *drv = NULL; + + dlist_for_each_data(drvlist, drv, struct sysfs_driver) + show_driver(drv); + } +} + +void show_root_device(struct sysfs_root_device *root) +{ + if (root != NULL) + dbg_print("Device is \"%s\" at \"%s\"\n", + root->name, root->path); +} + +void show_attribute(struct sysfs_attribute *attr) +{ + if (attr != NULL) { + if (attr->value) + remove_end_newline(attr->value); + dbg_print("Attr \"%s\" at \"%s\" has a value \"%s\" \n", + attr->name, attr->path, attr->value); + } +} + +void show_attribute_list(struct dlist *attrlist) +{ + if (attrlist != NULL) { + struct sysfs_attribute *attr = NULL; + + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) + show_attribute(attr); + } +} + +void show_link(struct sysfs_link *ln) +{ + if (ln != NULL) + dbg_print("Link at \"%s\" points to \"%s\"\n", + ln->path, ln->target); +} + +void show_links_list(struct dlist *linklist) +{ + if (linklist != NULL) { + struct sysfs_link *ln = NULL; + + dlist_for_each_data(linklist, ln, struct sysfs_link) + show_link(ln); + } +} + +void show_dir(struct sysfs_directory *dir) +{ + if (dir != NULL) + dbg_print("Directory \"%s\" is at \"%s\"\n", + dir->name, dir->path); +} + +void show_dir_list(struct dlist *dirlist) +{ + if (dirlist != NULL) { + struct sysfs_directory *dir = NULL; + + dlist_for_each_data(dirlist, dir, struct sysfs_directory) + show_dir(dir); + } +} + +void show_directory(struct sysfs_directory *dir) +{ + if (dir != NULL) { + show_dir(dir); + + if (dir->attributes) + show_attribute_list(dir->attributes); + if (dir->links) + show_links_list(dir->links); + if (dir->subdirs) + show_dir_list(dir->subdirs); + } +} + +void show_dir_tree(struct sysfs_directory *dir) +{ + if (dir != NULL) { + struct sysfs_directory *subdir = NULL; + + if (dir->subdirs) { + dlist_for_each_data(dir->subdirs, subdir, + struct sysfs_directory) { + show_dir(subdir); + show_dir_tree(subdir); + } + } + } +} + +void show_class_device(struct sysfs_class_device *dev) +{ + if (dev != NULL) + dbg_print("Class device \"%s\" belongs to the \"%s\" class\n", + dev->name, dev->classname); +} + +void show_class_device_list(struct dlist *devlist) +{ + if (devlist != NULL) { + struct sysfs_class_device *dev = NULL; + + dlist_for_each_data(devlist, dev, struct sysfs_class_device) + show_class_device(dev); + } +} + +void show_list(struct dlist *list) +{ + if (list != NULL) { + char *name = NULL; + + dlist_for_each_data(list, name, char) + dbg_print("%s\n", name); + } +} + diff --git a/test/write_attr.c b/test/write_attr.c new file mode 100644 index 0000000..5c28c7a --- /dev/null +++ b/test/write_attr.c @@ -0,0 +1,61 @@ +/* + * write_attr.c + * + * Utility to modify the value of a given class device attribute + * + * Copyright (C) IBM Corp. 2003 + * + * 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: write_attr [classname] [device] [attribute] [new_value]\n"); +} + +int main(int argc, char *argv[]) +{ + struct sysfs_attribute *attr = NULL; + + if (argc != 5) { + print_usage(); + return 1; + } + + attr = sysfs_open_classdev_attr(argv[1], argv[2], argv[3]); + if (attr == NULL) { + fprintf(stdout, "Attribute %s not defined for classdev %s\n", + argv[3], argv[2]); + return 1; + } + + fprintf(stdout, "Attribute %s presently has a value %s\n", + attr->name, attr->value); + if ((sysfs_write_attribute(attr, argv[4], strlen(argv[4]))) != 0) { + fprintf(stdout, "Error writing attribute value\n"); + sysfs_close_attribute(attr); + return 1; + } + fprintf(stdout, "Attribute value after write is %s\n", attr->value); + sysfs_close_attribute(attr); + return 0; +} + |