Data Model Analysis Tevfik Bultan University of California Santa Barbara Joint work with Jaideep Nijjar and Ivan Bocic.

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
CS162 Week 2 Kyle Dewey. Overview Continuation of Scala Assignment 1 wrap-up Assignment 2a.
1 Symbolic Execution for Model Checking and Testing Corina Păsăreanu (Kestrel) Joint work with Sarfraz Khurshid (MIT) and Willem Visser (RIACS)
1/20 Generalized Symbolic Execution for Model Checking and Testing Charngki PSWLAB Generalized Symbolic Execution for Model Checking and Testing.
CS 290C: Formal Models for Web Software Lecture 4: Implementing and Verifying Statecharts Specifications Using the Spin Model Checker Instructor: Tevfik.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
.NET Database Technologies: Open-Source Frameworks.
Background information Formal verification methods based on theorem proving techniques and model­checking –to prove the absence of errors (in the formal.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 13: Runtime Monitoring.
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
CS 290C: Formal Models for Web Software Lecture 9: MVC Architecture and Navigation Analysis Based on the MVC Architecture Instructor: Tevfik Bultan.
Houdini: An Annotation Assistant for ESC/Java Cormac Flanagan and K. Rustan M. Leino Compaq Systems Research Center.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
CS 290C: Formal Models for Web Software Lecture 1: Introduction Instructor: Tevfik Bultan.
Finding the Weakest Characterization of Erroneous Inputs Dzintars Avots and Benjamin Livshits.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
CS 267: Automated Verification Lecture 13: Bounded Model Checking Instructor: Tevfik Bultan.
1 Scenario-based Analysis of UML Design Class Models Lijun Yu October 4th, 2010 Oslo, Norway.
Looper: Lightweight Detection of Infinite Loops at Runtime Presenter: M. Amin Alipour Software Design Laboratory
Code Generation from CHARON Rajeev Alur, Yerang Hur, Franjo Ivancic, Jesung Kim, Insup Lee, and Oleg Sokolsky University of Pennsylvania.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Finding Bugs in Web Applications Using Dynamic Test Generation and Explicit-State Model Checking -Shreyas Ravindra.
RUBY ON RAILS It’s so rad. What we’ll cover  What is Ruby?  What is RoR?  Why RoR?  Developing with RoR  Deployment  Demo  Questions.
CS 290C: Formal Models for Web Software Lecture 9: Analyzing Data Models Using Alloy Analyzer and SMT-Solvers Instructor: Tevfik Bultan.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 17: Code Mining.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
Eliminating Bugs In MVC-Style Web Applications Tevfik Bultan Verification Lab (Vlab),
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Unbounded Data Model Verification Using SMT Solvers Jaideep NijjarTevfik Bultan University of California, Santa Barbara ASE 2012.
Why rails? Carlos Kirkconnell. Google Happiness leads to Productivity Happiness Matters.
An Integrated Data Model Verifier with Property Templates Jaideep Nijjar Ivan Bocic Tevfik Bultan {jaideepnijjar, bo, University of.
Data Model Property Inference and Repair
Lecture 11 Rails Topics SaaSSaaS Readings: SaaS book Ch February CSCE 740 Software Engineering.
Inferring Specifications to Detect Errors in Code Mana Taghdiri Presented by: Robert Seater MIT Computer Science & AI Lab.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
MVC Design Pattern Web Developer at Crimshield, Inc Application Developer at IBM Present - Delta Developer at Tides.
1 Test Selection for Result Inspection via Mining Predicate Rules Wujie Zheng
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Semantics In Text: Chapter 3.
CSV 889: Concurrent Software Verification Subodh Sharma Indian Institute of Technology Delhi Scalable Symbolic Execution: KLEE.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Declarative Languages and Model Based Development of Web Applications Besnik Selimi South East European University DAAD: 15 th Workshop “Software Engineering.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 9: Test Generation from Models.
Design-Directed Programming Martin Rinard Daniel Jackson MIT Laboratory for Computer Science.
Formal Verification. Background Information Formal verification methods based on theorem proving techniques and model­checking –To prove the absence of.
EMEA Beat Schwegler Architect Microsoft EMEA HQ Ingo Rammer Principal Consultant thinktecture
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
Specifying Multithreaded Java semantics for Program Verification Abhik Roychoudhury National University of Singapore (Joint work with Tulika Mitra)
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
Finding bugs with a constraint solver daniel jackson. mandana vaziri mit laboratory for computer science issta 2000.
Artificial Intelligence Knowledge Representation.
George Edwards Computer Science Department Center for Systems and Software Engineering University of Southern California
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Intro To MVC Architecture.
Introduction to Entity framework
Presentation Title 2/4/2018 Software Verification using Predicate Abstraction and Iterative Refinement: Part Bug Catching: Automated Program Verification.
Definition CASE tools are software systems that are intended to provide automated support for routine activities in the software process such as editing.
SS 2017 Software Verification Bounded Model Checking, Outlook
Logical architecture refinement
Aspect Validation: Connecting Aspects and Formal Methods
The Zoo of Software Security Techniques
Rich Model Toolkit – An Infrastructure for Reliable Computer Systems
Presentation transcript:

Data Model Analysis Tevfik Bultan University of California Santa Barbara Joint work with Jaideep Nijjar and Ivan Bocic

Web Application Dependability 2

3

President Obama: “I want to go in and fix myself, but I don't write code"

T RACKS : A todo list application Web Application Dependability 5 ContextRecurring Todo Feed the Dog EDIT

Web Application Architecture Model View Controller (MVC) pattern: Ruby on Rails, Zend for PHP, CakePHP, Struts for Java, Django for Python, … Object Relational Mapping (ORM) ActiveRecord, Hibernate, … 6 RESTful Controller View OOP Rel Db ORM Data Model

An Example Rails Data Model 7 class User < ActiveRecord::Base has_many :todos has_many :projects end class Project < ActiveRecord::Base belongs_to :user has_many :todos has_many :notes end class Todo < ActiveRecord::Base belongs_to :user belongs_to :project end class Note < ActiveRecord::Base belongs_to :project end class ProjectsController < ApplicationController def = do |note| note.delete respond_to(...) end Static Data Model Data Model Updates: Actions

Static Data Model ActiveRecord class declarations sets of objects ActiveRecord association declarations has_one, has_many, belongs_to, has_and_belongs_to_many Association declarations can be used to declare the three basic types of relations between classes one-to-one one-to-many many-to-many 8

Extensions to Static Data Model :through Option To express relations which are composition of other relations :conditions Option To relate a subset of objects to another class :polymorphic Option To express polymorphic relationships :dependent Option On delete, this option expresses whether to delete the associated objects or not 9

The :through Option class User < ActiveRecord::Base has_one :profile has_many :photos, :through => :profile end class Profile < ActiveRecord::Base belongs_to :user has_many :photos end class Photo < ActiveRecord::Base belongs_to :profile end Profile User Photo * *

The :dependent Option :delete directly delete the associated objects without looking at its dependencies :destroy first checks whether the associated objects themselves have associations with the :dependent option set class User < ActiveRecord::Base has_one :profile, :dependent => :destroy end class Profile < ActiveRecord::Base belongs_to :user has_many :photos, :dependent => :destroy end PhotoProfileUser *

Data Model Verification Formalize the static data model as A set of classes A set of relations between those classes A set of constraints on the relations that are imposed by the association declarations Given a formal data model we can automatically check if a given property holds for the data model Automated verification determines: Do the constraints of the data model imply the property? 12

Data Model Verification Alloy Encoder instance or unsat formula formal data model + property Alloy Analyzer Property ActiveRecord SMT Solver instance or unsat or unknown formula SMT-LIB Encoder Property Failed + Counterexample Property Verified Unknown Model Extraction Results Interpreter B OUNDED V ERIFICATION U NBOUNDED V ERIFICATION n Bound bound 13

How Automated is Automated Verification? All except one step: Property specification Example: It is possible to have a User who does not have any Photos. In Alloy: pred prop { all s: PreState | some u: User | all p: Photo | In SMT-LIB: Can we make it easier? 14 (p not in (s.photo_user).u) } (assert (exists ((a PolymorphicClass)) (forall ((p Photo)) (and (isUser a) (not (= p (a user_photo p)))) )))

Property Templates Property templates for property specification Language-neutral Do not require familiarity with SMT-LIB and Alloy Example property template: noOrphans[classA, classB] To check that deleting an object from classA does not cause related objects in classB to be orphaned Easily rerun tool and switch the verification technique, without having to rewrite the property We developed seven property templates for the most common data model properties 15

Can We Do More?

A utomatic Property Inference Automatically infer properties based on data model schema Data model schema: A directed, annotated graph that represents the relations Look for patterns in the data model schema and infer a property if a pattern that corresponds to a property appears For example, orphan prevention 17 01n...

Can We Do Even More? noOrphans(X, Y) property failing means deleting an object from class X creates an orphan chain that starts with associated object in class Y Repair: Set :dependent option to :destroy on association declaration in class X and on remaining relations in the chain that starts with class Y Set :dependent => :destroy on all relations in chain XYN Automated Data Model Repair

Summary Model Extraction Verification Verification Results Active Records Formal Data Model + Properties Property Inference Formal Data Model 19 Data Model Repair for failing properties

Experiment Results ApplicationProperty Type# Inferred# Timeout# Failed LovdByLess deletePropagates13010 noOrphans000 transitive101 Substruct deletePropagates27016 noOrphans201 transitive404 Tracks deletePropagates1506 noOrphans101 transitive120 FatFreeCRM deletePropagates32119 noOrphans500 transitive626 OSR deletePropagates19012 noOrphans101 transitive707 TOTAL

Property Type # Data Model & Application Errors # Data Model Errors # Failures Due to Rails Limitations # False Positives deletePropagates1900 noOrphans0000 transitive0001 deletePropagates1357 noOrphans0100 transitive0103 deletePropagates1131 noOrphans0001 transitive0705 deletePropagates01810 noOrphans0000 transitive0006 deletePropagates01200 noOrphans0100 transitive0700 TOTAL

What About Data Model Actions? 22 class User < ActiveRecord::Base has_many :todos has_many :projects end class Project < ActiveRecord::Base belongs_to :user has_many :todos has_many :notes end class Todo < ActiveRecord::Base belongs_to :user belongs_to :project end class Note < ActiveRecord::Base belongs_to :project end class ProjectsController < ApplicationController def = do |note| note.delete respond_to(...) end Static Data Model Data Model Updates: Actions

Verification of Data Model Actions 23

Abstract Data Stores 24 class User has_many :todos has_many :projects end class Project belongs_to :user has_many :todos has_many :notes end class Todo belongs_to :user belongs_to :project end class Note belongs_to :project end class User { 0+ Todo todos inverseof user 0+ Project projects inverseof user } class Project { 0..1 User user 0+ Todo todos inverseof project 0+ Note notes inverseof project } class Todo { 0..1 User user 0..1 Project project } class Note { 0..1 Project project } RailsAbstract Data Store

Abstract Data Stores 25 def = Project.find( do |note| note.delete respond_to(...) end action project_destroy() { at_project = oneof(allof(Project)) foreach note: at_project.notes { delete note } delete at_project } invariant(forall{ |project| !project.user.empty? }) invariant(forall{ |user| user.projects.todos.include?(user ) }) forall(Project project: not empty(project.user) ) forall(User user: user in user.projects.todos.users ) Our library allows developers to specify invariants in native Ruby

Extraction Extraction is hard for actions Dynamic type system Metaprogramming Eval Ghost Methods such as: User. find_by_name(‘Rob’) Observations The schema is static Action declarations are static ORM classes and methods do not change their semantic during execution even if the implementation code is generated dynamically 26

Extraction via Instrumented Execution Boot-up the Rails runtime in a simulated environment Without opening sockets or connecting to the database Prepare action methods for extraction ORM operations will record their invocation instead of communicating with the database Method calls propagate instrumentation just before execution Extraction is path insensitive, executing both branches subsequently Trigger an HTTP request that triggers an action 27

Verification via Translation to FOL A predicate is generated for each class and association User(o) means that o is an instance of User Project_user(t) means that t represents an association between a Project object and User object Type system constraints become axioms ∀ u: User(u) → ¬(Project(u) ∨ Todo(u)...) Cardinality of associations is expressed through axioms eg. 0..1: ∀ t 1, t 2 : (Project_user(t 1 ) ∧ Project_user(t 2 ) ∧ Project_user_lhs(t 1 ) = Project_user_lhs(t 2 )) → Project_user_rhs(t 1 ) = Project_user_rhs(t 2 ) 28

Translation of Statements to FOL An action is a sequential composition of statements. Statements A state is represented with a predicate denoting all entities that exist in a state A statement is a migration between states e.g., a create Note statement: ¬pre_state(newly_created()) ¬ ∃ t: post_state(t) ∧ Note_project_lhs(t) = newly_created() ∀ o: (post_state(o) ↔ (pre_state(o) ∨ o = newly_created())) 29

Translation of Loops to FOL We only support ForEach loops (for now) They correspond to universal quantification Statements can execute multiple times in loops Contexts to differentiate iterations Ordering of iterations Iteration interdependence 30

Inductive Verification Inv(s) is a formula denoting that all invariants hold in state s Action(s, s’) is a formula denoting that the action may transition from state s to state s’ Check if: ∀ s, s’: Inv(s) ∧ Action(s, s’) → Inv(s’) 31

Experiments Experimented on 3 open source Rails applications FatFreeCRM, Tracks, Kandan 272 actions, 23 invariants Identified 4 bugs Reported to original developers All immediately confirmed and, since, fixed Missed by previous verification efforts on these applications 32

Experiments 33

Publications Jaideep Nijjar and Tevfik Bultan. Bounded Verification of Ruby on Rails Data Models. In Proc. International Symposium on Software Testing and Analysis (ISSTA), pages 67–77, Jaideep Nijjar and Tevfik Bultan. Unbounded Data Model Verification Using SMT Solvers. In Proc. 27th IEEE/ACM Int. Conf. Automated Software Engineering (ASE), pages 210–219, Jaideep Nijjar, Ivan Bocic and Tevfik Bultan. An Integrated Data Model Verifier with Property Templates. In Proc. 1st FME Workshop on Formal Methods in Software Engineering (FormaliSE 2013). Jaideep Nijjar and Tevfik Bultan. Data Model Property Inference and Repair. In Proc. International Symposium on Software Testing and Analysis (ISSTA), pages 202—212, Ivan Bocic, and Tevfik Bultan. Inductive Verification of Data Model Invariants for Web Applications. In Proc. International Conference on Software Engineering (ICSE), 2014 Jaideep Nijjar, Ivan Bocic, and Tevfik Bultan. Data Model Property Inference, Verification and Repair for Web Applications. (Submitted to ACM Translations on Software Engineering and Methodology). 34