CS 23001 CS II Data Structures and Abstraction
CS 23001 CS II: Data Structures and Abstraction Compiling, Software Testing, Identifier Naming Xiang Lian Department of Computer Science Kent State University Email: xlian@kent. edu Homepage: http: //www. cs. kent. edu/~xlian/ 1
Objectives • Compiling • Software Testing • Identifier Naming 2
Interpreters & Compilers • Interpreter – A program that reads a source program and produces the results of executing that program • Compiler – A program that translates a program from one language (the source) to another (the target) 3
Interpreters & Compilers (cont'd) • Interpreted Language – Python – Javascript, PHP, … – Basic • Compiled Language – C, C++, C#, … – Java – FORTRAN – COBOL –… 4
Compiler • Read analyze the entire program • Translate to semantically equivalent program in another language – Presumably easier to execute or more efficient – Should “improve” the program in some fashion • Offline process – Tradeoff: compile time overhead (preprocessing step) vs execution performance 5
Compilers: The Big Picture Source code Compiler Assembly code Assembler Object code (machine code) Fully-resolved object code (machine code) Linker Loader Executable image 6
Compilers: The Big Picture (cont'd) Source code Visual Studio, Linux Programming Environment, … *. h, *. hpp, *. cpp, … Compiler Assembly code Assembler Object code (machine code) Fully-resolved object code (machine code) *. o, *. obj, … Linker *. exe Loader Executable image 7
Structure of a Compiler • Front end: analysis – Read source program and understand its structure and meaning • Back end: synthesis – Generate equivalent target language program Source Front End Back End Target 8
Standard Compiler Structure Source code (character stream) Lexical analysis Token stream Parsing Abstract syntax tree Front end (machine-independent) Intermediate Code Generation Intermediate code Optimization Back end Intermediate code Code generation (machine-dependent) Assembly code 9
Objectives • Compiling • Software Testing • Identifier Naming 10
Observations about Testing • “Testing is the process of executing a program with the intention of finding errors. ” – Myers • “Program testing can be a very effective way to show the presence of bugs, but it is hopelessly inadequate for showing their absence. ” Dijkstra
Definition of Software Testing is the process of executing a software system to determine whether it matches its specification and executes in its intended environment
Terminology: Bugs • Bugs, a. k. a. – Defect – Fault – Problem – Error – Incident – Anomaly – Variance – Failure – Inconsistency – Product Anomaly – Product Incidence – Feature : -)
Goal of Software Testing • Ideal goal: finding every fault in a software system • However, in practice, not all bugs/faults can be found – Too many possible paths – Too many possible inputs – Too many possible user environments 14
Too Many Possible Paths
Too Many Possible Paths • There are 5 paths from A to X without passing through the loop. • There are 520 paths from A to X after passing through the loop 20 times. • There are 5 + 52 + 53 +…+ 520 = 100 trillion possible paths in this program. • If you could test a path per second it would take more than 3 million years!
Too Many Possible Inputs • Programs take input in a variety of ways: mouse, keyboard, and other devices • Must test Valid and Invalid inputs • Most importantly, there an infinite amount of sequences of inputs to be tested
Too Many Possible User Environments • Difficult to replicate the user’s combination of hardware, peripherals, OS, and applications • Impossible to replicate a thousand-node network to test networking software
Reasons that Bugs Escape Testing • User executed untested code • User executed statements in a different order than was tested • User entered an untested combination of inputs • User’s operating environment was not tested
Test Methods • • • Unit Testing (White Box or Glass Box Testing) Function Testing (Black Box) Integration Testing Regression Testing System Test
Black-Box / White-Box Testing • Black-box tests are driven by the program’s specification • White-box tests are driven by the program’s implementation Specification Blackbox tests White-box Program tests
Black Box Testing • Checks that the product conforms to specifications • Cannot determine how much code has been tested Program Omissions detected by black-box tests
White Box Testing • Allows tester to be sure every statement has been tested • Difficult to discover missing functionality Program Commissions detected by White-box tests
Unit Testing (White Box) • Individual components are tested • It is a path test • To focus on a relatively small segment of code and aim to exercise a high percentage of the internal path • Disadvantage: the tester may be biased by previous experience, and the test value may not cover all possible values
Function Testing (Black Box) • • • Designed to test its external specifications Testers not biased by knowledge of the program’s design. Disadvantages: 1. The need for explicitly stated requirements 2. Only cover a small portion of the possible test conditions.
Integration Testing • Top-down Integration Test • Bottom-up Integration Test
Top-down Integration Test • The control program is tested first. Modules are integrated one at a time. Emphasize on interface testing • Advantages: – No test drivers needed – Interface errors are discovered early – Modular features aid debugging • Disadvantages: – Test stubs are needed – Errors in critical modules at low levels are found late.
Bottom-up Integration Test • Allow early testing aimed at proving feasibility Emphasize on module functionality and performance • Advantages: – No test stubs are needed – Errors in critical modules are found early • Disadvantages: – Test drivers are needed – Interface errors are discovered late
Regression Testing • Test the effects of the newly introduced changes on all the previously integrated code • The common strategy is to accumulate a comprehensive regression bucket but also to define a subset. • The full bucket is run only occasionally, but the subset is run against every spin. • Disadvantages: 1. To decide how much of a subset to use and which tests to select.
What is Test Planning? • • • Define the functions, roles and methods for all test phases. Test planning usually start during the requirements phase. Major test plan elements are: 1. Objectives for each test phase 2. Schedules and responsibilities for each test activity 3. Availability of tools, facilities and test libraries. 4. Set the criteria for test completion
Test Execution & Reporting • Testing should be treated like an experiment • Testing require that all anomalous behavior be noted and investigated • Big companies keep a special library with all copies of test reports, incident forms, and test plans
Real-Time Testing • • Real-Time testing is necessary because the deployment system is usually more complicate than development system Rules apply for testing real time system 1. Evaluate possible deadlocks, thrashing to special timing conditions 2. Use tests to simulate hardware faults 3. Use hardware simulation to stress the software design 4. Design ways to simulate modules missing in the development system
Objectives • Compiling • Software Testing • Identifier Naming 33
Identifiers • Identifier: name of a variable or any other named construct – Variable names – Function names – Class names – Object names –… 34
Identifiers (cont'd) • Naming Convention of Identifiers – The identifier in C++ must start with a letter or underscore symbol (_) – The rest of the characters should be letters, digits or underscores 35
Identifiers (cont'd) • Two Styles of Identifiers – C-style - terse, use abbreviations and underscores to separate the words, never use capital letters for variables – Camel Case - if multiple words: capitalize, do not use underscores • variant: first letter lowercased • Pick one style and use consistently 36
Identifiers (cont'd) • Examples: 37
Exercises -- Debugging Errors • • • unsigned int num=1; int num 2=-5; num = num 2; float num 3 = 5 f; Double num 4=+7. 0; bool bit=flase; num 5=9; long num 6=10 short num 7; int 8_num; char = "A"; int hello_world!_program = 0;
- Slides: 38