Lecture Slides
Lecture Slides
Software Development
Thomas Chiang
September – December 2023
Who am I?
1
1
My Background
2
Areas of Research
3
• Safety Engineering
Assruance Cases and Safety Cases
Safety Requirements Engineering
Risk Assessment and Safety Analysis
• Model Driven-Engineering
Model based design
Model based requirements
Code generation
2
Research in McSCert
4
• Automotive Software
Publication:
• Chiang, Thomas, et al. "Towards the adoption of model based system safety engineering in
the automotive industry." Proceedings of the 25th International Conference on Model
Driven Engineering Languages and Systems: Companion Proceedings. 2022.
• Paige, R. F., Polack, F. A., Zschaler, S., Chiang, T., & Annable, N. (2022). Interface
Contracts for Workflow+ Models: an Analysis of Uncertainty across Models. Journal of
Object Technology, 21(4).
• Annable, N., Chiang, T., Lawford, M., Paige, R. F., & Wassyng, A. (2022). Generating
Assurance Cases Using Workflow Models. In International Conference on Computer
Safety, Reliability, and Security (pp. 97-110). Springer, Cham.
• Chiang, T. (2021). Creating An Editor For The Implementation of WorkFlow+: A Framework
for Developing Assurance Cases (Doctoral dissertation).
COURSE INFO
5
• Recommended Reference:
“Fundamentals of Software Engineering” Carlo Ghezzi, Mehdi Jazayeri, Dino Mandrioli,
Second Edition.
3
TA
6
Course Description
7
4
Important Explanation
8
Lectures Project
System development Simulink
Design Communications
Implementation
5
Software Engineering - 1
10
built by teams
undergo changes
10
Software Engineering - 2
11
11
6
SE in system design
12
• Embedded software
Software constrained to work in a very specific environment
Need disciplined software development
Cyber Physical Systems (CPS) have become very complex and require a very well-
trained work force
12
• The following are examples from news services in the past few years
13
7
Health-care database
14
14
Pacemaker recall
15
15
8
Car stall due to software
16
16
UK tax software
17
17
9
Infusion pumps
18
18
Gamma Knife
19
19
10
Therapy Planning
20
20
Radiation Overdose
21
From the New York Times
21
11
And Again
22
22
Pacemaker Security
23
23
12
Pacemaker Security
24
24
25
13
Medical Device Security
26
26
27
14
Over-the-Air Updates
28
28
Over-the-Air Updates
for Cars! 29
29
15
Self Driving Tesla
30
30
31
16
Uber Self-driving Car
32
32
A Taste of Challenges
33
33
17
A Taste of Challenges
34
34
35
18
Regulatory Environments
36
36
37
19
Example: Medical Devices
38
38
Standards
39
39
20
Standards (continued)
40
40
Regulatory Summary
41
41
21
SOFTWARE DEVELOPMENT
STYLES 42
42
43
22
The (traditional) software
lifecycle - 2 44
Integration
Testing
SRS
Design
Unit
Testing
SDD
Review & Code
Verify
Application
Review &
Verify
44
*
System Reports
Requirements HAR
& Design Software Integration
Software Test Report
Requirements
Specification
* What happens in
a safety-critical
environment
Software
Design
Design Review and Description Unit Test
Verification Reports Report
Legend:
Documents produced in the
HAR
*
forward going development process
Documents produced by
verifications, reviews, analyses and
testing
* HAR
Code
Activities and data flow Code Review and
Verification Reports
HAR Hazard Analysis Report
45
23
The (traditional) software
lifecycle - 4 46
Spiral
model:
Boehm
1988
46
The V Model
47
An overview of the major steps – this view helps to start putting together
a view of “assurance”. We are primarily interested in safety assurance
User Acceptance
Testing
Implementation
47
24
Agile Development
48
• Different versions:
SCRUM
Extreme Programming (XP)
• https://agilemanifesto.org/
48
SCRUM
49
• User involved:
Product owner
Scrum master
Team members
• Workflow:
Product Backlog (Product Owner – top items to the team)
Sprint planning (Decide what goes to the next spring)
• Output: Sprint backlog (list of user stories for the next sprint)
Sprint
• 1-3 weeks to finish the sprint backlog
• Each day Daily Scrum
• Output: potentially shippable product
Sprint Review
• Show the project to the Owner
Sprint Retrospective
• How can we improve the process
49
25
Extreme Programming
50
50
51
26
Modern Trends
52
• Agile
Some people are distrustful of how Agile can be used to handle safety critical
engineering
Meant for smaller teams and smaller development cycles
• Waterfall
Some people dislike how long it takes to develop in waterfall
Bigger teams and bigger projects
Tried and tested for development of critical components
• Model-Driven Engineering
Likely to be THE development meth odology for the foreseeable future (in my
opinion)
52
Assurance
53
53
27
Summary: Development Life-Cycle
& Assurance 54
54
SOFTWARE CHALLENGES
55
• Complexity
• Lack of continuity
55
28
Complexity
56
Three structures of
varying complexity
56
With some
experience I may be
able to build this
without
requirements and a
design
57
29
How does complexity affect us?
58
58
No requirements.
No design.
No way!
59
30
How does complexity affect us?
60
No way!
60
61
31
Complexity in Software
62
A class diagram
[Example from
bitstorm.org]
Oracle e-Business
Suite has about 250K
classes, 6M methods!
62
Lines of code may not be a great measure of complexity, but they do measure something about complexity.
63
32
Continuity property
64
65
33
Lack of continuity property
66
66
Software is fragile!
from Ghezzi, Jazayeri, Mandrioli
67
34
Does Software Age?
68
68
• Is that true?
69
35
Does Software Age?
70
• Malfunctions and speed changes have implications for the way that the
software behaves – and if we do our job right, we can plan for those
changes so that the software does not “age”
70
Summary:
Why is software different? 71
• The engineering world has found that software is versatile, and that the
difficult and complex functions we need are easier to do in software
than in hardware – so software has become incredibly complex!
• For centuries we have learned to build system and test them relying on
the fact that physical systems exhibit a continuity property – but
software systems do not!
• Software does not age in the way that hardware does, so people
disregarded this as a problem – but software platforms (and the
environment in which the software operates) do age and this does
affect the way the software behaves!
71
36
Model-Driven Engineering
The Start 72
72
Model-Driven Engineering
(MDE) - 1 73
• Basic idea:
Models of the system you want to build – and its environment
Transformation of system model(s) through various phases, until we can generate
implementations (mechanical/electrical artifacts, code or other logic implementation)
73
37
Model-Driven Engineering
(MDE) - 2 74
• Benefits
Many types of analyses can be performed on the models to validate the initial model
Relatively easy methods for designing and communicating about software and
software concepts – from back of the envelope to full on code generation
74
Model-Driven Engineering
(MDE) - 3 75
Others include IBM Rational, and mainly in Europe, SCADE, and ANSYS
UML and its many profiles that are used for design and documentation of software
Note: Simulink is really a design environment. The constructs in the language are
focused on design rather than requirements – it is important to realize and
remember this!
Modularity: Up until recently Simulink designs did not use software engineering
principles to achieve effective modularity in the design. In particular, we would be
better off if we could design Simulink models so that they are more robust with
respect to future changes – we will discuss this in software design, in terms of
“information hiding”
75
38
Simulink – from the MathWorks
Web Site 76
76
• If we do not get the requirements “right” it does not matter how good we
are at building a system so that it complies with its requirements
• There are LOTS of ways of eliciting requirements (that is not the focus
of what we are going to do – but it is extremely important)
77
39
Requirements in Natural Language
78
78
Clear, unambiguous,
understandable 79
79
40
Clear, unambiguous,
understandable 80
80
81
41
Precise, unambiguous, clear
82
82
Consistent
83
83
42
Consistent
84
84
A (necessary) digression
Formal Specifications 85
85
43
Specifications - 1
86
consider floating-
point problems
86
Specifications - 2
87
87
44
Specifications - 2
88
88
Specifications - 2
89
89
45
Specifications - 3
90
Analysis
b = 0 Þ Ill defined
a=0: c
b¹0Þ x =-
b
b - 4ac < 0 Þ No real roots
2
b
a ¹ 0 : b2 - 4ac = 0 Þ x = -
2a
-b ± b 2 - 4ac
b 2 - 4ac > 0 Þ x =
2a
90
Specifications - 4
91
Tabular expression
Solution caption x1 x2
a = 0 b = 0 Ill defined — —
b ¹ 0 One root -c —
b
a ¹ 0 2
b - 4ac < 0 No real roots — —
-b
2
b - 4ac = 0 One root —
2a
2
b - 4ac > 0 b ³ 0 Two roots -b- b2 - 4ac c
2a ax1
91
46
Specifications - 4
92
92
Specifications - 5
93
Another example
• The operator in a real-time application requests or cancels a setpoint,
c_sp, by pressing momentary pushbuttons. There are two
pushbuttons, called m_pbON and m_pbOFF. They can take on the
values e_pressed and e_notPressed. We specify the required
behaviour as follows:
if (m_pbON = e_pressed ^ m_pbOFF = e_notPressed)
c_sp = e_requested
else if (m_pbON = e_notPressed ^ m_pbOFF = e_pressed)
c_sp = e_cancelled
93
47
Specifications - 5
94
Another example
• The operator in a real-time application requests or cancels a setpoint,
c_sp, by pressing momentary pushbuttons. There are two
pushbuttons, called m_pbON and m_pbOFF. They can take on the
values e_pressed and e_notPressed. We specify the required
behaviour as follows:
if (m_pbON = e_pressed ^ m_pbOFF = e_notPressed)
then c_sp = e_requested
else if (m_pbON = e_notPressed ^ m_pbOFF = e_pressed)
then c_sp = e_cancelled
• This is clearly a simple example. Any problems with this?
• What if both pushbuttons are not pressed?
• What if both pushbuttons are pressed?
94
Specifications - 5
95
Another example
• The operator in a real-time application requests or cancels a setpoint,
c_sp, by pressing momentary pushbuttons. There are two
pushbuttons, called m_pbON and m_pbOFF. They can take on the
values e_pressed and e_notPressed. We specify the required
behaviour as follows:
if (m_pbON = e_pressed ^ m_pbOFF = e_notPressed)
then c_sp = e_requested
else if (m_pbON = e_notPressed ^ m_pbOFF = e_pressed)
then c_sp = e_cancelled
95
48
Specifications - 5
96
Another example
• The operator in a real-time application requests or cancels a setpoint,
c_sp, by pressing momentary pushbuttons. There are two
pushbuttons, called m_pbON and m_pbOFF. They can take on the
values e_pressed and e_notPressed. We specify the required
behaviour as follows:
if (m_pbON = e_pressed ^ m_pbOFF = e_notPressed)
then c_sp = e_requested
else if (m_pbON = e_notPressed ^ m_pbOFF = e_pressed)
then c_sp = e_cancelled
• This is clearly a simple example. Any problems with this?
• What if both pushbuttons are not pressed?
• What if both pushbuttons are pressed? No specified behaviour
then no change in the
current value of c_sp.
And it is wrong!
96
Specifications - 5
97
Another example
• The operator in a real-time application requests or cancels a
setpoint, c_sp, by pressing momentary pushbuttons. There are two
pushbuttons, called m_pbON and m_pbOFF. They can take on the
values e_pressed and e_notPressed. We specify the required
behaviour as follows:
if (m_pbON = e_pressed ^ m_pbOFF = e_notPressed)
then c_sp = e_requested
else if (m_pbON = e_notPressed ^ m_pbOFF = e_pressed)
then c_sp = e_cancelled
• It is not clear to readers whether the unstated cases are really “no
action” cases, or oversights. In this example, if both pushbuttons
are not pressed it is reasonable (and correct) to assume there is no
change to c_sp. If both pushbuttons are pressed, the domain
experts (in the case I know about) required c_sp = e_requested!
97
49
Specifications - 6
98
Condition
c_sp
(m_pbON = e_notPressed) &
No Change
(m_pbOFF = e_notPressed)
(m_pbON = e_notPressed) &
e_cancelled
(m_pbOFF = e_pressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_notPressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_pressed)
98
Specifications - 6
99
Result
Condition
c_sp
(m_pbON = e_notPressed) &
No Change
(m_pbOFF = e_notPressed)
(m_pbON = e_notPressed) &
e_cancelled
(m_pbOFF = e_pressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_notPressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_pressed)
99
50
Specifications - 6
100
Condition
c_sp
(m_pbON = e_notPressed) &
No Change
(m_pbOFF = e_notPressed)
(m_pbON = e_notPressed) &
e_cancelled
(m_pbOFF = e_pressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_notPressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_pressed)
100
Specifications - 6
101
Condition
c_sp
(m_pbON = e_notPressed) &
No Change
(m_pbOFF = e_notPressed)
(m_pbON = e_notPressed) &
e_cancelled
(m_pbOFF = e_pressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_notPressed)
(m_pbON = e_pressed) &
e_requested
(m_pbOFF = e_pressed)
101
51
Specifications - 7
102
Condition
function name
condition 1 result 1
condition 2 result 2
… …
condition n result n
• Is equivalent to:
if (condition 1) then function name = result 1
else if (condition 2) then function name = result 2
else if …
else if (condition n) then function name = result n
• Disjointness: (so it is unambiguous)
condition i condition j FALSE i,j = 1,..,n, i ¹ j
• Completeness:
condition 1 condition 2 … condition n TRUE
102
Illustrates why the software design has different inputs and outputs from
the requirements!
103
52
The 4 Variable Model
104
NAT
M REQ C
IN I SOF O OUT
Software Design
Parnas, D.L., Madey, J.: Functional
documents for computer systems. C = REQ(M), and related to the
Science of
Computer Programming 25 software through
(1995) 41-61 I = IN(M) and C = OUT(O)
104
Variables
monitored NAT controlled
variables variables
M REQ C
input output
variables variables
IN I SOF O OUT
Software Design
Parnas, D.L., Madey, J.:
Functional documents for C = REQ(M), and related to the
computer systems. Science of
Computer Programming, 25 software through
(1995) 41-61 I = IN(M) and C = OUT(O)
105
53
The 4 Variable Model
106
M REQ C
requirements software
design
hardware hardware
IN I SOF O OUT
Software Design
Parnas, D.L., Madey, J.:
Functional documents for We now get a proof obligation:
computer systems. Science of
Computer Programming, 25 C=REQ(M)=OUT(SOF(IN(M)))
(1995) 41-61
106
Example of IN
107
107
54
Consequence
108
• Once we know this, we can deal with it really well, using a modified
version of the 4 Variable Model
108
109
55
Modified 4 Variable Model
110
110
111
56
In Class Example
112
112
In Class Example
113
113
57
Example Requirements
114
1. The security system has a detector that sends a trip signal when
motion is detected.
2. The security system is activated by pressing the SET button.
3. The SET button is illuminated when the system is active.
4. If a trip signal is detected while the system is active, an alarm is
sounded.
5. A three-digit code must be entered to turn off the alarm sound.
6. Correct entry of the three-digit code deactivates the device.
7. If a mistake is made when entering the code, the user must press the
CLEAR button before the entire code can be re-entered.
114
Notation
115
stimuli responses
trip signal
set pressed alarm sound (on/off)
clear pressed
good digit backlight (on/off)
bad digit
115
58
Notation
116
M_trip
M_set c_alarmSound
M_clear
M_goodDigit c_backlight
M_badDigit
116
Input Sequence
117
117
59
Input Sequence
118
118
Input Sequence
119
119
60
So how did that help us?
120
120
• Because now, for any sequence of stimuli, we know what the response
should be.
121
61
Responses
122
c_alarmSound c_backlight
no stimulus e_off e_off
M_set e_off e_on
M_set . M_trip e_on e_on
M_set . M_badDigit e_off e_on
M_set . M_goodDigit e_off e_on
M_set . M_trip . M_badDigit e_on e_on
M_set . M_trip . M_goodDigit e_on e_on
M_set . M_trip . M_goodDigit . M_goodDigit e_on e_on
M_set . M_goodDigit . M_goodDigit e_off e_on
122
Responses
123
c_alarmSound c_backlight
no stimulus e_off e_off
M_set e_off e_on
M_set . M_trip e_on e_on
M_set . M_badDigit e_off e_on
M_set . M_goodDigit e_off e_on
M_set . M_trip . M_badDigit e_on e_on
M_set . M_trip . M_goodDigit e_on e_on
M_set . M_trip . M_goodDigit . M_goodDigit e_on e_on
M_set . M_goodDigit . M_goodDigit e_off e_on
123
62
Responses
124
c_alarmSound c_backlight
no stimulus e_off e_off
M_set e_off e_on
M_set . M_trip e_on e_on
M_set . M_badDigit e_off e_on
M_set . M_goodDigit e_off e_on
M_set . M_trip . M_badDigit e_on e_on
M_set . M_trip . M_goodDigit e_on e_on
M_set . M_trip . M_goodDigit . M_goodDigit e_on e_on
M_set . M_goodDigit . M_goodDigit e_off e_on
One way: show current “state” & effect of each stimulus (try it)
124
125
63
Questions
126
• How does the sensor value that detects motion get into our software?
• How about the “secret” code to switch off the device or alarm sound?
How is it conveyed to the device?
126
Notation
127
127
64
M_badDigit & M_goodDigit
128
128
The true monitored variables are the digits ‘1’, ‘5’ etc
We should now determine how to “derive” badDigit and goodDigit given a monitored
variable M_digit for instance, where M_digit is one of ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’,
‘9’, ‘0’
129
65
Determining badDigit & goodDigit
130
• Given that the system knows the secret code (assume a string
of 3 characters called secretCode):
which leads us to …
130
131
66
M_trip
132
• In a real device, there would be hardware that detects motion and then
an interface to the software that delivers the value (in this case just the
equivalent of a boolean) so that the software can work with it
• In our case, we will just make a button that the user can click to trigger
M_trip
132
• To start, let us modify the requirements just a little, to say that a string
of 3 characters (numeric only) must be entered when the Set button is
pressed. Therefore, pressing the Set button will result in entering the
secret code and then switching the device on
133
67
Anything Else?
134
134
Anything Else?
135
• At this stage, we will simply have a red area on the form to indicate the
alarm is sounding
135
68
Using digits to enter secret code
136
136
Initial state
137
69
CAS Super Alarm in Visual Studio
138
Entering the
secret code
138
Device active
139
70
CAS Super Alarm in Visual Studio
140
Alarm sounding
after Trip was
pressed
140
• First attempt
Use M_goodDigit and M_badDigit as inputs to the class that you create to
implement the CAS alarm.
Use a textbox on the form to input the secret code – shown in the next slide. After
user enters the code, pressing “NEXT” will check that the code is legal. If yes it
starts the alarm device. If not, clears textbox and user tries again. (Display an
appropriate error message.)
141
71
CAS Super Alarm in Visual Studio
142
• Now try the same thing but without making a textbox for the secret
code.
• This time:
User presses “SET”, enters a mode where we can set the secret code.
After the 3rd one is pressed, button changes to “SET” and is backlit in yellow.
• Also, use M_one, M_two etc as the variables input to the CAS alarm
class.
142
Requirements
143
143
72
Summary: Requirements
(not much on Validation) 144
• Importance of requirements
• Tabular expressions
• Timing requirements
144
DESIGN
145
145
73
Software Architecture & Design
146
• What is design?
• Design notations
146
What is design?
147
147
74
Two meanings of “design”
activity in our context 148
148
Requirements
SDD
Decomposed so
Decomposed so
domain experts
software will be
can read &
structured for
understand it
easy maintenance
easily
149
75
The sw design activity
150
150
Software Architecture
151
151
76
Two important goals
152
152
Module
153
153
77
Modularity
154
154
Questions
155
155
78
Unified Modeling Language
156
156
Class Diagrams
157
• Class diagram
represents a software
entity
• A class is made of 3
parts:
Name
Attributes
[represents state]
Methods [describes
behavior]
157
79
Class Diagrams
158
• Visibility:
+ public: can be accessed by any
other class
- private: access only within the
object permitted
# protected: access by objects within
the same class and subclasses
permitted
~ friendly: access by objects within
the same package
• Attribute:
Visibility name: type [multiplicity]
• Method:
Visibility name (parameters): return
type
158
Class Diagrams
159
159
80
Class Diagrams
160
• 5 types of references:
Association
Composition
• Think of it as ownership (black
diamond owns the opposite end)
• Class on left is deleted, class on
right also deleted
160
Class Diagrams
161
Inheritance
• Inherits all the properties
from the white arrow
Interface
• Needs the white arrow
class to be used by other
entities
• Can be thought of as ‘uses’
161
81
Class Diagrams
162
162
163
82
State Machine Diagrams
164
• Typically FSM will have one initial state where everything starts
164
165
83
Sequence Diagrams
166
166
Sequence Diagrams
167
167
84
Sequence Diagrams
168
168
Sequence Diagrams
169
169
85
Sequence Diagrams
170
170
Sequence Diagrams
171
171
86
Sequence Diagrams
172
172
Sequence Diagrams
173
173
87
Sequence Diagrams
174
174
Sequence Diagrams
175
175
88
Sequence Diagrams
176
176
Sequence Diagrams
177
177
89
Sequence Diagrams
178
178
Sequence Diagrams
179
179
90
Sequence Diagrams
180
180
Relations 181
a graph
a DAG
181
91
The USES Relation
182
• A uses B
it is “statically” defined
• A is a client of B; B is a server
182
Desirable property
183
we can proceed from leaf nodes (who do not use others) upwards
183
92
Other hierarchies
184
• Composition hierarchy
Important to remember what modules are owned by others
• Inheritance hierarchy
When you inherit from another class, you inherit everything
Often end up with a lot of bloat in the classes when too much is inherited
184
understandable separately
185
93
Cohesion and Coupling
Visually 186
(a)(b)
Usually an
indication of
reasonable
cohesion
high coupling low coupling
186
Conceptual App
modules
Leaf modules
contain
code
187
94
Module Fundamentals
188
Name
Interface
Types
Constants
Access programs
188
Module Fundamentals
189
Name
Interface
Types
Constants
Access programs
Hidden
from Implementation
everyone Types
other Constants
than the Variables
designers
of the Details of access programs &
module local programs
189
95
Module Fundamentals
190
Module A Module B
int getS1 int getV
int getS2 setValue(int n)
setValues(int v1,v2)
190
Interface vs.
Implementation (1) 191
• The client imports the resources that are exported by its servers
191
96
Interface vs.
Implementation (2) 192
192
Interface vs.
Implementation (3) 193
193
97
Interface vs.
Implementation (3) 194
194
Interface vs.
Implementation (4) 195
• There are lots of different ways of doing this, ranging from natural
language to formal notations – we will look at some of them briefly later
in the course
195
98
Information Hiding
196
• They can be changed freely if the change does not affect the interface
INFORMATION HIDING
196
Information Hiding
197
• Hardware
• Behaviour
• Design decisions
197
99
Information Hiding
198
• Hardware
Sensors, input devices, actuators, output devices, floating point accelerators, the
computer platform/micro-controller
• Behaviour
Number of items, algorithm, timing behaviour,
• Design decisions
Data structures, algorithm, computer platform,
198
Information Hiding
199
• Things to do:
199
100
Interface Design
200
200
Prototyping
201
• Initial version acts as a prototype that evolves into the final product
201
101
Design frameworks/notations
202
202
203
102
RDP - MG
204
• The leaf modules that represent code will contain much more precise
responsibilities and secrets
204
RDP - MG Example
205
… … … …
205
103
Example Overview of a MG
206
206
RDP - MIS
207
• For each leaf module we need to document its interface and its
implementation.
207
104
MIS
208
208
RDP - Views
209
209
105
RDP - MID
210
210
211
106
Documentation of Modules 212
Note: in OOP
“modules” are Individual designers
“classes” and Program n+m Name
“access
programs” are ...
Interface design team
“methods”
Available to all designers
Program 2 Name
We will compare Defines design tasks for
module designers
modules and
classes later on, Program 1 Name
Spec ...
Access Program n Name
Parameters
Description
References
212
• Complete
Every software requirement is implemented in the design
Functions are complete on their input domains
• Correct
Every software requirement is correctly implemented – within tolerance
• Structure
USES relationship is a hierarchy
Modules (classes) exhibit low coupling and high cohesion
Interfaces do not include state variables
Interfaces do not disclose secrets
MIS and MID are adequate requirements for the implementation
The MID of a USED module is not required to design the internal of the module that
USES it
• Maintenance
A list of likely requirements & design changes is provided
Secrets are documented in the MG
Each secret is encapsulated in a module
213
107
System Design
214
System Requirements
System Design
214
NAT
However, that is almost always not
possible. The behaviour is too complex to
describe it in a single function/relation.
So, we use intermediate functions to M C
describe behaviours that still make sense
to the domain expert, and the overall
behaviour is given by the composition of
those functions.
215
108
System Design – Overview
216
216
The hardware
functions that M C
represent IN and
OUT must be
described by M-I
and O-C mappings.
217
109
Traditional Modules vs Classes
218
• Older design paradigms and coding languages used coding units which
were procedural abstractions – they encapsulated a series of program
steps so that they could be used over-and-over. Sometimes those steps
returned values calculated in that unit much like a mathematical
function, and sometimes they did not. In older languages like FORTRAN
they were called functions (returned a value associated with the name
of the function) or procedures (did not return a value, or returned values
associated with variables in the parameter list)
• This was a huge move forward to providing structures that we can use
to put together procedural abstractions together with data that they
operate on, all in one package
219
110
Abstract data types (ADTs)
220
• A stack ADT
indicates that details of the data
structure are hidden to clients. A clumsy
way of doing it, not necessary in OOP
module STACK_HANDLER
exports
type STACK = ?;
This is an abstract data-type module; the data structure
is a secret hidden in the implementation part.
procedure PUSH (S: in out STACK ; VAL: in integer);
procedure POP (S: in out STACK ; VAL: out integer);
function EMPTY (S: in STACK) : BOOLEAN;
.
.
.
end STACK_HANDLER
220
Object-oriented design
221
• You can think of it this way: “Class” acts as a kind of Type, and
Objects of the Class are really variables of that Type
• So, if we have Class STACK, with method push(int v), then we can
instantiate 2 objects of stacks, by
STACK S1, S2;
And
S1.push(3); S2.push(6);
pushes the number 3 onto stack S1 and pushes 6 onto stack S2. These
stacks are completely independent – they have their own storage areas
221
111
Syntactic changes in OOP
222
• If a is a reference to an object
a.op (params);
222
• A is a superclass of B
• B is a subclass of A
223
112
An example - 1
224
224
An example - 2
225
225
113
Inheritance
226
• Polymorphism
a variable referring to type A can refer to an object of type B if B is a subclass
of A
• Dynamic binding
the method invoked through a reference depends on the type of the object
associated with the reference at runtime
226
• Essentials
For each access program, description of its black-box behaviour, not how it is
implemented. Assumptions and limitations must also be described. An excellent
way of describing black-box behaviour of the access program is to describe the
relation between outputs and inputs of the program
227
114
Classification of specification
styles 228
• Operational
Behavior specification in terms of some abstract machine
• Descriptive
Behavior described in terms of properties
228
Example 1 229
229
115
Example 1 230
P
1 P
2
230
A descriptive specification
231
231
116
Example 2 232
232
233
117
DFDs - Graphical notation
234
234
DFD Example
235
b a d
c
specifies evaluation of
+ * +
(a + b) * (c + a * d)
235
118
An evaluation of DFDs - 1
236
• Outputs from A, B, C
are all needed?
• Outputs for E and F
are produced at the
same time?
236
An evaluation of DFDs - 2
237
Possible interpretations:
(a) A produces datum, waits until B consumes it
(b) B can read the datum many times without
consuming it
(c) a pipe is inserted between A and B
237
119
Formalization/extensions 238
238
borrow
book
return
book librarian
customer
library
update
239
120
Finite state machines again 240
• Defined as
a finite set of states, Q;
a finite set of inputs, I;
a transition function d : Q x I Q
(d can be a partial function)
State Transition
Diagram
240
q0 q1 q2 q3
a q1 q2 - -
b - q3 q3 -
c - - - q0
State Transition
Table
241
121
Finite state machines - 2 242
q0 q1 q2 q3
a q1 q2 - -
b - q3 q3 -
c - - - q0
State Transition
Table
242
FSM Limitations
243
• Finite memory
• State explosion
Given a number of FSMs with k1, k2, … kn states, their composition is a FSM with k1
* k2 *… * kn. This growth is exponential with the number of FSMs, not linear (we
would like it to be k1 + k2 +… + kn )
243
122
Mills’ Black-Box
244
System
R = f ( S, Sh )
S is the set of stimuli, Sh the set of
stimulus history, R the set of responses
244
Logic specifications
245
• x=yy=x
• x+1<x–1
• x > 3 or x < -6
245
123
Logic specifications
246
• x=yy=x
• x+1<x–1
246
Pre: precondition
Post: postcondition
247
124
Example - 1
248
• Division
248
Example - 2
249
249
125
Example - 3
250
250
Specifying procedures
251
{n > 0 }
procedure reverse (a: in out integer_array; n: in integer);
{for all i (1 i n) implies (a’(i) = ‘a(n - i +1))}
251
126
Specifying classes - 1
252
252
Specifying classes - 2
253
253
127
Specifying classes - 3
254
254
• They are easy to read and understand (you need just a little
practice to write them)
255
128
Disadvantage of Fn Tables
256
256
• Events can be viewed as “pulses” in time - they do not last (retain their
values) – we have referred to this as “time-discrete”
event
time
True condition
False
time
257
129
VERIFICATION
258
• Why we do it
• How we do it
258
Outline 259
259
130
Need for verification
260
• Designers are fallible even if they are skilled and follow sound
principles
260
Properties of verification
261
e.g., usability
e.g., robustness
261
131
Approaches to verification
262
dynamic technique
static technique
262
• No continuity of behavior
it can exhibit correct behavior in infinitely many cases, but may still be
incorrect in some cases
263
132
Goals of testing
264
264
• Should be repeatable
repeating the same experiment, we should get the same results
• this may not be true because of the effect of execution environment on testing
• because of non-determinism
• Should be accurate
265
133
Definitions (1)
266
P: D R (may be partial)
• Correctness defined by OR D R
266
Definitions (2)
267
• FAILURE
P(d) is not correct
• ERROR (DEFECT)
anything that may cause a failure
• typing mistake
• FAULT
incorrect intermediate state entered by program
267
134
Definitions (3) 268
• Test case t
– an element of D
• Test set T
– a finite subset of D
268
Definitions (4)
269
• if an ideal test set exists for any program, we could prove program
correctness by testing
269
135
Test criterion
270
C 2D
Example
C = {<x1, x2,..., xn> | n ³ 3 i, j, k, ( xi<0 xj=0 xk>0)}
<-5, 0, 22> is a test set that satisfies C
<-10, 2, 8, 33, 0, -19> also does
<1, 3, 99> does not
270
Properties of criteria
271
• C is consistent
for any pairs T1, T2 satisfying C, T1 is successful iff T2 is successful
• C is complete
if P is incorrect, there is a test set T of C that is not successful
271
136
Properties of criteria
272
• C is consistent
for any pairs T1, T2 satisfying C, T1 is successful iff T2 is successful
• C is complete
if P is incorrect, there is a test set T of C that is not successful
272
Properties of definitions
273
273
137
Empirical testing principles
274
274
Complete-Coverage Principle
275
275
138
Complete-Coverage Principle
276
example of a partition
276
277
139
White Box Testing
278
Pass if observed
result matches
expected result
within expected
tolerance –
otherwise Fail
278
• (In)adequacy criteria
Statement coverage
Edge coverage
Condition coverage
Path coverage
279
140
Statement-coverage criterion
280
280
Example 281
281
141
Weakness of the criterion
282
282
Edge-coverage criterion
283
• Select a test set T such that every edge (branch) of the control flow is
exercised at least once by some t in T
this requires formalizing the concept of the control graph, and how to
construct it
nodes at the ends of an edge represent entry into the statement and exit
283
142
Control graph construction rules
284
G1 G2 G1
I/O, assignment,
or procedure call
if-then-else if-then
G1
two sequential
statements
G1
G2
while loop
284
Simplification
285
285
143
Example: Euclid's algorithm
286
begin
read (x); read (y);
while x ≠ y loop
if x > y then x := x - y;
else y := y - x;
end if;
end loop;
gcd : = x;
end;
286
Weakness
287
test cases: (1) empty table, (2) table with 3 items, second of which is
the item to look for
287
144
Weakness
288
test cases: (1) empty table, (2) table with 3 items, second of which is
the item to look for
288
Condition-coverage criterion
289
• Select a test set T such that every edge of P’s control flow is traversed
and all possible values of the constituents of compound conditions are
exercised at least once
289
145
Weakness
290
290
Path-coverage criterion
291
• Select a test set T which traverses all paths from the initial to the final
node of P’s control flow
however, number of paths may be too large, or even infinite (see while loops)
291
146
The infeasibility problem
292
292
Further problem
293
• White box test cases derived from the code will ignore that part of the
specification!
293
147
Black Box Testing
294
Pass if observed
result matches
expected result
within expected
tolerance –
otherwise Fail
294
The specification
295
295
148
Did you consider these cases?
296
296
297
149
Logic specification of insertion
of invoice record in a file 298
insert(x, f)
{
sorted_by_date(f) and
for all k (old_f(k) = z implies exists j (f(j) = z)) and
for all k (f(k) = z and z ≠ x) implies exists j (old_f(j) = z) and
exists j (f(j). date = x. date and f(j) ≠ x) implies j < pos(x, f) and
result x.customer belongs_to customer_file and
warning (x belongs_to old_f or x.date < current_date or ....)
}
298
TRUE implies
sorted_by_date(f) and for all k old_f(k) = z
implies exists j (f(j) = z) and
for all k (f(k) = z and z ≠ x) implies exists j (old_f(j) = z)
and
(x.customer belongs_to customer_file) implies result
and
not (x.customer belongs_to customer_file and ...)
implies not result
and
x belongs_to old_y implies warning
and
x.date < current_date implies warning
and
....
299
150
Function table-based testing
300
Condition
f_name
y5 res 1
x<0 y=5
y>5 res 2
x=0 res 3
x>0 res 4 x=0
300
Condition
f_name
y5 res 1
x<0 y=5
y>5 res 2
x=0 res 3
x>0 res 4 x=0
301
151
Testing boundary conditions
302
302
Criterion
303
• After partitioning the input domain D into several classes, test the
program using input values not only “inside” the classes, but also at
their boundaries
303
152
MCDC Testing
304
304
305
153
Testing in the large
306
• Integration testing
integration of modules and subsystems
• System testing
testing the entire system
• Acceptance testing
performed by the customer
306
Module testing
307
stubs
• modules used by the module under test
driver
• module activating the module under test
307
154
Testing a functional module
308
PROCEDURE
STUB UNDER TEST DRIVER
CALL CALL
308
Integration testing
309
• Big-bang approach
• Incremental approach
309
155
Integration testing and USES
relation 310
310
Example
311
M
1 M
2
M
2,
1 M
2,
2
CASE 2
Implement M2,2 and test it by using a driver,
Implement M2,1 and test the combination of M2,1 and M2,2
(i.e., M2) by using a driver
Finally, implement M1 and test it with M2, using a driver for M1
311
156
Testing OO programs
312
• New issues
inheritance
genericity
polymorphism
dynamic binding
312
Inheritance
313
Personnel
Consultant Employee
313
157
How to test classes of the
hierarchy? 314
314
A sample strategy
315
• A test that must be performed for heir class X and all of its further
heirs
• A test that must be redone by applying the same input data, but
verifying that the output is not (or is) changed
315
158
Separate concerns in testing
316
• Overload testing
• Robustness testing
• Regression testing
organize testing with the purpose of verifying possible regressions of
software during its life—that is, degradations of correctness or other
qualities due to later modifications
316
317
159
Analysis
318
318
319
160
Informal analysis techniques
Code walkthroughs 320
• Recommended prescriptions
Small number of people (three to five)
Participants receive written documentation from the designer a few days before
the meeting
320
nonterminating loops;
321
161
Correctness Proofs
322
322
323
162
Model checking
324
324
Principles 325
the model checker either provides a proof that the property holds or gives a
counterexample in the form of a test case that exposes the system’s failure
to behave according to the property
325
163
Properties and proofs
326
there is always a computation that allows the left process to enter the critical region
there is no guarantee that the left process accesses the shared resource unless it
already owns it
326
• …
view all these as complementary
327
164
Debugging
328
328
• Important points about safety & security and how they are related
329
165
Safety Related Definitions
330
330
• Safety and security are global properties of a system, and are not
“compositional”
What does that mean? It means that if I take 2 components that are each safe on
their own, and put them together in some way, it is not necessarily true that their
composition is safe! Why does this happen? A primary culprit is emergent behaviour
– think of this as “feature interaction”
When we put the components together, the resulting system may exhibit behaviour
caused by the interaction of the components. That unanticipated, new behaviour
may or may not be safe!
• Often referred to as emergent behavior
Note: components not only interact with each other, they interact with the
environment as well
331
166
Intro to Hazard Analysis
332
• There are many different methods in use for hazard analysis. For a
very complete list and discussion you can see Clifton Ericson’s book(s)
332
333
167
How are safety & security
related? 334
H3
334
H3
335
168
What if there are malicious acts?
336
Design to Design to
eliminate eliminate H1
Hazard H2
Hazards
H2
H1
H3
Design to
eliminate Vulnerabilities
Hazard H3
336
Design to Design to
eliminate eliminate H1
Hazard H2
Hazards
H2
H1
H3
Design to
eliminate Vulnerabilities Threat
Hazard H3
337
169
Intro Safety Points
338
338
See “Understanding Integrity Level Concepts” in the Background Files for this course.
339
170
More (not so) Boring definitions
340
340
or
Trip Computer Shutdown
Channel D Mechanism
Redundant
Redundant shutdown
Trip Computer
Channels Channel E mechanisms
or
Shutdown
Mechanism
Trip Computer
Channel F
171
Why we need redundancy
342
342
343
172
Why we need diversity
344
or
Trip Computer Shutdown
or
Trip Computer Shutdown Channel G Mechanism
Channel D Mechanism
Trip Computer
Trip Computer Channel H
Channel E
or
Shutdown
or
Shutdown Mechanism
Mechanism
Trip Computer
Trip Computer Channel I
Channel F
Diverse designs
344
• Caution:
There was a great study years ago by Knight and Leveson that showed that simply
getting different teams to develop independent versions of a software application
(called N-version programming) typically does not help much, or at all, in avoiding
software design errors!
• We need to aim for something that has been called “enforced diversity”
External factors that make real diversity more likely
• Different hardware & software platforms
• Slightly different requirements – functional objectives
• Independent development teams
• A group of high level observers (project managers) who can direct diversity without
violating team diversity
345
173
We cannot live without DiD
346
State of the art – we do not even have theories for how to do a lot of what we want
to do
State of the practice – we do not even put into practice the things we do know how
to do
346
Examples:
• Physically – layered containment of radiation exposure in the event of a nuclear accident in
a generating station
• Conceptually – diversity in designs; redundancy in components subject to malfunction
• Procedurally – more than one way of performing verification
Testing to verify that implementation complies with requirements
Mathematical verification that implementation complies with requirements
347
174
Assuring safety
348
sub-claim
sub-claim
evidence
GSN COMMUNITY
STANDARD
VERSION 1 - 2011
348
349
175
(Safety) Lessons we have learned
350
350
HAZARD ANALYSIS
351
• Focus on:
Fault Tree Analysis (FTA)
Failure Modes and Effects Analysis (FMEA)
Systems Theoretic Process Analysis (STPA)
351
176
Fault Tree Analysis
352
352
From ConceptDraw.com
353
177
More than one way to do this
354
• Here is a an example done in our research unit some years ago – very
different from the one we just saw
354
Physician/ Patient
Technician
Insulin
User User
Control Flow
Settings Feedback
Controller
Infusion Delivery
Control
Writes to system log
Microcontroller
Status to Converting user
display on Ins tructions for input to system
LCD running the instructions
Context Diagram Actuator pump
Sensor
System Log LCD Mechanical Pump
User Input
Pump
transferring Controlled Process
insulin
Insulin Delivery
Insulin transfer
Display to to user
Available to User inputs
user
user through instructions
download Users
355
178
Example FTA: Insulin Pump
• Insulin Pump Extract – top event FTA
356
357
179
Example FTA: Insulin Pump
• Insulin Pump Extract – FTA - expand too low
358
Comparison
… …
…
… …
359
180
Cut Sets
360
• A Cut Set is a set of events that together cause the top event to occur
• One of the most common fault tree algorithms for generating CSs is
the MOCUS (Method of Obtaining CUt Sets) algorithm, developed by
J. Fussell and W. Vesely (1972)
• These days there are tools that will calculate cut sets once you define
the fault tree
• Minimal cut sets (MCs) have become important. A Cut Set is said to be
a minimal cut set if, when any basic event is removed from the set, the
remaining events collectively are no longer a cut set
360
361
181
Importance of Cut Sets
362
We know of one automotive OEM that has a rule that the minimum order allowed for
any Cut Set is 3
362
363
182
Failure Modes & Effects Analysis
364
• For years it has been the most popular hazard analysis technique
364
365
183
Definitions (from Ericson)
366
366
367
184
Example: FMEA for Insulin Pump
368
368
369
185
Example: FMEA Zoomed-in Right
370
371
186
Systems Theoretic Process
Analysis - STPA 372
372
Steps in STPA
373
• Model the control structure (create the control diagram(s) that govern
the analysis)
373
187
Purpose of the analysis
374
From
STPA Handbook
A hazard is a system state or set of conditions that, together with a particular set of
worst-case environmental conditions, will lead to a loss – Leveson
374
375
188
Current Control Diagram
376
From
STPA Handbook
376
Providing a potentially safe control action but too early, too late, or in the wrong
order
The control action lasts too long or is stopped too soon (for continuous control
actions, not discrete ones)
377
189
Control Diagram
378
378
Table of UCAs
379
Control Not providing Providing causes Too early, too Stopped too
Action causes hazard hazard late, out of order soon, too late
Action 1 UCA-1: text UCA-2: text UCA-3: text UCA-4: text
379
190
Example STPA: Insulin Pump
380
381
191
Example STPA: Insulin Pump
Zoomed-in
extract
382
383
192
Consider Control & Feedback
384
From
STPA Handbook
384
Losses
Hazards
Safety constraints
Unsafe control actions
Loss scenarios
Safety requirements
385
193
ASSURANCE CASES
386
• Motivation
• Examples
• Benefits of GSN
• Some advances
386
• Pre-safety cases
387
194
Motivation for Safety Cases
388
Software
Design
Design Review and Description Unit Test
Verification Reports Report
So – regulators:
HAR
• Pre-approved approximately 20
Legend:
Documents produced in the
process documents
forward going development process
• Audited development to be in
Documents produced by HAR
verifications, reviews, analyses and
testing
compliance with processes
Activities and data flow Code Review and
Code
• Audited output of the
Verification Reports
HAR Hazard Analysis Report
processes
• Witnessed in-plant testing
• And then give the regulators all the documents you have created
but the regulator then has to discover why we thought the system is safe
388
389
195
(Safety) Assurance Cases
Safety cases have been in use in the UK for more than 50 years
390
GSN is the most popular assurance case notation in the research literature
391
196
Basis for an Argument
392
His argument structure provided basic ideas of how an argument is formed, but the
structure was difficult to scale
• GSN and CAE look very similar – note one difference – the arrows
https://www.adelard.com/gsn.html https://www.adelard.com/asce/choosing-asce/cae.html
392
GSN
393
GSN COMMUNITY
STANDARD
VERSION 1 - 2011
393
197
GSN
394
GSN COMMUNITY
- claim STANDARD
VERSION 1 - 2011
394
GSN
395
GSN COMMUNITY
- claim STANDARD
VERSION 1 - 2011
- evidence
395
198
GSN
396
GSN COMMUNITY
- claim STANDARD
VERSION 1 - 2011
- evidence
GSN
397
GSN COMMUNITY
- claim STANDARD
VERSION 1 - 2011
- evidence
199
GSN
398
Justification
Assumption
GSN
399
Justification
Assumption
200
GSN
400
Justification
Evidence is
From the System
Assumption
Development
• The top level of the assurance case determines the entire structure of
the “argument”
• Many safety assurance cases use the argument that all hazards have
been eliminated and/or mitigated
Personally, I do not like or agree with this. There is more to safety than mitigating
hazards. We know that if the application does not deliver what is expected by users,
users look for workarounds. Sometimes those workarounds negate the safeguards
we have built into the system.
401
201
Coffee Cup Example – Top Level
402
Shows an argument
rather than a strategy
Module
Variation on argument
in previous slide From Thomas Chowdhury
PhD Thesis, 2021
402
Shows an argument
rather than a strategy
Variation on argument
in previous slide From Thomas Chowdhury
PhD Thesis, 2021
403
202
Support for Claim CR
404
404
405
203
GSN Benefits
406
• Benefits
I think GSN and similar notations like CAE (Claims Arguments and Evidence,
developed by Adelard) have had a very positive effect in producing safe(r) systems
• It is appealingly intuitive – I have seen practicing engineers (and students) pick-up the
basic idea in a GSN assurance case as fast as you would ever want them to … sometimes
faster
• Its primary success (I think) is to get people to look critically at the “argument” and ask
important and usually overlooked questions – and this is invaluable
• It has motivated many more developers and certifiers to consider seriously what we need to
do to demonstrate that a system is safe (or secure or dependable etc)
406
GSN Shortcomings
407
• A personal view
407
204
Assurance Case Templates
408
non-exclusive or
• Requires explicit reasoning
(not shown here)
0-1 0-1
• Try to make it robust with
optional path
optional path
respect to change
Legend:
• Assume it will be developed - Claim or sub-claim
by a community in the - Evidence
same way that standards A B - A is claim
B is premise
are acceptance criteria on evidence required specified in the template
408
non-exclusive or
• Non-exclusive – input
from glucose meter 0-1
0-1
and/or manual input
optional path
optional path
Legend:
- Claim or sub-claim
- Evidence
A B - A is claim
B is premise
acceptance criteria on evidence required specified in the template
409
205
Why Assurance Case Templates?
410
410
Initial assurance
nodes generated
Model by multiplicity and
other constraints
processes
Assurance nodes
generated from
initial assurance
nodes
(yellow & orange)
Model data produced
and used by processes
411
206
Zoom-in to See Constraints
412
20
412
This was an
assumption in the
GSN example but
would not be in
practice
413
207
Expansion from the previous slide
414
414
415
208