Natools

Check-in [b886bca8bd]
Login
Overview
Comment:chunked_strings-tests-memory: new test suite for memory usage
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b886bca8bdc8cf128fe68d10ea6244be2cd74b2b
User & Date: nat on 2013-09-15 15:28:25
Other Links: manifest | tags
Context
2013-09-22
15:29
References: new package implementing a reference counter check-in: 4306b2b680 user: nat tags: trunk
2013-09-15
15:28
chunked_strings-tests-memory: new test suite for memory usage check-in: b886bca8bd user: nat tags: trunk
2013-09-13
21:00
chunked_strings-tests-coverage: add a few more tests check-in: c9a8cc0df1 user: nat tags: trunk
Changes

Added tests/natools-chunked_strings-tests-memory.adb version [82efed8199].

















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
------------------------------------------------------------------------------
-- Copyright (c) 2013, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

procedure Natools.Chunked_Strings.Tests.Memory
  (Report : in out Natools.Tests.Reporter'Class)
is
   function Allocated_Size (Source : in Chunked_String) return Natural;
      --  Return the number of allocated characters in Source


   function Allocated_Size (Source : in Chunked_String) return Natural is
   begin
      if Source.Data = null or else Source.Data'Last < 1 then
         return 0;
      end if;

      return (Source.Data'Last - 1) * Source.Chunk_Size
        + Source.Data (Source.Data'Last)'Last;
   end Allocated_Size;

   package NT renames Natools.Tests;
begin
   NT.Section (Report, "Extra tests for memory usage");

   declare
      Name : constant String := "Procedure Preallocate";
      CS : Chunked_String;
      Memory_Ref : Natural;
      Repeats : constant Positive := 50;
   begin
      Preallocate (CS, Repeats * Name'Length);
      Memory_Ref := Allocated_Size (CS);

      for I in 1 .. Repeats loop
         Append (CS, Name);
      end loop;

      if Memory_Ref /= Allocated_Size (CS) then
         NT.Item (Report, Name, NT.Fail);
         NT.Info (Report, "Memory after preallocation:"
           & Natural'Image (Memory_Ref));
         NT.Info (Report, "Memory after insertions:"
           & Natural'Image (Allocated_Size (CS)));
      else
         NT.Item (Report, Name, NT.Success);
      end if;
   exception
      when Error : others => NT.Report_Exception (Report, Name, Error);
   end;

   declare
      Name : constant String := "Procedure Free_Extra_Memory";
      CS : Chunked_String;
      Memory_Ref : Natural;
      Repeats : constant Positive := 50;
   begin
      Preallocate (CS, Repeats * Name'Length);
      Memory_Ref := Allocated_Size (CS);
      Free_Extra_Memory (CS);

      if Memory_Ref <= Allocated_Size (CS) then
         NT.Item (Report, Name, NT.Fail);
         NT.Info (Report, "Memory before:"
           & Natural'Image (Memory_Ref));
         NT.Info (Report, "Memory after:"
           &  Natural'Image (Allocated_Size (CS)));
      else
         NT.Item (Report, Name, NT.Success);
      end if;
   exception
      when Error : others => NT.Report_Exception (Report, Name, Error);
   end;

   Natools.Tests.End_Section (Report);
end Natools.Chunked_Strings.Tests.Memory;

Added tests/natools-chunked_strings-tests-memory.ads version [8359a5ece7].





















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
------------------------------------------------------------------------------
-- Copyright (c) 2013, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.Chunked_Strings.Tests.Memory contains extra test cases to ensure --
-- memory usage works as expected.                                          --
------------------------------------------------------------------------------

with Natools.Tests;

generic procedure Natools.Chunked_Strings.Tests.Memory
  (Report : in out Natools.Tests.Reporter'Class);
pragma Preelaborate (Memory);

Modified tests/natools-chunked_strings-tests.adb from [ee8c88c27b] to [8cd7cb1ae5].

16
17
18
19
20
21
22

23
24
25
26
27
28
29

with Natools.Chunked_Strings.Tests.Coverage;
with Natools.Chunked_Strings.Tests.CXA4010;
with Natools.Chunked_Strings.Tests.CXA4011;
with Natools.Chunked_Strings.Tests.CXA4030;
with Natools.Chunked_Strings.Tests.CXA4031;
with Natools.Chunked_Strings.Tests.CXA4032;

with Natools.Accumulators.Tests;

package body Natools.Chunked_Strings.Tests is
   package NT renames Natools.Tests;

   procedure All_Blackbox_Tests (Report : in out Natools.Tests.Reporter'Class)
   is







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

with Natools.Chunked_Strings.Tests.Coverage;
with Natools.Chunked_Strings.Tests.CXA4010;
with Natools.Chunked_Strings.Tests.CXA4011;
with Natools.Chunked_Strings.Tests.CXA4030;
with Natools.Chunked_Strings.Tests.CXA4031;
with Natools.Chunked_Strings.Tests.CXA4032;
with Natools.Chunked_Strings.Tests.Memory;
with Natools.Accumulators.Tests;

package body Natools.Chunked_Strings.Tests is
   package NT renames Natools.Tests;

   procedure All_Blackbox_Tests (Report : in out Natools.Tests.Reporter'Class)
   is
56
57
58
59
60
61
62










63
64
65
66
67
68

69
70
71
72
73
74
75
      procedure Test_Coverage is new Coverage;
   begin
      NT.Section (Report, "Greybox tests for Chunked_Strings");
      Test_Coverage (Report);
      NT.End_Section (Report);
   end All_Greybox_Tests;












   procedure All_Tests (Report : in out Natools.Tests.Reporter'Class) is
   begin
      NT.Section (Report, "All tests of Chunked_Strings");
      All_Blackbox_Tests (Report);
      All_Greybox_Tests (Report);

      NT.End_Section (Report);
   end All_Tests;



   procedure Dump (Report : in out Natools.Tests.Reporter'Class;
                   Dumped : in     Chunked_String)







>
>
>
>
>
>
>
>
>
>






>







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
      procedure Test_Coverage is new Coverage;
   begin
      NT.Section (Report, "Greybox tests for Chunked_Strings");
      Test_Coverage (Report);
      NT.End_Section (Report);
   end All_Greybox_Tests;


   procedure All_Whitebox_Tests (Report : in out Natools.Tests.Reporter'Class)
   is
      procedure Test_Memory is new Memory;
   begin
      NT.Section (Report, "Whitebox tests for Chunked_Strings");
      Test_Memory (Report);
      NT.End_Section (Report);
   end All_Whitebox_Tests;


   procedure All_Tests (Report : in out Natools.Tests.Reporter'Class) is
   begin
      NT.Section (Report, "All tests of Chunked_Strings");
      All_Blackbox_Tests (Report);
      All_Greybox_Tests (Report);
      All_Whitebox_Tests (Report);
      NT.End_Section (Report);
   end All_Tests;



   procedure Dump (Report : in out Natools.Tests.Reporter'Class;
                   Dumped : in     Chunked_String)

Modified tests/natools-chunked_strings-tests.ads from [ab60cb24ca] to [00c67a17ec].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.Chunked_Strings.Tests is the test suite for Chunked_String.      --
--                                                                          --
-- It currently contains only black-box tests (i.e. without any assumption  --
-- on the internal implementaiton), taken from Unbounded_String tests in    --
-- ACATS.                                                                   --
--                                                                          --
-- It also provides private helper functions used in more specialized test  --
-- packages.                                                                --
------------------------------------------------------------------------------

with Natools.Tests;

generic package Natools.Chunked_Strings.Tests is
   pragma Preelaborate (Tests);

   procedure All_Blackbox_Tests (Report : in out Natools.Tests.Reporter'Class);

   procedure All_Greybox_Tests (Report : in out Natools.Tests.Reporter'Class);



   procedure All_Tests (Report : in out Natools.Tests.Reporter'Class);

private

   procedure Dump (Report : in out Natools.Tests.Reporter'Class;
                   Dumped : in     Chunked_String);







<
<
<
<












>
>







13
14
15
16
17
18
19




20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.Chunked_Strings.Tests is the test suite for Chunked_String.      --
--                                                                          --




-- It also provides private helper functions used in more specialized test  --
-- packages.                                                                --
------------------------------------------------------------------------------

with Natools.Tests;

generic package Natools.Chunked_Strings.Tests is
   pragma Preelaborate (Tests);

   procedure All_Blackbox_Tests (Report : in out Natools.Tests.Reporter'Class);

   procedure All_Greybox_Tests (Report : in out Natools.Tests.Reporter'Class);

   procedure All_Whitebox_Tests (Report : in out Natools.Tests.Reporter'Class);

   procedure All_Tests (Report : in out Natools.Tests.Reporter'Class);

private

   procedure Dump (Report : in out Natools.Tests.Reporter'Class;
                   Dumped : in     Chunked_String);