Towards an executable semantics of automobile RTOS standard and its application to conformance verification

11/24/2017 ∙ by Xiaoran Zhu, et al. ∙ East China Normal University NetEase, Inc 0

The automobile Real-Time Operating System (RTOS) is hard to design and implement due to its real time features and increasing complexity. Some automobile RTOS standards are released aiming at unifying the software architecture of vehicle systems. Most of the standards are presented informally in natural languages, which may lead to not only ambiguities in specifications but also difficulties in conformance verification. This paper proposes a rewriting-based approach for formalising the automobile RTOS standard. Taking the OSEK/VDX standard as an example, an executional formal semantics of the automobile RTOS kernel, which focuses on the real time features, is defined using K, a rewriting-based framework. We also report some ambiguous definitions of the OSEK/VDX standard, which we find in the process of formalisation. The K semantics of the OSEK/VDX standard is applied to conformance verification, which is used to check the conformance of not only the automobile operating system kernel but the applications.



There are no comments yet.


page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 introduction

Vast arrays of applications are increasingly used in automobile RTOSs to improve the functionality of the system. As a result, the automobile RTOS becomes more complex to design and implement. Some automobile RTOS standards have been put forward, with the purpose of improving the reusability of automobile applications and unifying the development process of software.

The automobile standards, such as OSEK/VDX OSEK , one of the most widely used automobile RTOS standard, define standard interfaces of operating system, network management and so on. The automobile RTOS venders are required to achieve a certification through some technical methods, such as conformance testing conformancetesting . The basic idea of conformance testing is to test the properties of automobile RTOSs with a test suite, which is generally derived from the standards. However, most of the standards are given in natural languages, which may cause ambiguities OSEKreview . The ambiguity may mislead not only developers on the implementations but testing engineers on the composition of test cases. Moreover, test cases may not cover all possibilities of the test targets. All these facts lead to the result of conformance testing incomplete. Conformance verification con-verification is another complementary approach, by which a specification in natural language is first formalised, and an implementation is verified whether it satisfies certain properties with respect to the formal specification.

Conformance verification is a kind of so-called formal method formalmethod , which is a mathematical technique for the specification, development and verification of computer systems. For its accuracy and unambiguity, formal method has been widely applied in many areas, including embedded systems. IBM verified the power gates IBM1 , registers IBM2 and IBM Power7 microprocessor IBM3 formally to guarantee the reliability of their products. Intel Core i7 processor has been formally verified before being introduced to the market Intel . Formal method has also been used to analyze and verify automobile RTOSs and applications. In SMT , an approach was proposed to verify the applications of automobile operating systems by bounded model checking. In formal model ; choi2013 , a formal model of an automobile RTOS is defined to generate test suite. In OSEK-K , an executable formal semantics of a part of the OSEK/VDX-based automobile RTOS (OSEK/VDX RTOS for abbreviation) is defined using framework K for the model checking of user-defined automobile applications. However, a common weak point of the mentioned existing work is that they do not consider the real time feature, which plays an important role in automobile RTOSs.

By extending the work OSEK-K , we propose in this paper a more complete formal semantics of the OSEK/VDX standard with considering its real time feature, and apply the formal semantics in conformance verification of an industrial automobile operating system. The formal semantics covers more features of the standard, such as the multiple activation of tasks and the alarm mechanism (see Section 4.3.2 and 4.3.3). In the process of formal analysis, we realise some ambiguous description in the OSEK/VDX standard, and give them formal definitions on the basis of our understandings and discussion with automobile electronical engineers. We show with a concrete case study how the conformance verification is achieved by the K semantics. In the case study, we detect some inconformities of an industrial operating system to the standards. After fixing the inconformities, we verified the conformance of the operating system by LTL model checking with respect to some important properties, such as starvation freedom.

In summary, the contributions of this paper are following:

  1. An executable formal semantics of automobile RTOS kernel based on OSEK/VDX standard is given. The formal semantics, which is defined using framework, not only specify the execution rules of OSEK/VDX system services, but also take the real time features into account.

  2. Some ambiguous descriptions in the OSEK/VDX standard are reported, and their corresponding formal semantics are defined.

  3. A new approach to system analysis with the K semantics called conformance verification is proposed. To demonstrate the usefulness of the approach, we conduct a case study on an industrial RTOS to it.

This paper is organized as follows. In Section 2, a brief introduction of the OSEK/VDX operating system is given. We analyze the ambiguous definitions of the OSEK/VDX standard in Section 3. Section 4 gives a formal description of the standard. Then an industrial application is analysed and verified in section 5. Section 6 and section 7 discuss some related work and conclude this paper respectively.

2 Key Conceptions in the OSEK/VDX standard

An OSEK/VDX RTOS is a multi-tasking system. This section gives some necessary knowledge of the OSEK/VDX standard for a better understanding of our work. Key conceptions in the standard include task, resource, event, alarms, etc. Task is a basic conception in the standard, which is used to implement complex control software. The execution of tasks is managed by a scheduler on the basis of priority. Tasks can synchronise by the means of events and resources. The real time features of OSEK/VDX RTOSs are implemented by alarms instead of timers, which are usually used in embedded operating systems. Figure 1 shows the relations of these conceptions.

Figure 1: Full preemptive scheduling

2.1 Task Scheduling

Scheduler plays an important role in OSEK/VDX RTOSs because it is used to control the execution of tasks. The scheduler decides the next task to run on the basis of its priority with a certain scheduling policy. It is assumed to be fixed-priority OSEKreview in that each task should be assigned statically a priority.

Controlled by the scheduler, a task changes between different states. There are two types of tasks, i.e. basic task and extended task, specified in the OSEK/VDX standard. A basic task has three states, i.e., ready, running and suspended. A suspended task is activated to be in ready state, while a running task also can be preempted to be ready. Once a ready task is able to be scheduled, the scheduler allocates it a processor and the task starts running. After finishing, a running task goes into suspended state. The extended task has a special state called waiting to indicate the task is waiting for some events. We omitted the state transitions of extended tasks here because it is not the emphasis of the paper. Interested readers are referred to OSEK for the details.

