A Safety-Critical Java Technology Compatibility Kit Hans Søndergaard Stephan Korsholm VIA University College, Horsens, Denmark & Anders P. Ravn Aalborg.

Slides:



Advertisements
Similar presentations
Chapter 17 Failures and exceptions. This chapter discusses n Failure. n The meaning of system failure. n Causes of failure. n Handling failure. n Exception.
Advertisements

Advanced programming tools at Microsoft
Program Verification Using the Spec# Programming System ETAPS Tutorial K. Rustan M. Leino, Microsoft Research, Redmond Rosemary Monahan, NUIM Maynooth.
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
1. Define the concept of assertions. 1 Explain the use of assertions. 2 Create Java program using assertions. 3 Run Java program using assertions. 4 2.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
J-Unit Framework.
Chapter 1: Computer Systems
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
The Java Modeling Language JML Erik Poll Digital Security Radboud University Nijmegen.
Dept. of Computer Science A Runtime Assertion Checker for the Java Modeling Language (JML) Yoonsik Cheon and Gary T. Leavens SERP 2002, June 24-27, 2002.
1 Design by Contract with JML CS 3331 Fall 2009 Gary T. Leavens and Yoonsik Cheon. Design by Contract with JML. Available from
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
ITEC200 Week02 Program Correctness and Efficiency.
Programming R-T Abstractions TSW November 2009 Anders P. Ravn Aalborg University.
The Java Programming Language
An overview of JML tools and applications Lilian Burdy Gemplus Yoonsik Cheon, Gary Leavens Iowa Univ. David Cok Kodak Michael Ernst MIT Rustan Leino Microsoft.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
JML and Class Specifications Class invariant JML definitions Queue example Running JML in Eclipse.
20-Jun-15 More About JUnit. Test suites A test suite is a group of JUnit tests You can create a test suite in Eclipse as follows: File  New  Other...
Outline Java program structure Basic program elements
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Software Quality: Testing and Verification II. 2 1.A failure is an unacceptable behaviour exhibited by a system — The frequency of failures measures software.
Transformation of Java Card into Diet Java Semester Project Presentation Erich Laube.
LSR 1 Jartege : a Tool for Random Generation of Unit Tests for Java Classes Catherine Oriat LSR/IMAG, Grenoble, France (presented by Yves Ledru) SOQUA’05,
The Real-Time Java Profile ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Ranga Rodrigo. Class is central to object oriented programming.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 18 Exception Handling.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Testing Especially Unit Testing. V-model Wikipedia:
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
1 Assertions. 2 assertions communicate assumptions about the state of the program, and stop processing if they turn out to be false very often comments.
A Novel Approach to Unit Test: The Aspect-Oriented Way Guoqing Xu and Zongyuan Yang Software Engineering Lab (SEL) East China Normal University
P.R. James © P.Chalin et al.1 An Integrated Verification Environment for JML: Architecture and Early Results Patrice Chalin, Perry R. James, and George.
Today’s Agenda  Quick Review  Continue on JML Formal Methods in Software Engineering1.
A Survey on Java Modeling Languages Gergely Kovásznai,Eszterházy Károly College Wolfgang Schreiner,Johannes Kepler University Gábor Kusper,Eszterházy Károly.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
ESO - Garching 23 June – 02 July, 2003 ACS Course JUnit for Java Unit Testing H. Sommer.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
A tool for test-driven development
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
Computer Science 209 Software Development Handing Errors and Creating Documentation.
Consensus-based Mining of API Preconditions in Big Code Hoan NguyenRobert DyerTien N. NguyenHridesh Rajan.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
Java FilesOops - Mistake Java lingoSyntax
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Exception Handling in C + + Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
Topic: Junit Presenters: Govindaramanujam, Sama & Jansen, Erwin.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Construction Lab 10 Unit Testing with JUnit
Working with Java.
G53SRP: Real Time Threads in RTSJ (part I)
Accessible Formal Methods A Study of the Java Modeling Language
null, true, and false are also reserved.
Java Modeling Language (JML)
RAC Support for JML on Eclipse Platform
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

