You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Martin Sebor <se...@roguewave.com> on 2006/06/01 03:21:00 UTC

Re: lib.string.capacity test update

Anton Pevtsov wrote:
[...]
> I started with cons test, here is my attempt to add verification of the
> allocator methods usage:
> http://people.apache.org/~antonp/stdcxx05312006b/
> I think that we are needed in access to allocator methods names. I
> modified the allocator header and implementation files to provide this
> access,
> but there may be another ways to do it.
> What do you think about this?

It's a good start. I wonder if you could commit the first set of
changes to the cons.cpp test (i.e., those that don't involve the
allocator members), and then post just the diff for the rest in
a separate patch. That way it will be easier to focus only on
the those without getting distracted by the former.

As a general comment, we should be on the lookout for ways to
reduce the amount of boilerplate code that will end up repeated
across all tests, such the snippet of code below. It would be
nice to be able to say something like:

     start_counting_calls_to_allocator_members (/* ... */);

     // do things to string that are expected to make use
     // of allocator members

     verify_number_of_calls_to_allocator_members (/*... */);

Where the /* ... */ might specify the set of allocator members
whose calls we want to count and verify. It could be a bitset
(e.g., in the form: m_allocate | m_deallocate | m_construct
| m_destroy), or it could be a list of individual arguments, or
some more complicated data structure. There should also be a way
to specify that we expect "no more than" or "at least as many as"
some number of calls.

Or, alternatively, the first call to start counting all calls
(i.e., simply zero out all the counters) and the second call
would specify the expected values of each counter with the
expected fuzziness factor which could be great enough for us
to ignore some counters altogether.

Let me see what I can cook up tomorrow.

Martin

PS The current hunk of code that I'm proposing to replace is
below:

     std::size_t total_alloc_calls [SharedAlloc::n_funs];
     std::size_t alloc_calls_idx [] = {
         SharedAlloc::m_construct,
         SharedAlloc::m_allocate,
         SharedAlloc::m_max_size
     };

     // for convenience
     std::size_t idxs = sizeof alloc_calls_idx / sizeof *alloc_calls_idx;

     for (std::size_t t = 0; t < idxs; t++) {
         total_alloc_calls [alloc_calls_idx [t] ] =
             pal->n_calls_ [alloc_calls_idx [t] ];
     }

     // ...

     const bool verify_alloc = test_alloc &&
         func.alloc_id_ == StringIds::UserAlloc && ret_ptr->size ();

     if (verify_alloc) {
          for (std::size_t t = 0; t < idxs; t++) {
             bool success = total_alloc_calls [alloc_calls_idx [t] ] <
                                    pal->n_calls_ [alloc_calls_idx [t] ];

             rw_assert (success, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{/*.*Gs} "
                        "construction: expected at least 1 call of "
                        "Allocator method %s, got 0",
                        __LINE__, cwidth, int (ret_ptr->size ()),
                        ret_ptr->data (),
                        rw_get_alloc_funname (alloc_calls_idx [t]));
         }
     }

     delete ret_ptr;