The scheduler works with a certain scheduling policy. In the standard, there are three scheduling policies specified, i.e., full preemptive scheduling, non preemptive scheduling and mixed preemptive scheduling.

By full preemptive scheduling, a running task needs to be rescheduled when a task with a higher priority enters into the ready queue. We summarise some occasions when a higher-priority task preempts the running task.

  • When a higher-priority task is activated by system services, such as ActivateTask and ChainTask.

  • When an extended task with a higher priority is waiting for some event and the event is set by the system serviceSetEvent.

  • When the running task releases its resource by the system service ReleaseResource, and after releasing the resource its current priority becomes lower than some ready task 111The priority of task changes dynamically because the OSEK/VDX RTOS adopts priority ceiling protocol..

For non preemptive scheduling, rescheduling will not happen unless the state of the running task is changed or a scheduler is called explicitly. Full preemptive scheduling and non preemptive scheduling can coexist in a system, resulting in a mixed preemptive scheduling policy.

2.2 Alarm

Time management of the OSEK/VDX RTOS is achieved through alarm mechanism. The alarm mechanism is implemented by alarms and counters. A counter, measured by “ticks”, is used to record the number of recurring sources sampled by sensors from the environment. An alarm is attached to a counter. When the counter reaches a predefined value, the alarm expires and triggers a configured operation. In this way, the real time features can be implemented by alarms, such as periodic task or interrupt at regular intervals.

The counters and alarms are configured statically by a system. A counter has three attributes.

  • MAXALLOWEDVALUE: to specify the maximum value a counter could be.

  • TICKSPERBASE: to define the count of “ticks” required by a counter unit.

  • MINICYCLE: to represent the minimum time of ticks for a cyclic alarm.

An alarm also has three attributes:

  • COUNTER: to specify the counter to which the alarm is attached.

  • ACTION: to define the type of notification, such as activating a task, setting an event or calling an alarm-callback routine.

  • AUTOSTART: to represent if the alarm is started automatically or not.

6ALARM a {
9  TASK= t;
10  };
11  AUTOSTART=false;
Figure 2: An example of counter and alarm

Figure 2 shows an example of counter and alarm. If counter c reaches its maximum allowed value 65535, it returns to 0 next time. The increment of the counter value is triggered every two “ticks”. If counter c is attached to a cyclic alarm, the cycle time of the alarm must not be less than 3 “ticks”. In the example, the counter is configured to alarm a. When the alarm expires, it will activate some predefined task t. The alarm can not be started automatically and must be set by system services to get started.

Two system services can be used to set alarms, i.e., SetRelAlarm (ID, increment, cycle) and SetAbsAlarm(ID, start, cycle). The parameters ID and cycle stand for the ID of alarm to be set and its cycle time respectively. If the value of cycle is non-zero, the alarm ID is cyclical. Otherwise, this alarm will expire only once after having been set. In case of calling SetRelAlarm, the alarm time is the sum of current time and the value of the increment. The parameter start represents the absolute alarm time without considering current time in SetAbsAlarm. The system service CancelAlarm(ID) is used to cancel an alarm according to the standard.

3 Ambiguities in the OSEK/VDX Standard

The OSEK/VDX standard aims at providing precise statements to represent a uniform environment for efficient implementation of automobile software. However, we found some ambiguous definitions in the process of formalising them. In this section, we report and discuss these ambiguities before giving them formal definitions.

3.1 Ambiguity in Multi-activation of Basic Tasks

According to the standard, there can be multiple requesting of activating a basic task. The system is able to accept an activation request for a task in the ready or running state in case of the maximum number of activation requests having not been reached. The maximum number of activation requests is assigned statically.

Figure 3: Full preemptive scheduling

The standard specifies that “If the task is not suspended, the activation request will only be recorded and performed later” OSEK . However, it does not define the exact time when activation request should be handled. Here comes a problem. When the task has been terminated, should the system activate it again first or perform the rescheduling first?

Figure 3 illustrates an example of multiple activation request. Both task T1 and T2 are full preemptible and T1 has a higher priority. Task T1 makes an activation request to itself in its running state. It goes into suspended state after being terminated. If the activation request is performed at this time, task T1 is transferred to ready state, which triggers rescheduling. Task T1 starts to run due to its higher priority. If rescheduling is performed before the activation request, task T2 is rescheduled to running state. These two cases may lead to different system behaviours.

3.2 Ambiguities in System Services about Alarm

We find ambiguities of two system services about alarm in the OSEK/VDX standard, i.e., CancelAlarm and SetRelAlarm.

The system service CancelAlarm is called to cancel an alarm. However, no more information can be found about it in the standard. There can be three understandings of cancelling an alarm leading to different results.

  • To delete the relation between alarm and its corresponding counter.

  • To set the value of alarm time and cycle time to an unreachable number, such as a number larger than the MAXALLOWEDVALUE.

  • To delete the alarm from the list of working alarms according to the explanation in program-in-OSEK .

In the first case, the relation can not be set again because the standard does not provide any corresponding system services. In the second case, the alarm needs to be checked every time when the value of the counter is changed although it never expires. This may impact on the execution efficiency. Compared with the first two cases, the third one is more reasonable. Once CancelAlarm is called, the corresponding alarm becomes invalid. But it can get valid again after being set by other system services.

The system service SetRelAlarm is not clearly defined. According to the standard, its second parameter increment stands for the value of relative alarm time. Namely, the alarm time is the sum of current counter value and the increment value. However, it is specified in the standard that “The behaviour of increment equal to 0 is up to the implementation”. There are two possible interpretations, i.e., the alarm expires immediately or the first alarm is simply ignored. The second one may cause problems when the third parameter of SetRelAlarm is 0. Details can be found in Section 4.

