]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
- Add 'unit_libcbase', the beginnings of a unit test module for m_libcbase.
authorNicholas Nethercote <njn@valgrind.org>
Fri, 20 Feb 2009 06:10:44 +0000 (06:10 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 20 Feb 2009 06:10:44 +0000 (06:10 +0000)
- Rename 'oset_test' as 'unit_oset' to make its meaning more clear.
- Remove VG_(atoll36), VG_(strtoll8)() and VG_(strtoll36)();  they're not
  used and so untested, but easy to crib from similar functions if they need
  to be added again later.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9204

coregrind/m_libcbase.c
include/pub_tool_libcbase.h
memcheck/tests/Makefile.am
memcheck/tests/unit_libcbase.stderr.exp [moved from memcheck/tests/oset_test.stderr.exp with 100% similarity]
memcheck/tests/unit_libcbase.vgtest [new file with mode: 0644]
memcheck/tests/unit_oset.c [moved from memcheck/tests/oset_test.c with 99% similarity]
memcheck/tests/unit_oset.stderr.exp [new file with mode: 0644]
memcheck/tests/unit_oset.stdout.exp [moved from memcheck/tests/oset_test.stdout.exp with 100% similarity]
memcheck/tests/unit_oset.vgtest [moved from memcheck/tests/oset_test.vgtest with 100% similarity]

index e78536f2327e52b0826f63d2d61c73764f90f76c..cf983509e7961ea098bdace66b2abdd32e5573ab 100644 (file)
@@ -50,12 +50,6 @@ Bool VG_(isdigit) ( Char c )
    Converting strings to numbers
    ------------------------------------------------------------------ */
 
-static Bool is_oct_digit(Char c, Long* digit)
-{
-   if (c >= '0' && c <= '7') { *digit = (Long)(c - '0'); return True; }
-   return False;
-}
-
 static Bool is_dec_digit(Char c, Long* digit)
 {
    if (c >= '0' && c <= '9') { *digit = (Long)(c - '0'); return True; }
@@ -70,40 +64,11 @@ static Bool is_hex_digit(Char c, Long* digit)
    return False;
 }
 
-static Bool is_base36_digit(Char c, Long* digit)
-{
-   if (c >= '0' && c <= '9') { *digit = (Long)(c - '0');        return True; }
-   if (c >= 'A' && c <= 'Z') { *digit = (Long)((c - 'A') + 10); return True; }
-   if (c >= 'a' && c <= 'z') { *digit = (Long)((c - 'a') + 10); return True; }
-   return False;
-}
-
-Long VG_(strtoll8) ( Char* str, Char** endptr )
-{
-   Bool neg = False;
-   Long n = 0, digit = 0;
-
-   // Skip leading whitespace.
-   while (VG_(isspace)(*str)) str++;
-
-   // Allow a leading '-' or '+'.
-   if (*str == '-') { str++; neg = True; }
-   else if (*str == '+') { str++; }
-
-   while (is_oct_digit(*str, &digit)) {
-      n = 8*n + digit;
-      str++;
-   }
-
-   if (neg) n = -n;
-   if (endptr) *endptr = str;    // Record first failing character.
-   return n;
-}
-
 Long VG_(strtoll10) ( Char* str, Char** endptr )
 {
-   Bool neg = False;
+   Bool neg = False, converted = False;
    Long n = 0, digit = 0;
+   Char* str0 = str;
 
    // Skip leading whitespace.
    while (VG_(isspace)(*str)) str++;
@@ -113,19 +78,22 @@ Long VG_(strtoll10) ( Char* str, Char** endptr )
    else if (*str == '+') { str++; }
 
    while (is_dec_digit(*str, &digit)) {
+      converted = True;          // Ok, we've actually converted a digit.
       n = 10*n + digit;
       str++;
    }
 
-   if (neg) n = -n;
+   if (!converted) str = str0;   // If nothing converted, endptr points to
+   if (neg) n = -n;              //   the start of the string.
    if (endptr) *endptr = str;    // Record first failing character.
    return n;
 }
 
 Long VG_(strtoll16) ( Char* str, Char** endptr )
 {
-   Bool neg = False;
+   Bool neg = False, converted = False;
    Long n = 0, digit = 0;
+   Char* str0 = str;
 
    // Skip leading whitespace.
    while (VG_(isspace)(*str)) str++;
@@ -143,33 +111,13 @@ Long VG_(strtoll16) ( Char* str, Char** endptr )
    }
 
    while (is_hex_digit(*str, &digit)) {
+      converted = True;          // Ok, we've actually converted a digit.
       n = 16*n + digit;
       str++;
    }
 
-   if (neg) n = -n;
-   if (endptr) *endptr = str;    // Record first failing character.
-   return n;
-}
-
-Long VG_(strtoll36) ( Char* str, Char** endptr )
-{
-   Bool neg = False;
-   Long n = 0, digit = 0;
-
-   // Skip leading whitespace.
-   while (VG_(isspace)(*str)) str++;
-
-   // Allow a leading '-' or '+'.
-   if (*str == '-') { str++; neg = True; }
-   else if (*str == '+') { str++; }
-
-   while (is_base36_digit(*str, &digit)) {
-      n = 36*n + digit;
-      str++;
-   }
-
-   if (neg) n = -n;
+   if (!converted) str = str0;   // If nothing converted, endptr points to
+   if (neg) n = -n;              //   the start of the string.
    if (endptr) *endptr = str;    // Record first failing character.
    return n;
 }
