usb_embedded_0.3.0_ed111b35/tests/src/tests-utils.adb

 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
with System.Storage_Elements; use System.Storage_Elements;

with AUnit.Assertions; use AUnit.Assertions;

with HAL; use HAL;

with USB.Utils; use USB.Utils;

package body Tests.Utils is

   ---------------------
   -- Basic_Mem_Alloc --
   ---------------------

   procedure Basic_Mem_Alloc (Unused      : in out Null_Fixture)
   is
      Alloc : USB.Utils.Basic_RAM_Allocator (256);

      procedure Test (Alignment   : UInt8;
                      Len         : USB.Packet_Size;
                      Expect_Fail : Boolean)
      is
         Addr : constant Integer_Address :=
           To_Integer (Allocate (Alloc, Alignment, Len));
      begin
         Assert (Addr /= 0 or else Expect_Fail, "Allocation failed");
         Assert ((Addr mod Integer_Address (Alignment)) = 0, "Bad alignment");
      end Test;
   begin
      Test (1, 1, False);
      Test (2, 1, False);
      Test (4, 1, False);
      Test (8, 1, False);
      Test (16, 1, False);
      Test (32, 1, False);
      Test (4, 512, True);
   end Basic_Mem_Alloc;

begin
   Suite.Add_Test (Null_Caller.Create ("Basic Mem Alloc", Basic_Mem_Alloc'Access));
end Tests.Utils;