From 4455e4c41a09080c9042cfac7476638ef396e162 Mon Sep 17 00:00:00 2001 From: mananth Date: Mon, 9 Feb 2004 12:08:23 +0000 Subject: Added testsuite in "test" directory Updated version info to 1.0.0 Updated autotools scripts to build testsuite Miscellaneous updates (CREDITS, README) --- COPYING | 5 +- CREDITS | 2 + ChangeLog | 5 + Makefile.am | 2 +- Makefile.in | 4 +- README | 8 +- TODO | 3 - aclocal.m4 | 78 --- config.h.in | 3 + configure | 41 +- configure.ac | 4 +- test/GPL | 272 ++++++++ test/Makefile.am | 6 +- test/Makefile.in | 39 +- test/test.c | 243 ++++++++ test/test.h | 183 ++++++ test/test_bus.c | 754 ++++++++++++++++++++++ test/test_class.c | 1111 +++++++++++++++++++++++++++++++++ test/test_dir.c | 1763 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_driver.c | 938 ++++++++++++++++++++++++++++ test/test_root.c | 897 ++++++++++++++++++++++++++ test/test_utils.c | 654 +++++++++++++++++++ test/testout.c | 187 ++++++ 23 files changed, 7079 insertions(+), 123 deletions(-) create mode 100644 test/GPL create mode 100644 test/test.c create mode 100644 test/test.h create mode 100644 test/test_bus.c create mode 100644 test/test_class.c create mode 100644 test/test_dir.c create mode 100644 test/test_driver.c create mode 100644 test/test_root.c create mode 100644 test/test_utils.c create mode 100644 test/testout.c diff --git a/COPYING b/COPYING index 355916d..39cac23 100644 --- a/COPYING +++ b/COPYING @@ -1,6 +1,7 @@ -The commands are licensed under the GNU General Public License (GPL) -Version 2, June 1991. The full text of the GPL is located at: +The commands and utilities under the "test" directory are licensed under the +GNU General Public License (GPL) Version 2, June 1991. The full text of the +GPL is located at: sysfsutils/cmd/GPL diff --git a/CREDITS b/CREDITS index 678e0f5..0835883 100644 --- a/CREDITS +++ b/CREDITS @@ -16,3 +16,5 @@ have made contributions: from Martin's library. o Martin Pitt - Supplied initial makefiles for lsbus and systool + o Martin Hicks + - Supplied patch to fix class_device functions diff --git a/ChangeLog b/ChangeLog index 9df22bd..616de1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ +02/04/2004 - Ananth Mavinakayanahalli + * Added testsuite in "test" directory + * Updated autotool scripts to build testsuite + * Changed version number to 1.0.0 + 02/04/2004 - Ananth Mavinakayanahalli * Fixed miscellaneous issues in sysfs_device/driver.c sources diff --git a/Makefile.am b/Makefile.am index f2d46fa..1407a56 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ man_MANS = lsbus.1 systool.1 -EXTRA_DIST = docs include $(man_MANS) +EXTRA_DIST = docs include $(man_MANS) CREDITS lib/LGPL cmd/GPL test/GPL SUBDIRS = lib cmd test include_HEADERS = include/libsysfs.h include/dlist.h diff --git a/Makefile.in b/Makefile.in index eb05d57..989e379 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,7 +84,7 @@ am__include = @am__include@ am__quote = @am__quote@ install_sh = @install_sh@ man_MANS = lsbus.1 systool.1 -EXTRA_DIST = docs include $(man_MANS) +EXTRA_DIST = docs include $(man_MANS) CREDITS lib/LGPL cmd/GPL test/GPL SUBDIRS = lib cmd test include_HEADERS = include/libsysfs.h include/dlist.h subdir = . @@ -328,7 +328,7 @@ distcleancheck_listfiles = find . -type f -print distdir: $(DISTFILES) $(am__remove_distdir) mkdir $(distdir) - $(mkinstalldirs) $(distdir)/include + $(mkinstalldirs) $(distdir)/cmd $(distdir)/include $(distdir)/lib $(distdir)/test @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,/[^/]*$$,,'`; \ diff --git a/README b/README index 6a33772..06c4534 100644 --- a/README +++ b/README @@ -26,6 +26,11 @@ This package currently includes: - lsbus: a small application to query system bus information. - systool: an application to view system device information by bus, class, and topology. +- A number of example usage routines in the "test" directory. +- A comprehensive testsuite, also shipped as part of the "test" directory. This + testsuite can be used to test _all_ the APIs exported by Libsysfs. + Please refer the libsysfs.txt file in the "docs" directory for + details as to how to use the testsuite. 2. How to Install @@ -42,6 +47,7 @@ as in ./configure --includedir="path for header installs" + 3. Licenses ----------- @@ -62,7 +68,7 @@ sysfsutils/lib/LGPL ----------------- Please direct all bugs to either the linux-diag mailing list - -linux-diag@lists.sourceforge.net - or to the authors: +linux-diag-devel@lists.sourceforge.net - or to the authors: Ananth Mavinakayanahalli Daniel Stekloff diff --git a/TODO b/TODO index e352500..488ad8c 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,3 @@ Commands: - Need to clean up error messages. - Clean up how attribute values are printed. -Test: ------ -- Design and implement test suites for the library. diff --git a/aclocal.m4 b/aclocal.m4 index bf9ed34..b73a11f 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -756,84 +756,6 @@ AC_CONFIG_COMMANDS_PRE( Usually this means the macro was only invoked conditionally.]) fi])]) -# Like AC_CONFIG_HEADER, but automatically create stamp file. -*- Autoconf -*- - -# Copyright 1996, 1997, 2000, 2001 Free Software Foundation, Inc. - -# 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; either version 2, or (at your option) -# any later version. - -# 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., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -AC_PREREQ([2.52]) - -# serial 6 - -# When config.status generates a header, we must update the stamp-h file. -# This file resides in the same directory as the config header -# that is generated. We must strip everything past the first ":", -# and everything past the last "/". - -# _AM_DIRNAME(PATH) -# ----------------- -# Like AS_DIRNAME, only do it during macro expansion -AC_DEFUN([_AM_DIRNAME], - [m4_if(regexp([$1], [^.*[^/]//*[^/][^/]*/*$]), -1, - m4_if(regexp([$1], [^//\([^/]\|$\)]), -1, - m4_if(regexp([$1], [^/.*]), -1, - [.], - patsubst([$1], [^\(/\).*], [\1])), - patsubst([$1], [^\(//\)\([^/].*\|$\)], [\1])), - patsubst([$1], [^\(.*[^/]\)//*[^/][^/]*/*$], [\1]))[]dnl -])# _AM_DIRNAME - - -# The stamp files are numbered to have different names. -# We could number them on a directory basis, but that's additional -# complications, let's have a unique counter. -m4_define([_AM_STAMP_Count], [0]) - - -# _AM_STAMP(HEADER) -# ----------------- -# The name of the stamp file for HEADER. -AC_DEFUN([_AM_STAMP], -[m4_define([_AM_STAMP_Count], m4_incr(_AM_STAMP_Count))dnl -AS_ESCAPE(_AM_DIRNAME(patsubst([$1], - [:.*])))/stamp-h[]_AM_STAMP_Count]) - - -# _AM_CONFIG_HEADER(HEADER[:SOURCES], COMMANDS, INIT-COMMANDS) -# ------------------------------------------------------------ -# We used to try to get a real timestamp in stamp-h. But the fear is that -# that will cause unnecessary cvs conflicts. -AC_DEFUN([_AM_CONFIG_HEADER], -[# Add the stamp file to the list of files AC keeps track of, -# along with our hook. -AC_CONFIG_HEADERS([$1], - [# update the timestamp -echo 'timestamp for $1' >"_AM_STAMP([$1])" -$2], - [$3]) -])# _AM_CONFIG_HEADER - - -# AM_CONFIG_HEADER(HEADER[:SOURCES]..., COMMANDS, INIT-COMMANDS) -# -------------------------------------------------------------- -AC_DEFUN([AM_CONFIG_HEADER], -[AC_FOREACH([_AM_File], [$1], [_AM_CONFIG_HEADER(_AM_File, [$2], [$3])]) -])# AM_CONFIG_HEADER - # libtool.m4 - Configure libtool for the host system. -*-Shell-script-*- # serial 46 AC_PROG_LIBTOOL diff --git a/config.h.in b/config.h.in index 401597e..6c53d1a 100644 --- a/config.h.in +++ b/config.h.in @@ -75,6 +75,9 @@ /* Define to 1 if you have the `strstr' function. */ #undef HAVE_STRSTR +/* Define to 1 if you have the `strtol' function. */ +#undef HAVE_STRTOL + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_SYS_DIR_H diff --git a/configure b/configure index dc0d19a..ea31a4f 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.53 for sysfsutils 0.4.0. +# Generated by GNU Autoconf 2.53 for sysfsutils 1.0.0. # # Report bugs to . # @@ -415,8 +415,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='sysfsutils' PACKAGE_TARNAME='sysfsutils' -PACKAGE_VERSION='0.4.0' -PACKAGE_STRING='sysfsutils 0.4.0' +PACKAGE_VERSION='1.0.0' +PACKAGE_STRING='sysfsutils 1.0.0' PACKAGE_BUGREPORT='linux-diag-devel@lists.sourceforge.net' ac_unique_file="config.h.in" @@ -921,7 +921,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sysfsutils 0.4.0 to adapt to many kinds of systems. +\`configure' configures sysfsutils 1.0.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -987,7 +987,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sysfsutils 0.4.0:";; + short | recursive ) echo "Configuration of sysfsutils 1.0.0:";; esac cat <<\_ACEOF @@ -1082,7 +1082,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -sysfsutils configure 0.4.0 +sysfsutils configure 1.0.0 generated by GNU Autoconf 2.53 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 @@ -1097,7 +1097,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sysfsutils $as_me 0.4.0, which was +It was created by sysfsutils $as_me 1.0.0, which was generated by GNU Autoconf 2.53. Invocation command line was $ $0 $@ @@ -1629,7 +1629,7 @@ fi # Define the identity of the package. PACKAGE=sysfsutils - VERSION=0.4.0 + VERSION=1.0.0 cat >>confdefs.h <<_ACEOF @@ -1756,12 +1756,8 @@ INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" -# Add the stamp file to the list of files AC keeps track of, -# along with our hook. ac_config_headers="$ac_config_headers config.h" - - # Check whether --enable-shared or --disable-shared was given. if test "${enable_shared+set}" = set; then enableval="$enable_shared" @@ -4171,7 +4167,7 @@ test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes case $host in *-*-irix6*) # Find out which ABI we are using. - echo '#line 4174 "configure"' > conftest.$ac_ext + echo '#line 4170 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -4707,7 +4703,7 @@ chmod -w . save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -o out/conftest2.$ac_objext" compiler_c_o=no -if { (eval echo configure:4710: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then +if { (eval echo configure:4706: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings if test -s out/conftest.err; then @@ -6500,7 +6496,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5 @@ -9917,7 +9914,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by sysfsutils $as_me 0.4.0, which was +This file was extended by sysfsutils $as_me 1.0.0, which was generated by GNU Autoconf 2.53. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -9979,7 +9976,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -sysfsutils config.status 0.4.0 +sysfsutils config.status 1.0.0 configured by $0, generated by GNU Autoconf 2.53, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" @@ -10622,12 +10619,6 @@ done; } cat $tmp/config.h rm -f $tmp/config.h fi - # Run the commands associated with the file. - case $ac_file in - config.h ) # update the timestamp -echo 'timestamp for config.h' >"./stamp-h1" - ;; - esac done _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF diff --git a/configure.ac b/configure.ac index da58a30..15fb98f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # Process this file with autoconf to produce a configure script. -AC_INIT(sysfsutils, 0.4.0, linux-diag-devel@lists.sourceforge.net) +AC_INIT(sysfsutils, 1.0.0, linux-diag-devel@lists.sourceforge.net) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([config.h.in]) AM_CONFIG_HEADER([config.h]) @@ -31,7 +31,7 @@ AC_TYPE_SIZE_T AC_FUNC_LSTAT AC_FUNC_MALLOC AC_FUNC_STAT -AC_CHECK_FUNCS([bzero getmntent isascii memset strchr strerror strrchr strstr]) +AC_CHECK_FUNCS([bzero getmntent isascii memset strchr strerror strrchr strstr strtol]) AC_CONFIG_FILES([Makefile cmd/Makefile 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 index 09181f4..bf88667 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,5 +1,5 @@ -bin_PROGRAMS = dlist_test get_class_dev get_device get_driver \ - get_bus_devices_list write_attr get_classdev_parent +bin_PROGRAMS = dlist_test get_class_dev get_device get_driver write_attr \ + get_bus_devices_list get_classdev_parent testlibsysfs dlist_test_SOURCES = dlist_test.c get_class_dev_SOURCES = get_class_dev.c get_device_SOURCES = get_device.c @@ -7,6 +7,8 @@ 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.h 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 index 92873ce..11254c4 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -83,8 +83,8 @@ 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 \ - get_bus_devices_list write_attr get_classdev_parent +bin_PROGRAMS = dlist_test get_class_dev get_device get_driver write_attr \ + get_bus_devices_list get_classdev_parent testlibsysfs dlist_test_SOURCES = dlist_test.c get_class_dev_SOURCES = get_class_dev.c @@ -93,6 +93,9 @@ 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.h + INCLUDES = -I../include LDADD = ../lib/libsysfs.la CFLAGS = -Wall -Wshadow -W -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls @@ -101,9 +104,9 @@ 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) \ - get_bus_devices_list$(EXEEXT) write_attr$(EXEEXT) \ - get_classdev_parent$(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) @@ -136,6 +139,13 @@ 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) @@ -154,6 +164,10 @@ am__depfiles_maybe = depfiles @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) @@ -165,9 +179,9 @@ LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ DIST_SOURCES = $(dlist_test_SOURCES) $(get_bus_devices_list_SOURCES) \ $(get_class_dev_SOURCES) $(get_classdev_parent_SOURCES) \ $(get_device_SOURCES) $(get_driver_SOURCES) \ - $(write_attr_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) $(write_attr_SOURCES) +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: all-am @@ -225,6 +239,9 @@ get_device$(EXEEXT): $(get_device_OBJECTS) $(get_device_DEPENDENCIES) 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) @@ -241,6 +258,14 @@ distclean-compile: @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: diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..8d85800 --- /dev/null +++ b/test/test.c @@ -0,0 +1,243 @@ +/* + * 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.h" +#include + +/*************************************************/ +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, +}; + +static void usage(void) +{ + fprintf(stdout, "testlibsysfs [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); + + 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.h b/test/test.h new file mode 100644 index 0000000..6dfe277 --- /dev/null +++ b/test/test.h @@ -0,0 +1,183 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libsysfs.h" +#include "dlist.h" + +/* + * FIXME: Change the following #defines appropriately for the system that you + * run the tests on. + */ +#define val_dir_path "/sys/bus/pci" +#define val_link_path "/sys/block/sda/device" +#define val_file_path "/sys/block/sda/dev" +#define val_link_name "device" +#define val_subdir_link_name "0000:00:00.0" +#define val_subdir_name "0000:00:00.0" +#define val_bus_id "0000:00:00.0" +#define val_bus "pci" +#define val_subsys "bus" +#define val_bus_name "pci" +#define val_class "net" +#define val_class_dev "eth0" +#define val_class_dev_path "/sys/class/net/eth0" +#define val_class_dev_attr "type" +#define val_block_class_dev_path "/sys/block/sda/sda1" +#define val_root_name "pci0000:00" +#define val_root_dev_path "/sys/devices/pci0000:00" +#define val_drv_name "scsi_debug" +#define val_drv_bus_name "pseudo" +#define val_drv_dev_name "adapter0" +#define val_drv_path "/sys/bus/pseudo/drivers/scsi_debug" +#define val_dev_path "/sys/devices/pci0000:00/0000:00:00.0" +#define val_dev_attr "vendor" +#define val_drv_attr_name "opts" +#define val_write_attr_path "/sys/class/net/eth0/tx_queue_len" +#define val_attr_name "online" +#define val_bus_attr "online" +#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_bus.c b/test/test_bus.c new file mode 100644 index 0000000..6392dd3 --- /dev/null +++ b/test/test_bus.c @@ -0,0 +1,754 @@ +/* + * 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 unsigned char *name); + * extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus, + * unsigned char *id); + * extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus, + * unsigned 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, + * unsigned char *attrname); + * extern int sysfs_find_driver_bus(const unsigned char *driver, + * unsigned char *busname, size_t bsize); + ****************************************************************************** + */ + +#include "test.h" +#include + +/** + * 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 unsigned 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, + * unsigned 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) + 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, + * unsigned 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) + 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) + 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) + 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) { +/* dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno);*/ + 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: 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) { + /*dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno);*/ + 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: 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, + * unsigned 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) { +/* dbg_print("%s: FAILED with flag = %d errno = %d\n", + __FUNCTION__, flag, errno); */ + 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: 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 unsigned char *driver, + * unsigned 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..4b29c44 --- /dev/null +++ b/test/test_class.c @@ -0,0 +1,1111 @@ +/* + * 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 unsigned char *path); + * extern struct sysfs_class_device *sysfs_open_class_device + * (const unsigned char *class, const unsigned 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 unsigned 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 *class, unsigned 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 unsigned char *name); + * extern struct sysfs_attribute *sysfs_open_classdev_attr + * (const unsigned char *classname, + * const unsigned char *dev, + * const unsigned char *attrib); + ***************************************************************************** + */ + +#include "test.h" +#include + +/** + * 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 unsigned 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 unsigned char *class, const unsigned 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) + 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) + 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) + 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 unsigned 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) + 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, unsigned 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) + 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) + 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) + 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 unsigned 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) + 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 unsigned char *classname, + * const unsigned char *dev, + * const unsigned 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) + 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..99a5d5f --- /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 unsigned char *path); + * extern int sysfs_read_attribute(struct sysfs_attribute *sysattr); + * extern int sysfs_read_attribute_value(const unsigned char *attrpath, + * unsigned char *value, size_t vsize); + * extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, + * const unsigned char *new_value, size_t len); + * extern unsigned char *sysfs_get_value_from_attributes(struct dlist *attr, + * const unsigned 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 unsigned 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, unsigned char *subname); + * extern void sysfs_close_link(struct sysfs_link *ln); + * extern struct sysfs_link *sysfs_open_link(const unsigned char *lnpath); + * extern struct sysfs_link *sysfs_get_directory_link + * (struct sysfs_directory *dir, unsigned char *linkname); + * extern struct sysfs_link *sysfs_get_subdirectory_link + * (struct sysfs_directory *dir, unsigned char *linkname); + * extern struct sysfs_attribute *sysfs_get_directory_attribute + * (struct sysfs_directory *dir, unsigned 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.h" +#include + +/** + * 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 unsigned 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 unsigned char *attrpath, + * unsigned 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 unsigned 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 unsigned char *sysfs_get_value_from_attributes(struct dlist *attr, + * const unsigned 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 unsigned 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, unsigned 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 unsigned 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, unsigned 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, unsigned 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, unsigned 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..576befb --- /dev/null +++ b/test/test_driver.c @@ -0,0 +1,938 @@ +/* + * 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 unsigned char *bus_name, const unsigned char *drv_name); + * extern struct sysfs_driver *sysfs_open_driver_path + * (const unsigned char *path); + * extern struct sysfs_attribute *sysfs_get_driver_attr + * (struct sysfs_driver *drv, const unsigned 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 unsigned char *name); + * extern struct dlist *sysfs_refresh_driver_attributes + * (struct sysfs_driver *driver); + * extern struct sysfs_attribute *sysfs_open_driver_attr + * (const unsigned char *bus, const unsigned char *drv, + * const unsigned char *attrib); + * + ****************************************************************************** + */ + +#include "test.h" +#include + +/** + * 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 unsigned 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 unsigned char *bus_name, const unsigned 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 unsigned 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) + 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; + + 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_attributes(driver); + + 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); + 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; + + 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_devices(driver); + + 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_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) + 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) + 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 unsigned 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) + 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) + 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 unsigned char *bus, const unsigned char *drv, + * const unsigned 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_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; + default: + return -1; + } + attr = sysfs_open_driver_attr(bus, drv, attrib); + + 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 (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..2e0c0b1 --- /dev/null +++ b/test/test_root.c @@ -0,0 +1,897 @@ +/* + * 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 unsigned 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 unsigned char *bus, const unsigned char *bus_id); + * extern struct sysfs_device *sysfs_get_device_parent + * (struct sysfs_device *dev); + * extern struct sysfs_device *sysfs_open_device_path + * (const unsigned char *path); + * extern struct sysfs_attribute *sysfs_get_device_attr + * (struct sysfs_device *dev, const unsigned 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 unsigned char *bus, + * const unsigned char *bus_id, + * const unsigned char *attrib); + * + ****************************************************************************** + */ + +#include "test.h" +#include + +/** + * 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 unsigned 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) + 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 unsigned char *bus, const unsigned 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) + 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 unsigned 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 unsigned 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_attr_name; + 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) + 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) + 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) + 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 unsigned char *bus, + * const unsigned char *bus_id, + * const unsigned 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) + 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..412de12 --- /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(unsigned char *mnt_path, size_t len); + * extern int sysfs_remove_trailing_slash(unsigned char *path); + * extern int sysfs_get_name_from_path(const unsigned char *path, + * unsigned char *name, size_t len); + * extern int sysfs_path_is_dir(const unsigned char *path); + * extern int sysfs_path_is_link(const unsigned char *path); + * extern int sysfs_path_is_file(const unsigned char *path); + * extern int sysfs_get_link(const unsigned char *path, unsigned char *target, + * size_t len); + * extern struct dlist *sysfs_open_subsystem_list(unsigned char *name); + * extern struct dlist *sysfs_open_bus_devices_list(unsigned char *name); + * extern void sysfs_close_list(struct dlist *list); + * + * + ***************************************************************************** + */ + +#include "test.h" +#include + +/** + * extern int sysfs_get_mnt_path(unsigned 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(unsigned 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 unsigned char *path, + * unsigned 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 unsigned 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 unsigned 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 unsigned 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 unsigned char *path, + * unsigned 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(unsigned 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(unsigned 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; + 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..fb6e31c --- /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 + +static void remove_end_newline(unsigned char *value) +{ + unsigned 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) { + unsigned char *name = NULL; + + dlist_for_each_data(list, name, unsigned char) + dbg_print("%s\n", name); + } +} + -- cgit v1.2.1