diff --git a/COPYING.kselftest b/COPYING.kselftest new file mode 100644 index 0000000000000000000000000000000000000000..610865a3b98e36a0ee894d0f604d3b308b693d2b --- /dev/null +++ b/COPYING.kselftest @@ -0,0 +1,349 @@ +This copyright notice covers the kselftest framework: + +tools/testing/unittest/kselftest.h +tools/testing/unittest/lib.mk +tools/testing/unittest/Makefile + + +---------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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. + + GNU GENERAL PUBLIC LICENSE + 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 + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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 of the License, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Makefile b/Makefile index 84aee5ba1f920e8a4231167f2d8733721d0163b7..fa72d66aa6f61346e6baaabb0941784d6e056a32 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION = 0 PATCHLEVEL = 0 SUBLEVEL = 1 EXTRAVERSION = -NAME = Zombeaver +NAME = Zombeaver # *DOCUMENTATION* # To see a list of typical targets execute "make help" @@ -569,7 +569,7 @@ export KBUILD_IMAGE ?= leanos export INSTALL_PATH ?= ./install -core-y := arch/sparc/ +core-y := arch/sparc/ init-y := init/ libs-y := lib/ @@ -669,6 +669,16 @@ headerdep: $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ $(srctree)/scripts/headerdep.pl -I$(srctree)/include +# --------------------------------------------------------------------------- +# Unit tests + +PHONY += unittest +unittest: + $(Q)$(MAKE) -C tools/testing/unittest run_tests + +unittest-clean: + $(Q)$(MAKE) -C tools/testing/unittest clean + ### # Cleaning is done on three levels. @@ -754,7 +764,7 @@ help: @echo ' dir/file.lst - Build specified mixed source/assembly target only' @echo ' (requires a recent binutils and recent build (System.map))' @echo ' kernelversion - Output the version stored in Makefile (use with make -s)' - echo '' + @echo '' @echo 'Static analysers' @echo ' includecheck - Check for duplicate included header files' @echo ' headerdep - Detect inclusion cycles in headers' @@ -769,6 +779,11 @@ help: @echo ' 3: more obscure warnings, can most likely be ignored' @echo ' Multiple levels can be combined with W=12 or W=123' @echo '' + @echo 'Unit Tests' + @echo ' unittest - Build and run tests' + @echo ' unittest-clean - Remove all test files' + @echo '' + @echo '' @echo 'Execute "make" or "make all" to build all targets marked with [*] ' @echo 'For further info see the ./README file' diff --git a/tools/testing/unittest/Makefile b/tools/testing/unittest/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..c923ae5f39736e6ea46fd2cb4f0475c1c0319722 --- /dev/null +++ b/tools/testing/unittest/Makefile @@ -0,0 +1,34 @@ +TARGETS += sysctl + +#Please keep the TARGETS list alphabetically sorted + +# Clear LDFLAGS and MAKEFLAGS if called from main +# Makefile to avoid test build failures when test +# Makefile doesn't have explicit build rules. + +CFLAGS += -fprofile-arcs -ftest-coverage + +ifeq (1,$(MAKELEVEL)) +override LDFLAGS = +override MAKEFLAGS = +else +export CFLAGS +export LDFLAGS = -lgcov --coverage +endif + + +all: + for TARGET in $(TARGETS); do \ + make -C $$TARGET; \ + done; + +run_tests: all + for TARGET in $(TARGETS); do \ + make -C $$TARGET run_tests; \ + done; +clean: + for TARGET in $(TARGETS); do \ + make -C $$TARGET clean; \ + done; + +.PHONY: install diff --git a/tools/testing/unittest/kselftest.h b/tools/testing/unittest/kselftest.h new file mode 100644 index 0000000000000000000000000000000000000000..0a5a25afc53c5ddf0cc25e85a91b46c25eec8bde --- /dev/null +++ b/tools/testing/unittest/kselftest.h @@ -0,0 +1,104 @@ +/* + * kselftest.h: kselftest framework return codes to include from + * selftests. + * + * Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com> + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Armin Luntzer <armin.luntzer@univie.ac.at> + * + * This file is released under the GPLv2. + */ +#ifndef __KSELFTEST_H +#define __KSELFTEST_H + +#include <stdlib.h> +#include <unistd.h> + +/* define kselftest exit codes */ +#define KSFT_PASS 0 +#define KSFT_FAIL 1 +#define KSFT_XFAIL 2 +#define KSFT_XPASS 3 +#define KSFT_SKIP 4 + +/* counters */ +struct ksft_count { + unsigned int ksft_pass; + unsigned int ksft_fail; + unsigned int ksft_xfail; + unsigned int ksft_xpass; + unsigned int ksft_xskip; +}; + +static struct ksft_count ksft_cnt; + +static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; } +static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; } +static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; } +static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; } +static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; } + +static inline void ksft_print_cnts(void) +{ + printf("\t\tPass: %d Fail: %d Xfail: %d Xpass: %d, Xskip: %d\n\n", + ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, + ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass, + ksft_cnt.ksft_xskip); +} + +static inline int ksft_exit_pass(void) +{ + exit(KSFT_PASS); +} +static inline int ksft_exit_fail(void) +{ + exit(KSFT_FAIL); +} +static inline int ksft_exit_xfail(void) +{ + exit(KSFT_XFAIL); +} +static inline int ksft_exit_xpass(void) +{ + exit(KSFT_XPASS); +} +static inline int ksft_exit_skip(void) +{ + exit(KSFT_SKIP); +} + +static void ksft_assert(int res, unsigned int line, + const char *cond, const char *file) +{ + if (!res) { + printf("\t\tTest failed: %s : %d -> %s\n", file, line, cond); + ksft_inc_fail_cnt(); + } + + ksft_inc_pass_cnt(); +} + +#define KSFT_ASSERT(value) \ +{ \ + ksft_assert((int) (value), __LINE__, #value, __FILE__); \ +}; + +#define KSFT_ASSERT_PTR_NOT_NULL(value) \ +{ \ + ksft_assert((int) (value != NULL), __LINE__, #value, __FILE__); \ +}; + +#define KSFT_ASSERT_PTR_NULL(value) \ +{ \ + ksft_assert((int) (value == NULL), __LINE__, #value, __FILE__); \ +}; + + +/* yes ... srsly */ +#define KSFT_RUN_TEST(str, func) \ +{ \ + printf("Test %s\n", (str)); \ + func(); \ +}; + +#endif /* __KSELFTEST_H */ diff --git a/tools/testing/unittest/lib.mk b/tools/testing/unittest/lib.mk new file mode 100644 index 0000000000000000000000000000000000000000..479fc114336d1163b560179dc0d176c282b36da3 --- /dev/null +++ b/tools/testing/unittest/lib.mk @@ -0,0 +1,28 @@ +# This mimics the top-level Makefile. We do it explicitly here so that this +# Makefile can operate with or without the kbuild infrastructure. +CC := $(CROSS_COMPILE)gcc + +# TODO add coverage analysis +# lcov --rc lcov_branch_coverage=1 --capture --directory ./ --output-file coverage.info +# genhtml --branch-coverage coverage.info --output-directory out +# + +define RUN_TESTS + @for TEST in $(TEST_PROGS); do \ + (./$$TEST && echo "selftests: $$TEST [PASS]") || echo "selftests: $$TEST [FAIL]"; \ + done; +endef + +run_tests: all + $(RUN_TESTS) + +define EMIT_TESTS + @for TEST in $(TEST_PROGS); do \ + echo "(./$$TEST && echo \"selftests: $$TEST [PASS]\") || echo \"selftests: $$TEST [FAIL]\""; \ + done; +endef + +emit_tests: + $(EMIT_TESTS) + +.PHONY: run_tests all clean emit_tests diff --git a/tools/testing/unittest/shared/malloc_test_wrapper.c b/tools/testing/unittest/shared/malloc_test_wrapper.c new file mode 100644 index 0000000000000000000000000000000000000000..ec044fd88866e6a639a606c0801796db328ad568 --- /dev/null +++ b/tools/testing/unittest/shared/malloc_test_wrapper.c @@ -0,0 +1,61 @@ +/** + * @file wrap_malloc.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @brief a mockup of malloc + * + */ + +#include <shared.h> +#include <stdint.h> +#include <stdlib.h> +#include <malloc_test_wrapper.h> + +#define MALLOC_FAIL_AFTER 2 + +static uint32_t malloc_cnt; + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status malloc_test_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + if (ws == SPECIAL) + malloc_cnt = 0; + + return status; +} + +/** + * @brief a wrapper of malloc depending on wrapper status + */ + +void *__wrap_malloc(size_t size) +{ + if (malloc_test_wrapper(QUERY) == DISABLED) + return __real_malloc(size); + + if (malloc_test_wrapper(QUERY) == SPECIAL) + if (malloc_cnt++ < MALLOC_FAIL_AFTER) + return __real_malloc(size); + + return NULL; +} diff --git a/tools/testing/unittest/shared/malloc_test_wrapper.h b/tools/testing/unittest/shared/malloc_test_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..2692731be7e0c5331da437b3b0b89ddb6693a45c --- /dev/null +++ b/tools/testing/unittest/shared/malloc_test_wrapper.h @@ -0,0 +1,28 @@ +/** + * @file malloc_test_wrapper.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + + +#include <shared.h> + +enum wrap_status malloc_test_wrapper(enum wrap_status ws); + +void *__real_malloc(size_t size); + +void *__wrap_malloc(size_t size); + + + diff --git a/tools/testing/unittest/shared/shared.h b/tools/testing/unittest/shared/shared.h new file mode 100644 index 0000000000000000000000000000000000000000..08276951e2b9aa7554b2615c2c8a54c60386aca0 --- /dev/null +++ b/tools/testing/unittest/shared/shared.h @@ -0,0 +1,26 @@ +/** + * @file shared.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @defgroup mockups Unit Test mockups of functions + * @brief A group of functions responding to calls with predefined behaviour. + */ + +#ifndef SHARED_H +#define SHARED_H + +enum wrap_status {DISABLED, ENABLED, SPECIAL, QUERY}; + +#endif diff --git a/tools/testing/unittest/shared/wrap_ahbstat_clear_new_error.c b/tools/testing/unittest/shared/wrap_ahbstat_clear_new_error.c new file mode 100644 index 0000000000000000000000000000000000000000..6a725e72228c4edad543d56eaf4e95226a5d5849 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_clear_new_error.c @@ -0,0 +1,49 @@ +/** + * @file wrap_ahbstat_clear_new_error.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_ahbstat_clear_new_error.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status ahbstat_clear_new_error_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of ahbstat_clear_new_error + */ + +void __wrap_ahbstat_clear_new_error(void) +{ + if (ahbstat_clear_new_error_wrapper(QUERY) == DISABLED) + __real_ahbstat_clear_new_error(); + + return; +} diff --git a/tools/testing/unittest/shared/wrap_ahbstat_clear_new_error.h b/tools/testing/unittest/shared/wrap_ahbstat_clear_new_error.h new file mode 100644 index 0000000000000000000000000000000000000000..5b6f0af5872b6e0b5abd11789b35434cbe5b14e9 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_clear_new_error.h @@ -0,0 +1,32 @@ +/** + * @file wrap_ahbstat_clear_new_error.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_AHBSTAT_CLEAR_NEW_ERROR +#define WRAP_AHBSTAT_CLEAR_NEW_ERROR + +#include <shared.h> +#include <stdint.h> +#include <ahb.h> + +enum wrap_status ahbstat_clear_new_error_wrapper(enum wrap_status ws); + +void __real_ahbstat_clear_new_error(void); + +void __wrap_ahbstat_clear_new_error(void); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_ahbstat_correctable_error.c b/tools/testing/unittest/shared/wrap_ahbstat_correctable_error.c new file mode 100644 index 0000000000000000000000000000000000000000..69ed09b61b34165ff24d69f976863367cc78f3f9 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_correctable_error.c @@ -0,0 +1,52 @@ +/** + * @file wrap_ahbstat_correctable_error.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_ahbstat_correctable_error.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status ahbstat_correctable_error_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of ahbstat_correctable_error + */ + +uint32_t __wrap_ahbstat_correctable_error(void) +{ + if (ahbstat_correctable_error_wrapper(QUERY) == DISABLED) + return __real_ahbstat_correctable_error(); + + if (ahbstat_correctable_error_wrapper(QUERY) == SPECIAL) + return 0; + + return 1; +} diff --git a/tools/testing/unittest/shared/wrap_ahbstat_correctable_error.h b/tools/testing/unittest/shared/wrap_ahbstat_correctable_error.h new file mode 100644 index 0000000000000000000000000000000000000000..97a245db0df1a3479ed6521aeb148c0d75944219 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_correctable_error.h @@ -0,0 +1,32 @@ +/** + * @file wrap_ahbstat_correctable_error.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_AHBSTAT_CORRECTABLE_ERROR +#define WRAP_AHBSTAT_CORRECTABLE_ERROR + +#include <shared.h> +#include <stdint.h> +#include <ahb.h> + +enum wrap_status ahbstat_correctable_error_wrapper(enum wrap_status ws); + +uint32_t __real_ahbstat_correctable_error(void); + +uint32_t __wrap_ahbstat_correctable_error(void); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_ahbstat_get_failing_addr.c b/tools/testing/unittest/shared/wrap_ahbstat_get_failing_addr.c new file mode 100644 index 0000000000000000000000000000000000000000..02db729664d86c8b865c8807da9aece6ad536502 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_get_failing_addr.c @@ -0,0 +1,72 @@ +/** + * @file wrap_ahbstat_get_failing_addr.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_ahbstat_get_failing_addr.h> +#include <iwf_fpga.h> +#include <wrap_malloc.h> + +static uint32_t fail_cnt; + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status ahbstat_get_failing_addr_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + if (ws == SPECIAL) + fail_cnt = 0; + + + return status; +} + + +/** + * @brief a wrapper of ahbstat_get_failing_addr + */ + +uint32_t __wrap_ahbstat_get_failing_addr(void) +{ + if (ahbstat_get_failing_addr_wrapper(QUERY) == DISABLED) + return __real_ahbstat_get_failing_addr(); + + if (ahbstat_get_failing_addr_wrapper(QUERY) == SPECIAL) { + + switch (fail_cnt++) { + case 0: + return IWF_FPGA_FLASH_1_DATA_BASE; + case 1: + return IWF_FPGA_FLASH_2_DATA_BASE; + case 2: + return IWF_FPGA_FLASH_3_DATA_BASE; + case 3: + return IWF_FPGA_FLASH_4_DATA_BASE; + default: + return 0; + } + } + + return SRAM1_SW_ADDR; +} diff --git a/tools/testing/unittest/shared/wrap_ahbstat_get_failing_addr.h b/tools/testing/unittest/shared/wrap_ahbstat_get_failing_addr.h new file mode 100644 index 0000000000000000000000000000000000000000..361af59ff47d155966ae3cdf975ef03894b66b85 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_get_failing_addr.h @@ -0,0 +1,32 @@ +/** + * @file wrap_ahbstat_get_failing_addr.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_AHBSTAT_GET_FAILING_ADDR +#define WRAP_AHBSTAT_GET_FAILING_ADDR + +#include <shared.h> +#include <stdint.h> +#include <ahb.h> + +enum wrap_status ahbstat_get_failing_addr_wrapper(enum wrap_status ws); + +uint32_t __real_ahbstat_get_failing_addr(void); + +uint32_t __wrap_ahbstat_get_failing_addr(void); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_ahbstat_new_error.c b/tools/testing/unittest/shared/wrap_ahbstat_new_error.c new file mode 100644 index 0000000000000000000000000000000000000000..e631b481ddd8974a9fd59f4468342afcadd49ad3 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_new_error.c @@ -0,0 +1,52 @@ +/** + * @file wrap_ahbstat_new_error.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_ahbstat_new_error.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status ahbstat_new_error_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of ahbstat_new_error + */ + +uint32_t __wrap_ahbstat_new_error(void) +{ + if (ahbstat_new_error_wrapper(QUERY) == DISABLED) + return __real_ahbstat_new_error(); + + if (ahbstat_new_error_wrapper(QUERY) == SPECIAL) + return 0; + + return 1; +} diff --git a/tools/testing/unittest/shared/wrap_ahbstat_new_error.h b/tools/testing/unittest/shared/wrap_ahbstat_new_error.h new file mode 100644 index 0000000000000000000000000000000000000000..5fe10152a34ea9abfc998298e6cc0b7da574a4ec --- /dev/null +++ b/tools/testing/unittest/shared/wrap_ahbstat_new_error.h @@ -0,0 +1,32 @@ +/** + * @file wrap_ahbstat_new_error.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_AHBSTAT_NEW_ERROR +#define WRAP_AHBSTAT_NEW_ERROR + +#include <shared.h> +#include <stdint.h> +#include <ahb.h> + +enum wrap_status ahbstat_new_error_wrapper(enum wrap_status ws); + +uint32_t __real_ahbstat_new_error(void); + +uint32_t __wrap_ahbstat_new_error(void); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_cbuf_peek16.c b/tools/testing/unittest/shared/wrap_cbuf_peek16.c new file mode 100644 index 0000000000000000000000000000000000000000..baecb942f33fcb0731c7be49972ab83fe8fd896c --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_peek16.c @@ -0,0 +1,63 @@ +/** + * @file wrap_cbuf_peek16.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @brief a mockup of cbuf_peek16 + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_cbuf_peek16.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status cbuf_peek16_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + +/** + * @brief a wrapper of cbuf_peek16 depending on wrapper status + */ + +uint32_t __wrap_cbuf_peek16(struct circular_buffer16 *p_buf, + uint16_t *dest, + uint32_t elem) +{ + if (cbuf_peek16_wrapper(QUERY) == DISABLED) + return __real_cbuf_peek16(p_buf, dest, elem); + + if (cbuf_peek16_wrapper(QUERY) == SPECIAL) { + + if (!p_buf->num_elem) + return 0; + + dest[0] = 12; + return 12; + } + + dest[0] = 0xdead; + + return elem; +} diff --git a/tools/testing/unittest/shared/wrap_cbuf_peek16.h b/tools/testing/unittest/shared/wrap_cbuf_peek16.h new file mode 100644 index 0000000000000000000000000000000000000000..0311f2909510048a1ea27c9d27194c438e49a2c1 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_peek16.h @@ -0,0 +1,36 @@ +/** + * @file wrap_cbuf_peek16.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_CBUF_PEEK16 +#define WRAP_CBUF_PEEK16 + +#include <shared.h> +#include <circular_buffer16.h> + +enum wrap_status cbuf_peek16_wrapper(enum wrap_status ws); + +uint32_t __real_cbuf_peek16(struct circular_buffer16 *p_buf, + uint16_t *dest, + uint32_t elem); + +uint32_t __wrap_cbuf_peek16(struct circular_buffer16 *p_buf, + uint16_t *dest, + uint32_t elem); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_cbuf_read16.c b/tools/testing/unittest/shared/wrap_cbuf_read16.c new file mode 100644 index 0000000000000000000000000000000000000000..470d78902159f2eded46353389bfd448f3b79b15 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_read16.c @@ -0,0 +1,58 @@ +/** + * @file wrap_cbuf_read16.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @brief a mockup of cbuf_read16 + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_cbuf_read16.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status cbuf_read16_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of cbuf_read16 depending on wrapper status + */ + +uint32_t __wrap_cbuf_read16(struct circular_buffer16 *p_buf, + uint16_t *dest, + uint32_t elem) +{ + if (cbuf_read16_wrapper(QUERY) == DISABLED) + return __real_cbuf_read16(p_buf, dest, elem); + + if (cbuf_read16_wrapper(QUERY) == SPECIAL) + return 0; + + dest[0] = 0xdead; + + return elem; +} diff --git a/tools/testing/unittest/shared/wrap_cbuf_read16.h b/tools/testing/unittest/shared/wrap_cbuf_read16.h new file mode 100644 index 0000000000000000000000000000000000000000..f51a9a4fa7c2ebeff5074417102ccae926cc7cd9 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_read16.h @@ -0,0 +1,35 @@ +/** + * @file wrap_cbuf_read16.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_CBUF_READ16 +#define WRAP_CBUF_READ16 + +#include <shared.h> +#include <circular_buffer16.h> + +enum wrap_status cbuf_read16_wrapper(enum wrap_status ws); + +uint32_t __real_cbuf_read16(struct circular_buffer16 *p_buf, + uint16_t *dest, + uint32_t elem); + + +uint32_t __wrap_cbuf_read16(struct circular_buffer16 *p_buf, + uint16_t *dest, + uint32_t elem); + +#endif diff --git a/tools/testing/unittest/shared/wrap_cbuf_read8.c b/tools/testing/unittest/shared/wrap_cbuf_read8.c new file mode 100644 index 0000000000000000000000000000000000000000..83a0ac3eb29a67e828e4697564573a5b241e6f92 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_read8.c @@ -0,0 +1,57 @@ +/** + * @file wrap_cbuf_read8.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @brief a mockup of cbuf_peek16 + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_cbuf_read8.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status cbuf_read8_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + +/** + * @brief a wrapper of cbuf_read8 depending on wrapper status + */ + +uint32_t __wrap_cbuf_read8(struct circular_buffer8 *p_buf, + uint8_t *dest, + uint32_t elem) +{ + if (cbuf_read8_wrapper(QUERY) == DISABLED) + return __real_cbuf_read8(p_buf, dest, elem); + + if (cbuf_read8_wrapper(QUERY) == SPECIAL) + return 0; + + dest[0] = 0xde; + + return elem; +} diff --git a/tools/testing/unittest/shared/wrap_cbuf_read8.h b/tools/testing/unittest/shared/wrap_cbuf_read8.h new file mode 100644 index 0000000000000000000000000000000000000000..12930ad3967f9326ca256ca586a16bd9c1eeb0b9 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_read8.h @@ -0,0 +1,34 @@ +/** + * @file wrap_cbuf_read8.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_CBUF_READ8 +#define WRAP_CBUF_READ8 + +#include <shared.h> +#include <circular_buffer8.h> + +enum wrap_status cbuf_read8_wrapper(enum wrap_status ws); + +uint32_t __real_cbuf_read8(struct circular_buffer8 *p_buf, + uint8_t *dest, + uint32_t elem); + +uint32_t __wrap_cbuf_read8(struct circular_buffer8 *p_buf, + uint8_t *dest, + uint32_t elem); + +#endif diff --git a/tools/testing/unittest/shared/wrap_cbuf_write16.c b/tools/testing/unittest/shared/wrap_cbuf_write16.c new file mode 100644 index 0000000000000000000000000000000000000000..55b84047511e12794a94440a7c99b411c213e649 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_write16.c @@ -0,0 +1,53 @@ +/** + * @file wrap_cbuf_write16.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @brief a mockup of cbuf_write16 + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_cbuf_write16.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status cbuf_write16_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of cbuf_write16 depending on wrapper status + */ + +uint32_t __wrap_cbuf_write16(struct circular_buffer16 *p_buf, + uint16_t *src, + uint32_t elem) +{ + if (cbuf_write16_wrapper(QUERY) == DISABLED) + return __real_cbuf_write16(p_buf, src, elem); + + return 0; +} diff --git a/tools/testing/unittest/shared/wrap_cbuf_write16.h b/tools/testing/unittest/shared/wrap_cbuf_write16.h new file mode 100644 index 0000000000000000000000000000000000000000..9472bf7a2c089f18f117fa3289236635ea31cba0 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_write16.h @@ -0,0 +1,36 @@ +/** + * @file wrap_cbuf_write16.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#ifndef WRAP_CBUF_WRITE16 +#define WRAP_CBUF_WRITE16 + +#include <shared.h> +#include <circular_buffer16.h> + +enum wrap_status cbuf_write16_wrapper(enum wrap_status ws); + +uint32_t __real_cbuf_write16(struct circular_buffer16 *p_buf, + uint16_t *src, + uint32_t elem); + + +uint32_t __wrap_cbuf_write16(struct circular_buffer16 *p_buf, + uint16_t *src, + uint32_t elem); + +#endif diff --git a/tools/testing/unittest/shared/wrap_cbuf_write8.c b/tools/testing/unittest/shared/wrap_cbuf_write8.c new file mode 100644 index 0000000000000000000000000000000000000000..c676a292d660c810f5b18c8b08b5acac2cfacbe9 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_write8.c @@ -0,0 +1,62 @@ +/** + * @file wrap_cbuf_write8.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + * @brief a mockup of cbuf_write8 + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_cbuf_write8.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status cbuf_write8_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of cbuf_write8 depending on wrapper status + */ + +uint32_t __wrap_cbuf_write8(struct circular_buffer8 *p_buf, + uint8_t *src, + uint32_t elem) +{ + if (cbuf_write8_wrapper(QUERY) == DISABLED) + return __real_cbuf_write8(p_buf, src, elem); + + if (cbuf_write8_wrapper(QUERY) == SPECIAL) { + + if (!p_buf->num_elem) + return 0; + + return elem; + } + + return 0; +} + diff --git a/tools/testing/unittest/shared/wrap_cbuf_write8.h b/tools/testing/unittest/shared/wrap_cbuf_write8.h new file mode 100644 index 0000000000000000000000000000000000000000..fabd7a160a73b031cbd2fa2bbb59ae06b8dd6627 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cbuf_write8.h @@ -0,0 +1,35 @@ +/** + * @file wrap_cbuf_write8.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_CBUF_WRITE8 +#define WRAP_CBUF_WRITE8 + +#include <shared.h> +#include <circular_buffer8.h> + +enum wrap_status cbuf_write8_wrapper(enum wrap_status ws); + +uint32_t __real_cbuf_write8(struct circular_buffer8 *p_buf, + uint8_t *src, + uint32_t elem); + + +uint32_t __wrap_cbuf_write8(struct circular_buffer8 *p_buf, + uint8_t *src, + uint32_t elem); + +#endif diff --git a/tools/testing/unittest/shared/wrap_cpus_next_valid_pkt_size.h b/tools/testing/unittest/shared/wrap_cpus_next_valid_pkt_size.h new file mode 100644 index 0000000000000000000000000000000000000000..605ed89c7e4d3faab2766f9217bcece1ca63f35c --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cpus_next_valid_pkt_size.h @@ -0,0 +1,57 @@ +/** + * @file wrap_cpus_next_valid_pkt_size.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#ifndef WRAP_CPUS_NEXT_VALID_PKT_SIZE_H +#define WRAP_CPUS_NEXT_VALID_PKT_SIZE_H + +#include <shared.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +static enum wrap_status cpus_next_valid_pkt_size_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + +__attribute__((unused)) +int32_t __real_cpus_next_valid_pkt_size(struct cpus_buffers *cpus); + +/** + * @brief a wrapper of cpus_next_valid_pkt_size + */ + +__attribute__((unused)) +int32_t __wrap_cpus_next_valid_pkt_size(struct cpus_buffers *cpus) +{ + if (cpus_next_valid_pkt_size_wrapper(QUERY) == DISABLED) + return __real_cpus_next_valid_pkt_size(cpus); + + errno = 0xdead; + return -1; +} + + +#endif diff --git a/tools/testing/unittest/shared/wrap_cpus_pop_packet.h b/tools/testing/unittest/shared/wrap_cpus_pop_packet.h new file mode 100644 index 0000000000000000000000000000000000000000..5b56e53b3be843494c1c20488ab1714f7586e973 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_cpus_pop_packet.h @@ -0,0 +1,57 @@ +/** + * @file wrap_cpus_pop_packet.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#ifndef WRAP_CPUS_POP_PACKET +#define WRAP_CPUS_POP_PACKET + +#include <shared.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +static enum wrap_status cpus_pop_packet_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + +__attribute__((unused)) +int32_t __real_cpus_pop_packet(struct cpus_buffers *cpus, uint8_t *pus_pkt); + + +/** + * @brief a wrapper of cpus_pop_packet + */ + +__attribute__((unused)) +int32_t __wrap_cpus_pop_packet(struct cpus_buffers *cpus, uint8_t *pus_pkt) +{ + if (cpus_pop_packet_wrapper(QUERY) == DISABLED) + return __real_cpus_pop_packet(cpus, pus_pkt); + + errno = 0xdead; + return -1; +} + +#endif diff --git a/tools/testing/unittest/shared/wrap_fpga_flash_empty.c b/tools/testing/unittest/shared/wrap_fpga_flash_empty.c new file mode 100644 index 0000000000000000000000000000000000000000..08e7f1a750a559a33510655950fcc9bd98c5393b --- /dev/null +++ b/tools/testing/unittest/shared/wrap_fpga_flash_empty.c @@ -0,0 +1,49 @@ +/** + * @file wrap_fpga_flash_empty.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_fpga_flash_empty.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status fpga_flash_empty_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of fpga_flash_empty + */ + +int32_t __wrap_fpga_flash_empty(uint32_t unit, uint32_t block) +{ + if (fpga_flash_empty_wrapper(QUERY) == DISABLED) + return __real_fpga_flash_empty(unit, block); + + return 1; +} diff --git a/tools/testing/unittest/shared/wrap_fpga_flash_empty.h b/tools/testing/unittest/shared/wrap_fpga_flash_empty.h new file mode 100644 index 0000000000000000000000000000000000000000..f73ddcca6253308dbc88b5566382785e2d155fd8 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_fpga_flash_empty.h @@ -0,0 +1,32 @@ +/** + * @file wrap_fpga_flash_empty.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_FPGA_FLASH_BLOCK_EMPTY +#define WRAP_FPGA_FLASH_BLOCK_EMPTY + +#include <shared.h> +#include <stdint.h> +#include <iwf_fpga.h> + +enum wrap_status fpga_flash_empty_wrapper(enum wrap_status ws); + +int32_t __real_fpga_flash_empty(uint32_t unit, uint32_t block); + +int32_t __wrap_fpga_flash_empty(uint32_t unit, uint32_t block); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_fpga_flash_read_status.c b/tools/testing/unittest/shared/wrap_fpga_flash_read_status.c new file mode 100644 index 0000000000000000000000000000000000000000..0a48c3f88373bea9ff40e6689742fb0153696b94 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_fpga_flash_read_status.c @@ -0,0 +1,82 @@ +/** + * @file wrap_fpga_flash_read_status.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2016 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_fpga_flash_read_status.h> + +static uint32_t cnt; + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status fpga_flash_read_status_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) { + status = ws; + cnt = 0; + } + + + return status; +} + + +/** + * @brief a wrapper of fpga_flash_read_status + */ + +int32_t __wrap_fpga_flash_read_status(uint32_t unit, uint32_t block) +{ + static uint32_t status; + + + if (fpga_flash_read_status_wrapper(QUERY) == DISABLED) + return __real_fpga_flash_read_status(unit, block); + + if (fpga_flash_read_status_wrapper(QUERY) == SPECIAL) + status = FLASH_STATUS_FAIL; + else + status = 0; + + cnt++; + + /* be careful changing these, the particular order is + * needed in flash_erase_block_test() + */ + + switch (cnt) { + case 1: + case 2: + return FLASH_BLOCK_VALID; + case 3: + return status; + break; + + case 4: + fpga_flash_read_status_wrapper(DISABLED); + cnt = 0; + return 0; + break; + default: + return cnt; + } +} diff --git a/tools/testing/unittest/shared/wrap_fpga_flash_read_status.h b/tools/testing/unittest/shared/wrap_fpga_flash_read_status.h new file mode 100644 index 0000000000000000000000000000000000000000..8f7e82f8cabb050fac284002603cfb8f75985e24 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_fpga_flash_read_status.h @@ -0,0 +1,32 @@ +/** + * @file wrap_fpga_flash_read_status.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_FPGA_FLASH_READ_STATUS +#define WRAP_FPGA_FLASH_READ_STATUS + +#include <shared.h> +#include <stdint.h> +#include <iwf_flash.h> + +enum wrap_status fpga_flash_read_status_wrapper(enum wrap_status ws); + +int32_t __real_fpga_flash_read_status(uint32_t unit, uint32_t block); + +int32_t __wrap_fpga_flash_read_status(uint32_t unit, uint32_t block); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_grspw2_add_pkt.c b/tools/testing/unittest/shared/wrap_grspw2_add_pkt.c new file mode 100644 index 0000000000000000000000000000000000000000..d6a32e1842aaa1b89e030ce6284bdbe11b78cb9f --- /dev/null +++ b/tools/testing/unittest/shared/wrap_grspw2_add_pkt.c @@ -0,0 +1,53 @@ +/** + * @file wrap_grspw2_add_pkt.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_grspw2_add_pkt.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status grspw2_add_pkt_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of grspw2_add_pkt + */ + +int32_t __wrap_grspw2_add_pkt(struct grspw2_core_cfg *cfg, + const void *hdr, uint32_t hdr_size, + const void *data, uint32_t data_size) +{ + if (grspw2_add_pkt_wrapper(QUERY) == DISABLED) + return __real_grspw2_add_pkt(cfg, + hdr, hdr_size, + data, data_size); + + return 1; +} diff --git a/tools/testing/unittest/shared/wrap_grspw2_add_pkt.h b/tools/testing/unittest/shared/wrap_grspw2_add_pkt.h new file mode 100644 index 0000000000000000000000000000000000000000..36fe40a558820f553f3d98b701b1735684c951b9 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_grspw2_add_pkt.h @@ -0,0 +1,36 @@ +/** + * @file wrap_grspw2_add_pkt.h + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_GRSPW2_ADD_PKT +#define WRAP_GRSPW2_ADD_PKT + +#include <shared.h> +#include <stdint.h> +#include <grspw2.h> + +enum wrap_status grspw2_add_pkt_wrapper(enum wrap_status ws); + +int32_t __real_grspw2_add_pkt(struct grspw2_core_cfg *cfg, + const void *hdr, uint32_t hdr_size, + const void *data, uint32_t data_size); + +int32_t __wrap_grspw2_add_pkt(struct grspw2_core_cfg *cfg, + const void *hdr, uint32_t hdr_size, + const void *data, uint32_t data_size); + + + +#endif diff --git a/tools/testing/unittest/shared/wrap_grspw2_get_pkt.c b/tools/testing/unittest/shared/wrap_grspw2_get_pkt.c new file mode 100644 index 0000000000000000000000000000000000000000..78df54495a072eed1f194ac1b541138b80037d65 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_grspw2_get_pkt.c @@ -0,0 +1,49 @@ +/** + * @file wrap_grspw2_get_pkt.c + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + * + */ + +#include <shared.h> +#include <stdint.h> +#include <wrap_grspw2_get_pkt.h> + + +/** + * @brief tracks the functional status of the wrapper + */ + +enum wrap_status grspw2_get_pkt_wrapper(enum wrap_status ws) +{ + static enum wrap_status status = DISABLED; + + if (ws != QUERY) + status = ws; + + return status; +} + + +/** + * @brief a wrapper of grspw2_get_pkt + */ + +uint32_t __wrap_grspw2_get_pkt(struct grspw2_core_cfg *cfg, uint8_t *pkt) +{ + if (grspw2_get_pkt_wrapper(QUERY) == DISABLED) + return __real_grspw2_get_pkt(cfg, pkt); + + return 0; +} diff --git a/tools/testing/unittest/shared/wrap_grspw2_get_pkt.h b/tools/testing/unittest/shared/wrap_grspw2_get_pkt.h new file mode 100644 index 0000000000000000000000000000000000000000..f94c0bbeb57ffd6aa8285720c772d5841616ba46 --- /dev/null +++ b/tools/testing/unittest/shared/wrap_grspw2_get_pkt.h @@ -0,0 +1,32 @@ +/** + * @file wrap_grspw2_get_pkt.h + * @ingroup mockups + * @author Armin Luntzer (armin.luntzer@univie.ac.at), + * @date 2015 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef WRAP_GRSPW2_GET_PKT +#define WRAP_GRSPW2_GET_PKT + +#include <shared.h> +#include <stdint.h> +#include <grspw2.h> + +enum wrap_status grspw2_get_pkt_wrapper(enum wrap_status ws); + +uint32_t __real_grspw2_get_pkt(struct grspw2_core_cfg *cfg, uint8_t *pkt); +uint32_t __wrap_grspw2_get_pkt(struct grspw2_core_cfg *cfg, uint8_t *pkt); + + + +#endif diff --git a/tools/testing/unittest/sysctl/Makefile b/tools/testing/unittest/sysctl/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..bed17b851663e58ca0a88dc2dc7e067cd03ae44a --- /dev/null +++ b/tools/testing/unittest/sysctl/Makefile @@ -0,0 +1,16 @@ +CFLAGS += -g -I../ -I../shared -I../../../../include/ -I../../../../lib +LDFLAGS+= -Wl,--wrap=malloc + +TEST_PROGS := sysctl_test + + +$(TEST_PROGS): sysctl_test.o ../shared/malloc_test_wrapper.o + + +all: $(TEST_PROGS) + + +include ../lib.mk + +clean: + $(RM) $(TEST_PROGS) sysctl_test.o ../shared/malloc_test_wrapper.o diff --git a/tools/testing/unittest/sysctl/sysctl_test.c b/tools/testing/unittest/sysctl/sysctl_test.c new file mode 100644 index 0000000000000000000000000000000000000000..ea715379a1b270446950012957db9f6fefddc9cd --- /dev/null +++ b/tools/testing/unittest/sysctl/sysctl_test.c @@ -0,0 +1,561 @@ +#define _GNU_SOURCE + +#include <stdio.h> +#include <errno.h> +#include <string.h> + +#include <kselftest.h> + +#include <shared.h> +#include <malloc_test_wrapper.h> + +/* include header + src file for static function testing */ +#include <kernel/sysctl.h> +#include <sysctl.c> + + +static ssize_t _show(__attribute__((unused)) struct sysobj *sobj, + __attribute__((unused)) struct sobj_attribute *sattr, + __attribute__((unused)) char *buf) +{ + buf[0] = '\0'; + + return 0; +} + +static ssize_t _store(__attribute__((unused)) struct sysobj *sobj, + __attribute__((unused)) struct sobj_attribute *sattr, + __attribute__((unused)) const char *buf, + __attribute__((unused)) size_t len) +{ + return 0; +} + + + + +/** + * @test sysobject name + */ + +static void sysobj_name_test(void) +{ + struct sysobj sobj; + + sobj.name = "test"; + + /* function returns pointer to object name */ + KSFT_ASSERT(sobj.name == sysobj_name(&sobj)); +} + + +/** + * @test sobj_sysset_join + */ + +static void sobj_sysset_join_test(void) +{ + struct sysobj *sobj; + struct sysset *sset; + + + sobj = sysobj_create(); + + bzero(sobj, sizeof(struct sysobj)); + + /* uninitialised */ + sobj_sysset_join(sobj); + + + sset = sysset_create_and_add("set", NULL, NULL); + sysobj_add(sobj, NULL, sset, "obj"); + + /* initialised */ + sobj_sysset_join(sobj); + + + + free(sset); + free(sobj); +} + + +/** + * @test sysobj_get_test + */ + +static void sysobj_get_test(void) +{ + struct sysobj sobj; + + KSFT_ASSERT(&sobj == sysobj_get(&sobj)); +} + + +/** + * @test sysobj_set_name + */ + +static void sysobj_set_name_test(void) +{ + struct sysobj sobj; + + + sysobj_set_name(&sobj, "test"); + + KSFT_ASSERT(strcmp("test", sobj.name) == 0); +} + + +/** + * @test sysobj_init_internal + */ + +static void sysobj_init_internal_test(void) +{ + struct sysobj sobj; + + + sysobj_init_internal(NULL); + + sobj.entry.prev = NULL; + sobj.entry.next = NULL; + + sysobj_init_internal(&sobj); + + KSFT_ASSERT(&sobj.entry == sobj.entry.prev); + KSFT_ASSERT(&sobj.entry == sobj.entry.next); +} + + +/** + * @test sysobj_init + */ + +static void sysobj_init_test(void) +{ + struct sysobj sobj; + + + sysobj_init(NULL); + + sobj.entry.prev = NULL; + sobj.entry.next = NULL; + + sysobj_init(&sobj); + + KSFT_ASSERT(&sobj.entry == sobj.entry.prev); + KSFT_ASSERT(&sobj.entry == sobj.entry.next); +} + + +/** + * @test sysobj_create + */ + +static void sysobj_create_test(void) +{ + struct sysobj *sobj; + + + + malloc_test_wrapper(ENABLED); + + sobj = sysobj_create(); + KSFT_ASSERT_PTR_NULL(sobj); + + malloc_test_wrapper(DISABLED); + + sobj = sysobj_create(); + KSFT_ASSERT(&sobj->entry == sobj->entry.prev); + KSFT_ASSERT(&sobj->entry == sobj->entry.next); + + free(sobj); +} + + +/** + * @test sysobj_add_internal + */ + +static void sysobj_add_internal_test(void) +{ + struct sysobj *sobj; + + + KSFT_ASSERT(sysobj_add_internal(NULL) == -1); + + sobj = sysobj_create(); + + KSFT_ASSERT(sysobj_add_internal(sobj) == 0); + + sobj->parent = NULL; + KSFT_ASSERT(sysobj_add_internal(sobj) == 0); + + sobj->sysset = sysset_create_and_add("test", NULL, NULL); + KSFT_ASSERT(sysobj_add_internal(sobj) == 0); + + sobj->parent = sobj; + KSFT_ASSERT(sysobj_add_internal(sobj) == 0); + + free(sobj->sysset); + free(sobj); +} + + +/** + * @test sysobj_add + */ + +static void sysobj_add_test(void) +{ + struct sysobj *sobj = NULL; + + + KSFT_ASSERT(sysobj_add(sobj, NULL, NULL, NULL) == -1); + + sobj = sysobj_create(); + + KSFT_ASSERT(sysobj_add(sobj, NULL, NULL, NULL) == 0); + + free(sobj); +} + + +/** + * @test sysobj_create_and_add + */ + +static void sysobj_create_and_add_test(void) +{ + struct sysobj *sobj = NULL; + + + malloc_test_wrapper(ENABLED); + + KSFT_ASSERT_PTR_NULL(sysobj_create_and_add("test", NULL)); + + malloc_test_wrapper(DISABLED); + + + sobj = sysobj_create_and_add("test", NULL); + KSFT_ASSERT_PTR_NOT_NULL(sobj); + + free(sobj); +} + + +/** + * @test sysobj_list_attr + */ +__extension__ +static void sysobj_list_attr_test(void) +{ + struct sysobj sobj; + struct sobj_attribute sattr = __ATTR(test, NULL, NULL); + struct sobj_attribute *attr[] = {&sattr, NULL}; + + sysobj_list_attr(NULL); + + sobj.sattr = NULL; + + sysobj_list_attr(&sobj); + + sobj.sattr = attr; + + sysobj_list_attr(&sobj); + +} + + +/** + * @test sysobj_show_attr + */ +__extension__ +static void sysobj_show_attr_test(void) +{ + struct sysobj sobj; + struct sobj_attribute sattr = __ATTR(test, _show, _store); + struct sobj_attribute sattr2 = __ATTR(nomatch, _show, _store); + struct sobj_attribute *attr[] = {&sattr, &sattr2, NULL}; + + char buf[256]; + + + sysobj_show_attr(NULL, NULL, buf); + + sysobj_show_attr(NULL, "test", buf); + + sobj.sattr = NULL; + + sysobj_show_attr(&sobj, "test", buf); + + sobj.sattr = attr; + + sysobj_show_attr(&sobj, "test", buf); +} + + +/** + * @test sysobj_store_attr + */ +__extension__ +static void sysobj_store_attr_test(void) +{ + struct sysobj sobj; + struct sobj_attribute sattr = __ATTR(test, _show, _store); + struct sobj_attribute sattr2 = __ATTR(nomatch, _show, _store); + struct sobj_attribute *attr[] = {&sattr, &sattr2, NULL}; + + sysobj_store_attr(NULL, NULL, NULL, 0); + + sysobj_store_attr(NULL, "test", NULL, 0); + + sobj.sattr = NULL; + + sysobj_store_attr(&sobj, "test", NULL, 0); + + sobj.sattr = attr; + + sysobj_store_attr(&sobj, "test", NULL, 0); +} + + +/** + * @test sysset_register + */ +static void sysset_register_test(void) +{ + struct sysset *sset; + + + sset = sysset_create("test", NULL, NULL); + + KSFT_ASSERT(sysset_register(NULL) == -1); + + KSFT_ASSERT(sysset_register(sset) == 0); + + + free(sset); +} + + +/** + * @test to_sysset + */ + +static void to_sysset_test(void) +{ + struct sysset *sset; + + + sset = sysset_create("test", NULL, NULL); + + KSFT_ASSERT_PTR_NULL(to_sysset(NULL)); + KSFT_ASSERT_PTR_NOT_NULL(to_sysset(&sset->sobj)); + + free(sset); +} + + +/** + * @test sysset_get + */ + +static void sysset_get_test(void) +{ + struct sysset *sset; + + + sset = sysset_create("test", NULL, NULL); + + KSFT_ASSERT_PTR_NULL(sysset_get(NULL)); + KSFT_ASSERT_PTR_NOT_NULL(sysset_get(sset)); + + free(sset); + +} + + +/* + * @test sysset_create + */ + +static void sysset_create_test(void) +{ + struct sysset *sset; + + + malloc_test_wrapper(ENABLED); + KSFT_ASSERT_PTR_NULL(sysset_create("test", NULL, NULL)); + malloc_test_wrapper(DISABLED); + + sset = sysset_create("test", NULL, NULL); + KSFT_ASSERT_PTR_NOT_NULL(sset); + + free(sset); +} + + +/* + * @test sysset_create_and_add + */ +static void sysset_create_and_add_test(void) +{ + struct sysset *sset; + + + malloc_test_wrapper(ENABLED); + KSFT_ASSERT_PTR_NULL(sysset_create_and_add("test", NULL, NULL)); + malloc_test_wrapper(DISABLED); + + sset = sysset_create_and_add("test", NULL, NULL); + KSFT_ASSERT_PTR_NOT_NULL(sset); + + free(sset); +} + + +/* + * @test sysset_find_obj + */ +static void sysset_find_obj_test(void) +{ + struct sysobj *sobj[2]; + + struct sysset *sset[3]; + + + sset[0] = sysset_create_and_add("test", NULL, NULL); + sset[1] = sysset_create_and_add("test2", NULL, sset[0]); + sset[2] = sysset_create_and_add(NULL, NULL, sset[1]); + + sobj[0] = sysobj_create(); + sysobj_add(sobj[0], NULL, sset[0], "blah"); + + sobj[1] = sysobj_create(); + sysobj_add(sobj[1], NULL, sset[1], "blah2"); + + sysset_find_obj(sset[0], "/nonexistent"); + sysset_find_obj(sset[0], "/test/nonexistent"); + sysset_find_obj(sset[0], "/test/blah"); + sysset_find_obj(sset[0], "/test/test2"); + sysset_find_obj(sset[0], "/test/test2/faux"); + + + + free(sset[0]); + free(sset[1]); + free(sset[2]); + + free(sobj[0]); + free(sobj[1]); +} + + +/* + * @test sysset_show_tree + */ +static void sysset_show_tree_test(void) +{ + struct sysobj *sobj[2]; + + struct sysset *sset[3]; + + + sset[0] = sysset_create_and_add("test", NULL, NULL); + sset[1] = sysset_create_and_add("test2", NULL, sset[0]); + sset[2] = sysset_create_and_add(NULL, NULL, sset[1]); + + sobj[0] = sysobj_create(); + sysobj_add(sobj[0], NULL, sset[0], "blah"); + + sobj[1] = sysobj_create(); + sysobj_add(sobj[1], NULL, sset[1], "blah2"); + + sysset_show_tree(sset[0]); + + + free(sset[0]); + free(sset[1]); + free(sset[2]); + + free(sobj[0]); + free(sobj[1]); +} + + + + +int main(int argc, char **argv) +{ + + printf("Testing sysctl interface\n\n"); + + KSFT_RUN_TEST("sysobj name", + sysobj_name_test); + + KSFT_RUN_TEST("sobj sysset join", + sobj_sysset_join_test); + + KSFT_RUN_TEST("sobj get", + sysobj_get_test); + + KSFT_RUN_TEST("sysobj set name", + sysobj_set_name_test); + + KSFT_RUN_TEST("sysobj init internal", + sysobj_init_internal_test); + + KSFT_RUN_TEST("sysobj init", + sysobj_init_test); + + KSFT_RUN_TEST("sysobj create", + sysobj_create_test); + + KSFT_RUN_TEST("sysobj add internal", + sysobj_add_internal_test); + + KSFT_RUN_TEST("sysobj add", + sysobj_add_test); + + KSFT_RUN_TEST("sysobj create and add", + sysobj_create_and_add_test); + + KSFT_RUN_TEST("sysobj list attr", + sysobj_list_attr_test); + + KSFT_RUN_TEST("sysobj show attr", + sysobj_show_attr_test); + + KSFT_RUN_TEST("sysobj store attr", + sysobj_store_attr_test); + + KSFT_RUN_TEST("sysset register", + sysset_register_test); + + KSFT_RUN_TEST("to sysset", + to_sysset_test); + + KSFT_RUN_TEST("sysset get", + sysset_get_test); + + KSFT_RUN_TEST("sysset create", + sysset_create_test); + + KSFT_RUN_TEST("sysset create", + sysset_create_and_add_test); + + KSFT_RUN_TEST("sysset find obj", + sysset_find_obj_test); + + KSFT_RUN_TEST("sysset show tree", + sysset_show_tree_test); + + + printf("syctl interface test complete:\n"); + + ksft_print_cnts(); + + return ksft_exit_pass(); +}