summaryrefslogtreecommitdiff
path: root/test/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* include/util: Remove swap macroTom Hughes2022-12-091-19/+0
| | | | | | | | | | | | | | | The swap macro is not used anywhere and it conflicts with std::swap in C++. BRANCH=none BUG=b:260234709 TEST=make buildall Change-Id: Ic2166265ed98c9c72b2c8d4f04a8209a788f9ee3 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4089950 Reviewed-by: Andrea Grandi <agrandi@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* Update license boilerplate text in source code filesMike Frysinger2022-09-121-1/+1
| | | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: Icd3a1723c20595356af83d190b2c6a9078b3013b Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3891203 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* tree-wide: const-ify argv for console commandsCaveh Jalali2022-09-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This updates the API for console commands from "int cmd(int argc, char **argv)" to "int cmd(int argc, const char **argv)" which is more accurate and in line with common convention. BRANCH=none BUG=b:244387210 TEST="make buildall" passes TEST="zmake build -a" passes TEST="util/compare_build.sh -b all" passes TEST="./twister -v -T zephyr/test" passes Cq-Depend: chrome-internal:4960125 Cq-Depend: chrome-internal:4959932 Change-Id: I57de9f35b85b8f3c7119df36aefb2abf25d2625f Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863941 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
* common/util: Add castsTom Hughes2022-07-161-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | When compiling against the standard library, clang complains: common/util.c:66:6: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts] tolower(*s) == 'f' || tolower(*s) == 'n') { ^~~~~~~~~~~ According to POSIX: The tolower() and tolower_l() functions have as a domain a type int, the value of which is representable as an unsigned char or the value of EOF. If the argument has any other value, the behavior is undefined. https://pubs.opengroup.org/onlinepubs/9699919799/functions/tolower.html BRANCH=none BUG=b:234181908 TEST=make utils-str Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I84f4bfb647f29b24b1c3bd7f5d222275354c4698 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3765458 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
* clang-format: Ran clang-format on all files againJack Rosenthal2022-07-081-1/+0
| | | | | | | | | | | | | | | | | | | | | | A number of files have had non-compliant changes uploaded since all files were formatted. Likely, the changes were uploaded before CL:3751770, so the author would not have seen any pre-upload failures. Re-format these files. This CL was generated via: clang-format -i $(find -name '*.[ch]' -type f -not -path '*third_party*') BUG=b:236386294 BRANCH=none TEST=none Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Iedad17d13c29f45c7601d43f7fa2ce3215cc678e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3751462 Commit-Queue: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* test: Remove TEST_CHECK macroBobby Casey2022-07-071-3/+6
| | | | | | | | | | | | | | | | | | | | | The TEST_CHECK macro returns a value (from the calling function) on either success or failure. This differs from all other TEST_* macros in test_util.h, which only return on failure. Returning on failure is appropriate and allows short circuiting a test on the first failure but returning on success results in short circuiting after the first successful check and bypassing subsequent checks. This behavior is somewhat confusing and easy to miss during review. BRANCH=none BUG=b:238120333 TEST=make runhosttests TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Bobby Casey <bobbycasey@google.com> Change-Id: I3777b427aa5e20a91689f86fc37daadffacf27f3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3748830 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* Move standard library tests to their own fileTom Hughes2022-07-071-161/+0
| | | | | | | | | | | | | | The standard library functions are being consolidated in stdlib.c, so this test mirrors the same layout. BRANCH=none BUG=none TEST=make buildall -j Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I2d7f7671f23a0c4e5f09ef9e0d5d8c25688cd376 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3724489 Reviewed-by: Edward Hill <ecgh@chromium.org>
* test/utils.c: Format with clang-formatJack Rosenthal2022-06-291-28/+27
| | | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Ica9779144679a2180d85e754c94aae1508b75f2b Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3730316 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* test/utils: Update expected speed gain on memcpy, memmove, memset testsPatryk Duda2022-01-251-40/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GCC 11 introduces some improvements for memcpy, memmove and memset functions when pointer is not aligned, eg. on bloonchipper: gcc version 8.3.0 (coreboot toolchain v_) Running test_memmove... (speed gain: 33741 -> 7743 us) OK Running test_memcpy... (speed gain: 33740 -> 7735 us) OK Running test_memset... (speed gain: 20879 -> 6725 us) OK gcc version 11.2.0 (coreboot toolchain v_) Running test_memmove... (speed gain: 21500 -> 9038 us) OK Running test_memcpy... (speed gain: 21448 -> 8996 us) OK Running test_memset... (speed gain: 16722 -> 6848 us) OK As we can see unaligned memcpy and memmove is 12ms faster, but they are also about 1ms slower when buffers are aligned. Simple memset is 4 ms faster. Optimized memset speed is the same. As there are so many factors that can influence speed gains (compiler, function inlining, CPU model, caches, architecture, and code placement in memory), we decided to just check if using aligned buffers/optimized memset takes less time to perform the operation. CL:3198155 updates coreboot-sdk to GCC 11. BUG=b:200828093 BRANCH=none TEST=Run "utils" hardware unit test on bloonchipper (STM32F4) and dartmonkey (STM32H7) make sure test pass. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: Id50f2504928b8b25795fc0c317867b18900bbd39 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3386834 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* test/utils: Switch to run-time test to fix clang buildTom Hughes2021-09-231-1/+4
| | | | | | | | | | | | | | | | | | | | | The BUILD_ASSERT that was used fails to compile with clang: error: static_assert expression is not an integral constant expression BUILD_ASSERT(str1 != str3) BRANCH=none BUG=b:172020503 TEST=make buildall -j TEST=./test/run_device_tests.py --board dartmonkey --compiler clang --tests=utils --remote 127.0.0.1:2551 TEST=./test/run_device_tests.py --board dartmonkey --compiler gcc --tests=utils --remote 127.0.0.1:2551 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Id93ea45b653b86fd5a79ed565e1fa94ffd317723 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3174596 Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
* system: fix system_get_scratchpad APIYuval Peress2021-08-201-1/+4
| | | | | | | | | | | | | | | The current API for system_get_scratchpad mixes the status and the value being read. Update the signature to allow both. BRANCH=none BUG=b:195481980 TEST=make testall && zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I3a5f5ad523d507c53a5d474806f58afafb82e70c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3074828 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* util: Add function to convert binary first base3 numberWai-Hong Tam2021-06-161-0/+25
| | | | | | | | | | | | | | | | | | | | | | Add an util function to convert a ternary bit array (each element is either 0, 1, or 2) to a non-standard ternary number system where the first 2^n natural numbers are represented as they would be in a binary system (without any Z digits) and the following 3^n-2^n numbers use the remaining ternary representations in the normal ternary system order (skipping the values that were already used up). This function is useful for converting BOARd ID, which is initially used a binary and later decided to switch to tri-state after some revisions have already been built. BRANCH=Trogdor BUG=b:190250108 TEST=make runhosttests Change-Id: I853a04f3b28eb54c61855251dc5232c7e6994fef Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2964389 Reviewed-by: Julius Werner <jwerner@chromium.org>
* cortex-m mpu: support configuring regions with difficult alignmentPeter Marheine2020-12-111-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The existing configuration code assumes that provided addresses are at least as aligned as the requested size, which is not true on NPCX797WC (and likely others) where RAM regions are only 64k-aligned but have larger sizes (like 256k). Use a new greedy approach to configuring the MPU which handles these situations corrently: for any given request take the largest possible chunk from the bottom of the memory region (subject to size and address alignment). Maximize the space by aggressively using MPU subregions- this means that in many well-aligned situations this algorithm selects a larger region than the requested size and enables one subregion, but in more difficult situations it is capable of enabling subregions with more exotic positions. BUG=b:169276765 BRANCH=zork TEST=With a test harness to print out computed configurations, manually verified the correctness of a variety taken from real chip configurations (request first, MPU region(s) indented): 0x20000000 size 0x1000 # stm32f03x 0x20000000 size 0x8000 srd fe 0x20000000 size 0x2000 # stm32f03x 0x20000000 size 0x10000 srd fe 0x20000000 size 0x2800 # stm32l100 0x20000000 size 0x4000 srd e0 0x20000000 size 0x4000 # stm32f412 0x20000000 size 0x20000 srd fe 0x80000 size 0xc000 # it8320 0x80000 size 0x20000 srd f8 0xff200000 size 0xa0000 # ish5p4 0xff200000 size 0x100000 srd e0 0x200b0000 size 0x20000 # npcx797wb 0x20080000 size 0x80000 srd e7 0x10070000 size 0x40000 # npcx797wb 0x10000000 size 0x80000 srd 7f 0x10080000 size 0x80000 srd f8 0x200c0000 size 0x10000 # npcx796f 0x20080000 size 0x80000 srd ef 0x10090000 size 0x30000 # npcx796f 0x10080000 size 0x80000 srd f1 0x10090000 size 0x20 0x10090000 size 0x100 srd fe Further verified MPU configuration with the new algorithm succeeds on Dalboz, and test/mpu.c passes on Dragonclaw. Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: I71d8e2b37c7e20fc7a39166b90eea0b7f7ebcf43 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2434601 Reviewed-by: Edward Hill <ecgh@chromium.org>
* test/utils.c: Adjust expected speedup for STM32H743Tom Hughes2020-10-091-8/+15
| | | | | | | | | | | | BRANCH=none BUG=b:158580909, b:170432597 TEST=On Icetower v0.1 connected to servo_micro: ./test/run_device_tests.py -b dartmonkey -t utils Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: If5dcd7ade6397611b40b9c7a6f9560402a11c042 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2459229 Reviewed-by: Edward Hill <ecgh@chromium.org>
* test/utils: Add unit tests for safe_memcmpTom Hughes2020-09-241-0/+15
| | | | | | | | | | | | BRANCH=none BUG=b:169156874 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I0bf4bdd654e6ba64b718c0d18650d561294744bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2424067 Reviewed-by: Diana Z <dzigterman@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* test: Correct memset speed expectation for stm32f412Yicheng Li2020-06-171-6/+15
| | | | | | | | | | | | | | | | On STM32F4, the speed gain of memset is slightly above 2x. Set this expectation explicitly. BRANCH=none BUG=b:155230812 TEST=verified that test_memset passes on nucleo-f412zg Signed-off-by: Yicheng Li <yichengli@chromium.org> Change-Id: Icb9951732fb03296007ceeca5f83ac26f7e0e709 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2242355 Tested-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Commit-Queue: Tom Hughes <tomhughes@chromium.org>
* test: Let shared_mem test support shmalloc implementationYicheng Li2020-06-151-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There are 2 implementations of shared_mem, an older one in common/share_mem.c and a newer one in common/shmalloc.c The newer one in shmalloc.c has higher quality, but will only be linked if CONFIG_MALLOC is configured. We would like to make the "utils" unit tests use shmalloc.c (for host and boards that run this test on-device). The shared_mem_acquire function in shmalloc.c sets the the buffer pointer to NULL on error, so the part of test_shared_mem that intentionally triggers an error must use a different pointer. After this change, this test can pass for both implementations. There will be follow-up changes that switch boards to use the shmalloc implementation, including the test on host. BRANCH=none BUG=b:155230812 TEST=verified that test_shared_mem and test_shared_mem_acquire_twice pass on bloonchipper (which uses shmalloc implementation). Signed-off-by: Yicheng Li <yichengli@chromium.org> Change-Id: Ic839cb841b4232a956882b0f9451b6f6861efcac Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2242354 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
* test: Pass commandline arguments to run_testTom Hughes2020-05-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | run_test is called by the "runtest" console command. Console commands can take arguments, so pass along the arguments to run_test to allow parameters to be passed to run_test. The following command was used for automatic replacement: git grep --name-only 'void run_test(void)' |\ xargs sed -i 's#void run_test(void)#void run_test(int argc, char **argv)##' BRANCH=none BUG=b:155897971 TEST=make buildall -j TEST=Build and flash flash_write_protect test > runtest 1 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ib20b955d5ec6b98f525c94c24aadefd7a6a320a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2209418 Reviewed-by: Yicheng Li <yichengli@chromium.org> Commit-Queue: Yicheng Li <yichengli@chromium.org> Tested-by: Yicheng Li <yichengli@chromium.org>
* common/util: Add is_alignedTom Hughes2020-05-151-0/+18
| | | | | | | | | | | | | | | Helper function to check power-of-two alignment. BRANCH=none BUG=b:155229277, b:156501835 TEST=make buildall -j TEST=make run-utils Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Iadcdaeb59e496f10035bd6c7f9660a3cc33a4898 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2202849 Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* builtin: Introduce and use inttypes.hEvan Green2019-10-051-6/+6
| | | | | | | | | | | | | | | | | | | | | In order to pass the right printf format specifiers for certain types that are compiled both in 32-bit EC and 64-bit host environments, standard macros PRIx64 and PRId64 must be introduced. These specify the correct printf format specifier in the given compilation environment for printing a 64-bit value. On the host, inttypes.h already exists. Add an inttypes.h for the EC codebase so that these macros can be used where they're needed. BUG=chromium:984041 TEST=make -j buildall BRANCH=none Change-Id: I76e3bdc88aef7da6e5234d5b86b595f7138ea9a1 Signed-off-by: Evan Green <evgreen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819642 Reviewed-by: caveh jalali <caveh@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* util: Add function to check whether a buffer is trivial (all 0x00 or all 0xff)Yicheng Li2019-10-041-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function's execution time depends only on the buffer length but not on the specific bytes in the buffer. BRANCH=nocturne BUG=chromium:927095 TEST=make -j buildall TEST=timed the execution of bytes_are_trivial() on a long array with the following contents: Array 1: 0x01, 0x00, 0x00, 0x00, ..., 0x00, 0x00 (first byte nontrivial) Array 2: 0x00, 0x00, 0x00, 0x00, ..., 0x00, 0x02 (last byte nontrivial) Array 3: 0x00, 0x00, ... , 0x00, 0x03, 0x00, ..., (middle byte nontrivial) Array 4: 0x00, 0x00 , ... (trivial) (These 4 arrays have the same length.) Verified that execution on these arrays take similar amount of time, proportional to the length of the array, specifically: For 256k bytes, takes 21~40 microseconds For 128k bytes, takes 10~17 microseconds For 64k bytes, takes 5~9 microseconds For 32k bytes, takes 2~5 microseconds Because the host timer inaccuracy and potential process scheduling variations, the execution time for arrays 1-4 are sometimes not exactly the same. To avoid test flakiness, this timing test is not written to unit tests. But it should prove that bytes_are_trivial() is a constant time algorithm. Change-Id: I131748e1a4ee3a3e19a105dba5dc443bb2371d30 Signed-off-by: Yicheng Li <yichengli@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1787870
* LICENSE: remove unnecessary (c) after CopyrightTom Hughes2019-06-191-1/+1
| | | | | | | | | | | | | | | | Ran the following command: git grep -l 'Copyright (c)' | \ xargs sed -i 's/Copyright (c)/Copyright/g' BRANCH=none BUG=none TEST=make buildall -j Change-Id: I6cc4a0f7e8b30d5b5f97d53c031c299f3e164ca7 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1663262 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* util: Add macro to swap two variablesDaisuke Nojiri2018-12-101-0/+20
| | | | | | | | | | | | | | | | | | | This patch adds swap(a,b), which swaps the values in two variables. It requires c99 for typeof. Swapping composites (e.g. a+b, x++) doesn't make sense. So, <a> and <b> can only be a variable (x) or a pointer reference (*x) without an operator. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=buildall Change-Id: Id656e173d372dfff759d9aee9314a008a6d91786 Reviewed-on: https://chromium-review.googlesource.com/1366306 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* rsa: Further optimization of multiplications for Cortex-M0Nicolas Boichat2018-05-291-3/+7
| | | | | | | | | | | | | | | | | | | | In RSA, we often need to actually compute (a*b)+c+d: provide some assembly optimized functions for that. With -O3, 3072-bit exponent, lower verification time from 104 ms to 88 ms on STM32F072 @48Mhz. BRANCH=poppy BUG=b:35647963 BUG=b:77608104 TEST=On staff, flash, verification successful TEST=make test-rsa, make test-rsa3 TEST=make BOARD=hammer test-utils test-rsa3, test on board Change-Id: I80e8a7258d091e4f6adea11797729ac657dfd85d Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1071411 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* rsa: Optimization of multiplications for Cortex-M0Nicolas Boichat2018-05-281-0/+27
| | | | | | | | | | | | | | | | | | | | | | | We multiply 2 32-bit numbers (and not 64-bit numbers), and then add another 32-bit number, which makes it possible to optimize the assembly and save a few instructions. With -O3, 3072-bit exponent, lower verification time from 122 ms to 104 ms on STM32F072 @48Mhz. Optimized mac function from Dmitry Grinberg <dmitrygr@google.com>. BRANCH=poppy BUG=b:35647963 BUG=b:77608104 TEST=On staff, flash, verification successful TEST=make test-rsa, make test-rsa3 TEST=Flash test-utils and test-rsa to hammer => pass Change-Id: I584c54c631a3f59f691849a279b308e8d4b4b22d Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/449024 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* test/utils: Fix memchr testNicolas Boichat2018-05-261-2/+2
| | | | | | | | | | | | | | | | | | memchr does not take into account end of string, so the test `memchr("123", '4', 8)` actually does a buffer overflow. On some boards, a '4' might be found in the 4 bytes that follow "123", and the test might fail. Fix another potential overflow as well. BRANCH=none BUG=none TEST=Flash test-utils to hammer, test passes Change-Id: I53755c0855bbd5b180801e4198341de1cec7b425 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1071409 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* tests: Split utils in 2 subtestsNicolas Boichat2017-05-251-141/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | utils test is a little too large for hammer's small RO, so we split it in 2 test: utils and utils_str. Instead of one test that requires about 8kb extra flash, we have 2 tests that take respectively 3.4kb (utils_str) and 4.6kb (utils) of extra flash. BRANCH=none BUG=chromium:726113 TEST=make BOARD=hammer tests -j util/flash_ec --board=hammer --image=build/hammer/test-utils.bin runtest => pass Repeat with test-utils_str.bin TEST=Before this change: make runtests -j ./util/run_host_test utils | grep Running | sort > old Apply this change: make runtests -j (./util/run_host_test utils; ./util/run_host_test utils_str) \ | grep Running | sort > new diff old new => No difference (except timing) Change-Id: I917d572e671d6ce0a8799508761f55de7bd83133 Reviewed-on: https://chromium-review.googlesource.com/514604 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* builtin: Expands string.h / stdint.hNadim Taha2017-02-171-0/+47
| | | | | | | | | | | | | | Declares UINT8_MAX, INT8_MAX and defines strnlen(), strncpy(), strncmp() & memchr(). Needed by a module I'm integrating into cr51. BRANCH=none BUG=none TEST=make buildall -j Change-Id: I894b0297216df1b945b36fc77cd3bc5c4ef8aa2b Signed-off-by: Nadim Taha <ntaha@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/436786 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* test: fix scratchpad testing on targetVincent Palatin2014-03-261-2/+2
| | | | | | | | | | | | | | | | | | | | | On STM32, the scratchpad size is limited to the 16 LSB (due to a limitation on STM32F100). Let's adapt the test to pass also on those targets. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=none TEST=run "utils" test on STM32 Discovery board. Change-Id: I04e9ae39b38afa14e4e72faa0e544c991c9ec1df Reviewed-on: https://chromium-review.googlesource.com/189152 Reviewed-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/191513 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Measure speed gain in utils test only on deviceVic Yang2014-03-131-2/+17
| | | | | | | | | | | | | | | | | When measuring speed gain of mem*() in utils test on host, there are too many reasons that the results may be fluctuate. This gets even worse when the unit tests run on buildbots. Let's only check for speed gain on device. BUG=chromium:351870 TEST=Check the speed gain check assertion is not compiled. BRANCH=None Change-Id: I0369d07d1da8cbb469d3a2a9d846406415c06745 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/189804 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* test: remove one more 64-bit multiplicationVincent Palatin2014-03-071-1/+1
| | | | | | | | | | | | | | | | | | | On some CPU cores, the compiler needs an helper to perform the 64-bit multiplication. As the only remaining 64-bit multiplication in the code base is not necessary, fix it rather than adding the helper. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=none TEST=build for Cortex-M0 platform. Change-Id: I88dd7a4f2eabeca5b03fb3db232bbca9a037dcf8 Reviewed-on: https://chromium-review.googlesource.com/189151 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
* test: remove 64-bit multiplicationVincent Palatin2014-03-061-2/+2
| | | | | | | | | | | | | | | | | | | | On some CPU cores, the compiler needs an helper to perform the 64-bit multiplication. As the only 64-bit multiplication in the code base is not necessary, fix it rather than adding the helper. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=none TEST=build for Cortex-M0 platform. Change-Id: Id5d6b4b6641f81732a456dacb78dee7262f6729d Reviewed-on: https://chromium-review.googlesource.com/188980 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
* Remove time-dependent test from coverage measurementsBill Richardson2014-03-051-0/+3
| | | | | | | | | | | | | | | | | | | Compiling with coverage enabled screws up the time that things take, so don't test for a particular speedup in that case. It fails unreliably. BUG=chrome-os-partner:20881 BRANCH=ToT TEST=manual cd src/platform/ec make coverage Before, it failed about half the time. Now it doesn't. Change-Id: I535f0193bf450a922b486777b296fea1b2768a1a Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/188790 Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Optimize memsetDaisuke Nojiri2014-03-011-4/+55
| | | | | | | | | | | | | | | | | | | | | | | | | This speeds up memset by copying a word at a time. Ran the unit test on Peppy: > runtest ... Running test_memset... (speed gain: 141532 -> 32136 us) OK ... Ran make buildall: ... Running test_memset... (speed gain: 1338 -> 280 us) OK ... TEST=Described above. BUG=chrome-os-partner:23720 BRANCH=none Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: If34b06ad70f448d950535a4bea4f6556627a9b6f Tested-by: Daisuke Nojiri <dnojiri@google.com> Reviewed-on: https://chromium-review.googlesource.com/185936 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@google.com>
* Optimize memmoveDaisuke Nojiri2014-02-131-8/+35
| | | | | | | | | | | | | | | | | | | | | | | | | This speeds up memmove by copying a word at a time. Ran the unit test on Peppy: > runtest ... Running test_memmove... (speed gain: 2156 -> 592 us) OK ... Ran make buildall: ... Running test_memmove... (speed gain: 143918 -> 32367 us) OK ... TEST=Described above. BUG=chrome-os-partner:23720 BRANCH=none Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@google.com> Change-Id: I6a3ac6aed27a404c3bef227b6c886a59414b51d7 Reviewed-on: https://chromium-review.googlesource.com/186020 Reviewed-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
* Optimize memcpyDaisuke Nojiri2014-02-121-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This speeds up memcpy by copying a word at a time if source and destination are aligned in mod 4. That is, if n and m are a positive integer: 4n -> 4m: aligned, 4x speed. 4n -> 4m+1: misaligned. 4n+1 -> 4m+1: aligned in mod 4, 4x speed. Ran the unit test on Peppy: > runtest ... Running test_memcpy... (speed gain: 120300 -> 38103 us) OK ... Ran make buildall -j: ... Running test_memcpy... (speed gain: 2084 -> 549 us) OK ... Note misaligned case is also optimized. Unit test runs in 298 us on Peppy while it takes about 475 with the original memcpy. TEST=Described above. BUG=chrome-os-partner:23720 BRANCH=none Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Ic12260451c5efd0896d6353017cd45d29cb672db Tested-by: Daisuke Nojiri <dnojiri@google.com> Reviewed-on: https://chromium-review.googlesource.com/185618 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@google.com>
* Support multi-bit mask in STM32L's GPIO functionsVic Yang2013-09-111-0/+15
| | | | | | | | | | | | | | | | | | The definition of GPIO interface allows passing in multi-bit mask, and this is what's done by gpio_config_module(). Fix STM32L's function so that it doesn't accidentally set incorrect GPIO register values. BUG=chrome-os-partner:22605 TEST=On Kirby, do 'led r 0' and check the value of 0x40020800 is 0x01540000. BRANCH=None Change-Id: I9a1c8074aab7345485a590ecf138bf99d0742997 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/168739 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
* Add abstract "cond_t" type to detect state transitions.Bill Richardson2013-08-091-0/+98
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We often need to watch for transitions between one state and another, so that we can issue warnings or take action ONCE. This abstracts that "have I already reacted to this" stuff into a single set of functions. For example, this code reads a GPIO every time through the loop, but it only generates an event when the GPIO value changes from 0 to 1: cond_t c; cond_init_false(&c); while(1) { int val = read_some_gpio(); cond_set(&c, val); if (cond_went_true(&c)) host_event(SOMETHING_HAPPENED); sleep(1); } BUG=none BRANCH=falco,peppy TEST=manual make BOARD=falco runtests Change-Id: I42393fcf3c4eb71b9551118a0f442d55c0691315 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/65071
* More utils unit testVic Yang2013-06-131-3/+114
| | | | | | | | | | | BUG=chrome-os-partner:19236 TEST=Pass the test. BRANCH=None Change-Id: I4075f3fb0ef23a54b4ca249a21fe28e698e595cb Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/58329 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Put test utility macros in headerVic Yang2013-05-081-41/+3
| | | | | | | | | | | | | | Several test utility macros have been duplicated across tests. Let's put them in a single place. BUG=chrome-os-partner:19236 TEST='make runtests', 'BOARD=spring make tests' BRANCH=None Change-Id: Ib0c9f829715425cc23e33b8ef456b17dfadab13c Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50513 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Add persistent storage for emulatorVic Yang2013-05-071-0/+10
| | | | | | | | | | | | | | This is needed for non-volatile register emulation. Also, this can be used to implement system jump or reset flags. BUG=chrome-os-partner:19235 TEST=Run utils test. Check persistent storage file exists. BRANCH=None Change-Id: I699f95718ef6f5de6c3bbb4e37619ee015fb6c4a Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50313 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Pthread-based emulator for unit testingstabilize-4100.38.BVic Yang2013-05-071-7/+10
| | | | | | | | | | | | | | This is the first version of pthread-based RTOS emulator. With this, we will be able to test high-level modules entirely on the host machine. BUG=chrome-os-partner:19325 TEST='make runtests' and see tests passing. BRANCH=None Change-Id: I1f5fcd76aa84bdb46c7d35c5e60ae5d92fd3a319 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49954 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Add shared memory testVic Yang2013-04-211-15/+55
| | | | | | | | | | | | | Also changes utils test to use EC_SUCCESS to indicate test success. BUG=chrome-os-partner:18598 TEST=Run on Spring BRANCH=None Change-Id: I4a9b08550c15f09cd467706b6a3c0142dd06a558 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/48751 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
* Add a test for testing common utilitiesVic Yang2013-04-131-0/+83
BUG=chrome-os-partner:18598 TEST=Run on Spring BRANCH=None Change-Id: Ie10f81783a0c22a10b9535350dc29b972bffd87e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47962