Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit e409f50

Browse files
akashlalpdeligia
authored andcommitted
Addon fix for #402 (#403)
* Addon fix for #402 * minor edits
1 parent 6f228b4 commit e409f50

File tree

3 files changed

+57
-26
lines changed

3 files changed

+57
-26
lines changed

Source/Core/Runtime/Machines/Machine.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ protected void Raise(Event e)
415415
// If the event is null, then report an error and exit.
416416
this.Assert(e != null, $"Machine '{base.Id}' is raising a null event.");
417417
this.RaisedEvent = new EventInfo(e, new EventOriginInfo(
418-
base.Id, this.GetType().Name, StateGroup.GetQualifiedStateName(this.CurrentState)));
418+
base.Id, this.GetType().Name, Machine.GetStateNameForLogging(this.CurrentState)));
419419
base.Runtime.NotifyRaisedEvent(this, this.RaisedEvent);
420420
}
421421

@@ -732,7 +732,7 @@ private EventInfo GetDefaultEvent()
732732
{
733733
base.Runtime.Logger.OnDefault(this.Id, this.CurrentStateName);
734734
return new EventInfo(new Default(), new EventOriginInfo(
735-
base.Id, this.GetType().Name, StateGroup.GetQualifiedStateName(this.CurrentState)));
735+
base.Id, this.GetType().Name, Machine.GetStateNameForLogging(this.CurrentState)));
736736
}
737737

738738
#endregion
@@ -1122,7 +1122,7 @@ private async Task ExecuteAction(CachedAction cachedAction)
11221122
private async Task GotoState(Type s, string onExitActionName)
11231123
{
11241124
this.Logger.OnGoto(this.Id, this.CurrentStateName,
1125-
$"{s.DeclaringType}.{StateGroup.GetQualifiedStateName(s)}");
1125+
$"{s.DeclaringType}.{Machine.GetStateNameForLogging(s)}");
11261126

11271127
// The machine performs the on exit action of the current state.
11281128
await this.ExecuteCurrentStateOnExit(onExitActionName);
@@ -1694,6 +1694,14 @@ private MethodInfo GetActionWithName(string actionName)
16941694
return method;
16951695
}
16961696

1697+
/// <summary>
1698+
/// Returns the state name to be used for logging purposes.
1699+
/// </summary>
1700+
/// <param name="state">The machine state.</param>
1701+
/// <returns>The state name.</returns>
1702+
internal static string GetStateNameForLogging(Type state) =>
1703+
state == null ? "None" : StateGroup.GetQualifiedStateName(state);
1704+
16971705
#endregion
16981706

16991707
#region code coverage methods

