Automatic Generation of Provably Correct Embedded Systems Shang-Wei LIN, Yang LIU, Pao-Ann HSIUNG, Jun SUN, and Jin Song DONG Temasek Laboratories National University of Singapore ICFEM 2012, Kyoto Japan 1

Motivation Models

Properties

Implementation Code

?

Properties

• Can we generate code automatically? • Verification results are still valid

2

Outline • • • • •

Overall Flow Code Generation Approach Example Case Studies Future Work

3

Overall Flow CSP# Model

Model Checking

Counterexample

No

Non-functional Information

Scheduling

Specification Satisfied

Yes

Schedulable

No

Un-schedulable Information Front End Back End

Yes Implementation Mapping

Implementation Configuration File

Code Generation

Software C/C++ Code

4

Overall Flow (cont.) • Input – Communicating Sequential Program (CSP#) • • • •

Extension of Communicating Sequential Process (CSP) Message passing and shared memory Declaration of variables Data operations on declared variables

• Output – C/C++ software code 5

Outline • • • • •

Overall Flow Code Generation Approach Example Case Studies Future Work

6

Code Generation Approach • CSP#  state machines  QP active objects – Generated code is OS-independent and hardware-independent

Application (Active Objects) Quantum Platform (QP) Linux/BSD 80x86

Windows/WinCE

μC/OS-II

ARM-Cortex/ARM9/ARM7

… …

7

CSP# to State Machines • Translation rule for each primitive CSP# process – – – – – – – – – –

Stop Skip: √ Stop prefix: e { prog }  P invariant: [b] P conditional choice: if b { P } else { Q } channel input: ch?x  P channel output: ch!x  P interleaving: P ||| Q sequential: P ; Q general choice: P [] Q 8

Translation Rules • Stop

• Skip – √  Stop

9

Translation Rules (cont.) • e { prog }  P

• [b] P

10

Translation Rules (cont.) • if b { P } else { Q }

11

Translation Rules (cont.) • ch?x  P

• ch!x  P

12

Translation Rules (cont.) • P; Q

• P [] Q

13

Correctness Theorem 1. The translated state machine is a bisimulation of the original CSP# model

[proof idea] • The translated state machine for each primitive process is a bisimulation. • A CSP# process is composed with several primitive processes inductively. • For example, ch?x  P ch?x  P

ch?x /

ch?x P

M

s0

P ≈ MP ↓ ch?x  P ≈ M

s0 P … MP 14

State Machines to C/C++ Code Active Object

Active Object

publish event e

init()

e = queue.get()

dispatch(e)

TIMEOUT event

e Quantum Platform (QP) 15

State Machines to C/C++ Code (cont.)

Theorem 2. The behavior of the implementation in active objects conforms to the original state machines. [proof idea] Each transition in an active object conforms to the operational semantics of its corresponding state machine

16

Overall Correctness CSP# Processes ↔ state machines ↔ active objects Theorem 1

Theorem 2

[Assumption] The execution of the action on a transition of an active object is atomic [Discharge] synchronization using mutexes on the execution of the action

17

Generic Hardware APIs CSP# Model

Model Checking

Counterexample

No

Non-functional Information

Scheduling

Specification Satisfied

Yes

Schedulable

No

Un-schedulable Information Front End Back End

Yes Implementation Mapping

Implementation Configuration File

Code Generation

Software C/C++ Code

18

Generic Hardware APIs CSP# models

code generation

Generated C++ Code (QP Active Objects)

... call(LCD_blink,1) ... call(LCD_blink,2) ...

cross-compilation

HardwareAPIs.h inclusion

selection of Hardware + OS

HardwareAPIs.cpp

PAT Hardware Library PC + Windows

Creator + Linux

HardwareAPIs.h

HardwareAPIs.h

Target Binary Files

... HardwareAPIs.cpp

HardwareAPIs.cpp 19

Outline • • • • •

Overall Flow Code Generation Approach Example Case Studies Future Work

20

Peterson’s Protocol #define N 2; var turn; var pos[N]; P0() = req.0{pos[0] = 1; turn=1} -> Wait0(); cs.0 -> reset.0{pos[0] = 0} -> P0(); Wait0() = if (pos[1]==1 && turn == 1) { Wait0() };

P1() = req.1{pos[1] = 1; turn=0} -> Wait1(); cs.1 -> reset.1{pos[1] = 0} -> P1(); Wait1() = if (pos[0]==1 && turn == 0) { Wait1() };

Peterson() = P0() ||| P1(); 21

Peterson’s Protocol (cont.) Translated state machine for process P0

22

Peterson’s Protocol (cont.) class P0 : public QActive { public: P0(); ~P0(); private: static static static static static

QState QState QState QState QState

/** P0.h

**/

initial(P0 *me, QEvent const *e); P0_0(P0 *me, QEvent const *e); P0_1(P0 *me, QEvent const *e); P0_2(P0 *me, QEvent const *e); P0_3(P0 *me, QEvent const *e);

public: void req_0(); void cs_0(); void reset_0(); private: QTimeEvt m_timeEvt; };

23

Peterson’s Protocol (cont.) P0::P0() : /** P0.cpp **/ QActive((QStateHandler)&P0::initial),m_timeEvt(TIMEOUT_SIG){} P0::~P0(){}

QState P0::initial(P0 *me, QEvent const *){ return Q_TRAN(&P0::P0_0); } void P0::req_0(){ std::cout<<"req_0"<
24

Peterson’s Protocol (cont.) QState P0:: P0_0(P0 *me, QEvent const *e){ QEvent *pe;

/** P0.cpp (cont.)**/

switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: me->req_0(); pos[0]=1;turn=1; return Q_TRAN(&P0::P0_1); } return Q_SUPER(&QHsm::top); }

25

Peterson’s Protocol (cont.) QState P0:: P0_1(P0 *me, QEvent const *e){ QEvent *pe;

/** P0.cpp (cont.)**/

switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED();

case TIMEOUT_SIG: if(((pos[1] == 1) && (turn == 1))){ return Q_TRAN(&P0::P0_1); } if(!(((pos[1] == 1) && (turn == 1)))){ return Q_TRAN(&P0::P0_2); } } return Q_SUPER(&QHsm::top); }

