Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #18600

Re: Regression testing for pointers

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Regression testing for pointers
Date 2012-03-13 07:23 +1300
Message-ID <9s6t8nFa8vU6@mid.individual.net> (permalink)
References (4 earlier) <jjf5gt$n6m$1@speranza.aioe.org> <9s0o1eFtf6U7@mid.individual.net> <jjg8eu$jfs$1@speranza.aioe.org> <9s1vp0Ftf6U8@mid.individual.net> <jjl7n8$mt4$1@speranza.aioe.org>

Show all headers | View raw


On 03/13/12 05:19 AM, Don Y wrote:
> Hi Ian,
>
> On 3/10/2012 2:35 PM, Ian Collins wrote:
>
>>>> In the case above, just use conditionally compiled constants for heap
>>>> base and size.
>>>
>>> That assumes you can put the heap where your test suite wants
>>> it. E.g., on a tiny processor, the heap might be at 0xA000;
>>> on a desktop, at 0x40020000; on a 64b machine...
>>>
>>> Similarly, the amount of memory *in* the heap might vary.
>>> You could allocate 1MB on a desktop platform but 10KB on
>>> a tiny machine might be "oodles". If you've written with
>>> the tiny machine in mind, perhaps you've a latent bug where
>>> you expected pointers to be 16b instead of 32b (sure, you
>>> can code to deal with this; but, you can also FORGET TO
>>> CODE to deal with this!).
>>>
>>> The alignment constraints of the processor might change from
>>> what your test cases "expect".
>>>
>>> Etc. You could *code* a "test routine" that examines these
>>> things and *intelligently* invokes the UUT. But, that means
>>> you start migrating complexity into the "tester" that can be
>>> just as tricky (if not trickier!) as the code you are hoping
>>> to "test".
>>
>> OK, it's a dull Sunday morning, so I cooked up a quick working example
>> using Google Test.
>>
>> The simple function myMalloc() will:
>>
>> Return NULL for a zero size request.
>> Return a correctly aligned pointer within the heap for a non-zero request.
>> Use a fixed heap base of 0xA000 and size of 0x1000 on TARGET_X.
>
> But those criteria might not test the full capabilities of
> myMalloc.  E.g., does it behave when the heap size is increased
> to 0x6000?  Does it behave if I move the heap to 0x0000?  Does
> it work for "big" requests -- e.g., a megabyte?  (it *should*
> on TARGET_Y but that wouldn't make sense on TARGET_X... two
> different test suites?)

This is a demonstration, not a full test suite.  I've been designing 
allocators for 20 odd year and non of them have worked differently is 
different locations.

>> #if defined TARGET_X
>> const uint8_t* heapBase = 0xA000;
>> const size_t heapSize = 0x1000;
>> const size_t minAlign = 8;
>> #else
>> uint8_t* heapBase = NULL;
>> size_t heapSize = 0x1000;
>> size_t minAlign = 8;
>> #endif
>
> You are relying on being able to enumerate all of the test
> conditions for each potential platform.

No I'm not, that's just an example of allowing either constant or 
variable parameters. The allocator code should be position independent.

> But you can't write
> that test suite "today" without knowledge of what they will be
> (e.g., 1MB request).

Why not?  Just add maxRequest as a constant/variable to the mix.

> The problem is inherent in the fact that this is an area
> (pointers, size_t) where the language gives the implementation
> lots of flexibility.  OTOH, you *know* that a double will
> be good for ~10+ digits...

Flexibility that should not change the relative behaviour of the code.

>> TEST_F( MyMallocTest,
>> returnIsNullForZeroByteRequest )
>> {
>> ASSERT_FALSE( myMalloc(0) );
>> }
>
> Should be null for "too big" request.

So add a test.

>> TEST_F( MyMallocTest,
>> returnIsInHeapForOneByteRequest )
>> {
>> ASSERT_TRUE( myMalloc(1)>= heapBase );
>> ASSERT_TRUE( myMalloc(1)<  heapBase+heapSize );
>> }
>
> Should be "in heap" for *all* requests.

So add a test.

>> TEST_F( MyMallocTest,
>> returnForOneByteRequestCorrectlyAlligned )
>> {
>> ASSERT_EQ( 0, (size_t)myMalloc(1)%minAlign );
>> }
>
> Should be correctly aligned for *all* requests.

So add a test.

>> TEST_F( MyMallocTest,
>> returnForOneByteRequestCorrectlyAllignedFor128Bytes )
>> {
>> minAlign = 128;
>> ASSERT_EQ( 0, (size_t)myMalloc(1)%minAlign );
>> }
>>
>> The Google test code is at the end to avoid clutter.
>
> The point of my "should be's" is that you can pin the
> function's return values down much tighter than that.  And,
> you *need* to be able to do so in order to assure yourself
> that it truly is operating properly.
>
> If I run the returnIsInHeapForOneByteRequest 0x1000 times,
> will it always pass (without an intervening free())?