Source/TestingServices/Runtime/TestingRuntime.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ private EventInfo EnqueueEvent(Machine machine, Event e, BaseMachine sender, Gui
777777
if (sender != null && sender is Machine)
778778
{
779779
originInfo = new EventOriginInfo(sender.Id, (sender as Machine).GetType().Name,
780-
this.GetStateNameForCoverageReport((sender as Machine).CurrentState));
780+
Machine.GetStateNameForLogging((sender as Machine).CurrentState));
781781
}
782782
else
783783
{
@@ -1504,7 +1504,7 @@ private void ReportActivityCoverageOfReceivedEvent(Machine machine, EventInfo ev
15041504
string originState = eventInfo.OriginInfo.SenderStateName;
15051505
string edgeLabel = eventInfo.EventType.Name;
15061506
string destMachine = machine.GetType().Name;
1507-
string destState = this.GetStateNameForCoverageReport(machine.CurrentState);
1507+
string destState = Machine.GetStateNameForLogging(machine.CurrentState);
15081508

15091509
this.CoverageInfo.AddTransition(originMachine, originState, edgeLabel, destMachine, destState);
15101510
}
@@ -1519,12 +1519,12 @@ private void ReportActivityCoverageOfMonitorEvent(BaseMachine sender, Monitor mo
15191519
{
15201520
string originMachine = (sender == null) ? "Env" : sender.GetType().Name;
15211521
string originState = (sender == null) ? "Env" :
1522-
(sender is Machine) ? this.GetStateNameForCoverageReport((sender as Machine).CurrentState) :
1522+
(sender is Machine) ? Machine.GetStateNameForLogging((sender as Machine).CurrentState) :
15231523
"Env";
15241524

15251525
string edgeLabel = e.GetType().Name;
15261526
string destMachine = monitor.GetType().Name;
1527-
string destState = this.GetStateNameForCoverageReport(monitor.CurrentState);
1527+
string destState = Machine.GetStateNameForLogging(monitor.CurrentState);
15281528

15291529
this.CoverageInfo.AddTransition(originMachine, originState, edgeLabel, destMachine, destState);
15301530
}
@@ -1587,31 +1587,31 @@ private void ReportActivityCoverageOfMonitor(Monitor monitor)
15871587
private void ReportActivityCoverageOfStateTransition(Machine machine, EventInfo eventInfo)
15881588
{
15891589
string originMachine = machine.GetType().Name;
1590-
string originState = this.GetStateNameForCoverageReport(machine.CurrentState);
1590+
string originState = Machine.GetStateNameForLogging(machine.CurrentState);
15911591
string destMachine = machine.GetType().Name;
15921592

15931593
string edgeLabel = string.Empty;
15941594
string destState = string.Empty;
15951595
if (eventInfo.Event is GotoStateEvent)
15961596
{
15971597
edgeLabel = "goto";
1598-
destState = this.GetStateNameForCoverageReport((eventInfo.Event as GotoStateEvent).State);
1598+
destState = Machine.GetStateNameForLogging((eventInfo.Event as GotoStateEvent).State);
15991599
}
16001600
else if (eventInfo.Event is PushStateEvent)
16011601
{
16021602
edgeLabel = "push";
1603-
destState = this.GetStateNameForCoverageReport((eventInfo.Event as PushStateEvent).State);
1603+
destState = Machine.GetStateNameForLogging((eventInfo.Event as PushStateEvent).State);
16041604
}
16051605
else if (machine.GotoTransitions.ContainsKey(eventInfo.EventType))
16061606
{
16071607
edgeLabel = eventInfo.EventType.Name;
1608-
destState = this.GetStateNameForCoverageReport(
1608+
destState = Machine.GetStateNameForLogging(
16091609
machine.GotoTransitions[eventInfo.EventType].TargetState);
16101610
}
16111611
else if (machine.PushTransitions.ContainsKey(eventInfo.EventType))
16121612
{
16131613
edgeLabel = eventInfo.EventType.Name;
1614-
destState = this.GetStateNameForCoverageReport(
1614+
destState = Machine.GetStateNameForLogging(
16151615
machine.PushTransitions[eventInfo.EventType].TargetState);
16161616
}
16171617
else
@@ -1631,10 +1631,10 @@ private void ReportActivityCoverageOfStateTransition(Machine machine, EventInfo
16311631
private void ReportActivityCoverageOfPopTransition(Machine machine, Type fromState, Type toState)
16321632
{
16331633
string originMachine = machine.GetType().Name;
1634-
string originState = this.GetStateNameForCoverageReport(fromState);
1634+
string originState = Machine.GetStateNameForLogging(fromState);
16351635
string destMachine = machine.GetType().Name;
16361636
string edgeLabel = "pop";
1637-
string destState = this.GetStateNameForCoverageReport(toState);
1637+
string destState = Machine.GetStateNameForLogging(toState);
16381638

16391639
this.CoverageInfo.AddTransition(originMachine, originState, edgeLabel, destMachine, destState);
16401640
}
@@ -1647,20 +1647,20 @@ private void ReportActivityCoverageOfPopTransition(Machine machine, Type fromSta
16471647
private void ReportActivityCoverageOfMonitorTransition(Monitor monitor, Event e)
16481648
{
16491649
string originMachine = monitor.GetType().Name;
1650-
string originState = this.GetStateNameForCoverageReport(monitor.CurrentState);
1650+
string originState = Machine.GetStateNameForLogging(monitor.CurrentState);
16511651
string destMachine = originMachine;
16521652

16531653
string edgeLabel = string.Empty;
16541654
string destState = string.Empty;
16551655
if (e is GotoStateEvent)
16561656
{
16571657
edgeLabel = "goto";
1658-
destState = this.GetStateNameForCoverageReport((e as GotoStateEvent).State);
1658+
destState = Machine.GetStateNameForLogging((e as GotoStateEvent).State);
16591659
}
16601660
else if (monitor.GotoTransitions.ContainsKey(e.GetType()))
16611661
{
16621662
edgeLabel = e.GetType().Name;
1663-
destState = this.GetStateNameForCoverageReport(
1663+
destState = Machine.GetStateNameForLogging(
16641664
monitor.GotoTransitions[e.GetType()].TargetState);
16651665
}
16661666
else
@@ -1734,14 +1734,6 @@ internal Fingerprint GetProgramState()
17341734
return fingerprint;
17351735
}
17361736

1737-
/// <summary>
1738-
/// Returns the state name to be used for reporting code coverage.
1739-
/// </summary>
1740-
/// <param name="state">The machine state.</param>
1741-
/// <returns>The state name.</returns>
1742-
private string GetStateNameForCoverageReport(Type state) =>
1743-
state == null ? "None" : StateGroup.GetQualifiedStateName(state);
1744-
17451737
#endregion
17461738

17471739
#region logging

Tests/TestingServices.Tests.Unit/Features/OnExceptionTest.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected override OnExceptionOutcome OnException(string method, Exception ex)
200200
}
201201
}
202202

203-
class Done: Event { }
203+
class Done : Event { }
204204

205205
class GetsDone : Monitor
206206
{
@@ -260,6 +260,27 @@ protected override void OnHalt()
260260
}
261261
}
262262

263+
class M6 : Machine
264+
{
265+
[Start]
266+
class Init : MachineState { }
267+
268+
protected override OnExceptionOutcome OnException(string method, Exception ex)
269+
{
270+
try
271+
{
272+
this.Assert(ex is UnhandledEventException);
273+
this.Send(this.Id, new E(this.Id));
274+
this.Raise(new E());
275+
}
276+
catch (Exception)
277+
{
278+
this.Assert(false);
279+
}
280+
return OnExceptionOutcome.HandledException;
281+
}
282+
}
283+
263284
[Fact]
264285
public void TestExceptionSuppressed1()
265286
{
@@ -353,5 +374,15 @@ public void TestMachineHalt2()
353374
AssertSucceeded(test);
354375
}
355376

377+
[Fact]
378+
public void TestSendOnUnhandledEventException()
379+
{
380+
var test = new Action<PSharpRuntime>((r) => {
381+
var m = r.CreateMachine(typeof(M6));
382+
r.SendEvent(m, new E());
383+
});
384+
385+
AssertSucceeded(test);
386+
}
356387
}
357388
}

0 commit comments

Comments
 (0)