A Dynamic Analysis Tool for Textually Modeled State Machines Using Umple
Total Page:16
File Type:pdf, Size:1020Kb
UmpleRun: a Dynamic Analysis Tool for Textually Modeled State Machines using Umple Hamoud Aljamaan, Timothy Lethbridge, Miguel Garzón, Andrew Forward School of Electrical Engineering and Computer Science University of Ottawa Ottawa, Canada [email protected], [email protected], [email protected], [email protected] Lethbridge.book Page 299 Tuesday, November 16, 2004 12:22 PM Abstract— In this paper, we present a tool named UmpleRun 4 demonstrates the tool usage. Subsequent sections walk that allows modelers to run the textually specified state machines through an example of instrumenting our example system and under analysis with an execution scenario to validate the model's performing dynamic analysis. dynamic behavior. In addition, trace specification will output Section 8.2 State diagrams 299 execution traces that contain model construct links. This will permit analysis of behavior at the model level. II. EXAMPLE CAR TRANSMISSION MODEL TO BE EXECUTED In this section, we will present the car transmission model Keywords— UmpleRun; Umple; UML; MOTL; stateNested machine; substates that and will guard be conditions our motivating example through this paper. It will execution trace; analysis Aalso state be diagram used to can explain be nested Umple inside and a state.MOTL The syntax. states of The the innerCar diagram are calledtransmission substates model. was inspired by a similar model in I. INTRODUCTION LethbridgeFigure 8.18 and shows Lagani a stateère’s diagram book [4] of. anThe automatic model consists transmission; of at the top one class with car transmission behavior captured by the state Umple [1,2] is a model-oriented programming language level this has three states: ‘Neutral’, ‘Reverse’ and a driving state, which is not machine shown in Fig. 1. The state machine consists of three that allows modelers to model UML constructs textually or explicitly named. The driving state is divided into substates corresponding to states: two simple states (‘neutral’ & ‘reverse’) and one graphically and generate high quality code in a number of the three gears that the system automatically chooses. The advantage of the composite state (‘drive’). The initial state for state machine is targeted programming languages. In an extension to the Umple nesting‘neutral’ is state.that it The shows composite compactly ‘drive’ that the state driving has three substates substates are all very similar language, MOTL was introduced to allow trace specification at tofor each transmission other – in levels particular, (i.e. ‘first’,that they ‘second’, can all transition and ‘third’). to ‘Neutral’ There at any time, the model level for various modeling constructs using model uponare events the user’s to trigger command. transitions The start between symbol states inside and the drivingsome are state shows that level textual trace directives [3]. Trace specification of state itguarded by default as in starts [driveSelected] at the ‘First’, substate.where event However, reachSecondSpeed the user can also manually machines, for instance, has the flexibility of tracing different selectwill not ‘First’ cause or ‘Second’a transition to force unless the Boolean transmission guard to is move evaluated into, and to stay in, these state machine components such as the whole state machine, substates.true. any state (at any level of nesting), and specific events. In this paper, we are presenting the UmpleRun a tool that selectReverse will allow modelers to execute textually modeled state Neutral Reverse machines written in Umple and validate their dynamic selectNeutral behavior using execution scenarios. If a modeler has written selectFirst selectDrive selectSecond selectNeutral MOTL trace directives for the model under analysis, reachSecondSpeed reachThirdSpeed UmpleRun will generate informative execution traces in [driveSelected] [driveSelected] First Second Third addition to the validation verdict. Execution traces can be used dropBelowSecondSpeed dropBelowThirdSpeed to analyse the system under the inspection. [driveSelected] Benefits of our approach include: selectFirst selectSecond • High-level validation of model dynamicFigure behavior 8.18: State diagram forFig. a 1.car’s Car automatic Transmission transmission State Machine showing [4] substates Accomplished by running models against execution scenarios to assert model behavior. The notation reachSecondSpeed[driveSelected] illustrates the use of a guard • White box testing of models: Thorough analysis, conditionThe .Car The transmission system will system only behaviorrespond wasto textuallythe indicated event verification and debugging of the models themselves (modeledreachSecondSpeed using Umple) if the conditionas shown in i nsquare Listing brackets 1. Lines is true. 3 to In 29Figure 8.18, this becomes possible. Models can be traced and then isrepresent used to theprevent car transmissionthe transmission status from state changing machine. gear Line if the4 driver had executed to produce execution traces, which can in manuallyshows the selected state name, first or while second lin gear.e 14 Adeclares guard condition that there differs is an from the type addition be analyzed. ofexit condition action associated we saw in withFigure this 8.14: state. a guard Line condition19 is an example is only evaluatedof a when its guarded event. In line 30 we are doing a code injection to event The remaining sections of this paper are organized as associated event occurs. selectDrive to set the Boolean attribute ‘driveSelected’ to true follows: Section 2 presents a Car transmission system example Figure 8.19 shows how we have converted Figure 8.14 to use nested substates. to differentiate it from the manual triggering caused by event that will be used to help illustrate our approach. Section 3 Now we need to show only one cancel transition and one requestToRegister ‘selectFirst’ which indicates the manual diving mode. describes the UmpleRun tool and execution scenarios. Section transition. Note that the ‘Planned’ state has a transition that points directly to the ‘NotEnoughStudents’ substate, and both the transitions to the ‘Closed’ state comes directly from the inner ‘EnoughStudents’ state. Finally, note that we have added an activity to the ‘Canceled’ state that deletes all registrations. Exercises 16 E162 There is a missing transition in Figure 8.18. Study the diagram, and see if you can find it (do not add any new states or event types). Listing 1: Car transmission Umple code constructor invocations, or method calls such as state machine event calls. Umple 1 class CarTransmission { 2 Boolean driveSelected = false; Listing 3: Execution scenario template 3 status { 4 neutral { Execution Scenario 5 selectReverse -> reverse; command, method_calls_after_commands ... 6 selectDrive -> drive; command_1, values_from_method_calls ... 7 selectFirst -> first; command_2, values_from_method_calls ... 8 selectSecond -> second; ... 9 } command_n, values_from_method_calls ... 10 reverse { 11 selectNeutral -> neutral; 12 } 13 drive { UmpleRun interprets and executes the commands in an 14 exit / { driveSelected = false;} execution scenario to produce a model validation verdict, 15 selectNeutral -> neutral; including the failed assertions. 16 selectFirst -> first; 17 selectSecond -> second; The dynamic validation process in this architecture is 18 first { presented in Fig. 2 and described below: 19 reachSecondSpeed [driveSelected] -> second; 20 } 1. Compilation: The input is an Umple model (named 21 second { 22 reachThirdSpeed [driveSelected] -> third; uModel). At this stage, uModel is parsed, analyzed 23 dropBelowSecondSpeed [driveSelected] -> first; and a Java system is created from the input model by 24 } the Umple compiler. 25 third { 2. Packaging: The Java classes are then packaged into a 26 dropBelowThirdSpeed -> second; 27 } container (JAR). 28 } 3. Loading the model into memory: A dynamic loader 29 } is created using the previously obtained JAR that will 30 before selectDrive { 31 driveSelected = true; allow creating new instances of the classes previously 32 } generated by our input model. 33 } 4. Validation: The commands in the execution scenario are run against the class instances and the assertions Using MOTL, we can write trace directives for trace are validated. The validation verdict is produced at specification of attributes and state machine. Listing 2 presents this final stage. an example of trace directives for the car transmission system. Using Umple’s mixin capability, we can write MOTL trace directives independent of the model. Line 2 indicates that we are interested in tracing any changes to the value of Boolean attribute ‘driveSelected’. Line 3 traces any incoming or outgoing transitions from or into state ‘neutral’. The directive in line 4 will trace whenever event ‘selectReverse’ is triggered causing a transition. More details on MOTL syntax can be found here [3]. Listing 2: MOTL trace directive examples Umple 1 class CarTransmission { 2 trace driveSelected; 3 trace neutral; 4 trace selectReverse; 5 } III. UMPLERUN UmpleRun is our tool for running a set of execution scenarios against a targeted model. This takes as input an execution scenario, a template for which is shown in Fig. 2. Line 1 of any scenario has the keyword ‘command’, then a set of query methods to execute at every step of execution. Lines 2 and onwards are of a set of commands to be executed to drive the scenario, along with assertions of the expected return values of the query methods. The commands can be object Fig. 2.