Skip to content

Commit

Permalink
Switch to Alire test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Chouteau committed Feb 14, 2025
1 parent a623206 commit b2f8fc2
Show file tree
Hide file tree
Showing 30 changed files with 559 additions and 626 deletions.
1 change: 0 additions & 1 deletion tests/alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.0.0"
executables = ["run_tests"]

[[depends-on]]
aunit = "*"
aaa = "~0.2.4"
usb_embedded = "*"

Expand Down
51 changes: 51 additions & 0 deletions tests/src/control_data_out.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
with AAA.Strings;

with HAL; use HAL;

with USB_Testing.UDC_Stub; use USB_Testing.UDC_Stub;
with USB_Testing.UDC_Scenarios;
with USB_Testing; use USB_Testing;
with USB.HAL.Device; use USB.HAL.Device;
with USB; use USB;

procedure Control_Data_Out is
Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => False) &
Stub_Scenario'(1 => (Kind => Set_Verbose, Verbose => True),
2 => (Kind => UDC_Event_E,
Evt => (Kind => Setup_Request,

-- Use an invalid request to trigger a stall
-- after the data transfer.
Req => ((Dev, 0, Class, Host_To_Device),
42, 0, 0, 16),
Req_EP => 0)),
3 => (Kind => UDC_Event_E,
Evt => (Kind => Transfer_Complete,
EP => (0, EP_Out),
BCNT => 16)
)
);

RX_Data : aliased constant UInt8_Array := (1 .. 16 => 42);

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Verbose on")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (HOST_TO_DEVICE,CLASS,DEV) Req: 42 Val: 0 Index: 0 Len: 16")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_OUT 0] BCNT: 16")
.Append ("UDC OUT Transfer [EP_OUT 0] 16 bytes")
.Append ("0000_0000_0000_0000: 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************")
.Append ("USB Class 1 Setup_Request Type: (HOST_TO_DEVICE,CLASS,DEV) Req: 42 Val: 0 Index: 0 Len: 16")
.Append ("0000_0000_0000_0000: 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************")
.Append ("UDC EP_Stall [EP_IN 0] TRUE")
.Append ("UDC EP_Stall [EP_OUT 0] TRUE")
.Append ("UDC Poll -> NONE");

begin
USB_Testing.UDC_Scenarios.Basic_UDC_Test (Scenario,
Expected,
RX_Data,
Early_Address => True);
end Control_Data_Out;
44 changes: 44 additions & 0 deletions tests/src/device_descriptor.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
with AAA.Strings;

with HAL; use HAL;

with USB_Testing.UDC_Scenarios;
with USB_Testing.UDC_Stub;
with USB_Testing; use USB_Testing;

procedure Device_Descriptor is

Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => True);

RX_Data : aliased constant UInt8_Array := (0 .. 1 => 0);

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Request_Buffer ([EP_IN 0], Len => 64)")
.Append ("UDC Request_Buffer ([EP_OUT 0], Len => 64)")
.Append ("UDC Initialize")
.Append ("UDC Start")
.Append ("UDC Poll -> RESET")
.Append ("UDC Reset")
.Append ("UDC EP_Setup [EP_IN 0] Type: CONTROL")
.Append ("UDC EP_Setup [EP_OUT 0] Type: CONTROL")
.Append ("UDC Set_Address 0")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Reset")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (DEVICE_TO_HOST,STAND,DEV) Req: 6 Val: 256 Index: 0 Len: 64")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Write_Packet [EP_IN 0] 18 bytes")
.Append ("0000_0000_0000_0000: 12 01 10 01 00 00 00 40 66 66 42 42 21 01 01 02 .......@ffBB!...")
.Append ("0000_0000_0000_0010: 03 01 ..")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 18")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_OUT 0] BCNT: 0")
.Append ("UDC Poll -> NONE");

begin
USB_Testing.UDC_Scenarios.Basic_UDC_Test (Scenario,
Expected,
RX_Data,
Early_Address => False,
Init_Verbose => True);
end Device_Descriptor;
36 changes: 36 additions & 0 deletions tests/src/get_device_config.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
with AAA.Strings;

with HAL; use HAL;

with USB_Testing.UDC_Stub; use USB_Testing.UDC_Stub;
with USB_Testing.UDC_Scenarios;
with USB_Testing; use USB_Testing;

procedure Get_Device_Config is

Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => False) &
UDC_Scenarios.Set_Address (Verbose => False, Addr => 42) &
UDC_Scenarios.Get_Config (Verbose => True);

