STM Unit - I
STM Unit - I
STM Unit - I
INTRODUCTION
1. PURPOSE OF TESTING:
Testing consumes atleast half of the time and work required to produce a functional
program.
MYTH: Good programmers write code without bugs. (Its wrong!!!)
History says that even well written programs still have 1-3 bugs per hundred statements.
Productivity and Quality in software:
o In production of comsumer goods and other products, every manufacturing stage
is subjected to quality control and testing from component to final stage.
o If flaws are discovered at any stage, the product is either discarded or cycled back
for rework and correction.
o Productivity is measured by the sum of the costs of the material, the rework, and
the discarded componenets, and the cost of quality assurance and testing.
o There is a trade off between quality assurance costs and manufacturing costs: If
UNIT – 1
sufficient time is not spent in quality assurance, the reject rate will be high and so
will be the net cost. If inspection is good and all errors are caught as they occur,
inspection costs will dominate, and again the net cost will suffer.
o Testing and Quality assurance costs for 'manufactured' items can be as low as 2%
in consumer products or as high as 80% in products such as space-ships, nuclear
reactors, and aircrafts, where failures threaten life. Where as the manufacturing
cost of a software is trivial.
o The biggest part of software cost is the cost of bugs: the cost of detecting them, the
cost of correcting them, the cost of designing tests that discover them, and the cost
of running those tests.
o For software, quality and productivity are indistinguishable because the cost of a
software copy is trivial.
Testing and Test Design are parts of quality assurance should also focus on bug
prevention. A prevented bug is better than a detected and corrected bug.
Phases in a tester's mental life can be categorised into the following 5 phases:
1. Phase 0: (Until 1956: Debugging Oriented) There is no difference between
testing and debugging. Phase 0 thinking was the norm in early days of software
development till testing emerged as a discipline.
2. Phase 1: (1957-1978: Demonstration Oriented) The purpose of testing here is to
show that software works. Highlighted during the late 1970s. This failed because
the probability of showing that software works 'decreases' as testing
increases. i.e. The more you test, the more likely you'ill find a bug.
3. Phase 2: (1979-1982: Destruction Oriented) The purpose of testing is to show
that software doesnt work. This also failed because the software will never get
Formal proofs of correctness rely on a combination of functional and human rather than machine. Some consequences of a bug on a scale of one to ten are:
structural concepts. 1. Mild: The symptoms of the bug offend us aesthetically (gently); a misspelled
Requirements are stated in a formal language (e.g. Mathematics) and output or a misaligned printout.
each program statement is examined and used in a step of an inductive 2. Moderate: Outputs are misleading or redundant. The bug impacts the system's
proof that the routine will produce the correct outcome for all possible performance.
input sequences. 3. Annoying: The system's behaviour because of the bug is
The IMPRACTICAL thing here is that such proofs are very expensive dehumanizing. E.g. Names are truncated orarbitarily modified.
and have been applied only to numerical routines or to formal proofs 4. Disturbing: It refuses to handle legitimate (authorized / legal) transactions. The
for crucial software such as system’s security kernel or portions of ATM wont give you money. My credit card is declared invalid.
compilers. 5. Serious: It loses track of its transactions. Not just the transaction itself but the fact
o Each approach leads to the conclusion that complete testing, in the sense of a proof that the transaction occurred. Accountability is lost.
is neither theoretically nor practically possible. 6. Very Serious: The bug causes the system to do the wrong transactions. Instead of
losing your paycheck, the system credits it to another account or converts deposits
THEORITICAL BARRIERS OF COMPLETE TESTING: to withdrawals.
o "We can never be sure that the specifications are correct" 7. Extreme: The problems aren't limited to a few users or to few transaction types.
o "No verification system can verify every correct program" They are frequent and arbitrary instead of sporadic infrequent) or for unusual
o "We can never be certain that a verification system is correct" cases.
Not only all known approaches to absoulte demonstrations of correctness impractical, but 8. Intolerable: Long term unrecoverable corruption of the database occurs and the
they are impossible. Therefore, our objective must shift from a absolute proof to a corruption is not easily discovered. Serious consideration is given to shutting the
'suitably convincing' demonstration. system down.
9. Catastrophic: The decision to shut down is taken out of our hands because the
4. CONSEQUENCES OF BUGS: system fails.
10. Infectious: What can be worse than a failed system? One that corrupt other
IMPORTANCE OF BUGS: The importance of bugs depends on frequency, correction systems even though it doesnot fall in itself ; that erodes the social physical
cost, installation cost, and consequences. environment; that melts nuclear reactors and starts war.
1. Frequency: How often does that kind of bug occur? Pay more attention to the
more frequent bug types.
Also includes evaluation of boolean expressions in deeply nested short, typically the processing time of one transaction. A storage object may be
IF-THEN-ELSE constructs. used to hold dynamic data of different types, with different formats, attributes
If the bugs are parts of logical (i.e. boolean) processing not related to control and residues.
flow, they are characterized as processing bugs. Dynamic data bugs are due to leftover garbage in a shared resource. This can be
If the bugs are parts of a logical expression (i.e control-flow statement) which is handled in one of the three ways: (1) Clean up after the use by the user (2)
used to direct the control flow, then they are categorized as control-flow bugs. Common Cleanup by the resource manager (3) No Clean up
11. Processing Bugs: Static Data are fixed in form and content. They appear in the source code or
Processing bugs include arithmetic bugs, algebraic, mathematical function database directly or indirectly, for example a number, a string of characters, or a
evaluation, algorithm selection and general processing. bit pattern.
Examples of Processing bugs include: Incorrect conversion from one data Compile time processing will solve the bugs caused by static data.
representation to other, ignoring overflow, improper use of grater-than-or-eual Information, parameter, and control: Static or dynamic data can serve in one of
etc three roles, or in combination of roles: as a parameter, for control, or for information.
Although these bugs are frequent (12%), they tend to be caught in good unit Content, Structure and Attributes: Content can be an actual bit pattern, character
testing. string, or number put into a data structure. Content is a pure bit pattern and has no
12. Initialization Bugs: meaning unless it is interpreted by a hardware or software processor. All data bugs
Initialization bugs are common. Initialization bugs can be improper and result in the corruption or misinterpretation of content. Structure relates to the size,
superfluous. shape and numbers that describe the data object, that is memory location used to store
Superfluous bugs are generally less harmful but can affect performance. the content. (e.g A two dimensional array). Attributes relates to the specification
Typical initialization bugs include: Forgetting to initialize the variables before meaning that is the semantics associated with the contents of a data object. (e.g. an
first use, assuming that they are initialized elsewhere, initializing to the wrong integer, an alphanumeric string, a subroutine). The severity and subtlelty of bugs
format, representation or type etc increases as we go from content to attributes because the things get less formal in that
Explicit declaration of all variables, as in Pascal, can reduce some initialization direction.
problems.
Dept. of CSE Page 14 . Dept. of CSE Page 15
CODING BUGS: 4. Operating System Bugs:
Coding errors of all kinds can create any of the other kind of bugs. Program bugs related to the operating system are a combination of
Syntax errors are generally not important in the scheme of things if the source language hardware architecture and interface bugs mostly caused by a
translator has adequate syntax checking. misunderstanding of what it is the operating system does.
If a program has many syntax errors, then we should expect many logic and coding Use operating system interface specialists, and use explicit interface
bugs. modules or macros for all operating system calls.
The documentation bugs are also considered as coding bugs which may mislead the This approach may not eliminate the bugs but at least will localize them
maintenance programmers. and make testing easier.
INTERFACE, INTEGRATION, AND SYSTEM BUGS: 5. Software Architecture:
Various categories of bugs in Interface, Integration, and System Bugs are: Software architecture bugs are the kind that called - interactive.
1.External Interfaces: Routines can pass unit and integration testing without revealing such
The external interfaces are the means used to communicate with the bugs.
world. Many of them depend on load, and their symptoms emerge only when
These include devices, actuators, sensors, input terminals, printers, and the system is stressed.
communication lines. Sample for such bugs: Assumption that there will be no interrupts,
The primary design criterion for an interface with outside world should Failure to block or un block interrupts, Assumption that memory and
be robustness. registers were initialized or not initialized etc
All external interfaces, human or machine should employ a protocol. Careful integration of modules and subjecting the final system to a
The protocol may be wrong or incorrectly implemented. stress test are effective methods for these bugs.
Other external interface bugs are: invalid timing or sequence 6. Control and Sequence Bugs (Systems Level):
assumptions related to external signals These bugs include: Ignored timing, Assuming that events occur in a
Misunderstanding external input or output formats. specified sequence, Working on data before all the data have arrived
Insufficient tolerance to bad input data. from disc, Waiting for an impossible combination of prerequisites,
2. Internal Interfaces: Missing, wrong, redundant or superfluous process steps.
Internal interfaces are in principle not different from external interfaces The remedy for these bugs is highly structured sequence control.
but they are more controlled. Specialize, internal, sequence control mechanisms are helpful.
A best example for internal interfaces are communicating routines. 7. Resource Management Problems:
The external environment is fixed and the system must adapt to it but Memory is subdivided into dynamically allocated resources such as
the internal environment, which consists of interfaces with other buffer blocks, queue blocks, task control blocks, and overlay buffers.
components, can be negotiated. External mass storage units such as discs, are subdivided into memory
Internal interfaces have the same problem as external interfaces. resource pools.
3. Hardware Architecture: Some resource management and usage bugs: Required resource not
Bugs related to hardware architecture originate mostly from obtained, Wrong resource used, Resource is already in use, Resource
misunderstanding how the hardware works. dead lock etc
Examples of hardware architecture bugs: address generation error, i/o Resource Management Remedies: A design remedy that prevents
device operation / instruction error, waiting too long for a response, bugs is always preferable to a test method that discovers them.
incorrect interrupt handling etc. The design remedy in resource management is to keep the resource
The remedy for hardware architecture and interface problems is two structure simple: the fewest different kinds of resources, the fewest
fold: (1) Good Programming and Testing (2) Centralization of hardware pools, and no private resource management.
interface software in programs written by hardware interface
specialists.
Figure 1.2: Program Example (PDL) Figure 1.4: Control Flowgraph for example in Figure 1.2
Dept. of CSE Page 22 Dept. of CSE Page 23
Linked List representation of Flow Graph:
The final transformation is shown in Figure 1.6, where we've dropped the node numbers to
achieve an even simpler representation. The way to work with control flowgraphs is to use the Figure 1.7: Linked List Control Flowgraph Notation
simplest possible representation - that is, no more information than you need to correlate back to
the source program or PDL. FLOWGRAPH - PROGRAM CORRESPONDENCE:
LINKED LIST REPRESENTATION: A flow graph is a pictorial representation of a program and not the program itself, just as a
topographic map.
Although graphical representations of flowgraphs are revealing, the details of the control flow You cant always associate the parts of a program in a unique way with flowgraph parts because
inside a program they are often inconvenient. many program structures, such as if-then-else constructs, consists of a combination of decisions,
In linked list representation, each node has a name and there is an entry on the list for each link in junctions, and processes.
the flow graph. only the information pertinent to the control flow is shown. The translation from a flowgraph element to a statement and vice versa is not always unique. (See
Figure 1.8)
An improper translation from flowgraph to code during coding can lead to bugs, and improper For X negative, the output is X + A, while for X greater than or equal to zero, the output is X + 2A.
translation during the test design lead to missing test cases and causes undiscovered bugs. Following prescription 2 and executing every statement, but not every branch, would not reveal
FLOWGRAPH AND FLOWCHART GENERATION: the bug in the following incorrect version:
Flowcharts can be
1. Handwritten by the programmer.
2. Automatically produced by a flowcharting program based on a mechanical analysis of the
source code.
3. Semi automatically produced by a flow charting program based in part on structural analysis
of the source code and in part on directions given by the programmer.
There are relatively few control flow graph generators. A negative value produces the correct answer. Every statement can be executed, but if the test
cases do not force each branch to be taken, the bug can remain hidden. The next example uses a
PATH TESTING - PATHS, NODES AND LINKS: test based on executing each branch but does not force the execution of all statements:
Path: a path through a program is a sequence of instructions or statements that starts at an entry,
junction, or decision and ends at another, or possibly the same junction, decision, or exit. A path
may go through several junctions, processes, or decisions, one or more times.
Paths consists of segments.
The segment is a link - a single process that lies between two nodes.
A path segment is succession of consecutive links that belongs to some path.
The length of path measured by the number of links in it and not by the number of the
instructions or statements executed along that path.
The name of a path is the name of the nodes along the path.
The hidden loop around label 100 is not revealed by tests based on prescription 3 alone because
no test forces the execution of statement 100 and the following GOTO statement. Furthermore,
Execute all possible control flow paths through the program: typically, this Not looping. But, experience shows that many loop-related bugs are not discovered
is restricted to all possible entry/exit paths through the program. by C1+C2. Bugs hide themselves in corners and congregate at boundaries - in the
If we achieve this prescription, we are said to have achieved 100% path cases of loops, at or around the minimum or maximum number of times the loop can
coverage. This is the strongest criterion in the path testing strategy family: be iterated. The minimum number of iterations is often zero, but it need not be.
it is generally impossible to achieve. CASE 1: Single loop, Zero minimum, N maximum, No excluded values
1. Statement Testing (P1): 1. Try bypassing the loop (zero iterations). If you can't, you either have a
Execute all statements in the program at least once under some test. If we bug, or zero is not the minimum and you have the wrong case.
do enough tests to achieve this, we are said to have achieved 100% 2. Could the loop-control variable be negative? Could it appear to specify a
statement coverage. negative number of iterations? What happens to such a value?
An alternate equivalent characterization is to say that we have achieved 100% 3. One pass through the loop.
node coverage. We denote this by C1. 4. Two passes through the loop.
This is the weakest criterion in the family: testing less than this for new 5. A typical number of iterations, unless covered by a previous test.
software is unconscionable (unprincipled or can not be accepted) and 6. One less than the maximum number of iterations.
should be criminalized. 7. The maximum number of iterations.
2. Branch Testing (P2): 8. Attempt one more than the maximum number of iterations. What
Execute enough tests to assure that every branch alternative has been prevents the loop-control variable from having this value? What will
exercised at least once under some test. happen with this value if it is forced?
If we do enough tests to achieve this prescription, then we have achieved
100% branch coverage.
An alternative characterization is to say that we have achieved 100% link CASE 2: Single loop, Non-zero minimum, No excluded values
coverage.