From f3deab469924265309aacfa7bca468d4e5c3db7a Mon Sep 17 00:00:00 2001 From: Ayush Mehra <97939637+amehra-ni@users.noreply.github.com> Date: Sat, 12 Feb 2022 02:06:58 +0530 Subject: [PATCH] Bug fix for timeout event with 0ms doesn't work with webvi. (#698) WebVI does not execute when an event structure is used with a timeout event of 0 ms. BUG [link](https://ni.visualstudio.com/DevCentral/_workitems/edit/1474951) Whenever event structure timeout was 0ms it goes to InitObservableTimerState with tickCount as 0x7FFFFFFFFFFFFFFF setting it to infinite wait instead of executing event structure immediately. ![1](https://user-images.githubusercontent.com/97939637/152923175-6637ef0a-9691-46e1-b215-3470675e1b2c.PNG) At first, I tried adding a condition in ReserveObservationStatesWithTimeout to check if tickCount>= 0 , pass tickCount in InitObservableTimerState so that we immediately trigger the observer whenever the timeout is 0. But during testing we found that it affected the behavior of other nodes as well such as the OneButtonDialog. So, didn't move forward with this approach. Now, I have added a condition if the timeout given is 0ms we execute the event structure immediately by going to the desired branch target. I have tested it with different configurations and the behavior was the same as the current vireo version. Have added test cases and have also tested with other test cases. --- source/core/Events.cpp | 2 +- .../EventStructureWith0msTimeout.vtr | 3 + .../EventStructureWithPositiveTimeout.vtr | 3 + .../ViaTests/EventStructureWith0msTimeout.via | 207 ++++++++++++++++++ .../EventStructureWithPositiveTimeout.via | 206 +++++++++++++++++ test-it/testList.json | 2 + 6 files changed, 422 insertions(+), 1 deletion(-) create mode 100644 test-it/ExpectedResults/EventStructureWith0msTimeout.vtr create mode 100644 test-it/ExpectedResults/EventStructureWithPositiveTimeout.vtr create mode 100644 test-it/ViaTests/EventStructureWith0msTimeout.via create mode 100644 test-it/ViaTests/EventStructureWithPositiveTimeout.via diff --git a/source/core/Events.cpp b/source/core/Events.cpp index cabb66d07..109456846 100644 --- a/source/core/Events.cpp +++ b/source/core/Events.cpp @@ -1052,7 +1052,7 @@ VIREO_FUNCTION_SIGNATUREV(WaitForEventsAndDispatch, WaitForEventsParamBlock) if (!occ.HasOccurred(staticCount, false)) { Observer* pObserver = clump->GetObservationStates(2); if (!pObserver) { - PlatformTickType future = msTimeout > 0 ? gPlatform.Timer.MillisecondsFromNowToTickCount(msTimeout) : 0; + PlatformTickType future = msTimeout >= 0 ? gPlatform.Timer.MillisecondsFromNowToTickCount(msTimeout) : 0; pObserver = clump->ReserveObservationStatesWithTimeout(2, future); occ.InsertObserver(pObserver+1, occ.Count()+1); return clump->WaitOnObservableObject(_this); diff --git a/test-it/ExpectedResults/EventStructureWith0msTimeout.vtr b/test-it/ExpectedResults/EventStructureWith0msTimeout.vtr new file mode 100644 index 000000000..60a72b6c7 --- /dev/null +++ b/test-it/ExpectedResults/EventStructureWith0msTimeout.vtr @@ -0,0 +1,3 @@ +User event generated +User event executed +Timeout event executed diff --git a/test-it/ExpectedResults/EventStructureWithPositiveTimeout.vtr b/test-it/ExpectedResults/EventStructureWithPositiveTimeout.vtr new file mode 100644 index 000000000..60a72b6c7 --- /dev/null +++ b/test-it/ExpectedResults/EventStructureWithPositiveTimeout.vtr @@ -0,0 +1,3 @@ +User event generated +User event executed +Timeout event executed diff --git a/test-it/ViaTests/EventStructureWith0msTimeout.via b/test-it/ViaTests/EventStructureWith0msTimeout.via new file mode 100644 index 000000000..04d5d1e39 --- /dev/null +++ b/test-it/ViaTests/EventStructureWith0msTimeout.via @@ -0,0 +1,207 @@ +// Autogenerated Vireo assembly file +// Generated on 02/10/2022 10:20:07 +//--------------------------------------------------- +//VI Definition: ::VireoDevSystem::Interactive::WebApp::index.gviweb +define (WebApp%3A%3Aindex%2Egviweb dv(.VirtualInstrument ( + Events: c( + e(c( // Event Struct 0 + e(dv(c( + e(.UInt32 eventSource) + e(.UInt32 eventType) + e(.UInt32 controlUID) + e(.UInt32 dynamicIndex) + ) (25 1000 0 1 ))local4) + e(dv(c( + e(.UInt32 eventSource) + e(.UInt32 eventType) + e(.UInt32 controlUID) + e(.UInt32 dynamicIndex) + ) (0 1 0 0 ))local9) + )) + ) + Locals: c( // Data Space + e(dv(.String 'WebApp::index.gviweb')local10) + de(dv(.String '')dataItem_String) + e(.String local12) + ce(dv(.String '')c13) + e(.UserEventRefNum<.String> local14) + e(.ErrorCluster local15) + e(.ErrorCluster local16) + e(.Boolean local17) + e(.EventRegRefNum eventRefnum) + ) ) + )> local20) + e(.ErrorCluster local21) + e(.UserEventRefNum<.String> local22) + e(.ErrorCluster local23) + ce(dv(.Boolean false)c24) + ce(dv(.Boolean true)c25) + e(.ErrorCluster local26) + e(.Boolean local27) + e(.Int32 local28) + e(.String local29) + e(.ErrorCluster local30) + ce(dv(.Int32 0)c31) + ce(dv(.Int32 2)c32) + ce(dv(.Int32 0)c33) + e(.Int32 local34) + e(.Int32 local35) + de(dv(.Boolean false)dataItem_Stop) + e(.Boolean local37) + e(.Int32 local38) + e(.Int32 local39) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + e(.UserEventRefNum<.String> UsrEvtRef) + e(.String event%20data) + ) local46) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + ) local51) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + e(.UserEventRefNum<.String> UsrEvtRef) + e(.String event%20data) + ) local58) + e(.String local59) + e(.String local60) + de(dv(.String '')dataItem_String_2) + e(.String local62) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + ) local67) + e(.UInt32 local68) + ce(dv(.String 'timeouts')c69) + de(dv(.String '')dataItem_String_3) + e(.String local71) + e(.EventRegRefNum eventRefnum) + ) ) + )> local74) + e(.EventRegRefNum eventRefnum) + ) ) + )> local77) + e(.EventRegRefNum eventRefnum) + ) ) + )> local80) + e(.ErrorCluster local81) + e(.ErrorCluster local82) + de(dv(.ErrorCluster (false 0 '' ))dataItem_ErrorOut) + e(.ErrorCluster local84) + e(.ErrorCluster local85) + e(.ErrorCluster local86) + ce(dv(.Int32 1000)c87) + ce(dv(.Boolean false)c88) + e(.Boolean local89) + e(.Boolean local90) + e(.ErrorCluster local91) + e(.Occurrence local92) + e(.Boolean local93) + ce(dv(.Int32 0)c94) + e(.EventRegRefNum eventRefnum) + ) ) + )> local97) + ce(dv(.Boolean false)c98) + ce(dv(.Int32 0)c99) + ce(dv(.Int32 0)c100) + ce(dv(.Int32 1)c101) + ) + clump(1 + Perch(3) + Copy(dataItem_String local12) + Copy(local85 local15) + CreateUserEvent(local14 local15) + Copy(local15 local16) + Copy(local16.status local17) + Copy(local86 local21) + RegisterForEvents(local20 local21 c87 local14) + Copy(local14 local22) + GenerateUserEvent(local22 local12 c88 local21) + Printf("User event generated\n") + Xor(c24 local17 local89) + BranchIfFalse(1 local89) + Xor(c25 local17 local90) + BranchIfFalse(2 local90) + Branch(3) + Perch(1) + Branch(0) + Perch(2) + Copy(local16 local26) + Copy(local26.status local27) + Copy(local26.code local28) + Copy(local26.source local29) + Copy(local91 local30) + JavaScriptInvoke(local92 true * 'LogLabVIEWError' * local27 local28 local29) + Branch(0) + Perch(0) + IsGE(c33 c32 local93) + BranchIfTrue(5 local93) + Branch(6) + Perch(6) + Copy(c94 local34) + Copy(c32 local35) + Copy(local20 local97) + Perch(7) + CopyAndReset(dataItem_Stop local37 c98) + WaitForEventsAndDispatch(c31 local20 c99 c100 local46 9 c101 local51 10) + Branch(8) + Perch(9) + Copy(local46 local58) + Copy(local58.event%20data local59) + Printf("User event executed\n") + StringToUpper(local59 local60 ) + Copy(local60 dataItem_String_2) + Copy(local20 local74) + Branch(8) + Perch(10) + Copy(local51 local67) + Copy(local67.Time local68) + Copy(c69 dataItem_String_3) + Copy(local20 local74) + Printf("Timeout event executed\n") + Branch(8) + Perch(8) + Increment(local34 local34 ) + BranchIfGE(11 local34 local35) + BranchIfTrue(11 local37) + Branch(7) + Perch(11) + Copy(local74 local80) + Branch(4) + Perch(5) + Copy(local77 local80) + Branch(4) + Perch(4) + UnregisterForEvents(local80 local21) + DestroyUserEvent(local22 local21) + Copy(local21 dataItem_ErrorOut) +/* Clump Ended. */ ) +))) +enqueue (WebApp%3A%3Aindex%2Egviweb) +//Finished!! :D diff --git a/test-it/ViaTests/EventStructureWithPositiveTimeout.via b/test-it/ViaTests/EventStructureWithPositiveTimeout.via new file mode 100644 index 000000000..c6e58ffbd --- /dev/null +++ b/test-it/ViaTests/EventStructureWithPositiveTimeout.via @@ -0,0 +1,206 @@ +// Autogenerated Vireo assembly file +// Generated on 02/10/2022 09:42:03 +//--------------------------------------------------- +define (WebApp%3A%3Aindex%2Egviweb dv(.VirtualInstrument ( + Events: c( + e(c( // Event Struct 0 + e(dv(c( + e(.UInt32 eventSource) + e(.UInt32 eventType) + e(.UInt32 controlUID) + e(.UInt32 dynamicIndex) + ) (25 1000 0 1 ))local4) + e(dv(c( + e(.UInt32 eventSource) + e(.UInt32 eventType) + e(.UInt32 controlUID) + e(.UInt32 dynamicIndex) + ) (0 1 0 0 ))local9) + )) + ) + Locals: c( // Data Space + e(dv(.String 'WebApp::index.gviweb')local10) + de(dv(.String '')dataItem_String) + e(.String local12) + ce(dv(.String '')c13) + e(.UserEventRefNum<.String> local14) + e(.ErrorCluster local15) + e(.ErrorCluster local16) + e(.Boolean local17) + e(.EventRegRefNum eventRefnum) + ) ) + )> local20) + e(.ErrorCluster local21) + e(.UserEventRefNum<.String> local22) + e(.ErrorCluster local23) + ce(dv(.Boolean false)c24) + ce(dv(.Boolean true)c25) + e(.ErrorCluster local26) + e(.Boolean local27) + e(.Int32 local28) + e(.String local29) + e(.ErrorCluster local30) + ce(dv(.Int32 10)c31) + ce(dv(.Int32 2)c32) + ce(dv(.Int32 0)c33) + e(.Int32 local34) + e(.Int32 local35) + de(dv(.Boolean false)dataItem_Stop) + e(.Boolean local37) + e(.Int32 local38) + e(.Int32 local39) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + e(.UserEventRefNum<.String> UsrEvtRef) + e(.String event%20data) + ) local46) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + ) local51) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + e(.UserEventRefNum<.String> UsrEvtRef) + e(.String event%20data) + ) local58) + e(.String local59) + e(.String local60) + de(dv(.String '')dataItem_String_2) + e(.String local62) + e(c( + e(.UInt32 Source) + e(.UInt32 Type) + e(.UInt32 Time) + e(.UInt32 Index) + ) local67) + e(.UInt32 local68) + ce(dv(.String 'timeouts')c69) + de(dv(.String '')dataItem_String_3) + e(.String local71) + e(.EventRegRefNum eventRefnum) + ) ) + )> local74) + e(.EventRegRefNum eventRefnum) + ) ) + )> local77) + e(.EventRegRefNum eventRefnum) + ) ) + )> local80) + e(.ErrorCluster local81) + e(.ErrorCluster local82) + de(dv(.ErrorCluster (false 0 '' ))dataItem_ErrorOut) + e(.ErrorCluster local84) + e(.ErrorCluster local85) + e(.ErrorCluster local86) + ce(dv(.Int32 1000)c87) + ce(dv(.Boolean false)c88) + e(.Boolean local89) + e(.Boolean local90) + e(.ErrorCluster local91) + e(.Occurrence local92) + e(.Boolean local93) + ce(dv(.Int32 0)c94) + e(.EventRegRefNum eventRefnum) + ) ) + )> local97) + ce(dv(.Boolean false)c98) + ce(dv(.Int32 0)c99) + ce(dv(.Int32 0)c100) + ce(dv(.Int32 1)c101) + ) + clump(1 + Perch(3) + Copy(dataItem_String local12) + Copy(local85 local15) + CreateUserEvent(local14 local15) + Copy(local15 local16) + Copy(local16.status local17) + Copy(local86 local21) + RegisterForEvents(local20 local21 c87 local14) + Copy(local14 local22) + GenerateUserEvent(local22 local12 c88 local21) + Xor(c24 local17 local89) + Printf("User event generated\n") + BranchIfFalse(1 local89) + Xor(c25 local17 local90) + BranchIfFalse(2 local90) + Branch(3) + Perch(1) + Branch(0) + Perch(2) + Copy(local16 local26) + Copy(local26.status local27) + Copy(local26.code local28) + Copy(local26.source local29) + Copy(local91 local30) + JavaScriptInvoke(local92 true * 'LogLabVIEWError' * local27 local28 local29) + Branch(0) + Perch(0) + IsGE(c33 c32 local93) + BranchIfTrue(5 local93) + Branch(6) + Perch(6) + Copy(c94 local34) + Copy(c32 local35) + Copy(local20 local97) + Perch(7) + CopyAndReset(dataItem_Stop local37 c98) + WaitForEventsAndDispatch(c31 local20 c99 c100 local46 9 c101 local51 10) + Branch(8) + Perch(9) + Copy(local46 local58) + Copy(local58.event%20data local59) + Printf("User event executed\n") + StringToUpper(local59 local60 ) + Copy(local60 dataItem_String_2) + Copy(local20 local74) + Branch(8) + Perch(10) + Copy(local51 local67) + Copy(local67.Time local68) + Copy(c69 dataItem_String_3) + Copy(local20 local74) + Printf("Timeout event executed\n") + Branch(8) + Perch(8) + Increment(local34 local34 ) + BranchIfGE(11 local34 local35) + BranchIfTrue(11 local37) + Branch(7) + Perch(11) + Copy(local74 local80) + Branch(4) + Perch(5) + Copy(local77 local80) + Branch(4) + Perch(4) + UnregisterForEvents(local80 local21) + DestroyUserEvent(local22 local21) + Copy(local21 dataItem_ErrorOut) +/* Clump Ended. */ ) +))) +enqueue (WebApp%3A%3Aindex%2Egviweb) +//Finished!! :D diff --git a/test-it/testList.json b/test-it/testList.json index e9696b4e4..8969d4c77 100644 --- a/test-it/testList.json +++ b/test-it/testList.json @@ -200,6 +200,8 @@ "Equals2DArr.via", "Ethan1.via", "EthanOpts2.via", + "EventStructureWith0msTimeout.via", + "EventStructureWithPositiveTimeout.via", "ExtraArrayInializers.via", "FixedArrays.via", "FlattenArray.via",