RX_Data : aliased constant UInt8_Array := (0 .. 1 => 0);

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Verbose on")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (DEVICE_TO_HOST,STAND,DEV) Req: 6 Val: 512 Index: 0 Len: 255")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Write_Packet [EP_IN 0] 59 bytes")
.Append ("0000_0000_0000_0000: 09 02 3B 00 01 01 00 80 32 00 00 00 00 00 00 00 ..;.....2.......")
.Append ("0000_0000_0000_0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................")
.Append ("0000_0000_0000_0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................")
.Append ("0000_0000_0000_0030: 00 00 00 00 00 00 00 00 00 00 00 ...........")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 59")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_OUT 0] BCNT: 0")
.Append ("UDC Poll -> NONE");
begin
USB_Testing.UDC_Scenarios.Basic_UDC_Test (Scenario,
Expected,
RX_Data,
Early_Address => True);
end Get_Device_Config;
31 changes: 31 additions & 0 deletions tests/src/get_status.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
with AAA.Strings;

with HAL; use HAL;

with USB_Testing.UDC_Stub; use USB_Testing.UDC_Stub;
with USB_Testing.UDC_Scenarios;
with USB_Testing; use USB_Testing;

procedure Get_Status is
Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => False) &
UDC_Scenarios.Get_Status (Verbose => True);

RX_Data : aliased constant UInt8_Array := (1 .. 2 => 0);

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Verbose on")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (DEVICE_TO_HOST,STAND,DEV) Req: 0 Val: 0 Index: 0 Len: 2")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Write_Packet [EP_IN 0] 2 bytes")
.Append ("0000_0000_0000_0000: 00 00 ..")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 2")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Poll -> NONE");
begin

USB_Testing.UDC_Scenarios.Basic_UDC_Test (Scenario,
Expected,
RX_Data,
Early_Address => True);
end Get_Status;
67 changes: 67 additions & 0 deletions tests/src/iface_setup_dispatch.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
with AAA.Strings;

with HAL; use HAL;

with USB_Testing.UDC_Stub; use USB_Testing.UDC_Stub;
with USB_Testing.UDC_Scenarios;
with USB_Testing; use USB_Testing;
with USB.HAL.Device; use USB.HAL.Device;
with USB; use USB;

procedure Iface_Setup_Dispatch is

-- The Stub classes only have one interface each, so the interface IDs
-- should be:
-- -- Class 1 -> interface ID 0
-- -- Class 2 -> interface ID 1

Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => False) &
Stub_Scenario'(1 => (Kind => Set_Verbose, Verbose => True),
2 => (Kind => UDC_Event_E,
Evt => (Kind => Setup_Request,
Req => ((Iface, 0, Stand, Host_To_Device),
0, 0,
0, -- Interface ID of class 1
0),
Req_EP => 0)),
3 => (Kind => UDC_Event_E,
Evt => (Kind => Setup_Request,
Req => ((Iface, 0, Stand, Host_To_Device),
0, 0,
1, -- Interface ID of class 2
0),
Req_EP => 0)),
4 => (Kind => UDC_Event_E,
Evt => (Kind => Setup_Request,
Req => ((Iface, 0, Stand, Host_To_Device),
0, 0,
2, -- Invalid interface ID
0),
Req_EP => 0))
);

RX_Data : aliased constant UInt8_Array := (0 .. 1 => 0);

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Verbose on")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (HOST_TO_DEVICE,STAND,IFACE) Req: 0 Val: 0 Index: 0 Len: 0")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("USB Class 1 Setup_Request Type: (HOST_TO_DEVICE,STAND,IFACE) Req: 0 Val: 0 Index: 0 Len: 0")
.Append ("UDC EP_Write_Packet [EP_IN 0] ZLP")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 0")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (HOST_TO_DEVICE,STAND,IFACE) Req: 0 Val: 0 Index: 1 Len: 0")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("USB Class 2 Setup_Request Type: (HOST_TO_DEVICE,STAND,IFACE) Req: 0 Val: 0 Index: 1 Len: 0")
.Append ("UDC EP_Write_Packet [EP_IN 0] ZLP")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 0")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (HOST_TO_DEVICE,STAND,IFACE) Req: 0 Val: 0 Index: 2 Len: 0")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Stall [EP_IN 0] TRUE")
.Append ("UDC EP_Stall [EP_OUT 0] TRUE")
.Append ("UDC Poll -> NONE");
begin
USB_Testing.UDC_Scenarios.Two_Classes_UDC_Test (Scenario,
Expected,
RX_Data);
end Iface_Setup_Dispatch;
148 changes: 148 additions & 0 deletions tests/src/mouse.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
with Interfaces; use Interfaces;

with AAA.Strings;

with HAL; use HAL;
with USB_Testing.Output;

with USB_Testing.UDC_Stub; use USB_Testing.UDC_Stub;
with USB_Testing.UDC_Scenarios;
with USB_Testing; use USB_Testing;
with USB.HAL.Device; use USB.HAL.Device;

with USB; use USB;
with USB.Device.HID.Mouse;
with USB.Device; use USB.Device;

