aboutsummaryrefslogtreecommitdiff
path: root/libc
AgeCommit message (Collapse)AuthorFilesLines
2015-02-26sparse: fix libc declarationsCédric Le Goater1-6/+8
Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-26sparse: fix Using plain integer as NULL pointer warningCédric Le Goater2-2/+2
Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-26sparse: declare errnoCédric Le Goater1-0/+1
Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-23atoi/atol should assume base 10, not autodetect base.Daniel Axtens3-6/+9
The behaviour of atoi/atol on glibc (and according to the spec) is to assume base 10, not to autodetect the base. Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Cyril Bur <cyrilbur@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-23Don't recognise a double hex prefix (0x0xNN) as valid.Daniel Axtens3-8/+3
When autodetecting the base, the code would strip hex prefixes twice. Now the string is not modified in the detection stage. Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Cyril Bur <cyrilbur@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-23Test libc stdlib functions (atoi/strtol and friends)Daniel Axtens1-0/+60
This increases coverage of atoi, atol, strtol and strtoul to 100%. Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Cyril Bur <cyrilbur@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-11Make abort() update sp attn area (like assert does)Stewart Smith1-1/+7
Gives better diagnostics in error logs/dumps Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-09Fix commit 16c80346Jeremy Kerr1-2/+11
Commit 16c80346 change included some reverts of previous commits, which we need. This change reverts those reverts, leaving the original intent of that change. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-05Add OPAL_INVALID_CALL explicitly in opal.h and docsStewart Smith1-11/+2
Was mentioned in linux as possibly being used by some external test modules. It's harmless to make this official behaviour. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-02-05Makefile: clean the gcov files created during coverageNeelesh Gupta1-2/+11
Fix the Makefile to clean up the coverage data files generated through gcov. Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-01-27add libc/test/.gitignore for the new libc unit testsStewart Smith1-0/+10
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-01-20Add skeleton for libc/ctype unit testsStewart Smith3-1/+62
Now it shows up as untested in lcov! Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-01-20Add skeleton for libc/stdlib unit testStewart Smith3-1/+62
Now it shows up as untested in lcov! Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-01-20Skeleton unit tests for libc memops (libc/string/*)Stewart Smith3-1/+71
This means that it shows up in lcov as untested. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-01-20Add some skiboot snprintf test casesStewart Smith4-5/+242
Initial implementation and support for more libc test cases Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-01-19Merge branch 'update-2.1.1.1'Stewart Smith1-55/+108
2015-01-19opal: Fix buffer overrun in print_* functions.skiboot-2.1.1-fw810.20-4Mahesh Salgaonkar1-55/+108
While running HMI tests I saw a massive corruption in OPAL for one of the HMI test that injects TB error. On investigation I found that vsnprintf()->print_itoa() was the culprit. print_itoa function uses tmp array of size 16 to convert unsigned long value to ASCII. But an unsigned value of 0xffffffffffffffff needs atleast 25 characters to print its ASCII representation. This caused an array to overflow resulting into corruption, unpredictable behavior and finally system termination. We could fix this by increasing the size of tmp[] array but that still won't fix this bug completely. While auditing vsnprintf() function I found that it makes use of print_*() functions to write data to buffer. But none of the print_* function have any check on buffer size before writing data to it. Without size check print_*() can easily overrun buffer passed by vprlog()->vsnprintf()->print_format()->print_*() causing massive corruption leading to unpredictable behavior. This patch fixes this bug by modifying print_*() function to check for buffer size to avoid buffer overrun. - Modified print_format(), print_fill() and print_itoa() to take bufsize as argument and added a size check while writing to buffer. - Remove temporary array from print_itoa(), instead write data directly to buffer. - Added two new function print_str_fill() and print_str() to be used as helper routine for '%s' fmt case in print_format() function. These new routines now has a check on buffer size while copying NULL terminated string to buffer. - Added "!bufsize" check in vsnprintf() to avoid buffer overrun while setting NULL character before returning. I ran HMI tests with this patch successfully. I also tested this patch by reducing size of the buffer (in core/console-log.c:vprlog()) from 320 to 50 and booted the lid successfully with no corruption at all. Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Acked-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-12-19Exclude all test cases from coverage-reportStewart Smith1-0/+2
This way we get a true representation from the lcov coverage-report about what firmware code we're testing (besides, test cases are always going to only have 50% of branches hit - we're asserting the tests pass!) Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-12-19Pretty print make check and coverage outputStewart Smith1-4/+4
Can still get the details with V=1, just like normal make. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-12-15Fix makefile dependency generation, especially for HOSTCCStewart Smith1-7/+0
Instead of having individual rules to generate .d, add -MMD to HOSTCC parameters, and just include the generated .d files. This fixes a few weird dependency issues. Also, make the mambo hello_kernel test depend on skiboot.lid Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-11-28Remove vsprintf: just like sprintf, vsnprintf is a much better ideaStewart Smith3-21/+1
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-11-28Remove sprintf: there's no good reason to have this in firmwareStewart Smith3-32/+1
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-11-26Merge branch 'update-2.1.1.1'Stewart Smith2-9/+10
2014-11-26Include stdint.h for libc/test/run-time.c, fixing buildStewart Smith1-0/+1
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-11-26vsnprintf: Change print_itoa to use less stackShreyas B. Prabhu1-9/+9
Remove recursive call in print_itoa to reduce the stack usage. Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-11-25use $(wildcard ) in test MakefilesDan Streetman1-1/+1
The core/test/ and libc/test/ Makefile.check files both contain: -include core/test/*.d (or libc/test/*d) which is incorrect, since that evaluates literally to a *.d file. This results in each build trying to find that file, and creating it when not found (in an incorrect way because of other problems in the Makefile). The correct way to specify it is: -include $(wildcard core/test/*.d) Signed-off-by: Dan Streetman <ddstreet@ieee.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-10-22Preliminary code coverage reporting infrastructureStewart Smith1-1/+11
Add support in core/test/Makefile.check to build -gcov binaries (with -lgcov and -fprofile-blah-blah) as well as some targets for producing lcov HTML code coverage reports. As part of this, I had to fix up an oddity in run-mem_region_init where that due to running under Valgrind, we'd be malloc()ed a heap with a small address, well inside the mem_regions we added but when not running under valgrind (e.g. for code coverage reporting) we would get a much larger address, outside this range and hit an assert. So, after fiddling with the memory stuff for this test, I think I have it right - it passes both under valgrind and not and does produce code coverage data. Currently, we're at this level of code coverage by unit tests: Hit Total Coverage Lines: 1936 2574 75.2 % Functions: 177 225 78.7 % Branches: 1243 2360 52.7 % The totals should largely be ignored due to the only code being counted is that linked into the unit tests (total LOC is ~50kLOC according to sloccount... so unit tests currently cover < 5%) Try the "make coverage-report" target, you'll get coverage-report directory with a LCOV HTML report Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2014-10-01libc/test: Fix timeJoel Stanley1-1/+0
There is no use for time, remove it. Fixes the following error (and the warning once stdint.h was included): libc/test/run-time.c:40:2: error: unknown type name ‘uint32_t’ uint32_t time; libc/test/run-time.c:41:11: warning: unused variable ‘time’ [-Wunused-variable] uint32_t time; Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-08-15libc: Add mktime and gmtime_rAlistair Popple5-3/+250
Both the FSP RTC and the upcoming IPMI RTC implementation need to manipulate time in various ways. Rather than re-implementing slightly different versions of the calculations twice lets implement some standard library functions (with tests) and use those. This patch adds mktime and gmtime_r to the libc. Signed-off-by: Alistair Popple <alistair@popple.id.au> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-08-13attn: Add git version and backtrace details to user dataAruna Balakrishnaiah1-1/+2
For better debugability, the patch adds git version and backtrace details to user data section (along with file info which was already present). After adding required details TermImmedData looks like: TermImmedData | | 00000000 63386631 6639322D 64697274 793A0000 c8f1f92-dirty:.. | | 00000010 00000000 00000000 00000000 00000000 ................ | | 00000020 00000000 00000000 43505520 30303030 ........CPU 0000 | | 00000030 30303264 20426163 6B747261 63653A0A 002d Backtrace:. | | 00000040 20533A20 30303030 30303030 33316162 S: 0000000031ab | | 00000050 36626130 20523A20 30303030 30303030 6ba0 R: 00000000 | | 00000060 33303031 33306238 0A20533A 20303030 300130b8. S: 000 | | 00000070 30303030 30333161 62366334 3020523A 0000031ab6c40 R: | | 00000080 20303030 30303030 30333030 34623738 000000003004b78 | | 00000090 380A2053 3A203030 30303030 30303331 8. S: 0000000031 | | 000000A0 61623663 63302052 3A203030 30303030 ab6cc0 R: 000000 | | 000000B0 30303330 30313736 31300A20 533A2030 0030017610. S: 0 | | 000000C0 30303030 30303033 31616236 64343020 000000031ab6d40 | | 000000D0 523A2030 30303030 30303033 30303035 R: 0000000030005 | | 000000E0 3133340A 20533A20 30303030 30303030 134. S: 00000000 | | 000000F0 33316162 36663030 20523A20 30303030 31ab6f00 R: 0000 | | 00000100 30303030 33303030 32353534 0A000000 000030002554.... | | 00000110 00000000 00000000 00000000 00000000 ................ | | 00000120 00000000 00000000 00000000 00000000 ................ | | 00000130 00000000 00000000 00000000 00000000 ................ | | 00000140 00000000 00000000 00000000 00000000 ................ | | 00000150 00000000 00000000 00000000 00000000 ................ | | 00000160 00000000 00000000 00000000 00000000 ................ | | 00000170 00000000 00000000 00000000 00000000 ................ | | 00000180 00000000 00000000 00000000 00000000 ................ | | 00000190 00000000 00000000 00000000 00000000 ................ | | 000001A0 00000000 00000000 00000000 00000000 ................ | | 000001B0 00000000 00000000 00000000 00000000 ................ | | 000001C0 00000000 00000000 00000000 636F7265 ............core | | 000001D0 2F6F7061 6C2E633A 3233383A 30000000 /opal.c:238:0... | |------------------------------------------------------------------------------| Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-08-08Use PR_EMERG priority in assert() codepathStewart Smith2-24/+1
Moving assert_fail() out of libc and into core/utils.c so that we can sanely call prlog(PR_EMERG). We shorten it from three fputs calls down to one prlog() call. This may increase the number of cycles and stack usage for when we hit an assert, which may not be desirable. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-08-08replace printf() with console log, level 5 aka INFO messagesStewart Smith2-28/+1
Replace the libc printf implementation with a wrapper that does fancy log things such as display timestamp and the log level. Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-08-01ATTN: Set up attention area to handle attentionAruna Balakrishnaiah1-2/+6
At present CPU control area ntuple in SPIRA structure is NULL. ATTN component in Service Processor side checks for this field and if its empty, it logs hardcoded SRC (0xBB821410) and generates SYSDUMP. So we have 1 SRC for all failure (assert call) from OPAL side. This makes difficult to debug the issue. Service processor provides attention area interface (FIPS PHyp Attentions spec), so that we can pass SRC and user data (error message) to service processor. This will helps us identify different failures in OPAL. This patch enables attention area and provides interface (update_sp_attn_area()) to add src and user data (error message) through assert macro. Attention SRC format: 1st byte - Opal src type 2-4 bytes - Holds the address of the assert function call Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com> Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-07-02Initial commit of Open Source releaseBenjamin Herrenschmidt65-0/+2536
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>