How To Write A Test Engine For A Microsoft Microsoft Web Browser (Php) For A Web Browser For A Non-Procedural Reason)

Similar documents
Rigorous Software Development CSCI-GA

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Computing Concepts with Java Essentials

Rigorous Software Development CSCI-GA

The C Programming Language course syllabus associate level

DEFINING CONTRACTS WITH DIFFERENT TOOLS IN SOFTWARE DEVELOPMENT

Formal Engineering for Industrial Software Development

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

StaRVOOrS: A Tool for Combined Static and Runtime Verification of Java

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Software Engineering Techniques

Tool-Assisted Unit-Test Generation and Selection Based on Operational Abstractions

Pemrograman Dasar. Basic Elements Of Java

Databases 2011 The Relational Model and SQL

Java Application Developer Certificate Program Competencies

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

Using JML to protect Java code against SQL injection. Johan Janssen June 26, 2007

Programming by Contract vs. Defensive Programming: A Comparison of Run-time Performance and Complexity

Java Programming Fundamentals

How To Improve Autotest

CS 111 Classes I 1. Software Organization View to this point:

Appendix... B. The Object Constraint

Design by Contract beyond class modelling

PL/SQL Practicum #2: Assertions, Exceptions and Module Stability

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

Chapter 6: Programming Languages

Formally speaking: How to apply OCL

VoiceXML-Based Dialogue Systems

VDM vs. Programming Language Extensions or their Integration

Rigorous Software Engineering Hoare Logic and Design by Contracts

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Safe Object-Oriented Software: The Verified Design-By-Contract Paradigm

Software Construction

Computer Programming I

App Development with Talkamatic Dialogue Manager

Specification and Analysis of Contracts Lecture 1 Introduction

Certified PHP/MySQL Web Developer Course

GContracts Programming by Contract with Groovy. Andre Steingress

Vérification de bytecode et ses applications

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

JOURNAL OF OBJECT TECHNOLOGY

Java SE 8 Programming

Programming Languages CIS 443

Web Development using PHP (WD_PHP) Duration 1.5 months

CS346: Database Programming.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

SQL Server An Overview

Crash Course in Java

6.170 Tutorial 3 - Ruby Basics

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

The Best Software Testing Arie Van Deursen TU Delft, 2011

Verifying Semantic of System Composition for an Aspect-Oriented Approach

Precise XSS Detection with Static Analysis using String Analysis

On the Relation between Design Contracts and Errors: A Software Development Strategy

Chair of Software Engineering. Software Verification. Assertion Inference. Carlo A. Furia

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Computer Programming I

The System Designer's Guide to VHDL-AMS

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Two Flavors in Automated Software Repair: Rigid Repair and Plastic Repair

introduction to program monitoring

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Towards Contract-based Testing of Web Services

Examples of Design by Contract in Java

Adapting C++ Exception Handling to an Extended COM Exception Model

Designing and Writing a Program DESIGNING, CODING, AND DOCUMENTING. The Design-Code-Debug Cycle. Divide and Conquer! Documentation is Code

Fundamentals of Java Programming

Code Contracts User Manual

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Tutorial on Writing Modular Programs in Scala

f...-. I enterprise Amazon SimpIeDB Developer Guide Scale your application's database on the cloud using Amazon SimpIeDB Prabhakar Chaganti Rich Helms

BUSINESS RULES CONCEPTS... 2 BUSINESS RULE ENGINE ARCHITECTURE By using the RETE Algorithm Benefits of RETE Algorithm...

#820 Computer Programming 1A

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Java (12 Weeks) Introduction to Java Programming Language

Testing, Debugging, and Verification

Coverability for Parallel Programs

Introducing Formal Methods. Software Engineering and Formal Methods

Component Approach to Software Development for Distributed Multi-Database System

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Case studies: Outline. Requirement Engineering. Case Study: Automated Banking System. UML and Case Studies ITNP090 - Object Oriented Software Design

Automatic Test Data Generation for TTCN-3 using CTE

WIRIS quizzes web services Getting started with PHP and Java

Software Component Specification Using Design by Contract

CS506 Web Design and Development Solved Online Quiz No. 01

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Software Engineering

The Smalltalk Programming Language. Beatrice Åkerblom

SQL INJECTION ATTACKS By Zelinski Radu, Technical University of Moldova

HybriDroid: Analysis Framework for Android Hybrid Applications

Logical Testing. Hoare-style Specification Meets Executable Validation

The Designer's Guide to VHDL

Logistics. Software Testing. Logistics. Logistics. Plan for this week. Before we begin. Project. Final exam. Questions?

irods and Metadata survey Version 0.1 Date March Abhijeet Kodgire 25th

Database Programming with PL/SQL: Learning Objectives

The programming language C. sws1 1

Transcription:

Praspel: A Specification Language for Contract-Driven Testing in PHP Ivan Enderlin Frédéric Dadeau Alain Giorgetti Abdallah Ben Othman October 27th, 2011 Meetings: LTP MTVV Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 1 / 30