procedure Mouse is
Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => False) &
UDC_Scenarios.Set_Config (Verbose => True, Config_Id => 1) &
Stub_Scenario'(1 => (Kind => Set_Verbose, Verbose => True),
2 => (Kind => UDC_Event_E,
Evt => (Kind => Setup_Request,
-- Get Report descriptor
Req => ((Iface, 0, Stand, Device_To_Host),
6, 16#2200#, 0, 255),
Req_EP => 0)),
-- ACK the IN transfer with a ZLP
3 => (Kind => UDC_Event_E,
Evt => (Kind => Transfer_Complete,
EP => (0, EP_Out),
BCNT => 0))

);

RX_Data : aliased constant UInt8_Array := (1 .. 16 => 42);

HID_Class : aliased USB.Device.HID.Mouse.Instance;

Output : aliased USB_Testing.Output.Text_Output;

UDC : aliased UDC_Stub.Controller (Output'Unchecked_Access,
Scenario'Unchecked_Access,
RX_Data'Unchecked_Access,
Has_Early_Address => False,
Max_Packet_Size => 64,
EP_Buffers_Size => 256,
Number_Of_EPs => 1,
Init_Verbose => False);
Stack : USB.Device.USB_Device_Stack (Max_Classes => 1);
Result : USB.Device.Init_Result;

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Verbose on")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (HOST_TO_DEVICE,STAND,DEV) Req: 9 Val: 1 Index: 0 Len: 0")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Setup [EP_IN 1] Type: INTERRUPT")
.Append ("UDC EP_Write_Packet [EP_IN 0] ZLP")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 0")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (DEVICE_TO_HOST,STAND,IFACE) Req: 6 Val: 8704 Index: 0 Len: 255")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Write_Packet [EP_IN 0] 50 bytes")
.Append ("0000_0000_0000_0000: 05 01 09 02 A1 01 09 01 A1 00 05 09 19 01 29 03 ..............).")
.Append ("0000_0000_0000_0010: 15 00 25 01 95 03 75 01 81 02 95 01 75 05 81 03 ..%...u.....u...")
.Append ("0000_0000_0000_0020: 05 01 09 30 09 31 15 81 25 7F 75 08 95 02 81 06 ...0.1..%.u.....")
.Append ("0000_0000_0000_0030: C0 C0 ..")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 50")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_OUT 0] BCNT: 0")
.Append ("UDC Poll -> NONE")
.Append ("UDC EP_Write_Packet [EP_IN 1] 3 bytes")
.Append ("0000_0000_0000_0000: 00 0A 00 ...")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 1] BCNT: 3")
.Append ("UDC Poll -> NONE")
.Append ("UDC EP_Write_Packet [EP_IN 1] 3 bytes")
.Append ("0000_0000_0000_0000: 00 00 F6 ...")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 1] BCNT: 3")
.Append ("UDC Poll -> NONE")
.Append ("UDC EP_Write_Packet [EP_IN 1] 3 bytes")
.Append ("0000_0000_0000_0000: 01 00 00 ...")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 1] BCNT: 3")
.Append ("UDC Poll -> NONE");

S : Natural := 1;
begin

pragma Assert
(Stack.Register_Class (HID_Class'Unchecked_Access),
"USB STACK register class failed");

Result := Stack.Initialize
(Controller => UDC'Unchecked_Access,
Manufacturer => To_USB_String ("Manufacturer"),
Product => To_USB_String ("Product"),
Serial_Number => To_USB_String ("Serial"),
Max_Packet_Size => 64);

pragma Assert
(Result = Ok, "USB STACK Init failed: " & Result'Img);

Stack.Start;

loop
Stack.Poll;

if HID_Class.Ready then
case S is
when 1 =>
HID_Class.Set_Click (Btn1 => False,
Btn2 => False,
Btn3 => False);
HID_Class.Set_Move (10, 0);
HID_Class.Send_Report (UDC);
when 2 =>
HID_Class.Set_Click (Btn1 => False,
Btn2 => False,
Btn3 => False);
HID_Class.Set_Move (0, -10);
HID_Class.Send_Report (UDC);
when 3 =>
HID_Class.Set_Move (0, 0);
HID_Class.Set_Click (Btn1 => True,
Btn2 => False,
Btn3 => False);
HID_Class.Send_Report (UDC);
when others =>
null;
end case;
S := S + 1;
end if;

pragma Warnings (Off, "possible infinite loop");
exit when UDC.End_Of_Scenario;
pragma Warnings (On, "possible infinite loop");
end loop;

declare
use USB_Testing.Output;

Actual : constant AAA.Strings.Vector := Output.Dump;
begin
pragma Assert
(Equal (Expected, Actual),
"Diff in output: " & ASCII.LF &
Diff (Expected, Actual, "Expected", "Actual").Flatten (ASCII.LF));
end;

end Mouse;
Loading

0 comments on commit b2f8fc2

Please sign in to comment.