A Safety-Critical Java Technology Compatibility Kit Hans Søndergaard Stephan Korsholm VIA University College, Horsens, Denmark & Anders P. Ravn Aalborg University JTRES 2014 October 2014

Test Suite – why? Java Community Process (JCP) The formal process for developing or revising Java technology Specifications. Final Release The final stage in a JSR when the Specification, RI, and TCK have been completed. Technology Compatibility Kit (TCK) The suite of tests, tools, and documentation that allows an organization to determine if its implementation is compliant with the Specification. 2

Ingredients in a TCK Tests Test cases and test datasets Tools for test execution Execute the tests and generate results Test report documents Classification of results 3

Test Case Development Checks conformance with a specification  Must be implementation independent: - data representations must be hidden  Black-box testing using public entities only Must check specification of classes  Invariants and Pre- and Post-conditions ?Intuition or formalization in development ? !JML (Java Modeling Language) 4

Background Anders P. Ravn and Hans Søndergaard. A Test Suite for Safety- Critical Java using JML Yoonsik Cheon and Gary T. Leavens. A Simple and Practical Approach to Unit Testing: The JML and JUnit Way A. Sarcar and Y. Cheon. A new Eclipse-based JML compiler built using AST merging JML4c L. Zhao, D. Tang, and J. Vitek. A Technology Compatibility Kit for Safety Critical Java

Specification of Invariants Class: public abstract class HighResolutionTime Specification: ” A time object in normalized form represents negative time if both components are nonzero and negative, or one is nonzero and negative and the other is zero.” Invariant: public invariant (this.getMilliSeconds() >= 0 && (0 <= this.getNanoSeconds() && this.getNanoSeconds() < )) || (this.getMilliSeconds() <= 0 && ( < this.getNanoSeconds() && this.getNanoSeconds() <= 0)); 6

Pre/Post-conditions Normal behaviour Class: public abstract class HighResolutionTime Specification: public void set(HighResolutionTime time) “Change the value represented by this to that of the given time. … Throws ClassCastException if the time parameter is not of the same class as this. Throws IllegalArgumentException if the time parameter is null....” public normal_behaviour requires time != null && this.getClass() == time.getClass(); ensures this.getMilliseconds() == time.getMilliseconds(); ensures this.getNanoseconds() == time.getNanoseconds(); ensures this.getClock() == time.getClock(); 7

Exceptions Class: public abstract class HighResolutionTime Specification: public void set(HighResolutionTime time) “Change the value represented by this to that of the given time. … Throws ClassCastException if the time parameter is not of the same class as this. Throws IllegalArgumentException if the time parameter is null....” also public exceptional_behaviour requires time == null; signals (IllegalArgumentException) true; public exceptional_behaviour requires time != null && this.getClass() != time.getClass(); signals (ClassCastException) true; 8

JML annotations compiled and executed Compilation of JML annotations – Uses a JML compiler – Compiled to Java bytecode – Translated to runtime assertion checks Execution of the extended Java bytecode – Constructor: Runtime check of Precondition Constructor execution Runtime check of Postcondition and Invariant – Method: Runtime check of Invariant and Precondition Method execution Runtime check of Postcondition and Invariant Violation of runtime checks – Throws a JMLAssertionError