26

Peterson’s Protocol (cont.) QState P0:: P0_2(P0 *me, QEvent const *e){ QEvent *pe; switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: me->cs_0(); return Q_TRAN(&P0::P0_3);

} return Q_SUPER(&QHsm::top); } 27

Peterson’s Protocol (cont.) QState P0:: P0_3(P0 *me, QEvent const *e){ QEvent *pe; switch(e->sig){ case Q_ENTRY_SIG: me->m_timeEvt.postIn(me, WAIT_TIME); return Q_HANDLED(); case Q_EXIT_SIG: return Q_HANDLED(); case TIMEOUT_SIG: me->reset_0(); pos[0]=0; return Q_TRAN(&P0::P0_0);

} return Q_SUPER(&QHsm::top); } 28

Peterson’s Protocol (cont.) // Main.cpp static P0 __P0; static P1 __P1; static QEvent const *l_P0_QueueSto[10]; static QEvent const *l_P1_QueueSto[10]; static QSubscrList

l_subscrSto[MAX_PUB_SIG];

static union SmallEvents { void *e0; uint8_t e1[sizeof(DataEvent)]; // other event types to go into this pool } l_smlPoolSto[2 * (1 + 0) * 2]; // storage for the small event pool … 29

Peterson’s Protocol (cont.) int main(int argc, char *argv[]) {

QF::init(); QF::psInit(l_subscrSto, Q_DIM(l_subscrSto)); QF::poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0])); __P0.start((uint8_t)(1), l_tableQueueSto, Q_DIM(l_tableQueueSto), (void *)0, 0, (QEvent *)0);

__P1.start((uint8_t)(2), l_tableQueueSto, Q_DIM(l_tableQueueSto), (void *)0, 0, (QEvent *)0); QF::run(); return 0; } 30

Outline • • • • •

Overall Flow Code Generation Approach Example Case Studies Future Work

31

Case Studies • Entrance Guard System (EGS) – controls the entrance of a building – Input, Display, Controller, DBMS, Actuator, Alarm

• Secure Communication Box (SCB) – provides a secure communication between two clients

32

Example - Secure Communication Box #define USER_CONNECT 77; #define DATA 79;

channel chAdmin 5;

#define SERVER_READY 78; #define POWER_ON 80;

channel chA 5;

channel chB 5;

Admin() = chAdmin!POWER_ON -> Skip; User1() = chA!USER_CONNECT -> chA?SERVER_READY -> SendData1(); SendData1() = chA!DATA -> send_data_1 -> ReceiveData1(); ReceiveData1() = chA?x -> receive_data_1 -> SendData1(); User2() = chB!USER_CONNECT -> chB?SERVER_READY -> ReceiveData2(); ReceiveData2() = chB?x -> receive_data_2 -> SendData2(); SendData2() = chB!DATA -> send_data_2 -> ReceiveData2();

Server() = chAdmin?POWER_ON -> power_up {call(LCD_blink,1)} -> initializatioin -> User1Connected(); User1Connected() = chA?USER_CONNECT {call(LCD_blink,2)} -> chA!SERVER_READY -> User2Connected(); User2Connected() = chB?USER_CONNECT {call(LCD_blink,3)} -> chB!SERVER_READY -> transimitData(); transimitData() = chA?x {call(LCD_blink,4)} -> chB!x {call(LCD_blink,5)} -> transimitData(); System = User1() ||| Server() ||| User2() ||| Admin(); 33

Outline • • • • •

Overall Flow Code Generation Approach Example Case Studies Future Work

34

Future Work • Automatic Code Generation for – Real-time Systems – Multi-core Platforms

35

Automatic Generation of Provably Correct Embedded ...