@@ -217,11 +165,6 @@ Long VG_(atoll16) ( Char* str )
    return VG_(strtoll16)(str, NULL);
 }
 
-Long VG_(atoll36) ( Char* str )
-{
-   return VG_(strtoll36)(str, NULL);
-}
-
 /* ---------------------------------------------------------------------
    String functions
    ------------------------------------------------------------------ */
index 53fd0f16136ca6ed752c36e0b8049e088c81119c..bc224ac418b8a4dc868cc56e95baf496d486181a 100644 (file)
@@ -47,25 +47,28 @@ extern Bool VG_(isdigit) ( Char c );
 // accepts an initial "0x" or "0X" prefix, but only if it's followed by a
 // hex digit (if not, the '0' will be read and then it will stop on the
 // "x"/"X".)  If 'endptr' isn't NULL, it gets filled in with the first
-// non-digit char.  None of them test that the number fits into 64 bits.
+// non-digit char.  Returns 0 if no number could be converted, and 'endptr'
+// is set to the start of the string.  None of them test that the number
+// fits into 64 bits.
 //
 // Nb: if you're wondering why we don't just have a single VG_(strtol) which
 // takes a base, it's because I wanted it to assert if it was given a bogus
 // base (the standard glibc one sets 'errno' in this case).  But
 // m_libcbase.c doesn't import any code, not even vg_assert. --njn
-extern Long  VG_(strtoll8)  ( Char* str, Char** endptr );
 extern Long  VG_(strtoll10) ( Char* str, Char** endptr );
 extern Long  VG_(strtoll16) ( Char* str, Char** endptr );
-extern Long  VG_(strtoll36) ( Char* str, Char** endptr );
 
-   // Convert a string to a double.  After leading whitespace is ignored,
-   // it accepts a non-empty sequence of decimal digits possibly containing
-   // a '.'.
+   // Convert a string to a double.  After leading whitespace is ignored, a
+   // '+' or '-' is allowed, and then it accepts a non-empty sequence of
+   // decimal digits possibly containing a '.'.  Hexadecimal floats are not
+   // accepted, nor are "fancy" floats (eg. "3.4e-5", "NAN").
 extern double VG_(strtod)  ( Char* str, Char** endptr );
 
+   // These are just like their VG_(strtoll*) counterparts, except that you
+   // cannot tell if an error occurred (because 0 is returned) or if there
+   // is any trailing non-numeric characterws (eg. in "123xyz").
 extern Long  VG_(atoll)   ( Char* str ); // base 10
 extern Long  VG_(atoll16) ( Char* str ); // base 16; leading 0x accepted
