[#60671] tests: Add tests for peripherals with aliases
diff --git a/tests/tests.yaml b/tests/tests.yaml
index 6787e34..dcc93b4 100644
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -150,4 +150,5 @@
- tests/peripherals/S32K3XX_FlexCAN.robot
- tests/platforms/BeagleV-StarLight.robot
- tests/unit-tests/virtual-time.robot
+- tests/unit-tests/platform-file-aliases.robot
- tests/peripherals/VirtIO.robot
diff --git a/tests/unit-tests/PeripheralWithAliases.cs b/tests/unit-tests/PeripheralWithAliases.cs
new file mode 100644
index 0000000..60fc81c
--- /dev/null
+++ b/tests/unit-tests/PeripheralWithAliases.cs
@@ -0,0 +1,42 @@
+//
+// Copyright (c) 2010-2024 Antmicro
+//
+// This file is licensed under the MIT License.
+// Full license text is available in 'licenses/MIT.txt'.
+//
+using System.Collections.Generic;
+using Antmicro.Renode.Peripherals.Bus;
+using Antmicro.Renode.Core.Structure.Registers;
+using Antmicro.Renode.Core;
+using Antmicro.Renode.Time;
+using Antmicro.Renode.Logging;
+
+namespace Antmicro.Renode.Peripherals.Mocks
+{
+ public class PeripheralWithAliases : IPeripheral
+ {
+ public PeripheralWithAliases(
+ int normalParameter,
+ PeripheralModes mode,
+ [NameAlias("ctorAlias")] int aliasedParameter,
+ [NameAlias("ctorAliasDefault", warnOnUsage: false)] int aliasedParameterDefault = 0
+ )
+ {
+ this.InfoLog("{0} = {1}", nameof(normalParameter), normalParameter);
+ this.InfoLog("{0} = {1}", nameof(mode), mode);
+ this.InfoLog("{0} = {1}", nameof(aliasedParameter), aliasedParameter);
+ this.InfoLog("{0} = {1}", nameof(aliasedParameterDefault), aliasedParameterDefault);
+ }
+
+ public void Reset()
+ {
+ }
+
+ [NameAlias("Modes")]
+ public enum PeripheralModes
+ {
+ Mode1,
+ Mode2,
+ }
+ }
+}
diff --git a/tests/unit-tests/platform-file-aliases.robot b/tests/unit-tests/platform-file-aliases.robot
new file mode 100644
index 0000000..d45842f
--- /dev/null
+++ b/tests/unit-tests/platform-file-aliases.robot
@@ -0,0 +1,40 @@
+*** Keywords ***
+Create Machine
+ ${TEST_DIR}= Evaluate r"${CURDIR}".replace(" ", "\\ ")
+
+ Execute Command mach create
+ Execute Command i @${TEST_DIR}/PeripheralWithAliases.cs
+ Create Log Tester 0
+
+Create Test Peripheral
+ [Arguments] ${parameters}=${EMPTY}
+ Execute Command machine LoadPlatformDescriptionFromString "test: Mocks.PeripheralWithAliases @ sysbus {${parameters}}"
+
+*** Test Cases ***
+Should Create Peripheral Without Using Aliases
+ Create Machine
+ Create Test Peripheral normalParameter: 5; mode: PeripheralModes.Mode1; aliasedParameter: 10
+ Wait For Log Entry normalParameter = 5
+ Wait For Log Entry mode = Mode1
+ Wait For Log Entry aliasedParameter = 10
+ Wait For Log Entry aliasedParameterDefault = 0
+
+Should Create Peripheral Using Aliases
+ Create Machine
+ Create Test Peripheral normalParameter: -12; mode: Modes.Mode2; ctorAlias: 100; ctorAliasDefault: 15
+ Wait For Log Entry normalParameter = -12
+ Wait For Log Entry mode = Mode2
+ Wait For Log Entry aliasedParameter = 100
+ Wait For Log Entry aliasedParameterDefault = 15
+
+Should Warn When Using Aliases
+ Create Machine
+ Create Test Peripheral normalParameter: 5; mode: Modes.Mode1; ctorAlias: 10; ctorAliasDefault: 15
+ Wait For Log Entry Using alias 'Modes' for type 'PeripheralModes'
+ Wait For Log Entry Using alias 'ctorAlias' for parameter 'aliasedParameter'
+ Should Not Be In Log Using alias 'ctorAliasDefault' for parameter 'aliasedParameterDefault'
+
+Should Not Accept Invalid Aliases
+ Create Machine
+ Run Keyword And Expect Error *Could not find corresponding attribute for parameter 'aliasedParameter'*
+ ... Create Test Peripheral normalParameter: 5; mode: Modes.Mode1; invalidParameter: 10