640 likes | 746 Views
Advisor : Dr. Jeff Gray Thesis Committee : Dr. Barrett Bryant Dr. Brian Toone Dr. Chengcui Zhang Dr. Marjan Mernik Dr. Mikhail Auguston. Grammar-Driven Generation of Domain-Specific Language Testing Tools Using Aspects. Ph.D. Defense Hui Wu wuh@cis.uab.edu http://www.cis.uab.edu/wuh
E N D
Advisor: Dr. Jeff Gray Thesis Committee: Dr. Barrett Bryant Dr. Brian Toone Dr. Chengcui Zhang Dr. Marjan Mernik Dr. Mikhail Auguston Grammar-Driven Generation of Domain-Specific Language Testing Tools Using Aspects Ph.D. Defense Hui Wu wuh@cis.uab.edu http://www.cis.uab.edu/wuh 10/29/2007
Lack of end-user DSL testing tools public class Robot{ … x=0; y=0; time=0; //move left move_left(); Overview of Presentation Eclipse PDE Motivation Background Testing support for DSLs Domain-SpecificLanguages Research Goals Raise AOP to a higher level of abstraction My Approach Generative Programming Evaluation 2 Experimental Evaluation and Generality Analysis AOP
Categories of DSL End-Users Spreadsheet Admin Assistants Business Query Systems Business Person Modeling Language Auto Factory Worker DSL for Physics Scientist 3
The Benefits of Using DSLs • Case studies and empirical evaluations documented in the research literature have identified the following benefits of DSLs • DSLs can hide the lower level programming language details from end-user programmers • DSLs assist in software maintenance whereby end-users can directly use the DSLs to make required routine modifications • DSLs assist end-users in writing more concise, descriptive, and platform independent programs • The use of DSLs increases flexibility, productivity, reliability, and usability; shorten the application development time and reduce the development cost significantly
Motivation of Proposed Research Editor Compiler Domain Experts program at DSL level Domain Experts deal with GPL Visualizer Debugger Profiler DSL translated into General Purpose Language (GPL) Integrated Development Environment (IDE) Domain Experts deal with DSL Test Engine 5
Mismatch Between Abstraction Levels Generated Java Parser Code ANTLR Grammar …. public final void commands() throws RecognitionException, TokenStreamException { try { // for error handling { switch ( LA(1)) { case CALL: case INIT: case SET: case PRINT: { command(); commands(); break; } case END: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); … public final void function_name() throws RecognitionException, TokenStreamException { try { // for error handling { switch ( LA(1)) { case RIGHT: { match(RIGHT); fileio.print(" //move right"); fileio.print(" move_right();"); fileio.print(" "); break; } case LEFT: { match(LEFT); sllinenumber=dsllinenumber+1; fileio.print(" //move left"); fileio.print(" move_left();"); fileio.print(" "); break; } … …. commands : ( c:command cs:commands | ) ; command : ( RIGHT { fileio.print("//move right"); fileio.print("x=x+1;"); fileio.print("time=time+1;"); fileio.print(" "); } |LEFT { fileio.print("//move left"); fileio.print("x=x-1;"); fileio.print("time=time+1;"); fileio.print(" "); … 6
A Matrix of DSL Testing Tools Generalized approach to automatically produce a software product line of DSL testing tools from DSL grammars Research Goal Imperative DSL Debugger Declarative DSL Debugger Hybrid DSL Debugger Imperative DSL Test Engine Declarative DSL Test Engine Hybrid DSL Test Engine AspectG Imperative DSL Profiler Declarative DSL Profiler Hybrid DSL Profiler Future Work after PhD
Outline • Background • DSL Debugging Framework (DDF) • DSL Unit Testing Framework (DUTF) • AspectG • Future Work and Conclusion
Different Types of Debuggers • Categorized by [Zellweger, 1984] based on behavior of a debugger • expected behavior debugger • truthful behavior debugger • Categorized by [Auguston, 1998] based on the behavioral models of higher level debugging mechanisms • algorithmic debugger • declarative debugger • event-based debugger • The work in this dissertation represents expected behavior debuggers that perform typical debugging tasks on DSL programs
Categories of Domain-Specific Languages • Imperative DSL • Robot DSL • Declarative DSL • Feature Description Language (FDL) • Backus–Naur Form (BNF) language syntax specification • Hybrid DSL • Swing User-interface Language (SWUL) • Hybrid Robot DSL 10
Categories of Domain-Specific Languages • Imperative DSL: Centered around assignment expressions or control flow statements • Robot Language • … • 17 Down: • 18 position(+0,-1) • Down: • … • 21 Init position(0,0) • 22 Call left • 23 Call down • 24 Call knight • 25 Set position(5,6) • 26 Call up • 27 Call right • 28 Print position • … 11
Categories of Domain-Specific Languages • Declarative DSL: declares the relationship between inputs and outputs • Feature Description Language (FDL) 1 Car : all (Carbody, Transmission, Engine, Horsepower, opt(pullsTrailer)) 2 Transmission : oneof(automatic, manual) 3 Engine : moreof (electric, gasoline) 4 Horsepower : oneof (lowPower, mediumPower, highPower) 5 include pullsTrailer 6 pullsTrailer requires highPower • Backus–Naur Form (BNF) language syntax • specification: a set of derivation rules START ::= begin COMMANDS end ; COMMANDS :: = COMMAND COMMANDS | epsilon ; COMMAND :: = left | right | up | down ; 12
Categories of Domain-Specific Languages • Hybrid DSL: embedded GPL code within the DSL description (Robot) … Random: { String answer; int max; JOptionPane myGUI = new JOptionPane(); Random rand = new Random(); answer = myGUI.showInputDialog("Generate a random number for X-axis between 1 and "); max = Integer.parseInt(answer); x = rand.nextInt(max); answer = myGUI.showInputDialog("Generate a random number for Y-axis between 1 and "); max = Integer.parseInt(answer); y = rand.nextInt(max); myGUI.showMessageDialog(null, "Generated Position(" + x + "," + y+ ")"); } Random: … Init position(0,0) Call left Call down Call knight Set position(5,6) Call up Call random Call right Print position … 13
Categories of Domain-Specific Languages • Hybrid DSL: embedded DSL description (SWUL) within the GPL code import javax.swing.*; import java.awt.*; public class WelcomeSwing { public static void main(String[] ps) { JFrame frame = frame { title = "Welcome!" content = panel of border layout { center = label { text = "Hello World" } south = panel of grid layout { row = { button { text = "cancel" } button { text = "ok" } } } } }; frame.pack(); frame.setVisible(true); } } 14
Eclipse Debug Perspective JUnit Eclipse Plug-in Eclipse Plug-In Based Software Development a) Variable Inspector b) Navigation Toolbar 15
Program Transformation with the Design Maintenance System Design Maintenance System (DMS) is a transformation and re-engineering toolkit developed by Semantic Designs Provides lower level transformation functions such as parsing, AST generation and manipulation, pretty printing, powerful pattern matching, and source translation capabilities Pre-constructed domains for several dozen GPLs (e.g., Java, C++, and Object Pascal) This research required the creation of a new domain for ANTLR 16
Overview of my Approach Syntax-Directed Translation Plug-In Based Software Development ANTLR Eclipse public class Robot{ … x=0; y=0; time=0; //move left move_left(); Design Patterns Generative Programming Model-View-Controller Adapter Pattern pointcutproductions(): within(command.*); before(): productions() { dsllinenumber=dsllinenumber+1;} … Aspect-Oriented Programming on DSL Grammars AspectG 17
Outline • Background • DSL Debugging Framework (DDF) • DSL Unit Testing Framework (DUTF) • AspectG • Future Work and Conclusion
Process of DSL Debugger Generation Robot DSL corresponding GPL code generated in Java DSL grammar is defined using ANTLR Notation DSL is the input of the Lexer and Parser generated by ANTLR Additional Mapping code generated in Java DSL translation process Corresponding GPL and Mapping Code are inputs of Mapping component Eclipse Debugging perspective communicates with mapping component jdb communicates with mapping component 20
Source Code Mapping {13, "Robot.java", 20, 21, "main", "none"} 21
Debugging Results Mapping Black: Basic functionality Blue: Source code mapping Red: Debugging results mapping 24
Hybrid SWUL Debugger Video Demo • There are 7 sets of demos in 3 different video formats • Available at: www.cis.uab.edu/wuh/ddf/demos.html
Generality Analysis of DDF • 19 software components: 3,429 lines of code can be reused 33
Related Work in the Area of Domain-Specific Language Debuggers • Khepera • Support optimization code debugger; store transformation information in a database • Execution time and cost are high • JSR-045 • Establishes standardized debugging tools for correlating Java bytecode to the source code of languages other than Java • Does not have a debugging result mapping process • ANTLR Studio • An example of a hybrid debugger • Based on the JSR-045 mapping mechanism • Display only Java variable values • TIDE • Although uses gdb, TIDE requires the end-user to understand a precise language specification in ASF+SDF • Knowledge of the rewrite rules in the built-in library is required to construct a debugger for a new language 35
Outline • Background • DSL Debugging Framework (DDF) • DSL Unit Testing Framework (DUTF) • AspectG • Future Work and Conclusion
DSL Application Software Errors! • Before locating software errors how do we know there are bugs inside a DSL application?
DSL Unit Testing Framework (DUTF) • Complement to the DDF – the DUTF assists in identifying the presence of errors and the DDF assists in isolating the specific location of the error • Architecture and process of construction is similar to the DSL Debugging Framework (DDF) architecture 38
DSL Unit Testing Framework (DUTF) • Test Cases Mapping {1, “TestRobot.java”,11,“testknight”} 40
DSL Unit Testing Framework (DUTF) • Test Cases Mapping 41
DSL Unit Testing Framework (DUTF)Robot Language Unit Test Engine 42
Generality Analysis on DUTF • Among 22 software components in DUTF, there are 3,001 lines of code that are generalized and reused to generate the different DSL unit test engines. 44
Related Works in the Area ofDomain-Specific Language Tools • ASF+SDF • Generate program analysis and transformation tools, and produce software renovation tools • The unit testing tool support has not been reported • JST • Complicated mechanism (e.g., Language extension) • Does not focus on language tools generation • LISA • Can generate editor, parser, and visualizer for new languages • Debugger, test engine, and profiler are not the target language tools, LISA can be used as the front-end of our framework • SmartTools • Base on Java and XML technologies • Debugger, test engine, and profiler are not target language tools • Other Related Testing Tools • Parameterized unit testing • Testing grammar-driven functionality • Generating unit tests using symbolic execution • Generating test inputs of AspectJ programs 46
Outline • Background • DSL Debugging Framework (DDF) • DSL Unit Testing Framework (DUTF) • AspectG • Future Work and Conclusion
Crosscutting Concerns in Tool Generation Process Crosscutting concerns observed in DSL grammars during the generation of DSL debuggers and unit test engines How do we address such concerns in DSL grammars? 48
AspectG • Crosscutting concerns emerge in different software artifacts (e.g., model, grammar, and source code) • AspectG: A domain-specific aspect language for language grammars written in ANTLR 49
Addition of Debugging Support: A Crosscutting Grammar Concern Base Grammar … command :( RIGHT { fileio.print(" //move right"); fileio.print(" x=x+1;"); fileio.print(" time=time+1;"); fileio.print(" "); } |LEFT { fileio.print(" //move left"); fileio.print(" x=x-1;"); fileio.print(" time=time+1;"); fileio.print(" "); } | … What if this line changes? Change here Duplicate Debugging Aspect Code dsllinenumber=dsllinenumber+1; gplbeginline=fileio.getLinenumber(); gplendline=fileio.getLinenumber(); filemap.print(" mapping.add(new Map("+dsllinenumber+", \"Robot.java\","+gplbeginline+","+gplendline+"));"); dsllinenumber=dsllinenumber+1; gplbeginline=fileio.getLinenumber(); gplendline=fileio.getLinenumber(); filemap.print(" mapping.add(new Map("+dsllinenumber+", \"Robot.java\","+gplbeginline+","+gplendline+"));"); Change here Change …… 50