Scheduling. Model. Checking ... Model. Non-functional. Information. Counterexample. Software. C/C++ Code. Implementation ... e = queue.get() dispatch(e) e.

965KB Sizes 1 Downloads 242 Views

Recommend Documents

Automatic Test Data Generation from Embedded C Code.pdf ...
There was a problem loading this page. Automatic Test Data Generation from Embedded C Code.pdf. Automatic Test Data Generation from Embedded C Code.

A Provably Correct Functional Programming Approach ...
The advantages of starting the development of a software ..... structure of the specification, the validation cycle is easier. Finally ... complete set of rules, see [4].

ESPRIT BRA 3104 ProCoS project: Provably Correct ...
of laws may be found in HPB90]. A mathematical definition of the relation v, and the consistency of the laws with respect a specification-oriented semantics of the language are explored in He90]. The program Abort represents the completely arbitrary

Automatic generation of synthetic sequential ...
M. D. Hutton is with the Department of Computer Science, University of. Toronto, Ontario M5S ... terization and generation efforts of [1] and [2] to the more dif- ficult problem of ..... for bounds on the fanin (in-degree) and fanout (out-degree) of

Automatic Generation of Scientific Paper Reviews
maximizing the expected reward using reinforcement learning. ..... Oh, A.H., Rudnicky, A.I.: Stochastic natural language generation for spoken dialog systems.

Automatic Generation of Scientific Paper Reviews
whose incentives may or may not actually drive the overall process toward those ideal goals. ... (c) conveys a recommendation specified as input. A tool that is ..... Toutanova, K., Klein, D., Manning, C.D., Singer, Y.: Feature-rich part-of-speech.

Automatic Generation of Release Notes
mining approaches together to address the problem of re- lease note generation, for ... ing data sets of the three evaluation studies. Paper structure. Section 2 ... To design ARENA, we performed an exploratory study aimed at understanding ...

Automatic Generation of Scientific Paper Reviews
paper_overly_honest_citation_slips_into_peer_reviewed_journal.html ... Oh, A.H., Rudnicky, A.I.: Stochastic natural language generation for spoken dialog.

Automatic generation of synthetic sequential ...
M. D. Hutton is with the Department of Computer Science, University of. Toronto ..... an interface to other forms of circuits (e.g., memory [20]) or to deal with ...

Automatic Navmesh Generation via Watershed ...
we do not necessarily need a convex area, just simpler area .... A Navigation Graph for Real-time Crowd Animation on Multilayered and Uneven Terrain.

Towards Automatic Generation of Security-Centric ... - Semantic Scholar
Oct 16, 2015 - ically generate security-centric app descriptions, based on program analysis. We implement a prototype ... Unlike traditional desktop systems, Android provides end users with an opportunity to proactively ... perceive such differences

Automatic Generation of Efficient Codes from Mathematical ... - GitHub
Sep 22, 2016 - Programming language Formura. Domain specific language for stencil computaion. T. Muranushi et al. (RIKEN AICS). Formura. Sep 22, 2016.

“Best Dinner Ever!!!”: Automatic Generation of ...
Although the services hosting product reviews do apply filters and procedures aimed at limiting the proliferation of false reviews, an attacker able to generate ...

Automatic Generation of Test-Cases Using Model ...
The methods and tools addressing model based test generation can be classified based on .... test generation meeting various structural and behavioral criteria.

Automatic generation of instruction sequences targeting ...
Testing a processor in native mode by executing instruc- tions from cache has been shown to be very effective in dis- covering defective chips. In previous work, we showed an efficient technique for generating instruction sequences tar- geting specif

Comparing SMT Methods for Automatic Generation of ...
In this paper, two methods based on statistical machine trans- lation (SMT) are ... Lecture Notes in Computer Science: Authors' Instructions pronunciations for ...

Automatic generation of research trails in web ... - Research at Google
Feb 10, 2010 - thematic exploration, though the theme may change slightly during the research ... add or rank results (e.g., [2, 10, 13]). Research trails are.

G4LTL-ST: Automatic Generation of PLC Programs
G4LTL-ST generates code in IEC 61131-3-compatible Structured. Text, which is ... Linear temporal logic specification with arithmetic constraints and a timer.

Best Dinner Ever!!'': Automatic Generation of Restaurant ...
Oct 16, 2016 - People buy products/services online/offline. When choosing seller, they trust other people's opinion (reviews). Bartoli et al. (UniTs). Generation ...

Automatic Generation of Regular Expressions from ... - Semantic Scholar
Jul 11, 2012 - ABSTRACT. We explore the practical feasibility of a system based on genetic programming (GP) for the automatic generation of regular expressions. The user describes the desired task by providing a set of labeled examples, in the form o

Automatic generation of instructions to robustly test ...
This led to broadside testing [5], where. ATPG spreads to two ... good small delay fault model, are actually paths. We use ... instruction based testing might be the best option in detecting .... The DATPG procedure deals with the circuit as a com-.