So add a test.

> Shouldn't it fail at the 0x1000/minAlign point, instead?
> Am I sure that no two of the returned pointers EVER coincide?

So add a test.

> E.g., you wouldn't write:
>
> ASSERT(sqrt(3)>  1)
> ASSERT(sqrt(3)<  2)
> ASSERT(sqrt(3)>  sqrt(2))
> ASSERT(sqrt(3)<  sqrt(4))
>
> *All* of these are appropriate.  But, what you really want
> to know is
>
> ASSERT(sqrt(3) =~ 1.732...)
>
> This embodies *all* of the above tests and gives the
> function far less "wiggle room".
>
> (malloc -- and your myMalloc -- are too loosely defined for
> robust formal testing.

It's only a demonstration to address some of your questions of a work in 
progress.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-09 16:43 -0700
  Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-10 12:56 +1300
    Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-09 19:40 -0700
      Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-10 17:53 +1300
        Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-10 18:12 +1300
        Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-10 02:05 -0700
          Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-10 23:17 +1300
            Re: Regression testing for pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-10 12:00 +0000
              Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-11 11:00 +1300
                Re: Regression testing for pointers Ike Naar <ike@iceland.freeshell.org> - 2012-03-10 22:23 +0000
                Re: Regression testing for pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-10 22:40 +0000
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-11 12:12 +1300
                Re: Regression testing for pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-11 00:42 +0000
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-11 14:26 +1300
                Re: Regression testing for pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-11 03:09 +0000
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-11 18:16 +1300
            Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-10 12:01 -0700
              Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-11 10:35 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 09:19 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 07:23 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 16:23 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 17:25 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 00:19 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 20:34 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 01:00 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 21:22 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 10:19 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-14 07:25 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-14 02:00 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-14 22:18 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-14 11:32 -0700
                Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-15 05:58 -0700
                Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-15 05:55 -0700
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-15 11:32 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-16 18:14 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-20 01:43 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-20 21:59 +1300
                Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-16 03:05 -0700
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-20 02:33 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-24 11:49 +1300
          Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-11 05:01 -0700
            Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-11 09:44 -0700
              Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-12 09:56 +1300
    Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-10 02:28 -0800
      Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-10 11:09 -0700
      Re: Regression testing for pointers Kaz Kylheku <kaz@kylheku.com> - 2012-03-10 18:29 +0000
        Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-11 05:22 -0700
          Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-11 09:50 -0700
            Re: Regression testing for pointers "io_x" <a@b.c.invalid> - 2012-03-13 13:09 +0100
  Re: Regression testing for pointers Kaz Kylheku <kaz@kylheku.com> - 2012-03-10 03:14 +0000
    Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-10 12:42 -0700
  Re: Regression testing for pointers Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-10 08:42 +0000
    Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-10 02:19 -0700
      Re: Regression testing for pointers "BartC" <bc@freeuk.com> - 2012-03-10 15:54 +0000
        Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-10 11:49 -0700
          Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-11 06:09 -0700
            Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-11 12:33 -0700
              Re: Regression testing for pointers nick_keighley_nospam@hotmail.com - 2012-03-12 03:29 -0700
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 10:01 -0700
                Re: Regression testing for pointers "BartC" <bc@freeuk.com> - 2012-03-13 18:56 +0000
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 16:31 -0700
      Re: Regression testing for pointers Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-12 00:30 +0000
        Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 16:41 -0700
      Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-12 13:39 +1300
        Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 09:36 -0700
          Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 07:25 +1300
            Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 16:28 -0700
              Re: Regression testing for pointers Kaz Kylheku <kaz@kylheku.com> - 2012-03-13 04:20 +0000
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 17:34 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 00:29 -0700
              Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 17:31 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 01:05 -0700
                Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-13 21:30 +1300
                Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-13 10:43 -0700
  Re: Regression testing for pointers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-10 15:41 -0800
    Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-11 11:23 -0700
      Re: Regression testing for pointers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-13 13:43 -0700
        Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-14 01:45 -0700
          Re: Regression testing for pointers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-14 15:15 -0700
            Re: Regression testing for pointers Kaz Kylheku <kaz@kylheku.com> - 2012-03-14 22:57 +0000
              Re: Regression testing for pointers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-03-15 13:10 -0700
                Re: Regression testing for pointers jgk@panix.com (Joe keane) - 2012-03-16 22:20 +0000
                Re: Regression testing for pointers "io_x" <a@b.c.invalid> - 2012-03-18 07:15 +0100
            Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-14 23:13 -0700
  Re: Regression testing for pointers gordonb.b29ri@burditt.org (Gordon Burditt) - 2012-03-12 19:37 -0500
    Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-12 19:23 -0700
  Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-14 13:12 +1300
    Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-14 01:54 -0700
      Re: Regression testing for pointers Ian Collins <ian-news@hotmail.com> - 2012-03-14 22:05 +1300
        Re: Regression testing for pointers Don Y <this@isnotme.com> - 2012-03-14 11:54 -0700

csiph-web