Test Case Using class TestCase from JUnit public class TestAbsoluteTime extends TestCase {... public void test(int i) { AbsoluteTime abs; switch (i) {... // AbsoluteTime(long millis, int nanos) case 32: new AbsoluteTime(0,0); break; case 33: new AbsoluteTime(0, ); break;... // wrap around value case 37: abs = new AbsoluteTime(Long.MAX_VALUE, ); assert abs.getNanoseconds() == ; break;...

Test Cases - exceptions // AbsoluteTime(AbsoluteTime time) case 39: abs = new AbsoluteTime(); new AbsoluteTime(abs); break; case 40: abs = null; try{ new AbsoluteTime(abs); assert false; } catch (IllegalArgumentException e){}; break;... case 91:... default: break; } public static final int testCount = 91;

Beyond Unit Testing 12 Class: public abstract class Clock Specification: public abstract RelativeTime getResolution(); “Gets the resolution of the clock defined as the nominal interval between ticks. “ public behaviour requires true; ensures \result != null; ensures (\result.getMilliSeconds() > 0 || \result.getMilliSeconds() == 0 && \result.getNanoSeconds() > 0); Is unit testing sufficient for a Clock?

Specification of clock test method 13 Specification: behaviour requires true; ensures !failure; ensures (\forall int i; 0 < i && i < SIZE; sample[i-1].compareTo(sample[i]) < 0); // time is moving forward ensures (\forall int i; 0 < i && i < SIZE; (sample[i].subtract(sample[i-1])).compareTo(c.getResolution()) >= 0 ); // distance between two samples >= resolution Use JML to specify test methods! case 14: clockTest(clk); break;

Implementation of the clock test method 14 boolean failure; AbsoluteTime[] sample; RelativeTime resolution; behaviour... // JML specification here void clockTest(Clock c) { resolution = c.getResolution(); sample = new AbsoluteTime[SIZE]; failure = false; sample[0] = c.getTime(sample[0]); for (int i = 1; i < SIZE; i++){ int j = 0; do { sample[i] = c.getTime(sample[i]); j++; } while ( sample[i].subtract(sample[i-1]). compareTo (resolution) < 0 && j < MAXLOOPS ); if (j == MAXLOOPS) { failure = true; break;} }

Tools for test execution Requirements – Executable on different VMs, e.g. VMs for resource constrained platforms HVM has been extended with reflection JML compilers – jmlc works with Java 1.4 source files – jml4c works with Java 1.5, including generics built on the Eclipse Java compiler JUnit – a subset of junit is used package framework – class TestResult has been extended add JML error to a list of errors 15

TestSuite assembly and execution public class AllTests { public static final TestResult result = new TestResult(); public static void main (String[] args) { TestSuite suite = new TestSuite(); suite.addTest(test_AbsoluteTime); suite.addTest(test_RelativeTime);... suite.run(result);... // TestCase objects defined here (next slide) } 16

TestCase object public class AllTests { public static final TestResult result = new TestResult();... public static TestCase test_AbsoluteTime = new TestAbsoluteTime(”AbsoluteTime”) { public void runTest () { try { for (int i = 1; i <= TestAbsoluteTime.testCount; i++) test(i); } catch (JMLAssertionError e) {result.addJMLError(this, e);} catch (Throwable e) { result.addError(this, e); } } }; } 17

Test report No errors Test cases: 2 Test errors: 0 JML errors: 0 If e.g. an JML error Test number is 67, By method AbsoluteTime.add Regarding specifications at File "./src/javax/realtime/AbsoluteTime.java", line 216, character 15 With values nanos: millis: 0

Where are we? javax.realtime 47 classes and interfaces 24 finished 15 are Empty

Where are we? javax.safetycritical 35 classes and interfaces 12 (nearly) finished 3 are Empty

Conclusion Tests JML is an efficient vehicle for generating test conditions and may even improve the informal specifications. Concrete Test cases Guided by specifications and also additional cases based on “intuition”. Tools for test execution The tools involved are able to run on a resource constrained VM (HVM). Test report documents A simple test report. 21

Conformance tests of other SCJ implementations Extract the JML specifications from our SCJ implementation (simple) Merge this extract with another SCJ implementation (more complicated) Use the test cases (no change) Compile classes with JML annotations into Java bytecode, using jml4c (? depends of the VM) Run the test suites, using (part of) JUnit (simple). 22