Motivations Context Types are the main verification mechanism massively adopted Annotation is more and more a common processus for developers Unit testing is used to maintain large softwares (with a thousand of manual tests) Initial ideas An easy language to express contracts Automate tests (data) generation and execution A complete, clean and modular test framework Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 2 / 30

Design-by-Contract Realistic domains for PHP Definition Invented by B. Meyer in 1992 with Eiffel language Describes a model using annotations Expresses formal constraints: pre-, postconditions, invariants... Included directly in the source code: classes attributes, methods arguments... Semantics of contracts Contractual agreement: caller: I commit to satisfy your pre-condition when I m calling you called: In this case, I commit to establish my post-condition Invariants must be satisfied before and after the execution of the methods Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 3 / 30

Contract-Driven Testing Definition Exploits the contract for generating tests: uses preconditions to generate test data uses postconditions to establish test verdict by runtime assertion checking Issue How to describe realistic data for being able to generate them? Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 4 / 30

Contributions 3 points Realistic domains overlay/refinement of types structures to automate the validation and the generation for test data Praspel, a new specification language adopts Design-by-Contract paradigm based on realistic domains implementation in PHP for PHP uses Praspel to perform Contract-Driven Testing Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 5 / 30

Outline Realistic domains for PHP 1 Realistic domains for PHP 2 3 4 5 Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 6 / 30

About of realistic domains Definition and goal Specify a set of relevant values that can be assigned to a data for a specific context (e.g. an email address) in a given program Come with properties for the validation and generation of data values Realistic domains are intended to be used for test generation purposes Two important properties Predicability, checks if a value belongs to the realistic domain Samplability, generates values that belong to the realistic domain. The sampler can be of many kinds: a random generator, a walk in the domain, an incrementation of values etc. Properties are implemented by the end-user. Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 7 / 30

Realistic domains in PHP Implementation In PHP, we have implemented realistic domains as classes providing at least two methods, corresponding to the two features of realistic domains: predicate($q), takes a value $q as input, returns a boolean indicating the membership of the value to the realistic domain sample($sampler), generates values that belong to the realistic domain according to a basic numeric-sampler $sampler Skeleton of a realistic domain class MyOwnRealdom extends... { } public function predicate ( $q ) { return $aboolean =...; } public function sample ( Sampler $sampler ) { return $data =...; } Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 8 / 30

Realistic domains in PHP Our implementation exploits the PHP object programming paradigm and benefits from the following principles: Hierarchical inheritance PHP realistic domains can inherit from each other standard library user library void boolean integer float string array class undefined inheritance Parameterizable Realistic domains may have parameters. They can receive arguments of many kinds: constants or realistic domains themselves Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 9 / 30

Examples of realistic domains Basic realistic domain with constant arguments boundinteger(7, 42) contains all the integers between 7 and 42 Realistic domain with constants and realistic domains as arguments string(boundinteger(4, 12), 0x20, 0x7e) is intended to contain all the strings of length between 4 and 12 constitued of characters from 0x20 to 0x7e (Unicode code-points) User-defined realistic domain email() is intended to contain all email addresses Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 10 / 30

Outline Realistic domains for PHP Assigning realistic domains to data Designing contracts in Praspel 1 Realistic domains for PHP 2 Assigning realistic domains to data Designing contracts in Praspel 3 4 5 Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 11 / 30

Assigning realistic domains to data Designing contracts in Praspel Presentation of Praspel Signification and format PHP Realistic Annotation and SPEcification Language Written in the API documentation (/**... */) Makes it possible to express formal constraints, called clauses (starting with the standard @ symbol) Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 12 / 30

Assigning realistic domains to data Designing contracts in Praspel Operator : Syntax and semantics The syntactic construction: i: t 1 (...) or... or t n (...) associates at least one realistic domain among t 1 (... ),..., t n (... ) to an identifier i. Examples of realistic domains declarations y: integer() or float() or boolean() means that y can either be an integer, a floating-point number or a boolean u: email() or userlogin() specifies that u is either an email address or a user login Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 13 / 30

Array description Realistic domains for PHP Assigning realistic domains to data Designing contracts in Praspel Syntax and semantics An array description has the following form: array([ from T1 1 1 (...) or... or Ti (...) to Ti+1 1 (...) or... or T n 1 (...),. from T1 k k (...) or... or Tj (...) to Tj+1 k (...) or... or T m(...) k ], size) from domains to co-domains (pairs separated by,), each ones are domains disjunctions Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 14 / 30