-extern Long  VG_(atoll36) ( Char* str ); // base 36
 
 /* ---------------------------------------------------------------------
    String functions and macros
index d0fb56c02aca3ecbd5f6ef7ac043ff7a5e1e3716..635ade0622190a4589093ed2ec9fda164fa0ba30 100644 (file)
@@ -92,6 +92,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \
        memcmptest.stderr.exp memcmptest.stderr.exp2 \
        memcmptest.stdout.exp memcmptest.vgtest \
        mempool.stderr.exp mempool.stderr.exp64 mempool.vgtest \
+       metadata.stderr.exp metadata.stdout.exp metadata.vgtest \
        mismatches.stderr.exp mismatches.stderr.exp64 mismatches.vgtest \
        mmaptest.stderr.exp mmaptest.vgtest \
        nanoleak.stderr.exp nanoleak.vgtest \
@@ -117,7 +118,6 @@ EXTRA_DIST = $(noinst_SCRIPTS) \
        origin6-fp.vgtest origin6-fp.stdout.exp \
        origin6-fp.stderr.exp-glibc25-amd64 \
        origin6-fp.stderr.exp-glibc27-ppc64 \
-       oset_test.stderr.exp oset_test.stdout.exp oset_test.vgtest \
        overlap.stderr.exp overlap.stdout.exp overlap.vgtest \
        partiallydefinedeq.vgtest partiallydefinedeq.stderr.exp \
        partiallydefinedeq.stderr.exp2 \
@@ -151,7 +151,8 @@ EXTRA_DIST = $(noinst_SCRIPTS) \
        suppfree.stderr.exp suppfree.vgtest \
        toobig-allocs.stderr.exp toobig-allocs.vgtest \
        trivialleak.stderr.exp trivialleak.vgtest \
-       metadata.stderr.exp metadata.stdout.exp metadata.vgtest \
+       unit_libcbase.stderr.exp unit_libcbase.stdout.exp unit_libcbase.vgtest \
+       unit_oset.stderr.exp unit_oset.stdout.exp unit_oset.vgtest \
        varinfo1.vgtest varinfo1.stdout.exp varinfo1.stderr.exp \
        varinfo2.vgtest varinfo2.stdout.exp varinfo2.stderr.exp \
        varinfo3.vgtest varinfo3.stdout.exp varinfo3.stderr.exp \
@@ -200,9 +201,10 @@ check_PROGRAMS = \
        malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
        match-overrun \
        memalign_test memalign2 memcmptest mempool mmaptest \
+       mismatches new_override metadata \
        nanoleak nanoleak2 new_nothrow \
        noisy_child \
-       null_socket oset_test \
+       null_socket \
        origin1-yes origin2-not-quite origin3-no \
        origin4-many origin5-bz2 origin6-fp \
        overlap \
@@ -216,7 +218,7 @@ check_PROGRAMS = \
        stack_changes strchr str_tester \
        supp_unknown supp1 supp2 suppfree \
        trivialleak \
-       mismatches new_override metadata \
+       unit_libcbase unit_oset \
        varinfo1 varinfo2 varinfo3 varinfo4 \
        varinfo5 varinfo5so.so varinfo6 \
        vcpu_fbench vcpu_fnfns \
diff --git a/memcheck/tests/unit_libcbase.vgtest b/memcheck/tests/unit_libcbase.vgtest
new file mode 100644 (file)
index 0000000..1908904
--- /dev/null
@@ -0,0 +1,2 @@
+vgopts: -q
+prog: unit_libcbase
similarity index 99%
rename from memcheck/tests/oset_test.c
rename to memcheck/tests/unit_oset.c
index 10033a2dfa2356dad26996b8f45031de8280cae9..f06f5826c6e1daa362db8e20c30a3afe7a5cfc14 100644 (file)
@@ -213,7 +213,6 @@ void example1b(void)
    Int  i, n;
    Word v = 0, prev;
    Word vs[NN];
-   Word *pv;
 
    // Create a static OSet of Ints.  This one uses fast (built-in)
    // comparisons.
diff --git a/memcheck/tests/unit_oset.stderr.exp b/memcheck/tests/unit_oset.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29