@@ -600,6 +600,25 @@ int expect_strne(const char *expr, int llen, const char *cmp)
600600 return ret ;
601601}
602602
603+ #define EXPECT_STRBUFEQ (cond , expr , buf , val , cmp ) \
604+ do { if (!(cond)) result(llen, SKIPPED); else ret += expect_str_buf_eq(expr, buf, val, llen, cmp); } while (0)
605+
606+ static __attribute__((unused ))
607+ int expect_str_buf_eq (size_t expr , const char * buf , size_t val , int llen , const char * cmp )
608+ {
609+ llen += printf (" = %lu <%s> " , expr , buf );
610+ if (strcmp (buf , cmp ) != 0 ) {
611+ result (llen , FAIL );
612+ return 1 ;
613+ }
614+ if (expr != val ) {
615+ result (llen , FAIL );
616+ return 1 ;
617+ }
618+
619+ result (llen , OK );
620+ return 0 ;
621+ }
603622
604623/* declare tests based on line numbers. There must be exactly one test per line. */
605624#define CASE_TEST (name ) \
@@ -991,6 +1010,14 @@ int run_stdlib(int min, int max)
9911010 for (test = min ; test >= 0 && test <= max ; test ++ ) {
9921011 int llen = 0 ; /* line length */
9931012
1013+ /* For functions that take a long buffer, like strlcat()
1014+ * Add some more chars after the \0, to test functions that overwrite the buffer set
1015+ * the \0 at the exact right position.
1016+ */
1017+ char buf [10 ] = "test123456" ;
1018+ buf [4 ] = '\0' ;
1019+
1020+
9941021 /* avoid leaving empty lines below, this will insert holes into
9951022 * test numbers.
9961023 */
@@ -1007,6 +1034,19 @@ int run_stdlib(int min, int max)
10071034 CASE_TEST (strchr_foobar_z ); EXPECT_STRZR (1 , strchr ("foobar" , 'z' )); break ;
10081035 CASE_TEST (strrchr_foobar_o ); EXPECT_STREQ (1 , strrchr ("foobar" , 'o' ), "obar" ); break ;
10091036 CASE_TEST (strrchr_foobar_z ); EXPECT_STRZR (1 , strrchr ("foobar" , 'z' )); break ;
1037+ #ifdef NOLIBC
1038+ CASE_TEST (strlcat_0 ); EXPECT_STRBUFEQ (1 , strlcat (buf , "bar" , 0 ), buf , 3 , "test" ); break ;
1039+ CASE_TEST (strlcat_1 ); EXPECT_STRBUFEQ (1 , strlcat (buf , "bar" , 1 ), buf , 4 , "test" ); break ;
1040+ CASE_TEST (strlcat_5 ); EXPECT_STRBUFEQ (1 , strlcat (buf , "bar" , 5 ), buf , 7 , "test" ); break ;
1041+ CASE_TEST (strlcat_6 ); EXPECT_STRBUFEQ (1 , strlcat (buf , "bar" , 6 ), buf , 7 , "testb" ); break ;
1042+ CASE_TEST (strlcat_7 ); EXPECT_STRBUFEQ (1 , strlcat (buf , "bar" , 7 ), buf , 7 , "testba" ); break ;
1043+ CASE_TEST (strlcat_8 ); EXPECT_STRBUFEQ (1 , strlcat (buf , "bar" , 8 ), buf , 7 , "testbar" ); break ;
1044+ CASE_TEST (strlcpy_0 ); EXPECT_STRBUFEQ (1 , strlcpy (buf , "bar" , 0 ), buf , 3 , "test" ); break ;
1045+ CASE_TEST (strlcpy_1 ); EXPECT_STRBUFEQ (1 , strlcpy (buf , "bar" , 1 ), buf , 3 , "" ); break ;
1046+ CASE_TEST (strlcpy_2 ); EXPECT_STRBUFEQ (1 , strlcpy (buf , "bar" , 2 ), buf , 3 , "b" ); break ;
1047+ CASE_TEST (strlcpy_3 ); EXPECT_STRBUFEQ (1 , strlcpy (buf , "bar" , 3 ), buf , 3 , "ba" ); break ;
1048+ CASE_TEST (strlcpy_4 ); EXPECT_STRBUFEQ (1 , strlcpy (buf , "bar" , 4 ), buf , 3 , "bar" ); break ;
1049+ #endif
10101050 CASE_TEST (memcmp_20_20 ); EXPECT_EQ (1 , memcmp ("aaa\x20" , "aaa\x20" , 4 ), 0 ); break ;
10111051 CASE_TEST (memcmp_20_60 ); EXPECT_LT (1 , memcmp ("aaa\x20" , "aaa\x60" , 4 ), 0 ); break ;
10121052 CASE_TEST (memcmp_60_20 ); EXPECT_GT (1 , memcmp ("aaa\x60" , "aaa\x20" , 4 ), 0 ); break ;
0 commit comments