Thread: [libposix-development] [PATCH] strncpy implementation and tests
Status: Pre-Alpha
Brought to you by:
hdante
From: Tordek <ke...@gm...> - 2009-07-01 00:02:22
Attachments:
smime.p7s
|
Signed-off-by: Guillermo O. Freschi <to...@to...> --- CMakeLists.txt | 4 ++++ mandatory/include/string.h | 1 + mandatory/string.c | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 0 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6be902..435d8d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,15 +85,19 @@ add_executable(printf_scanner tests/internal/printf_scanner.c ${PROJECT_BINARY_DIR}/${runtime_file_name}) add_executable(printf_parser tests/internal/printf_parser.c ${PROJECT_BINARY_DIR}/${runtime_file_name}) +add_executable(strncpy tests/internal/strncpy.c + ${PROJECT_BINARY_DIR}/${runtime_file_name}) add_test(puts_hello puts_hello) add_test(hello hello) add_test(printf_scanner printf_scanner) add_test(printf_parser printf_parser) +add_test(strncpy strncpy) target_link_libraries(posix ${LIBPOSIX_COMPILER_STYLE}) target_link_libraries(hello posix) target_link_libraries(puts_hello posix) target_link_libraries(printf_scanner posix) target_link_libraries(printf_parser posix) +target_link_libraries(strncpy posix) install(TARGETS posix DESTINATION ${LIBPOSIX_LIBRARY_DIRECTORY}) install(DIRECTORY ${mandatory_include_path}/ DESTINATION ${LIBPOSIX_INCLUDE_DIRECTORY}) diff --git a/mandatory/include/string.h b/mandatory/include/string.h index 0c9d517..fe690bd 100644 --- a/mandatory/include/string.h +++ b/mandatory/include/string.h @@ -41,5 +41,6 @@ char *strcat(char *restrict, const char *restrict); char *strchr(const char *, int); int strcmp(const char *, const char *); char *strcpy(char *restrict, const char *restrict); +char *strncpy(char *restrict s1, const char *restrict s2, size_t n); #endif /* _STRING_H_DEFINED_ */ diff --git a/mandatory/string.c b/mandatory/string.c index db91b92..fad1f1e 100644 --- a/mandatory/string.c +++ b/mandatory/string.c @@ -77,6 +77,26 @@ char *strcat(char *restrict dst, const char *restrict src) return dst; } +char *strncpy(char *restrict s1, const char *restrict s2, size_t size) { + char *d = (unsigned char *) s1; + char *s = (unsigned char *) s2; + + while(size--) { + *d++ = *s++; + + if(*s == '\0') + break; + } + + size++; + + while(size--) { + *d++ = '\0'; + } + + return s1; +} + void *memset(void *ptr, int value, size_t size) { char *p = (char *)ptr; -- 1.6.3.3 -- Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. http://tordek.com.ar :: http://twitter.com/tordek http://www.arcanopedia.com.ar - Juegos de Rol en Argentina |
From: Henrique A. <hd...@gm...> - 2009-07-01 00:07:51
|
Hello. :-) Thanks for the patch. The test file is missing (also it can go in the "tests" directory, strncpy is a standard function). 2009/6/30 Tordek <ke...@gm...>: > > Signed-off-by: Guillermo O. Freschi <to...@to...> > --- > CMakeLists.txt | 4 ++++ > mandatory/include/string.h | 1 + > mandatory/string.c | 20 ++++++++++++++++++++ > 3 files changed, 25 insertions(+), 0 deletions(-) > > diff --git a/CMakeLists.txt b/CMakeLists.txt > index c6be902..435d8d0 100644 > --- a/CMakeLists.txt > +++ b/CMakeLists.txt > @@ -85,15 +85,19 @@ add_executable(printf_scanner > tests/internal/printf_scanner.c > ${PROJECT_BINARY_DIR}/${runtime_file_name}) > add_executable(printf_parser tests/internal/printf_parser.c > ${PROJECT_BINARY_DIR}/${runtime_file_name}) > +add_executable(strncpy tests/internal/strncpy.c > + ${PROJECT_BINARY_DIR}/${runtime_file_name}) > add_test(puts_hello puts_hello) > add_test(hello hello) > add_test(printf_scanner printf_scanner) > add_test(printf_parser printf_parser) > +add_test(strncpy strncpy) > target_link_libraries(posix ${LIBPOSIX_COMPILER_STYLE}) > target_link_libraries(hello posix) > target_link_libraries(puts_hello posix) > target_link_libraries(printf_scanner posix) > target_link_libraries(printf_parser posix) > +target_link_libraries(strncpy posix) > install(TARGETS posix DESTINATION ${LIBPOSIX_LIBRARY_DIRECTORY}) > install(DIRECTORY ${mandatory_include_path}/ > DESTINATION ${LIBPOSIX_INCLUDE_DIRECTORY}) > diff --git a/mandatory/include/string.h b/mandatory/include/string.h > index 0c9d517..fe690bd 100644 > --- a/mandatory/include/string.h > +++ b/mandatory/include/string.h > @@ -41,5 +41,6 @@ char *strcat(char *restrict, const char *restrict); > char *strchr(const char *, int); > int strcmp(const char *, const char *); > char *strcpy(char *restrict, const char *restrict); > +char *strncpy(char *restrict s1, const char *restrict s2, size_t n); > > #endif /* _STRING_H_DEFINED_ */ > diff --git a/mandatory/string.c b/mandatory/string.c > index db91b92..fad1f1e 100644 > --- a/mandatory/string.c > +++ b/mandatory/string.c > @@ -77,6 +77,26 @@ char *strcat(char *restrict dst, const char > *restrict src) > return dst; > } > > +char *strncpy(char *restrict s1, const char *restrict s2, size_t > size) { > + char *d = (unsigned char *) s1; > + char *s = (unsigned char *) s2; > + > + while(size--) { > + *d++ = *s++; > + > + if(*s == '\0') > + break; > + } > + > + size++; > + > + while(size--) { > + *d++ = '\0'; > + } > + > + return s1; > +} > + > void *memset(void *ptr, int value, size_t size) > { > char *p = (char *)ptr; > -- > 1.6.3.3 > > > -- > Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. > http://tordek.com.ar :: http://twitter.com/tordek > http://www.arcanopedia.com.ar - Juegos de Rol en Argentina > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > > -- Henrique Dante de Almeida hd...@gm... |
From: Tordek <ke...@gm...> - 2009-07-01 03:31:52
Attachments:
smime.p7s
0002-Relocated-test.patch
|
Henrique Almeida wrote: > Hello. :-) Thanks for the patch. The test file is missing (also it > can go in the "tests" directory, strncpy is a standard function). Heh, I was bound to miss something in my first patch :P. I'll get cracking writing tests, I guess. There's a trivial version of assert in the test file. (BTW, what's the proper way to send patches? Attachments ok?) -- Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. http://tordek.com.ar :: http://twitter.com/tordek http://www.arcanopedia.com.ar - Juegos de Rol en Argentina |
From: Henrique A. <hd...@gm...> - 2009-07-01 20:55:41
|
2009/6/30 Tordek <ke...@gm...>: > Henrique Almeida wrote: >> Hello. :-) Thanks for the patch. The test file is missing (also it >> can go in the "tests" directory, strncpy is a standard function). > > Heh, I was bound to miss something in my first patch :P. > > I'll get cracking writing tests, I guess. There's a trivial version > of assert in the test file. > > (BTW, what's the proper way to send patches? Attachments ok?) Attachments are ok. I just need to review the coverage for the strncpy test, then I'll merge it. I'll also write recomendations for tests in libposix. > > -- > Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. > http://tordek.com.ar :: http://twitter.com/tordek > http://www.arcanopedia.com.ar - Juegos de Rol en Argentina > > ------------------------------------------------------------------------------ > > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > > -- Henrique Dante de Almeida hd...@gm... |
From: Henrique A. <hd...@gm...> - 2009-07-04 04:21:39
|
I have reviewed the tests and the problem is that there's not enough coverage. Whenever the functions are easy to implement, a single file is enough to cover all tests we could possibly do for the function. In the case, there were missing tests for out of bounds overwriting, some border cases, like zero or one length strings, testing strncpy return value and copies of strings that are more general, like binary strings. The problem with partial tests is that they give the false sense that the code is conformant. If the function were more complicated, multiple tests could be made, so that the implementation gradually passed the tests. It's not a problem if the functions don't pass the tests. Actually, tests can be made before the functions. I've applied the patch and added those tests for a reference of a more complete coverage. Note that with the improved coverage, an out of bounds error was found: Assertion failed in file /home/hdante/código/libposix/libposix/tests/strncpy.c, function main, line 128: d[i] == r[i] So, remember to fix that bug in the strncpy implementation. I'll add an article in the wiki explaining the recommended way to write tests for libposix. 2009/7/1 Henrique Almeida <hd...@gm...>: > 2009/6/30 Tordek <ke...@gm...>: >> Henrique Almeida wrote: >>> Hello. :-) Thanks for the patch. The test file is missing (also it >>> can go in the "tests" directory, strncpy is a standard function). >> >> Heh, I was bound to miss something in my first patch :P. >> >> I'll get cracking writing tests, I guess. There's a trivial version >> of assert in the test file. >> >> (BTW, what's the proper way to send patches? Attachments ok?) > > Attachments are ok. I just need to review the coverage for the > strncpy test, then I'll merge it. I'll also write recomendations for > tests in libposix. > >> >> -- >> Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. >> http://tordek.com.ar :: http://twitter.com/tordek >> http://www.arcanopedia.com.ar - Juegos de Rol en Argentina >> >> ------------------------------------------------------------------------------ >> >> _______________________________________________ >> Libposix-development mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libposix-development >> >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > -- Henrique Dante de Almeida hd...@gm... |
From: Henrique A. <hd...@gm...> - 2009-07-08 19:12:26
|
2009/7/4 Henrique Almeida <hd...@gm...>: > > I'll add an article in the wiki explaining the recommended way to > write tests for libposix. A small guide to writing tests for libposix is now available at: https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests > > Henrique Dante de Almeida > hd...@gm... > -- Henrique Dante de Almeida hd...@gm... |
From: Henrique A. <hd...@gm...> - 2009-07-12 16:16:17
|
I've added a macro, available to the build system to add tests: add_libposix_test(test_name source1 source2 ...) CMakeLists.txt now can add tests with a single line rule. 2009/7/8 Henrique Almeida <hd...@gm...>: > 2009/7/4 Henrique Almeida <hd...@gm...>: >> >> I'll add an article in the wiki explaining the recommended way to >> write tests for libposix. > > A small guide to writing tests for libposix is now available at: > > https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests > >> >> Henrique Dante de Almeida >> hd...@gm... >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > -- Henrique Dante de Almeida hd...@gm... |
From: Chris F. <ch...@fa...> - 2009-07-15 21:16:18
|
What are people's thoughts on using a "real" testing framework, to avoid the need to manually specify things in various places? The required plumbing can be done with just sh+coreutils. -----Original Message----- From: Henrique Almeida [mailto:hd...@gm...] Sent: Monday, 13 July 2009 4:16 a.m. To: lib...@li... Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests I've added a macro, available to the build system to add tests: add_libposix_test(test_name source1 source2 ...) CMakeLists.txt now can add tests with a single line rule. 2009/7/8 Henrique Almeida <hd...@gm...>: > 2009/7/4 Henrique Almeida <hd...@gm...>: >> >> I'll add an article in the wiki explaining the recommended way to >> write tests for libposix. > > A small guide to writing tests for libposix is now available at: > > https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests > >> >> Henrique Dante de Almeida >> hd...@gm... >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > -- Henrique Dante de Almeida hd...@gm... ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Libposix-development mailing list Lib...@li... https://lists.sourceforge.net/lists/listinfo/libposix-development |
From: Henrique A. <hd...@gm...> - 2009-07-15 23:22:46
|
2009/7/15 Chris Forbes <ch...@fa...>: > What are people's thoughts on using a "real" testing framework, to avoid the need to manually specify What do you have in mind ? things in various places? The required plumbing can be done with just sh+coreutils. But can it be done with CMake/CTest too ? > > -----Original Message----- > From: Henrique Almeida [mailto:hd...@gm...] > Sent: Monday, 13 July 2009 4:16 a.m. > To: lib...@li... > Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests > > I've added a macro, available to the build system to add tests: > > add_libposix_test(test_name source1 source2 ...) > > CMakeLists.txt now can add tests with a single line rule. > > 2009/7/8 Henrique Almeida <hd...@gm...>: >> 2009/7/4 Henrique Almeida <hd...@gm...>: >>> >>> I'll add an article in the wiki explaining the recommended way to >>> write tests for libposix. >> >> A small guide to writing tests for libposix is now available at: >> >> https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests >> >>> >>> Henrique Dante de Almeida >>> hd...@gm... >>> >> >> >> >> -- >> Henrique Dante de Almeida >> hd...@gm... >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > -- Henrique Dante de Almeida hd...@gm... |
From: Chris F. <ch...@fa...> - 2009-07-16 02:46:06
|
I have no idea about cmake/ctest; I don't use them for my own stuff, since I try to avoid needing a C++ compiler. Anyway, here's what I use for an embedded project. It's probably horrible in lots of ways, but it allows you to write tests like: TEST( my_test_name ) { assert( blah ); } or TEST( my_other_test, "somestubs.c", "someotherstubs.c" ) { assert( blah blah ); } It's just two files: $(PROJECT)/gentests.sh: #!/bin/bash # generate and run test wrappers # c. forbes (ch...@fa...) testsources=`grep -l "TEST(" *.c` succeeded=0 failed=0 for f in $testsources do echo -n "Searching for tests in \`$f\`... " tests=`grep "TEST(" $f | cut -d'(' -f 2 | cut -d, -f1 | cut -d')' -f1` echo `echo $tests | wc -w` found. for t in $tests do deps=`grep "$t" $f | cut -sd, -f2- | cut -d')' -f1` deps=`echo $deps | sed -e 's/[,\"]//g'` # echo $t deps: $deps testbin=.test-$f-$t tmpsrc=`mktemp`.c cat > $tmpsrc << EOT extern void __test__{{}}( void ); int main( int argc, char ** argv ) { __test__{{}}(); return 0; } EOT cat $tmpsrc | sed -e "s/{{}}/$t/g" > $testbin.c gcc -DTEST_FRAMEWORK -o $testbin.elf -pipe $testbin.c $f $deps if ./$testbin.elf; then # echo SUCCESS let "succeeded=succeeded+1" else # echo FAILED let "failed=failed+1" fi done done rm .test* if [ $failed = 0 ]; then echo "$succeeded tests passed." else echo "FAILURES!!!" echo "$failed failed $succeeded ok" fi $(INCLUDE)/testfx.h: #ifndef _TESTFX_H #define _TESTFX_H #define TEST( test_name, ... )\ void __test__ ## test_name( void ) #endif -----Original Message----- From: Henrique Almeida [mailto:hd...@gm...] Sent: Thursday, 16 July 2009 11:23 a.m. To: lib...@li... Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests 2009/7/15 Chris Forbes <ch...@fa...>: > What are people's thoughts on using a "real" testing framework, to avoid the need to manually specify What do you have in mind ? things in various places? The required plumbing can be done with just sh+coreutils. But can it be done with CMake/CTest too ? > > -----Original Message----- > From: Henrique Almeida [mailto:hd...@gm...] > Sent: Monday, 13 July 2009 4:16 a.m. > To: lib...@li... > Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests > > I've added a macro, available to the build system to add tests: > > add_libposix_test(test_name source1 source2 ...) > > CMakeLists.txt now can add tests with a single line rule. > > 2009/7/8 Henrique Almeida <hd...@gm...>: >> 2009/7/4 Henrique Almeida <hd...@gm...>: >>> >>> I'll add an article in the wiki explaining the recommended way to >>> write tests for libposix. >> >> A small guide to writing tests for libposix is now available at: >> >> https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests >> >>> >>> Henrique Dante de Almeida >>> hd...@gm... >>> >> >> >> >> -- >> Henrique Dante de Almeida >> hd...@gm... >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > -- Henrique Dante de Almeida hd...@gm... ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Libposix-development mailing list Lib...@li... https://lists.sourceforge.net/lists/listinfo/libposix-development |
From: Henrique A. <hd...@gm...> - 2009-07-16 03:10:30
|
If I understood correctly, CTest is already providing that functionallity. For TEST(), we have add_libposix_test(), which works the same way. The test script is automatically provided by CTest. For example, if I run "make test" on my system I get: Running tests... Start processing tests Test project /home/hdante/código/libposix/libposix.build 1/ 6 Testing puts_hello Passed 2/ 6 Testing hello Passed 3/ 6 Testing printf_scanner Passed 4/ 6 Testing print_parser Passed 5/ 6 Testing strncpy Passed 6/ 6 Testing stdlib_test ***Failed 83% tests passed, 1 tests failed out of 6 The following tests FAILED: 6 - stdlib_test (Failed) Errors while running CTest make: ** [test] Erro 8 I have written some comments about CTest in: https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests The only thing that is missing now is the ability of detecting correct standard output on certain tests (like hello world). I have already found a recipe for that (bizarrely, it's not trivial to do that with CTest) and I expect to include the functionality in a few weeks (and also complete the CTest documentation in the wiki). I'll put those in the task page as soon as possible. 2009/7/15 Chris Forbes <ch...@fa...>: > I have no idea about cmake/ctest; I don't use them for my own stuff, since I try to avoid needing a C++ compiler. > Anyway, here's what I use for an embedded project. It's probably horrible in lots of ways, but it allows you to write tests like: > > TEST( my_test_name ) > { > assert( blah ); > } > > or > > TEST( my_other_test, "somestubs.c", "someotherstubs.c" ) > { > assert( blah blah ); > } > > It's just two files: > > $(PROJECT)/gentests.sh: > > #!/bin/bash > > # generate and run test wrappers > # c. forbes (ch...@fa...) > > testsources=`grep -l "TEST(" *.c` > succeeded=0 > failed=0 > > for f in $testsources > do > echo -n "Searching for tests in \`$f\`... " > tests=`grep "TEST(" $f | cut -d'(' -f 2 | cut -d, -f1 | cut -d')' -f1` > echo `echo $tests | wc -w` found. > > for t in $tests > do > deps=`grep "$t" $f | cut -sd, -f2- | cut -d')' -f1` > deps=`echo $deps | sed -e 's/[,\"]//g'` > # echo $t deps: $deps > > testbin=.test-$f-$t > tmpsrc=`mktemp`.c > cat > $tmpsrc << EOT > extern void __test__{{}}( void ); > > int main( int argc, char ** argv ) > { > __test__{{}}(); > return 0; > } > EOT > cat $tmpsrc | sed -e "s/{{}}/$t/g" > $testbin.c > gcc -DTEST_FRAMEWORK -o $testbin.elf -pipe $testbin.c $f $deps > > if ./$testbin.elf; then > # echo SUCCESS > let "succeeded=succeeded+1" > else > # echo FAILED > let "failed=failed+1" > fi > done > done > > rm .test* > if [ $failed = 0 ]; then > echo "$succeeded tests passed." > else > echo "FAILURES!!!" > echo "$failed failed $succeeded ok" > fi > > > > $(INCLUDE)/testfx.h: > > #ifndef _TESTFX_H > #define _TESTFX_H > > #define TEST( test_name, ... )\ > void __test__ ## test_name( void ) > > #endif > > -----Original Message----- > From: Henrique Almeida [mailto:hd...@gm...] > Sent: Thursday, 16 July 2009 11:23 a.m. > To: lib...@li... > Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests > > 2009/7/15 Chris Forbes <ch...@fa...>: >> What are people's thoughts on using a "real" testing framework, to avoid the need to manually specify > > What do you have in mind ? > > things in various places? The required plumbing can be done with just > sh+coreutils. > > But can it be done with CMake/CTest too ? > >> >> -----Original Message----- >> From: Henrique Almeida [mailto:hd...@gm...] >> Sent: Monday, 13 July 2009 4:16 a.m. >> To: lib...@li... >> Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests >> >> I've added a macro, available to the build system to add tests: >> >> add_libposix_test(test_name source1 source2 ...) >> >> CMakeLists.txt now can add tests with a single line rule. >> >> 2009/7/8 Henrique Almeida <hd...@gm...>: >>> 2009/7/4 Henrique Almeida <hd...@gm...>: >>>> >>>> I'll add an article in the wiki explaining the recommended way to >>>> write tests for libposix. >>> >>> A small guide to writing tests for libposix is now available at: >>> >>> https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests >>> >>>> >>>> Henrique Dante de Almeida >>>> hd...@gm... >>>> >>> >>> >>> >>> -- >>> Henrique Dante de Almeida >>> hd...@gm... >>> >> >> >> >> -- >> Henrique Dante de Almeida >> hd...@gm... >> >> ------------------------------------------------------------------------------ >> Enter the BlackBerry Developer Challenge >> This is your chance to win up to $100,000 in prizes! For a limited time, >> vendors submitting new applications to BlackBerry App World(TM) will have >> the opportunity to enter the BlackBerry Developer Challenge. See full prize >> details at: http://p.sf.net/sfu/Challenge >> _______________________________________________ >> Libposix-development mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libposix-development >> ------------------------------------------------------------------------------ >> Enter the BlackBerry Developer Challenge >> This is your chance to win up to $100,000 in prizes! For a limited time, >> vendors submitting new applications to BlackBerry App World(TM) will have >> the opportunity to enter the BlackBerry Developer Challenge. See full prize >> details at: http://p.sf.net/sfu/Challenge >> _______________________________________________ >> Libposix-development mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libposix-development >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > -- Henrique Dante de Almeida hd...@gm... |
From: Tordek <ke...@gm...> - 2009-07-04 11:51:14
Attachments:
smime.p7s
0001-strncpy-OOB-error-and-tests-fixed.patch
|
Henrique Almeida wrote: > I've applied the patch and added those tests for a reference of a > more complete coverage. Note that with the improved coverage, an out > of bounds error was found: > > Assertion failed in file > /home/hdante/código/libposix/libposix/tests/strncpy.c, function main, > line 128: d[i] == r[i] > > So, remember to fix that bug in the strncpy implementation. There is an error on the test on the definition of r; r[6] == 0, but it's compared to d[6], which is 'g'. The assertion on line 123 shows this to be the case, and the strncpy on 125 doesn't touch it. Also, on line 101, assert(c+40 == strncpy(c+40, b, 40)); seems wrong; should't it be b+40? Fixing those errors on the test do leave the error on copying empty strings, which should be fixed by the patch. Passes all tests on my machine, please check. P.S.: Lovely printf, helped me track down the buggers ;P -- Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. http://tordek.com.ar :: http://twitter.com/tordek http://www.arcanopedia.com.ar - Juegos de Rol en Argentina |
From: Henrique A. <hd...@gm...> - 2009-07-04 14:27:52
|
2009/7/4 Tordek <ke...@gm...>: > > There is an error on the test on the definition of r; r[6] == 0, but > it's compared to d[6], which is 'g'. The assertion on line 123 shows > this to be the case, and the strncpy on 125 doesn't touch it. > > Also, on line 101, assert(c+40 == strncpy(c+40, b, 40)); seems > wrong; should't it be b+40? Yes, both were wrong. > > Fixing those errors on the test do leave the error on copying empty > strings, which should be fixed by the patch. Passes all tests on my > machine, please check. Passed here too. The patch was applied. > > P.S.: Lovely printf, helped me track down the buggers ;P Are you using printf do debug ? :-) If you need a debugger, CMake has support for automatically adding debug symbols in the targets. Run ccmake and set CMAKE_BUILD_TYPE to Debug. Then you can use a debug with the test applications. I'll add that flag to the installation instructions. I'm currently using insight, but it's not working perfectly, I'm thinking about testing nemiver. http://projects.gnome.org/nemiver/ > > -- > Guillermo O. «Tordek» Freschi. Programador, Escritor, Genio Maligno. > http://tordek.com.ar :: http://twitter.com/tordek > http://www.arcanopedia.com.ar - Juegos de Rol en Argentina > > ------------------------------------------------------------------------------ > > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > > -- Henrique Dante de Almeida hd...@gm... |
From: Chris F. <ch...@fa...> - 2009-07-16 03:18:43
|
My point was to avoid having to do `add_posix_test()` in a cmake config file someplace; Instead I automatically determine the tests that exist, and specify their dependencies at the same point where the test is defined (in the C file). -----Original Message----- From: Henrique Almeida [mailto:hd...@gm...] Sent: Thursday, 16 July 2009 3:10 p.m. To: lib...@li... Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests If I understood correctly, CTest is already providing that functionallity. For TEST(), we have add_libposix_test(), which works the same way. The test script is automatically provided by CTest. For example, if I run "make test" on my system I get: Running tests... Start processing tests Test project /home/hdante/código/libposix/libposix.build 1/ 6 Testing puts_hello Passed 2/ 6 Testing hello Passed 3/ 6 Testing printf_scanner Passed 4/ 6 Testing print_parser Passed 5/ 6 Testing strncpy Passed 6/ 6 Testing stdlib_test ***Failed 83% tests passed, 1 tests failed out of 6 The following tests FAILED: 6 - stdlib_test (Failed) Errors while running CTest make: ** [test] Erro 8 I have written some comments about CTest in: https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests The only thing that is missing now is the ability of detecting correct standard output on certain tests (like hello world). I have already found a recipe for that (bizarrely, it's not trivial to do that with CTest) and I expect to include the functionality in a few weeks (and also complete the CTest documentation in the wiki). I'll put those in the task page as soon as possible. 2009/7/15 Chris Forbes <ch...@fa...>: > I have no idea about cmake/ctest; I don't use them for my own stuff, since I try to avoid needing a C++ compiler. > Anyway, here's what I use for an embedded project. It's probably horrible in lots of ways, but it allows you to write tests like: > > TEST( my_test_name ) > { > assert( blah ); > } > > or > > TEST( my_other_test, "somestubs.c", "someotherstubs.c" ) > { > assert( blah blah ); > } > > It's just two files: > > $(PROJECT)/gentests.sh: > > #!/bin/bash > > # generate and run test wrappers > # c. forbes (ch...@fa...) > > testsources=`grep -l "TEST(" *.c` > succeeded=0 > failed=0 > > for f in $testsources > do > echo -n "Searching for tests in \`$f\`... " > tests=`grep "TEST(" $f | cut -d'(' -f 2 | cut -d, -f1 | cut -d')' -f1` > echo `echo $tests | wc -w` found. > > for t in $tests > do > deps=`grep "$t" $f | cut -sd, -f2- | cut -d')' -f1` > deps=`echo $deps | sed -e 's/[,\"]//g'` > # echo $t deps: $deps > > testbin=.test-$f-$t > tmpsrc=`mktemp`.c > cat > $tmpsrc << EOT > extern void __test__{{}}( void ); > > int main( int argc, char ** argv ) > { > __test__{{}}(); > return 0; > } > EOT > cat $tmpsrc | sed -e "s/{{}}/$t/g" > $testbin.c > gcc -DTEST_FRAMEWORK -o $testbin.elf -pipe $testbin.c $f $deps > > if ./$testbin.elf; then > # echo SUCCESS > let "succeeded=succeeded+1" > else > # echo FAILED > let "failed=failed+1" > fi > done > done > > rm .test* > if [ $failed = 0 ]; then > echo "$succeeded tests passed." > else > echo "FAILURES!!!" > echo "$failed failed $succeeded ok" > fi > > > > $(INCLUDE)/testfx.h: > > #ifndef _TESTFX_H > #define _TESTFX_H > > #define TEST( test_name, ... )\ > void __test__ ## test_name( void ) > > #endif > > -----Original Message----- > From: Henrique Almeida [mailto:hd...@gm...] > Sent: Thursday, 16 July 2009 11:23 a.m. > To: lib...@li... > Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests > > 2009/7/15 Chris Forbes <ch...@fa...>: >> What are people's thoughts on using a "real" testing framework, to avoid the need to manually specify > > What do you have in mind ? > > things in various places? The required plumbing can be done with just > sh+coreutils. > > But can it be done with CMake/CTest too ? > >> >> -----Original Message----- >> From: Henrique Almeida [mailto:hd...@gm...] >> Sent: Monday, 13 July 2009 4:16 a.m. >> To: lib...@li... >> Subject: Re: [libposix-development] [PATCH] strncpy implementation and tests >> >> I've added a macro, available to the build system to add tests: >> >> add_libposix_test(test_name source1 source2 ...) >> >> CMakeLists.txt now can add tests with a single line rule. >> >> 2009/7/8 Henrique Almeida <hd...@gm...>: >>> 2009/7/4 Henrique Almeida <hd...@gm...>: >>>> >>>> I'll add an article in the wiki explaining the recommended way to >>>> write tests for libposix. >>> >>> A small guide to writing tests for libposix is now available at: >>> >>> https://sourceforge.net/apps/mediawiki/libposix/index.php?title=How_to_write_tests >>> >>>> >>>> Henrique Dante de Almeida >>>> hd...@gm... >>>> >>> >>> >>> >>> -- >>> Henrique Dante de Almeida >>> hd...@gm... >>> >> >> >> >> -- >> Henrique Dante de Almeida >> hd...@gm... >> >> ------------------------------------------------------------------------------ >> Enter the BlackBerry Developer Challenge >> This is your chance to win up to $100,000 in prizes! For a limited time, >> vendors submitting new applications to BlackBerry App World(TM) will have >> the opportunity to enter the BlackBerry Developer Challenge. See full prize >> details at: http://p.sf.net/sfu/Challenge >> _______________________________________________ >> Libposix-development mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libposix-development >> ------------------------------------------------------------------------------ >> Enter the BlackBerry Developer Challenge >> This is your chance to win up to $100,000 in prizes! For a limited time, >> vendors submitting new applications to BlackBerry App World(TM) will have >> the opportunity to enter the BlackBerry Developer Challenge. See full prize >> details at: http://p.sf.net/sfu/Challenge >> _______________________________________________ >> Libposix-development mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libposix-development >> > > > > -- > Henrique Dante de Almeida > hd...@gm... > > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > ------------------------------------------------------------------------------ > Enter the BlackBerry Developer Challenge > This is your chance to win up to $100,000 in prizes! For a limited time, > vendors submitting new applications to BlackBerry App World(TM) will have > the opportunity to enter the BlackBerry Developer Challenge. See full prize > details at: http://p.sf.net/sfu/Challenge > _______________________________________________ > Libposix-development mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libposix-development > -- Henrique Dante de Almeida hd...@gm... ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Libposix-development mailing list Lib...@li... https://lists.sourceforge.net/lists/listinfo/libposix-development |
From: Henrique A. <hd...@gm...> - 2009-07-16 17:07:01
|
2009/7/16 Chris Forbes <ch...@fa...>: > My point was to avoid having to do `add_posix_test()` in a cmake config file someplace; Instead I automatically determine the tests that exist, In that case I don't think that's necessary. Isolating the build system from code has more advantages than disadvantages. For example, it's easier to replace the build system and people that need to copy the test code to their own projects don't need to worry about the extra markup code. I'm planning splitting the main make file and moving test rules to the tests directory (this task is available at TaskFreak), so that the test list can grow without messing the root CMakeLists.txt. The goal is to have a very simple 1 or 2 line command sequence for specifying tests, for example: add_libposix_test(test_name source1 source2 source3 [INPUT input_file] [EXPECTED_OUPUT output_file] [EXPECTED_ERROR error_file] [INVERT_RESULT]) > and specify their dependencies at the same point where the test is defined (in the C file). > -- Henrique Dante de Almeida hd...@gm... |