1 //
2 // Copyright (c) 2010-2023 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 using Antmicro.Renode.Peripherals.Miscellaneous;
8 using Antmicro.Renode.Testing;
9 
10 namespace Antmicro.Renode.RobotFramework
11 {
12     internal class LedKeywords : TestersProvider<LEDTester, ILed>, IRobotFrameworkKeywordProvider
13     {
Dispose()14         public void Dispose()
15         {
16         }
17 
18         [RobotFrameworkKeyword(replayMode: Replay.Always)]
SetDefaultLedTimeout(float timeout)19         public void SetDefaultLedTimeout(float timeout)
20         {
21             globalDefaultTimeout = timeout;
22         }
23 
24         [RobotFrameworkKeyword(replayMode: Replay.Always)]
CreateLedTester(string led, float? defaultTimeout = null, string machine = null)25         public int CreateLedTester(string led, float? defaultTimeout = null, string machine = null)
26         {
27             return CreateNewTester(ledObject => new LEDTester(ledObject, defaultTimeout ?? globalDefaultTimeout), led, machine);
28         }
29 
30         [RobotFrameworkKeyword]
AssertLedState(bool state, float? timeout = null, int? testerId = null, bool pauseEmulation = false)31         public void AssertLedState(bool state, float? timeout = null, int? testerId = null, bool pauseEmulation = false)
32         {
33             GetTesterOrThrowException(testerId).AssertState(state, timeout, pauseEmulation);
34         }
35 
36         [RobotFrameworkKeyword]
AssertAndHoldLedState(bool initialState, float timeoutAssert, float timeoutHold, int? testerId = null, bool pauseEmulation = false)37         public void AssertAndHoldLedState(bool initialState, float timeoutAssert, float timeoutHold, int? testerId = null,
38             bool pauseEmulation = false)
39         {
40             GetTesterOrThrowException(testerId).AssertAndHoldState(initialState, timeoutAssert, timeoutHold, pauseEmulation);
41         }
42 
43         [RobotFrameworkKeyword]
AssertLedDutyCycle(float testDuration, double expectedDutyCycle, double tolerance = 0.05, int? testerId = null, bool pauseEmulation = false)44         public void AssertLedDutyCycle(float testDuration, double expectedDutyCycle, double tolerance = 0.05, int? testerId = null,
45             bool pauseEmulation = false)
46         {
47             GetTesterOrThrowException(testerId).AssertDutyCycle(testDuration, expectedDutyCycle, tolerance, pauseEmulation);
48         }
49 
50         [RobotFrameworkKeyword]
AssertLedIsBlinking(float testDuration, double onDuration, double offDuration, double tolerance = 0.05, int? testerId = null, bool pauseEmulation = false)51         public void AssertLedIsBlinking(float testDuration, double onDuration, double offDuration, double tolerance = 0.05,
52             int? testerId = null, bool pauseEmulation = false)
53         {
54             GetTesterOrThrowException(testerId).AssertIsBlinking(testDuration, onDuration, offDuration, tolerance, pauseEmulation);
55         }
56 
57         private float globalDefaultTimeout = 0;
58     }
59 }
60