PyModel Model-based testing in Python



Similar documents
Model-Based Testing of Web Applications using NModel

Welcome to PowerClaim Net Services!

NAS 253 Introduction to Backup Plan

Test Case 3 Active Directory Integration

Algorithmic Software Verification

Wharf T&T Limited DDoS Mitigation Service Customer Portal User Guide

Techniques and Tools for Rich Internet Applications Testing

Secure Messaging Service

WebSphere Business Monitor V7.0: Clustering Single cluster deployment environment pattern

How To Install A New Database On A 2008 R2 System With A New Version Of Aql Server 2008 R 2 On A Windows Xp Server 2008 (Windows) R2 (Windows Xp) (Windows 8) (Powerpoint) (Mysql

CentreWare for Microsoft Operations Manager. User Guide

Outlook Connector Installation & Configuration groupwaresolution.net Hosted MS Exchange Alternative On Linux

TTCN-3, Qtronic and SIP

Adobe Digital Publishing Security FAQ

EJGH Encryption User Tip Sheet of 8

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

Active Directory Integration

Napster and Gnutella: a Comparison of two Popular Peer-to-Peer Protocols. Anthony J. Howe Supervisor: Dr. Mantis Cheng University of Victoria

MANUAL USER GUIDE FOR EMR PRIMARY HEALTH CARE SYSTEM

OCS Virtual image. User guide. Version: Viking Edition

CA Nimsoft Service Desk

SOS SO S O n O lin n e lin e Bac Ba kup cku ck p u USER MANUAL

How to remotely access your Virtual Desktop from outside the college using VMware View Client. How to guide

MSSQL quick start guide

Replication on Virtual Machines

PhoneCrypt Desktop. Phone Encryption Software. PhoneCrypt Manual Mobile phone encryption for Windows Platforms

Configuring and Integrating Oracle

How To Use 1Bay 1Bay From Awn.Net On A Pc Or Mac Or Ipad (For Pc Or Ipa) With A Network Box (For Mac) With An Ipad Or Ipod (For Ipad) With The

FIRST HOPE BANK BUSINESS ONLINE BANKING DIRECT CONNECT WITH QUICKBOOKS

IBM Aspera Add-in for Microsoft Outlook 1.3.2

Quick Start : i-fax User Guide

How To Backup Your Computer With A Remote Drive Client On A Pc Or Macbook Or Macintosh (For Macintosh) On A Macbook (For Pc Or Ipa) On An Uniden (For Ipa Or Mac Macbook) On

How To Install Ru-Vpn On A Pc Or Macbook Or Ipad (For Macbook) With A Microsoft Macbook (For Pc) With An Ipad Or Ipa (For A Macbook). Pc (For An

Windows Clients and GoPrint Print Queues

How to create additional accounts. Click on the Accounts icon. From here the rest is pretty straight forward to Add a New Account.

Testing LTL Formula Translation into Büchi Automata

Model-based Testing: Next Generation Functional Software Testing

Egnyte App for Android Quick Start Guide

Diagonalization. Ahto Buldas. Lecture 3 of Complexity Theory October 8, Slides based on S.Aurora, B.Barak. Complexity Theory: A Modern Approach.

Creating a DUO MFA Service in AWS

Step 1 : Remove Old Versions of Java

SNMP Manager User s Manual

Check current version of Remote Desktop Connection for Mac.. Page 2. Remove Old Version Remote Desktop Connection..Page 8

SMock A Test Platform for the Evaluation of Monitoring Tools

Comodo LoginPro Software Version 1.5

HP Business Process Monitor

CMPT 471 Networking II

Semantic based Web Application Firewall (SWAF V 1.6) Operations and User Manual. Document Version 1.0

How To Set Up An Openfire With Libap On A Cdd (Dns) On A Pc Or Mac Or Ipad (Dnt) On An Ipad Or Ipa (Dn) On Your Pc Or Ipo (D

Users Guide. SelenioFlex File. Version

Formal Verification by Model Checking

Provincial User Manual

my.airproducts.com Windows Vista Client Configuration

Oracle EXAM - 1Z Oracle Weblogic Server 11g: System Administration I. Buy Full Product.

HP Operations Orchestration Software

Integrating Webalo with LDAP or Active Directory

Intrusion Detection via Static Analysis

Hosted Voice Product Training Automatic Call Distributor (ACD)

PrestoFax User Guide Version 3.0

NETASQ ACTIVE DIRECTORY INTEGRATION

Using MailStore to Archive MDaemon

Deployment of Keepit for Windows

How To Create A Diagram On Rational Software Development Platform

Zimbra Connector for Outlook User Guide. Release 6.0

Department of Veterans Affairs VistA Integration Adapter Release Enhancement Manual

Lab Configure Basic AP Security through IOS CLI

WhatsUp Gold v16.3 Installation and Configuration Guide

Remote PC Guide for Standalone PC Implementation

Project management integrated into Outlook

Simulation of wireless ad-hoc sensor networks with QualNet

Introduction to SPIN. Acknowledgments. Parts of the slides are based on an earlier lecture by Radu Iosif, Verimag. Ralf Huuck. Features PROMELA/SPIN

How to train your Browser Controller

CLIENT SERVER BASED FILE SHARING SYSTEM

Voice Call Addon for Ozeki NG SMS Gateway

FTP Use. Internal NPS FTP site instructions using Internet Explorer:

Mini User Guide. Updating your contact details..2. Setting your Security Questions..4. Changing your password..5. Forgotten password...

Campus VPN. Version 1.0 September 22, 2008

Listeners. Formats. Free Form. Formatted

About Node Manager and the WebLogic Scripting Tool

Database Selection Guide

Configuring Notification for Business Glossary

CA Performance Center

Getting Started with StoreGrid Cloud

Data Domain Profiling and Data Masking for Hadoop

Remote Web Access (vpn)

New Single Sign-on Options for IBM Lotus Notes & Domino IBM Corporation

OneLogin Integration User Guide

Model based testing tools. Olli Pekka Puolitaival

Communications Software Engineering Design Model

Voice over IP. Demonstration 1: VoIP Protocols. Network Environment

Preparing your Domain to transfer from Go Daddy

Using Microsoft Windows Authentication for Microsoft SQL Server Connections in Data Archive

Default configuration for the Workstation service and the Server service

Transcription:

PyModel University of Washington jon@u.washington.edu http://staff.washington.edu/jon/pymodel/www/

Model-based testing Unit testing: code each test case, including an assertion that checks whether the test passed Model-based testing: code a model that generates as many test cases as desired, and also acts as the oracle that checks whether any case passed A model-based testing project is a programming project! In PyModel the models are coded in Python. It is convenient when the implementation under test is also in Python (but this is not required).

Model-based testing What problem does model-based testing solve? Testing behavior: ongoing activities that may exhibit history-dependence and nondeterminism. Many variations (data values, interleavings, etc.) should be tested for each scenario (or use case). So many test cases are needed that it is not feasible to code them all by hand. Examples: communication protocols, web applications, control systems, user interfaces,...

Behavior We need to test behavior: ongoing activities that may exhibit history dependence and nondeterminism. We represent behavior with traces: sequences of actions with arguments. Specify a system by describing which traces are allowed, and which are forbidden. Example: alternating bit protocol Allowed Send() Ack() Send() Ack() Allowed Send() Send() Ack() Send() Ack() Ack() Send() Ack() Allowed Send() Send() Ack() Send() Ack() Send() Allowed Send() Ack() Send() Ack() Ack() Send() Ack() Forbidden Send() Ack() Send() Ack() Forbidden Send() Ack() Send() Ack()

Finite State Machines Finite State Machines (FSMs) can represent finite behaviors. Every path through the graph represents an allowed trace. Ack() Send() Send() Ack() Send() Ack() Ack() Send() Ack() Send() Ack() Ack() Send() Allowed Send() Ack() Send() Ack() Allowed Send() Send() Ack() Send() Ack() Ack() Send() Ack() Allowed Send() Send() Ack() Send() Ack() Send() Allowed Send() Ack() Send() Ack() Ack() Send() Ack() Forbidden Send() Ack() Send() Ack() Forbidden Send() Ack() Send() Ack()

Finite State Machines FSMs are one kind of model in PyModel, coded as follows: Ack() Send() Send() Ack() Send() Ack() Ack() Send() Ack() Send() Ack() Ack() Send() graph = ((, (Send, (,), None), ), (, (Ack, (,), None), ), (, (Send, (,), None), ), (, (Ack, (,), None), ),... etc.... (, (Send, (,), None), )) The PyModel Graphics program pmg generates graphics from an FSM in this form.

Generating tests The PyModel Tester pmt generates traces from a model. Each trace describes a test run, including the expected test results. Offline testing: pmt saves the traces in a test suite. On-the-fly testing: pmt executes the traces as they are generated. C:\Users\jon\Documents\mbt\samples\abp>pmt.py -n ABP Send(,) Send(,) Ack(,) Send(,) Ack(,) Send(,) Ack(,) Send(,) Ack(,) Ack(,) Finished at step, reached accepting state

Model programs Model programs are another kind of model in PyModel. They can describe behaviors where the action arguments can have an infinite (very large) number of values. A model program consists of state variables, action functions and enabling conditions. stack = list() # State def Push(x): # Push is always enabled global stack stack.insert(,x) def Pop(): # Pop requires an enabling condition global stack result = stack[] del stack[] return result def PopEnabled(): return stack # Pop is enabled when the stack is not empty

Exploration The PyModel Analyzer pma generates an FSM from a model program by a process called Exploration.

Exploration The PyModel Analyzer pma generates an FSM from a model program by a process called Exploration.

Exploration The PyModel Analyzer pma generates an FSM from a model program by a process called Exploration. Push() Push()

Exploration The PyModel Analyzer pma generates an FSM from a model program by a process called Exploration. Push() Push() Push() Pop() Push() Push() Push() 5 6

Exploration The PyModel Analyzer pma generates an FSM from a model program by a process called Exploration. Push() Push() etc... Push() Pop() Push() Push() Pop() Push() Pop() Push() Push() Push() Push() Push() Push() 5 6 5 6

Exploration We must limit exploration of infinite programs. Here we define a finite domain to limit the width of the graph, and a state filter to limit its depth. domains = { Push: { x :[,]} } def StateFilter(): return len(stack) < Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() 5 6 Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() 5 6 8 7 9 5 6

Strategies Test generation can select the next enabled action at random, or use an optional strategy to select an action that increases coverage according to some measure. > pmt.py Stack Push(,) Push(,) Push(,) Push(,) Pop(), Pop(), Pop(), Push(,) Push(,) Push(,) > pmt.py Stack -g ActionNameCoverage Push(,) Pop(), Push(,) Pop(), Push(,) Pop(), Push(,) Pop(), Push(,) Pop(), > pmt.py Stack -g StateCoverage Push(,) Push(,) Push(,) Push(,) Push(,) Push(,) Push(,) Push(,) Push(,) Push(,) ActionNameCoverage and StateCoverage are included in PyModel. You can also code your own custom strategy.

Composition We need scenario control to limit test runs to scenarios of interest. PyModel uses composition, a versatile technique combines two or more models to form a new model, the product. M M = P Usually we combine a contract model program (with action functions, etc.) with a scenario machine, an FSM. Contract Scenario = Product Composition can also be used for validation, program structuring, etc....

Composition Composition synchronizes shared actions. Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() 9

Composition Composition synchronizes shared actions. Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push()Pop() 9 Push()

Composition Composition synchronizes shared actions. Push() Pop() Push() Pop() Push()Pop() = Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push()Pop() Push()Pop() 9 Push() This usually has the effect of restricting behavior.

Composition Composition interleaves unshared actions. PowerOn()PowerOff()

Composition Composition interleaves unshared actions. PowerOn()PowerOff() IncrementSpeed() IncrementSpeed() IncrementSpeed()

Composition Composition interleaves unshared actions. PowerOff() PowerOn() IncrementSpeed() IncrementSpeed() IncrementSpeed() PowerOn()PowerOff() IncrementSpeed() = IncrementSpeed() IncrementSpeed() IncrementSpeed() PowerOn() PowerOff() IncrementSpeed() IncrementSpeed() PowerOn() PowerOff() 5 This usually has the effect of adding behavior.

Validation Composition with a scenario can help validate a model program. Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() 9

Validation Composition with a scenario can help validate a model program. Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push()Pop() 9

Validation Composition with a scenario can help validate a model program. Push() Pop() Push() Pop() = Push() Pop() Push() Pop() Push() Pop() Push() Pop() Push()Pop() Push() 9 The product shows whether the model program can execute the complete scenario. Does the product reach an accepting state?

Scenario Control In this example we compose the model program with a scenario machine to eliminate redundant startup and shutdown paths. ServerSocket() ClientSocket() ServerBind() ClientSocket() ServerSocket() 5 ServerListen() ClientSocket() ServerBind() 6 7 ClientSocket() ServerListen() 8 ClientSocket() ClientConnect() 9 ServerAccept() ClientSend() ServerReceive() ServerSend(double("")) ServerSend(double("99.9")) ClientClose() 5 7 ClientReceive_Finish(double("")) 6 ClientReceive_Finish(double("99.9")) ServerCloseConnection() ClientReceive_Start() ServerCloseConnection() ClientReceive_Start() 8 9 ServerCloseConnection() ClientReceive_Start() ClientReceive_Start() ServerCloseConnection() ServerCloseConnection() ClientReceive_Start() ClientReceive_Finish(double("")) ClientReceive_Finish(double("99.9")) ClientReceive_Start() 5 ClientReceive_Finish(double("")) ClientSend() ClientClose() ClientReceive_Finish(double("99.9")) 8 6 ClientSend() ClientClose() 9 7

Scenario Control In this example we compose the model program with a scenario machine to eliminate redundant startup and shutdown paths. ServerSocket() ClientSocket() ServerSocket() ServerBind() ClientSocket() ServerSocket() 5 ServerBind() ServerListen() ClientSocket() ServerBind() 6 7 ClientSocket() ServerListen() ServerListen() 8 ClientSocket() ClientConnect() ClientSend() ServerReceive() ServerSend(double("")) 9 ServerAccept() ServerSend(double("99.9")) 5 7 ClientReceive_Finish(double("")) 6 ClientClose() ClientReceive_Finish(double("99.9")) ClientSocket() ClientConnect() 5 ServerCloseConnection() ClientReceive_Start() ServerCloseConnection() ClientReceive_Start() ServerAccept() 8 9 ServerCloseConnection() 6 ClientReceive_Start() ClientReceive_Start() ClientClose() ServerCloseConnection() ClientReceive_Start() ClientReceive_Finish(double("")) ClientReceive_Finish(double("99.9")) ClientReceive_Start() ServerCloseConnection() 7 5 ServerCloseConnection() ClientReceive_Finish(double("")) ClientSend() ClientClose() ClientReceive_Finish(double("99.9")) 8 6 ClientSend() ClientClose() 8 9 7 9

Scenario Control In this example we compose the model program with a scenario machine to eliminate redundant startup and shutdown paths. ServerSocket() ClientSocket() ServerSocket() ServerSocket() ServerBind() ClientSocket() ServerSocket() 5 ServerBind() ServerBind() ServerListen() ClientSocket() ServerBind() 6 7 ClientSocket() ServerListen() ServerListen() ServerListen() 8 ClientSocket() ClientConnect() ClientSend() ServerReceive() ServerSend(double("")) 9 ServerAccept() ServerSend(double("99.9")) 5 7 ClientReceive_Finish(double("")) 6 ClientClose() ClientReceive_Finish(double("99.9")) ClientSocket() ClientConnect() 5 = ClientSocket() ClientConnect() 5 ServerCloseConnection() ClientReceive_Start() ServerCloseConnection() ClientReceive_Start() ServerAccept() ServerAccept() 8 9 ServerCloseConnection() 6 6 ClientReceive_Start() ClientReceive_Start() ClientClose() ClientSend() ServerReceive() ClientClose() ServerSend(double("99.9")) ClientReceive() / double("99.9") ServerSend(double("")) ClientReceive() / double("") ServerCloseConnection() ServerCloseConnection() 7 7 8 9 ClientReceive_Start() ClientReceive_Finish(double("")) ClientReceive_Finish(double("99.9")) ClientReceive_Start() 5 ServerCloseConnection() ServerCloseConnection() ClientReceive_Finish(double("")) ClientSend() ClientClose() ClientReceive_Finish(double("99.9")) 8 8 6 ClientSend() ClientClose() 9 7 9 Now the product will only generate interesting traces.

Test Harness Executing tests requires a harness (or adapter) to connect the model to the implementation. In PyModel a test harness is called a stepper. Its core TestAction function contains a branch for each action in the model. def TestAction(aname, args, modelresult):... if aname == Initialize : session = dict() # clear out cookies/session IDs from previous session elif aname == Login : user = users[args[]]... password = passwords[user] if args[] == Correct else wrongpassword postargs = urllib.urlencode({ username :user, password :password}) page = session[user].opener.open(webappurl).read() # GET login page... if result!= modelresult: return received Login %s, expected %s % (result, modelresult) elif aname == Logout :...

On-the-fly Testing On-the-fly testing generates test cases as the test run executes. It overcomes some disadvantages of offline test generation. No FSM is generated, needn t finitize Test runs can be indefinitely long, nonrepeating Especially Handles nondeterminism responds to the nondeterministic choice that the implementation actually made! This last requires an asynchronous stepper that distinguishes between controllable actions (functions the stepper can call) and observable actions (events the stepper can detect).

Implications Model-based testing can encourage different approaches to testing. Encourages on-the-fly testing but test runs may not be reproducible. Extends testing to noninvasive monitoring or run time verification if the harness supports observable actions, the tester can check log files or monitor network traffic for conformance violations. Enables better integration of design analysis with testing exploration is like model checking, can check for safety, liveness, and temporal properties. A rational workflow might be to write the model before writing the implementation, analyze and tweak the design, then implement and test.

Download PyModel PyModel is an open-source model-based testing framework. http://staff.washington.edu/jon/pymodel/www/