[asterisk-dev] [Code Review] 3476: Memory Pre- and Post-Test Condition

Mark Michelson reviewboard at asterisk.org
Thu Apr 24 18:11:53 CDT 2014



> On April 24, 2014, 10:46 p.m., Mark Michelson wrote:
> > ./asterisk/trunk/lib/python/asterisk/memory_test_condition.py, lines 151-153
> > <https://reviewboard.asterisk.org/r/3476/diff/1/?file=57812#file57812line151>
> >
> >     This seems like it's not going to work properly. related_test_condition.memory_info and self.memory_info are not guaranteed to have related memory allocations at the same ordinal positions in their lists. Also, it's possible for a requested allocation not to exist in related_test_condition.memory_info but to be present in self.memory_info.
> >     
> >     So I have two suggestions here. Change the  loop to iterate over self.memory_info instead of related_test_condition.memory_info. Get the precondition's memory information by key.
> >     
> >     Something like the following:
> >     
> >     for post_cond in self.memory_info:
> >         pre_cond = None
> >         for item in related_test_condition.memory_info:
> >             if post_cond['name'] == item['name']:
> >                 pre_cond = item
> >                 break
> >     
> >     Now you have your correlated pre and post memory counts for any given allocation. There may be some spiffier way of doing the inner loop, but I don't know it.
> >     
> >     Note that you may not find a corresponding pre_cond for a given post_cond. In this case, you'll have to assume that 0 bytes of memory had previously been allocated.

FWIW, I did find a bit of a slicker way to do the inner loop, but I don't really know if it's more readable:

for post_cond in self.memory_info:
    pre_cond = next((item for item in related_test_condition.memory_info if item['name'] == post_cond['name']), {})

That will set pre_cond to be either the corresponding item with the same name or an empty dict if none can be found.


- Mark


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/3476/#review11734
-----------------------------------------------------------


On April 24, 2014, 7:02 p.m., Benjamin Keith Ford wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/3476/
> -----------------------------------------------------------
> 
> (Updated April 24, 2014, 7:02 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Bugs: ASTERISK-18429
>     https://issues.asterisk.org/jira/browse/ASTERISK-18429
> 
> 
> Repository: testsuite
> 
> 
> Description
> -------
> 
> This testcondition can be enabled for any test using the keyword 'memory' under testconditions. The purpose of this testcondition is to check the memory allocated before and after the test, and make sure they are within a certain range. If the test wants to look at something specific (such as channel.c), then each allocation that you want to look at can also be specified in under 'allocations'. If both the global memory and individual allocations are to be checked by the test, that option can be enabled by setting 'both' to value True.
> 
> 
> Diffs
> -----
> 
>   ./asterisk/trunk/test-config.yaml 4944 
>   ./asterisk/trunk/lib/python/asterisk/test_conditions.py 4944 
>   ./asterisk/trunk/lib/python/asterisk/test_case.py 4944 
>   ./asterisk/trunk/lib/python/asterisk/memory_test_condition.py PRE-CREATION 
> 
> Diff: https://reviewboard.asterisk.org/r/3476/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Benjamin Keith Ford
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20140424/3529a541/attachment.html>


More information about the asterisk-dev mailing list