3.3 ambiguous in scheduling policy

The OSEK/VDX standard definitively specifies some conditions of triggering rescheduling OSEK . When anyone of the conditions occurs, rescheduling must be activated at once. However, it is possible that some alarm expires after occurrence of the condition but before the activation of rescheduling. It is unclear whether the scheduler should be activated first or not. This may lead to different scheduling results.

1Alarm M{
Figure 4: An example of application

Considering a concrete example as shown in Figure 4, there are three basic tasks, A, B, C and task C has the highest priority while the priority of task A is the lowest. We assume that task A is currently running and has just activated task B (line 28). At this time, the alarm M expires. If scheduling is handled first, task B is rescheduled to running state. Then task C will be activated. Because it has a higher priority than B, task C will preempt B and start to run. If alarm is handled first, rescheduling will be performed after task C having been activated. Task B can not run before C terminates.

4 Semantics of the OSEK/VDX Standard

The formal semantics of the standard using framework is presented in this section. The ambiguous definitions of the standard are defined formally after analysing the source code of some certified OSEK/VDX RTOSs developed by iSOFT Infrastructure Software Co., Ltd. isoft . Before presenting the formal semantics, we introduce framework briefly and the major challenges faced when formalising the standard.

4.1 Framework and its underlying Rewriting Logic

is a semantic definitional framework based on rewriting logic. Rewriting logic rewrite is a computational model for concurrency, distributed algorithms, programming languages, software and hardware systems. It can also be regarded as a logic for executable specification and analysis. Many languages and systems based on rewriting logic are designed and implemented, such as CafeOBJ cafeobj , ELAN ELAN , Maude dmaude and , among which, is one of the state-of-the-art frameworks with features of simplicity, executability, analysability, and scalability Kprimer .

framework is used to analyse the program languages based on their formal semantics. The syntax of language is defined using BNF ( Backus-Naur Form) in . And the semantic definitions are like operational semantics, which denote the transition rules of the system. framework integrates many capabilities of program analysis. Given a syntax and a semantics of a language, generates a parser, an interpreter, a model checker through its Maude backend and a deductive theorem prover by translating its semantics into Coq definitions coq . The parser and interpreter allow a program to execute based on its semantics. Furthermore, the can analyse the program more comprehensively than compilers. For example, the model checking capability helps the language designer to cover all the non-deterministic behaviors of certain language through the state-space exploration. The main advantages of are:

  • supports modular definition of formal semantics and user-defined data types.

  • The formal semantics defined in is executable, which provides not only a way to formally analyse programs but a way to test the correctness of defined semantics.

  • framework has many backend formal tools for interpreting programs, model checking and theorem proving.

is built upon three main components, which are configuration, computational rules and structural rules. The configuration is a nested cell to present the static state of a program being executed. The basic ingredient of a definition is cell, which is labeled and stands for a piece of information of a state. The rules are executed by changing the information of states stored in cells. Both computational rules and structural rules are rules. The difference is that computational rules are counted as computational steps while structural rules are to rearrange the structure of configuration. These concepts will be illustrated in Section 4.3, where we show how the OSEK/VDX standard is formalised in .

4.2 Challenges of Formalising the OSEK/VDX Standard

Many formidable challenges have been encountered when formalising the OSEK/VDX standard. The key challenges in this work are about the formalisation of real time features and interrupt.

The first challenge is the formalisation of real time features. In an automobile operating system time management is an essential part, which has a big influence on task scheduling. It is a key problem to depict real time features for the formal analysis of system behaviors. Time is counted by a physical clock in a vehicle system, which is hard to measure accurately in a laboratory environment. Moreover, does not provide any approach to the formalisation of time, and as far as we survey there is no existing work on it.

The challenge of depicting time is to choose an appropriate granularity. In the standard, the increment of a counter may be triggered by a physical clock. The clock time elapses along with the execution of code. Generally, in most of the automobile applications the execution time of an assembly instruction is in microsecond level, while the alarm time is in millisecond. Principally, alarm expiration may occur at any time when an assembly instruction is executed. However, a statement is formalised as an atomic operation in . Thus it is challenging work to formalise alarm expiration in instruction level. Moreover, we are not concerned with the implementation of system services, but instead just give there formal semantics according to their informal descriptions in the standard. Namely, each system service is considered as an atomic operation. The execution time of a system service, which depends on the amount of its code, the resource occupancy and some other unknown factors, is difficult to evaluate precisely. Meanwhile, we also have to consider the execution time of the statements except system services in tasks, which is another difficulty.

Another challenge is the case of interrupt. In the standard, it is not clearly defined whether the execution of system services can be interrupted or not. We find that some system services allow to be interrupted while the other APIs disable the interrupts in its execution in the implementation of a certified RTOS. It means that interrupt can occur during the execution of system service. Therefore, if the system service is considered as an atomic operation in formalisation, some interrupt may be missed. Otherwise, we have to formalise the concrete the implementation of system services. However, how to implement the system service is out of the scope of the standard. Another problem with interrupt is that an interrupt service routine (ISR) may call system services. However, the system services called by ISR are not allowed to be interrupted because the standard specifies that the interrupt can not be nested. These system services should be treated particularly.

Figure 5: Overview of the Semantic configuration

4.3 Semantics of the OSEK/VDX Standard

The basic idea of formalisation in is to represent the system states as configurations and transitions as rewrite rules. In an OSEK/VDX RTOS, a system state consists of the information of tasks, alarms, the scheduler and so on. In this work, we mainly consider the transitions of states that are caused through the executions of system services. These transitions are formalised as rewrite rules by defining the semantics of their corresponding system services.

In our formalisation, we consider the execution of a system service as atomic due to the fact that the standard is not concerned with the implementation. As discussed in Section 4.2, we need to give a reasonable execution time to each system service. We regard a millisecond as a unit time and consider the execution time of a system service is one unit time in our formal semantics. That is because in general a system service consists of hundreds of assembly instructions and executing an instruction spends several microseconds. Also, in most automobile applications the alarm time are configured in milliseconds. Treating system services as atomic causes the problems mentioned in the second challenge. So far, we have not taken the interrupt process into account and leave it as a piece of future work.

In this section, we show the formal definitions of configuration of system state, semantics of some typical system services on scheduling and alarm mechanism, and the execution time of tasks. We omit the details of the definition of system services on events and resources because it is not the emphasis of this paper.

4.3.1 Configuration of system state

A configuration in consists of possibly nested cells. The configuration defined for the standard is composed of over 50 nested cells, describing necessary information of tasks, alarms, the scheduler and so on. Figure 5 shows an overview of the configuration. The cell task is declared with multiplicity *, i.e., zero, one, or more tasks can be configured. The cell k enclosed in task is the computation cell to store the program to be executed. The activatedTime keeps the number of task activation requests, and its maximum number is stored in activationTime. In the alarm cell, there is a nested cell action holding the system service, i.e. ActivateTask or SetEvent, to be called by the alarm. The actedId keeps the identifier of the task to be activated or the event to be set. In the configuration, we define a cell sysCounter to represent a counter. This cell includes some nested cells to store the information of the counter, such as counter value in cValue, the alarms it corresponding to in alarmList and the MAXALLOWEDVALUE in maxvalue. The TICKSPERBASE is formalises to have the same value with MAXALLOWEDVALUE. We omit its cell in our semantics.




when N1 andBool


when N1 0

Figure 6: Main rewrite rules for scheduling

4.3.2 semantics of system services on scheduling

There are several system services that can trigger scheduling as mentioned in Section 2.1. We consider two typical system services ActivateTask and ChainTask as examples here. The two system services have different semantics on full preemptive tasks and non preemptive tasks, which should be formally defined respectively. The semantics on full preemptive tasks is shown in Figure 6.

There are six occasions when executing the system service ActivateTask(T) leads to different results. The first rule [ACTIVATETASK] in Figure 6 formalises the semantics of one occasion when the alarm expires. According to the standard, if ActivateTask(T) is called, the state of task T is transferred from suspended to ready as specified by the state cell of the second task. In the cell, the horizontal line indicates a reduction. The cells without horizontal lines are only read but do not change during the reduction. For instance, the cell state represents the task that is calling ActivateTask(T) is in running state. The system service ActivateTask(T) is consumed after having been executed. It is represented in cell k by the reduction from ActivateTask(T) to “.”, which stands for empty or the unit computation. The “…” are structural frames, which match the irrelevant portions of this cell. Because task T gets ready, it is added to the corresponding queue of ready tasks, which have the same priority N as T. This is specified by the cell readyTasks, where term L is reduced to add(T, N, L). L is a variable for the list of queues of ready tasks, and add(T, N, L) returns a new list by adding I to the queue in L with the priority N.

Executing the system service causes one-unit increment to the counter value. The value of counter needs to begin from 0 after it reaches it maximum allowed value, which is formalised by the reduction from RV to (RV+Int 1)%Int (MAV+Int 1). RV and (RV+Int 1)%Int (MAV+Int 1) are two terms to represent the counter values before and after the system service is executed respectively. MAV is a variable for the maximum allowed value of a counter, and +Int, %Int are two built-in operators for addition and modulo operations on integers.

Every time when the value of counter is changed, alarm expiration needs to be checked. In this rule, AT in cell alarmTime expresses the time when alarm expires. The expression RV +Int 1==Int AT following keyword when represents the condition of alarm expiration. On reaching the expiration time, a signal called alarmed is released. Meanwhile, the signal schedule is also released which represents that the scheduler needs to be triggered after the execution of ActivateTask(T). The release of these two signals is formalised by cell signal. The handling of these two signals is to be introduced in Section 4.3.3.

The second rule in Figure 6 specifies the semantics of ChainTask (T) in the case of multiple activation request. This system service may cause the termination of the running task and the activation of a task according to the OSEK/VDX standard. The rule is defined for the case that the task to be activated is just the task in running state. Namely, task T is requested to be multiply activated. Based on the analysis in Section 3.1, there can be two possible methods for handling the multiple activation request. In the second method, i.e., performing the scheduling first, it is unclear when the activation should be performed resulting in multiple interpretations on the activation time. In the first method, the activation time is clearly specified. Therefore, we adopt the first method, which means that no schedule signal is released, though the task T is terminated.

The rule has a condition N2<Int N1 meaning that the number of activation request of task should not exceed its maximum value. When the condition is met and the alarm does not expire, the activation time is increased by one as represented in cell activatedTime.

Rule [MULTIACTIVATED] formalises the handling of the activation information in the case that a multi-activated task T with priority N has transferred to suspended state. The state of task T is transferred to ready as soon as it is terminated, which triggers the schedule signal. Meanwhile, the activation time of this task is decreased by one, i.e. the value of N1 decreases to N1-1 in cell activatedTime.


when N2 0 andBool N1 0


when (I in L’) andBool (AT==Int RV)

Figure 7: Main rewrite rules for alarm mechanism

4.3.3 Semantics of Alarm

We formally define 12 rules for three system services on alarms and another 4 rules to specify the handling of alarmed signal. Figure 7 shows three typical rules of them.

The first rule [SETRELALARM] formalises one case of the system service SetRelAlarm(I, N1, N2). According to the standard, this system service is to start alarm I and set its relative alarm time as N1 and cycle time as N2. After the system service, the alarm time should be N1+Int RV. Besides, if the alarm time is greater than the maximum allowed value of the counter (MAV), it is becomes the value modulo MAV+Int 1. Namely, the alarm time is reduced to (N1+Int RV)%Int (MAV+Int 1) as represented in cell alarmTime. When N1 is 0, we discussed two possible interpretations of SetRelAlarm(I, N1, N2) in Section 3.2. By the second interpretation, the first alarm is simply ignored. However, if the value of N2 is 0 this alarm can never take effect because N2 being 0 means the alarm is not cyclic and just alarms once. In this sense, the first interpretation is more reasonable. Therefore, we take the first interpretation in our formal semantics, i.e. the alarm AlarmID expires immediately and alarmed signal is released, as represented in cell signal of this rule. After the alarm I is set it is added to current alarm list L, which is specified in cell alarmList.

The rule [CANCELALARM] specifies the execution of system service CancelAlarm(I). We have discussed three possible understandings to cancel an alarm in Section 3.2 and concluded that the third one is more reasonable. Therefore, we adopt the third understanding in our formalisation, that is, the alarm I is cancelled by moving from the alarm list in cell alarmList.

Rule [TWO-SIGNALS] formalises a case of the handling of signals. When both of the signal schedule and alarmed are triggered at the same time, there are two possible handling ways as discussed in Section 3.3. We first handle the signal alarmed on the basis that alarm is considered as a kind of interrupt in OSEKreview and the priority of interrupts is the highest with respect to the OSEK/VDX standard. In the rule, the condition specifies that the signal is released by alarm I. The cell alarm shows that the action of I is to activate task T. The formalisation of this action is same as the one of system service ActivateTask(T). We omit detailed explanations here. The cell cyclicity shows that alarm I is cyclic. Thus its next alarm time becomes AT+CT as shown in cell alarmTime. After the signal alarm is handled it is removed from the cell signal.

4.3.4 Formalisation of the execution time of tasks

As mentioned in the first challenge in Section 4.2, we need to take the execution time of the statements except system services in tasks into account. Because our work mainly focuses on the real time features, for simplicity we do not deal with the formal semantics of these statements but formalise their execution time. System services partition the statements in a task into several blocks. Instead of measuring each statement, we consider a block as a whole to evaluate its execution time. For the reason that in our formalisation the execution time of a system service is considered as one unit time, the execution time of a block is measured through the value that results from dividing the amount of statements in the block by the average amount of statements in system services.

In general, it is difficult to calculate the amount of statements in a block due to the fact that there may be recursive function calls, loops with uncertain times and so on. However, our survey shows that only simple statements, such as assignments, if statements and fixed-time loops and non-recursive function calls, are used in the industrial implementations of a task. Therefore, we assume that a block only consists of the above four kinds of statements. For if statements, we further assume that each branch has the same execution time and then the execution time of an if statement is equal to the one of its branches. For fixed-time loops and non-recursive function calls, we calculate the amount of statements by loop unrolling and function inlining.

In order to specify the execution time of a block, we introduce a special statement in form of TimeInterval=N to replace the block, where N stands for the execution time. The semantics of this statement is to add N to the counter value. The new value of counter has two possibilities, i.e., it exceeds alarm time or not. If the counter value does not exceed the alarm time, N is directly added to the counter value as shown in rule [TIMEINTERVAL2] of Figure 8. To deal with the other case, we need to divide N into two time intervals such that after the first time interval alarm happens to expire. Namely the first time interval is equal to the alarm time minus counter value. After the first time interval, we handle the alarm and then treat the second time interval as an independent one to deal with recursively. The handling of this case is formalised by rule [TIMEINTERVAL1]. In this way, we guarantee that no alarm expiration is missed during the execution of a block, which complies with the fact that alarm may expire during the execution of statements in a task.



Figure 8: Main rules for the formalisation of execution time

5 Application to Conformance Verification

The semantics can be used for system analysis in various ways, such as model checking, state space exploration and test case generation. The work OSEK-K shows these applications with the semantics of the OSEK/VDX standard. In this section, we propose another application to system analysis with the semantics called conformance verification and show a case study on it.

5.1 The Basic Idea of Conformance Verification

Automobile operating systems are required to conform to the standard in order to get certified by the OSEK/VDX organisation. The traditional technique for ensuring the conformance is conformance testing. A conformance testing method named MODISTARC modistarc has been proposed for the OSEK/VDX RTOS. The basic idea is to test the result of running an operating system kernel with a given suites of test cases in a given environment. The organisation certifies an operating system if it can pass the testing. This method is practical but has some limitations due to the testing technique. In addition, only system services in operating system kernel are tested in the method while an automobile operating system including its applications as a whole is supposed to conform to the standard.

Figure 9: The architecture of conformance verification approach

As a complementary approach, conformance verification is used to check the conformance of not only the operating system kernel but the applications. Figure 9 shows the architecture of the approach to conformance verification.

Firstly, we define the semantics of the OSEK/VDX and OIL standards OIL . The OIL is abbreviated for OSEK Implementation Language, used to configure resources, tasks and some other objects in OSEK/VDX applications. Then we extract some properties from the standards and formalise them as LTL formulae MC . These properties are supposed to be satisfied by any automobile operating system. Given a concrete implementation, we identify from the requirement the properties that should be satisfied by the applications. Next we verify the two kinds of properties by model checking the applications with the semantics of the OSEK/VDX and OIL standards. And we test these properties by executing the applications on the operating system kernel. Finally, we conclude conformity or inconformity of operating system kernel and applications on the basis of the verification and testing result.

Under the assumption that the formal semantics is correct, we obtain the relations between verification & testing result and conformance verification result as shown in Table 1. If the verification result of a property is consistent (or inconsistent) with the testing result, we can conclude the conformance (or unconformance) between the kernel and the standard with respect to the property. The conformance of applications can be directly concluded by the verification result.

Verification & Testing Result Conformance Verification Result
verification testing conformance of kernel conformance of app
pass pass
pass fail
fail pass
fail fail
  • : inconformity  : conformity

Table 1: Relations between verification & testing result and conformance verification result

The approach is feasible to automobile systems though the conformance verification result relies on the properties of applications. That is because the automobile system is a closed system in that no applications are allowed to install after it is deployed. It suffices to verify the conformance based on properties of the existing applications in an automobile system.

5.2 Case Study

We conduct a case study on an industrial RTOS and show how the conformance verification can be achieved by adopting an application called EMS, which is built in the system.

5.2.1 Overview of EMS application

EMS is one of the most important applications in the automotive operating system, which requires strict time constraints. It communicates with the operating system kernel by CAN (controller area network) bus. Because we are concerned with the real time features of the automobile system, we ignore the bus mechanism and assume a direct communication between EMS and the kernel.

EMS consists of two parts, i.e., configuration and implementation. The configuration specifies the statical attributes of alarms, tasks, events and so on. In EMS there are five preemptible tasks and they can not be multiply activated. The sketch of their implementation is shown in Figure 10. Task SystemInit is set as an autostart task in the configuration file 222We omit the configuration file of the application due to the space limitation.. It sets three alarms which are used to activate three tasks periodically. Task AL_Task_10ms is responsible for sampling A/D data and is activated with the period of 10 ms. Task AL_EMS_Task_100ms is used to get the rotational speed of the engine and is activated per 100 ms. Task AL_EMS_Task_10ms updates the engine state and triggers the combustion process in four cylinders every 10 ms. All the three tasks must be finished in a certain time. Otherwise they may be multiply activated, which violates the configuration and hence results in unexpected behaviors.

This work mainly focuses on the real time features of the system that rely on the execution time of not only system services but other statements in tasks. As mentioned in Section 4.3.4, we abstract the statements except system services as a special statement in form of TimeInterval=N to express their execution time. For instance, there are about 360 statements in the block of task EMS_Task_10ms after loop unrolling and function inlining, and the average amount of statements per system service is 110. Therefore, the execution time is 360/110, amount to 3 units time. We represent it as TimeInterval=3 (line 16 in Figure 10).

1int a;
3TASK EMS_Adap_Task_10ms{
4 while(true){
5  WaitEvent(Adap_Event);
6  ClearEvent(Adap_Event);
7  }
8  TerminateTask();
11TASK EMS_Task_100ms{
12  TerminateTask();
15TASK EMS_Task_10ms{
16  TimeInterval = 3;
17  TerminateTask();
20TASK Task_10ms{
21  SetEvent(EMS_Adap_Task_10ms, Adap_Event);
22  TerminateTask();
25TASK SystemInit{
26  SetRelAlarm(AL_Task_10ms,6 , 10);
27  /*ActivateTask(Task_10ms)*/
28  SetRelAlarm(AL_EMS_Task_100ms, 7, 100);
29  /*ActivateTask(EMS_Task_100ms)*/
30  SetRelAlarm(AL_EMS_Task_10ms, 8, 10);
31  /*ActivateTask(EMS_Task_100ms)*/
32  ActivateTask(EMS_Adap_Task_10ms);
33  TerminateTask();
Figure 10: Sketch of EMS implementation part

5.2.2 Conformance Verification

We verify the conformance between the industrial RTOS and the OSEK/VDX standard with respect to EMS. As depicted in Figure 9, we identify six properties from the standard and the application, and then verify them with the semantics of the standard. Two of them are verified invalid but they pass the testing on the RTOS. By the result we find two inconformities in the implementation.

The six properties used for conformance verification are listed below. The first three are extracted from the standard and the other three are extracted from the requirement of EMS.

  • Deadlock Freedom (DF): The system never reach a state from which no task can run.

  • Mutual Exclusion (EX): At any moment, there is at most one task in running state.

  • Priority Inversion Freedom (PIF): If a task becomes ready and its priority is higher than the one of the running task, it must preempt the running task next step.

  • Starvation Freedom (SF): The task that calls system service WaitEvent(E) must have been or will be set event E .

  • Periodic Execution (PE): A periodic task should be executed once at its specified interval.

  • Multiple-Activation Freedom (MAF): The task that is configured to be one-shot activation must not be activated in its running or ready state.

We formalise the above six properties and verify them using the built-in toolkit of K. For instance, deadlock freedom can be verified by exploring the state space of EMS. The command used for the verification is as follows:

krun EMS.osek --search-final

krun is a command, used to execute a specified program, e.g. EMS.osek, with the semantics of the language. The option --search-final of krun indicates to exploring all the possible executions and returning final states. There are two possibilities with final states, i.e. occurrence of deadlock or reaching the specified bound. However, in the task EMS_Adapt_Task_10ms there is an infinite loop (line 4 in Figure 10), which leads to non-termination of execution. We deal with it by setting a bound.

As another example, we consider the verification of the starvation freedom using LTL model checking in . The automobile operating system does not allow a task always being in waiting state. In EMS, when task EMS_Adap_Task_10ms waits for some events, at least one of the events it is waiting for must be set to EMS_Adap_Task_10ms sometime. This property can be described as the following LTL formula:

Here wait(Adap_Event, EMS_Adap_Task_10ms) is a Boolean function with parameters Adap_Event and EMS_Adap_Task_10ms, which returns true when task EMS_Adap_Task_10ms calls the system service WaitEvent(Adap_Event), and false otherwise. The function set(Adap_Event, EMS_Adap_Task_10ms) returns true when the event Adap_Event is set to EMS_Adap_Task_10ms.

The starvation freedom property can be verified through LTL model checking in MC with the following command:

krun EMS.osek --ltlmc ltlformula

The option --ltlmc indicates that a specified program, e.g. EMS.osek, is model checked with the LTL formula ltlformula. A counterexample is returned when ltlformula fails to be verified.

5.2.3 Verification Result

Table 2 shows the verification and testing results of the six properties. The results of the properties DE and MAF are inconsistent while those of other four properties are consistent. By Table 1 we can conclude that the operating system kernel and EMS are unconformant to the standard with respect to the properties DE and MAF.

We obtain two counterexamples when model checking the two properties. The counterexample of DE deadlock occurs when the value of counter is 16. In this time the alarm AL_Task_10ms expires and is expected to activate task Task_10ms. However, this task is in ready state and can not be activated because it is configured as a one-shot activation task. Hence the error occurs.

By analysing the implementation of EMS, We notice that the task Task_10ms has the lowest priority but the shortest period. It violates the general priority configuration criterion, that is, a shorter period task has a higher priority. After adjusting the priorities of the tasks in EMS under the criterion, the two properties are verified to be valid. Because EMS with original priorities passes the test on the kernel, there may be potential bugs in the kernel. A possible approach to detecting these bugs is to compose test cases according to the returned counterexamples and use them to test the kernel.

Properties Types verification result on semantics testing result on OS kernel
DF Std
ME Std
SF Std
PE App
  • Std: properties extracted from the OSEK/VDX standard.

  • App: properties extracted from EMS .

Table 2: Formal verification and test result

6 Related Work

Some efforts have been done to formally study the OSEK/VDX standard. For example, in work modelchecking the standard is partially formalised in Promela and verified by model checker Spin. Because the operating system kernel needs some environment models (applications) to run, they generate a bounded number of environment models for formal analysis. However, they do not consider alarm mechanism in their work. In work ORIENTAIS and CSP , a concrete automobile operating system based on the OSEK/VDX standard is formally specified in CSP and verified by model checker PAT. Their formalisations are built in the code level, and they mainly focus on analysing the operating system instead of the standard. Another work yes presents an approach to verifying the OSEK/VDX applications based on bounded model checking. But they do not take real time features of the system into account. All of the above works are based on model checking technique, which is also supported by framework.

As for the formal analysis of real time features in automobile RTOS, the work maude presents an approach to formalising and verifying the schedule table of an AUTOSAR-based RTOS using Real-Time Maude realtimemaude . AUTOSAR (AUTomotive Open System Architecture) AUTOSAR is the latest automobile standard based on OSEK/VDX. Real-Time Maude is an extension of Maude, which is also based on rewriting logic like but supports formalisation of real time features. This is the first work on analysing real time features on automobile systems to our knowledge. Inspired by this work, we achieve the formalisation of real time in . Compared with Real-Time Maude, is more scalable to describe complicated and large systems. For instance, there are several large-scale semantics having been defined in , like the semantics of C KC and Java Kjava .

As for the conformance verification of the OSEK/VDX RTOSs, the work choi2013 proposes a method for systematically constructing test cases by introducing a constraint specification language, called OSEK_CSL. They construct test cases automatically using model checker NuSMV. Similarly, the work spintest presents an approach to generating test cases by formalising the test requirement using Promela and Z-notation. Together with the formal models, the test cases can be generated by recording the search path in a tool called TGT (test case generation tool). However, both of these two works on conformance checking still relies on traditional testing techniques and mainly focus on the test of system services.

7 Conclusion

This paper presented an executable formal semantics of the OSEK/VDX standard. The formalisation includes most of the key components in the standard, such as task scheduling, event mechanism, resource management and in particular alarm mechanism. We reported some ambiguities of the standard which are found in the process of formalisation. We then defined a formal definition to these ambiguous descriptions after systematical analysis. Based on the formal semantics, we proposed an approach to verifying the conformance to the OSEK/VDX standard of an automobile operating system. We finally conducted a case study with an industrial automobile RTOS, which shows the effectiveness of the proposed approach.

Compared with the work in OSEK-K , the formal semantics of OSEK/VDX RTOS presented in this paper becomes more completed by including the real time features and clarifying some ambiguities. However, some problems mentioned in Section 4.2 remain challenging issues and should be solved before the proposed approach is applied to industry. For example, the interrupt is an essential mechanism of the OSEK/VDX standard. But interrupt may lead to state explosion during formal verification because it can occur almost at any time. In addition, we only considered the formal semantics of system services in the implementation of tasks. We also need to formalise the semantics of other statements in order to verify the properties that are specific to the tasks. Thanks to the semantics of C, it can be achieved by integrating these two semantics. However, it will introduce a new challenge, i.e. how to measure the execution time of each statement in a reasonable manner, which is one piece of our future work.

Another future work is to take the environment into consideration. The automobile operating system usually needs to interact with environment. For example, the system may need the engine temperature and the fuel load as parameters, which vary occasionally. Without knowing their values, the formal semantics can not be executed. One possible solution is symbolic execution, which treats variables with uncertain values as symbols symbolicexe . Fortunately, symbolic execution is also supported in framework symbolic .

A complete formal semantics of the OSEK/VDX standard is an essential basis for conformance verification. Another necessity is that we need to acquire all the applications and their execution results in an automobile operating system. To achieve it we should gain insight into not only the operating system kernel and standard but the implementation of applications of the automobile system.


  • [1] OSEK Group, et al.: OSEK/VDX Operating System Specification, 2009.
  • [2] Krichen, Moez, and Stavros Tripakis. Conformance testing for real-time systems. Formal Methods in System Design 34.3 (2009): 238-304.
  • [3] Feiler, Peter H. Real-time application development with OSEK: A review of the OSEK standards. No. CMU/SEI-2003-TN-004. CARNEGIE-MELLON UNIV PITTSBURGH PA SOFTWARE ENGINEERING INST, 2003.
  • [4] Vieira, Marlon ER, Marcio S. Dias, and Debra J. Richardson. Analyzing software architectures with Argus-I. Proceedings of the 22nd international conference on Software engineering. ACM, 2000.
  • [5] Woodcock J, Larsen P G, Bicarregui J, et al. Formal Methods: Practice and Experience. Acm Computing Surveys, 2009, 41(4):1729-1739.
  • [6] Eisner C R, Yorav K F. Functional verification of power gated designs by compositional reasoning: Springer US, US8086972[P]. 2011.
  • [7] Attie P C, Chockler H. Automatic Verification of Fault-Tolerant Register Emulations. Electronic Notes in Theoretical Computer Science, 2006, 149(1):49?60.
  • [8] Schubert K D, Roesner W, Ludden J M, et al. Functional verification of the IBM POWER7 microprocessor and POWER7 multiprocessor systems. Ibm Journal of Research & Development, 2011, 55(3):308-324.
  • [9] Kaivola R, Ghughal R, Narasimhan N, et al. Replacing Testing with Formal Verification in Intel CoreTM i7 Processor Execution Engine Validation. International Conference on Computer Aided Verification. Springer-Verlag, 2009:414-429.
  • [10] Zhang H, Aoki T, Lin H H, et al. SMT-Based Bounded Model Checking for OSEK/VDX Applications. Software Engineering Conference (APSEC), 2013 20th Asia-Pacific. IEEE, 2013:307-314.
  • [11] Fang L, Kitamura T, Do T B N, et al. Formal Model-Based Test for AUTOSAR Multicore RTOS. 2012 IEEE Fifth International Conference on Software Testing, Verification and Validation. IEEE Computer Society, 2012:251-259.
  • [12] Choi, Yunja. Constraint specification and test generation for OSEK/VDX-based operating systems. Software Engineering and Formal Methods. Springer Berlin Heidelberg, 2013. 305-319.
  • [13] Zhang M, Choi Y, Ogata K. A Formal Semantics of the OSEK/VDX Standard in K Framework and Its Applications. Rewriting Logic and Its Applications. Springer International Publishing, 2014:280-296.
  • [14] Roşu, Grigore, and Traian Florin Şerbănută. An overview of the K semantic framework. The Journal of Logic and Algebraic Programming 79.6 (2010): 397-434.
  • [15] Lemieux, Joseph. Programming in the OSEK/VDX Environment. Elsevier, 2001.
  • [16] OSEK VDX Portal-OSEK Products. URL
  • [17] Martí-Oliet, Narciso, and José Meseguer. Rewriting logic as a logical and semantic framework. Handbook of Philosophical Logic. Springer Netherlands, 2002. 1-87.
  • [18] Diaconescu, Razvan, and Kokichi Futatsugi. Logical semantics of CafeOBJ. Precise Semantics for Software Modeling Techniques (1996): 31-54.
  • [19] Borovanský, Peter, et al. An overview of ELAN. Electronic Notes in Theoretical Computer Science 15 (1998): 55-70.
  • [20] Clavel, Manuel, et al. Maude: Specification and programming in rewriting logic. Theoretical Computer Science 285.2 (2002): 187-243.
  • [21] Şerbănuţă T F, Arusoaie A, Lazar D, et al. The K primer (version 3.3). Electronic Notes in Theoretical Computer Science, 2014, 304: 57-80.
  • [22] Keller, Chantal, and Benjamin Werner. Importing HOL light into Coq. Interactive Theorem Proving. Springer Berlin Heidelberg, 2010. 307-322.
  • [23] John, Dirk. Osek/vdx conformance testing-modistarc. OSEK/VDX Open Systems in Automotive Networks (Ref. No. 1998/523), IEE Seminar. IET, 1998.
  • [24] Zahir, Andree. OIL-OSEK implementation language. OSEK/VDX Open Systems in Automotive Networks (Ref. No. 1998/523), IEE Seminar. IET, 1998.
  • [25] Clarke, Edmund M., Orna Grumberg, and Doron Peled. Model checking. MIT press, 1999.
  • [26] Yatake, Kenro, and Toshiaki Aoki. Model checking of OSEK/VDX OS design model based on environment modeling. Theoretical Aspects of Computing-ICTAC 2012. Springer Berlin Heidelberg, 2012. 183-197.
  • [27] Shi, Jianqi, et al. ORIENTAIS: Formal verified OSEK/VDX real-time operating system. Engineering of Complex Computer Systems (ICECCS), 2012 17th International Conference on. IEEE, 2012.
  • [28] Huang, Yanhong, et al. Modeling and verifying the code-level OSEK/VDX operating system with CSP. Theoretical Aspects of Software Engineering (TASE), 2011 Fifth International Symposium on. IEEE, 2011.
  • [29] Zhang H, Aoki T, Chiba Y. Yes! You can use your model checker to verify OSEK/VDX applications[J]. IEEE, 2015:1-10.
  • [30] Zhu, Longfei, et al. A timing verification framework for AUTOSAR OS component development based on Real-Time Maude. Theoretical Aspects of Software Engineering (TASE), 2013 International Symposium on. IEEE, 2013.
  • [31] Meseguer, José. Real-Time Maude: A tool for simulating and analyzing real-time and hybrid systems. Electronic Notes in Theoretical Computer Science 36 (2000): 361-382.
  • [32] AUTOSAR Consortium. AUTOSAR methodology. AUTOSAR Standard, v1 2 (2009): R3.
  • [33] ELLISON III, CHARLES MCEWEN. A formal semantics of C with applications. Diss. University of Illinois, 2012.
  • [34] Bogdanas, Denis, and Grigore Rosu. K-Java: a complete semantics of Java. Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 2015.
  • [35] Chen, Jiang, and Toshiaki Aoki. Conformance testing for OSEK/VDX operating system using model checking. Software Engineering Conference (APSEC), 2011 18th Asia Pacific. IEEE, 2011.
  • [36] Cadar, Cristian, and Koushik Sen. Symbolic execution for software testing: three decades later. Communications of the ACM 56.2 (2013): 82-90.
  • [37] Asavoae, Irina Mariuca, Mihail Asavoae, and Dorel Lucanu. Path directed symbolic execution in the K framework. Symbolic and Numeric Algorithms for Scientific Computing (SYNASC), 2010 12th International Symposium on. IEEE, 2010.