incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Pevtsov" <Ant...@moscow.vdiweb.com>
Subject RE: lib.string.capacity test update
Date Thu, 01 Jun 2006 15:29:11 GMT
Martin Sebor wrote:
> 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:
[...]

As a first step of this process I added new structure to keep
information about testing SharedAlloc method, the criteria and value
using to compare the number of calls. 
I.e this structure tells something like "<some_method> should be called
<criteria: at least, no more than, exactly, etc> n times".
The changes I made to rw_allocator.h, allocator.cpp and
21.string.cons.cpp are here:
http://people.apache.org/~antonp/stdcxx06012006/

I think that on next steps of simplification we may bind this new
structure with method overload id (there is a dependency between
information stored in the structure and this id) and
as a result verify the allocator usage in the same way as we done with
"usual" test cases.
What do you think about this?

Thanks,
Anton Pevtsov


-----Original Message-----
From: Martin Sebor [mailto:sebor@roguewave.com] 
Sent: Thursday, June 01, 2006 05:21
To: stdcxx-dev@incubator.apache.org
Subject: 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;

Mime
View raw message