Array description Realistic domains for PHP Assigning realistic domains to data Designing contracts in Praspel Examples of arrays a 1 : array([from integer() to boolean(), boundinteger(7, 42)) a 2 : array([to boolean(), to float()], 7) a 3 : array([to boolean() or float()], 7) a 4 : array([to integer()], boundinteger(1, 256)) Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 15 / 30

Assigning realistic domains to data Designing contracts in Praspel Defining a contract clause Contract content either the assignment of a realistic domain to a given data (:) or it is a predicate (expressed in the PHP syntax, enriched with the \result and \old(e) constructs) Praspel clauses Applied on classes: @invariant, invariant on class attributes Applied on methods: @requires, precondition on class attributes and method arguments @ensures, postcondition on class attributes, and method arguments and result @throwable, list of throwable exceptions by the method Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 16 / 30

Praspel clauses Realistic domains for PHP Assigning realistic domains to data Designing contracts in Praspel Example of a short Praspel contract /** * @requires needle: integer() and * haystack: array( * [to integer()], * boundinteger(1, 256) * ) and * matches: undefined(); * @ensures \result: boolean() and * matches: undefined(); */ public function exists ( $needle, $haystack, &$matches = false ) { $intersect = array_intersect($haystack, array($needle)); if(null === $matches) $matches = array_keys($intersect); } return 0 < count($intersect); Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 17 / 30

Assigning realistic domains to data Designing contracts in Praspel Organization in behaviors Several behaviors per method Each @behavior clause has a unique name inside a contract A behavioral clause contains @requires, @ensures and @throwable clauses By default, a global implicit behavior exists matches is no longer undefined /** *... * @behavior get_matches { * @requires matches: void(); * @ensures matches: array( * [to boundinteger(0, 255)], * boundinteger(0, 256) * ); * } *... */ Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 18 / 30

Outline Realistic domains for PHP 1 Realistic domains for PHP 2 3 4 5 Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 19 / 30

Unit test generator and test verdict Contract-Driven Testing The testing process works with the two features provided by the realistic domains: (samplability) the sampler is implemented as a random data generator that satisfies the precondition of the method (predicability) the predicate makes it possible to check the postcondition at runtime after the execution of the method Random test data generation Test data generation are used in the sample() method \pred thus introduces rejection in precondition Random generation was a first approach Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 20 / 30

Unit test generator and test verdict Contract-Driven Testing The testing process works with the two features provided by the realistic domains: (samplability) the sampler is implemented as a random data generator that satisfies the precondition of the method (predicability) the predicate makes it possible to check the postcondition at runtime after the execution of the method Runtime Assertion Checking and test verdict The RAC is performed by instrumenting the initial PHP code with additional code that checks the contract clauses Detected failures can be of five kinds: precondition, postcondition, throwable, invariant or internal precondition (propagation) failure Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 20 / 30

Example of instrumentation Instrument foo() public function foo (... ) { public function foo_pre (... ) { $this->foo_contract(); $this->foo_pre(...); try { } //... return $contract->verifyinvariants(...) && $contract->verifyprecondition(...); } $result = $this->foo_body(); } catch ( \Exception $e ) { } $this->foo_exception($e); throw $e; $this->foo_post($result,...); return $result; public function foo_post (... ) { } //... return $contract->verifypostcondition( $result,... ) && $contract->verifyinvariants(...); public function foo_exception ( $exception ) { } return $contract->verifyexception($exception) && $contract->verifyinvariants(...); Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 21 / 30

Implementation in the Praspel tool Environment for unit testing Clean and modular framework for generating and executing online tests Praspel and its tools are freely available in Hoa (http://hoa-project.net), a set of libraries for PHP Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 22 / 30

Outline Realistic domains for PHP 1 Realistic domains for PHP 2 3 4 5 Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 23 / 30

Realistic domains for PHP Case study Validate HTML code produced by second year student programs written in PHP, with different granularities: firstly with a general oracle: is the HTML code well-formed? secondly with a refined oracle: do attributes exist, are they well-positionned and are the values right Grammar as a dedicated realistic domain Grammars can be used to validate or generate data It is a new realistic domain Then, we have written grammar of HTML for the first oracle Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 24 / 30

Observations Simple and easy shows that tools are easy to use (2 commands), find bugs quickly and easily Simple mechanism to describe an oracle Simple mechanism to develop a new realistic domain (here, for grammar) It offers a good ratio effort/results (bugs found) Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 25 / 30

Outline Realistic domains for PHP 1 Realistic domains for PHP 2 3 4 5 Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 26 / 30

Related works Other contract-based specification languages Spec#: for C# language, contracts are written in C# JML: Java Modeling Language, contracts are expressed with logic formulæ ACSL: ANSI/C Specification Language, adds algebraic structures Parallel approach: UDITA our predicates = their filters differences: we can combine and parameterize realistic domains, they have delayed (lazy) evaluation for solving complex predicates/constraints Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 27 / 30

Conclusion What we have seen Realistic domain specifying test data for program variables provide two useful features for automated test generation: predicability and samplability Praspel, a new Design-by-Contract language implementing realistic domains A test generation and execution framework to automate unit testing in PHP Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 28 / 30

Current and future works Numerous perspectives... We have introduced Grammar-based Testing into a realistic domain Extend and generalize the concept of realistic domains to other programming languages to illustrate the benefits of this concept Improve data generators (Search-based Testing, Constraints-based Testing etc.) Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 29 / 30

Thanks! Realistic domains for PHP Thank you for your attention! Any questions? Ivan Enderlin, Frédéric Dadeau, Alain Giorgetti, Abdallah Ben Othman Praspel: Contract-Driven Testing for PHP 30 / 30