[SystemSafety] MC/DC handling of conditional operators
Ian Broster
ianb at rapitasystems.com
Thu Oct 31 13:04:17 CET 2024
Derek Jones wrote:
I have not seen an analysis of MC/DC that involves conditional operators in if-statement conditions
We (Rapita Systems) treat conditional operators like this in a Boolean context as MC/DC conditions. This is mentioned in DOT/FAA/AR-06/54 (4.3.2) and has been supported by RapiCover for a long time now.
With thanks to my colleague Joe for throwing this through the tool, below are some screenshots from a small example.
It would be interesting to run the Sqlite tests through RapiCover, but we have not tried.
Ian
1.
The conditional operator within an "if" gives rise to 2 conditions in the decision and only partial coverage achieved with c=0.
test_func_1:
[cid:0801db3a-1d18-4818-8542-bd012c7cde5b]
1.
The source code (red or yellow shows incomplete MC/DC coverage) for 2 similar functions.
[cid:0c2091cd-05d1-4aeb-a2cb-720b8360ff04]
2. test_func_2 list of decisions, for comparison.
[cid:776869f1-a5a8-4665-9993-2d2ffd6d0f21]
1.
Only when we have test cases where c is 0 and non-zero, we can achieve full coverage.
[cid:0bf35888-ef79-4f67-b016-f568eac779f7]
--
Dr Ian Broster
Chief Operating Officer - Rapita Systems Ltd (UK) / S.L.(Spain)
+44 7963 469 090
________________________________
From: systemsafety <systemsafety-bounces at lists.techfak.uni-bielefeld.de> on behalf of Derek M Jones <derek at knosof.co.uk>
Sent: Wednesday, October 30, 2024 12:10
To: systemsafety at lists.techfak.uni-bielefeld.de <systemsafety at lists.techfak.uni-bielefeld.de>
Subject: [SystemSafety] MC/DC handling of conditional operators
All,
I have not seen an analysis of MC/DC that involves
conditional operators in if-statement conditions.
Why would anybody use conditional operators (also known as
a ternary operator) in this context you ask?
I thought the same until some recent analysis of
if-statement conditions.
As its name suggests, the conditional operator involves a
condition, and as such looks like it needs to be addressed
by MC/DC (I have added parenthesis to the following examples
to make things clear):
In: 1+(c!=0 ? x : y)
if c is not equal to zero, the result is 1+x,
otherwise the result is 1+y.
Now in C, C++ and other languages we can write:
if (1+(c!=0 ? x : y) == z)
foo=bar;
or we can write the longer equivalent code
if (c != 0)
{
if (1+x == z)
foo=bar;
}
else
{
if (1+y == z)
foo=bar;
}
All the analysis of MC/DC that I have seen only involves
logical AND and logical OR.
Is the behavior of conditional operator something that gets
ignored?
Is there an unwritten MC/DC rule that conditional operators
not be used in if-statement conditions?
Shouldn't the conditional operator be part of the MC/DC
analysis, i.e., required to be tested along both arms?
SQLite says they achieve 100% MC/DC
https://www.sqlite.org/testing.html#mcdc
The SQLite source contains instances of the conditional
operator if if-statement conditions
https://shape-of-code.com/2024/10/13/if-statement-conditions-some-basic-measurements/
Does anybody know how SQLite+MC/DC deals with the
conditional operator?
--
Derek M. Jones Evidence-based software engineering
blog:https://shape-of-code.com
_______________________________________________
The System Safety Mailing List
systemsafety at TechFak.Uni-Bielefeld.DE
Manage your subscription: https://lists.techfak.uni-bielefeld.de/mailman/listinfo/systemsafety
--
Book your place for DO-178C Multicore Training taking place on 6 and 7 November in Munich<https://www.rapitasystems.com/events/do-178c-multicore-person-training-munich?utm_source=rs_email_sig>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.techfak.uni-bielefeld.de/pipermail/systemsafety/attachments/20241031/b22eeb83/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 12078 bytes
Desc: image.png
URL: <https://lists.techfak.uni-bielefeld.de/pipermail/systemsafety/attachments/20241031/b22eeb83/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 15008 bytes
Desc: image.png
URL: <https://lists.techfak.uni-bielefeld.de/pipermail/systemsafety/attachments/20241031/b22eeb83/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 12048 bytes
Desc: image.png
URL: <https://lists.techfak.uni-bielefeld.de/pipermail/systemsafety/attachments/20241031/b22eeb83/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 11379 bytes
Desc: image.png
URL: <https://lists.techfak.uni-bielefeld.de/pipermail/systemsafety/attachments/20241031/b22eeb83/attachment-0007.png>
More information about the systemsafety
mailing list