Repository navigation
Recognize FW_ASSERT in JPL CodeQL Rule 16 assertion queries - #5361
Conversation
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Coverage report — base
|
| Module | Line | Δ | Function | Δ | Branch | Δ |
|---|---|---|---|---|---|---|
Svc/DpCatalog |
77.11 | -0.45 | 100.00 | +0.00 | 65.08 | -0.72 |
Modules without UTs
CFDP/Checksum/GTest, Drv/ByteStreamDriverModel, Drv/Interfaces, Drv/LinuxGpioDriver, Drv/LinuxI2cDriver, Drv/LinuxSpiDriver, Drv/LinuxUartDriver, Drv/Ports, Drv/Ports/DataTypes, FppTestProject/FppTest/interfaces, FppTestProject/FppTest/topology/async, FppTestProject/FppTest/topology/components/Comp, FppTestProject/FppTest/topology/components/Framework, FppTestProject/FppTest/topology/components/Receiver, FppTestProject/FppTest/topology/components/Sender, FppTestProject/FppTest/topology/guarded, FppTestProject/FppTest/topology/ports, FppTestProject/FppTest/topology/sync, FppTestProject/FppTest/topology/top_ports, FppTestProject/FppTest/topology/types, Fw/Cmd, Fw/Com, Fw/Comp, Fw/FilePacket/GTest, Fw/Fpy, Fw/Interfaces, Fw/Obj, Fw/Port, Fw/Ports/CompletionStatus, Fw/Ports/Ready, Fw/Ports/Signal, Fw/Ports/SuccessCondition, Fw/Prm, Fw/SerializableFile/test/TestSerializable, Fw/Sm, Fw/Test, Fw/Types/GTest, Os/Models, Svc/Cycle, Svc/DpPorts, Svc/Fatal, Svc/FatalHandler, Svc/FileDownlinkPorts, Svc/FprimeProtocol, Svc/Interfaces, Svc/PassiveConsoleTextLogger, Svc/Ping, Svc/PolyIf, Svc/Ports/CommsPorts, Svc/Ports/FilePorts, Svc/Ports/OsTimeEpoch, Svc/Ports/TlmPacketizerPorts, Svc/Ports/VersionPorts, Svc/Sched, Svc/Seq, Svc/Subtopologies/CdhCore, Svc/Subtopologies/ComCcsds, Svc/Subtopologies/ComFprime, Svc/Subtopologies/ComLoggerTee, Svc/Subtopologies/DataProducts, Svc/Subtopologies/FileHandling, Svc/Types/TlmPacketizerTypes, Svc/WatchDog, TestDeploymentsProject/Ref/PingReceiver, TestDeploymentsProject/Ref/RecvBuffApp, TestDeploymentsProject/Ref/SendBuffApp, TestDeploymentsProject/Ref/Top, TestDeploymentsProject/Ref/TypeDemo, cmake/test/data/TestDeployment/TestBuildAutocoder, cmake/test/data/TestDeployment/TestChainedAutocoder, cmake/test/data/TestDeployment/TestHeaderAutocoder, cmake/test/data/TestDeployment/TestTargetAutocoder, cmake/test/data/test-fprime-library/TestLibrary/TestComponent, cmake/test/data/test-fprime-library2/TestLibrary2/TestComponent
Change Description
The upstream CodeQL JPL_C pack's Rule 16 ("Use assertions") queries rely on
semmle.code.cpp.commons.Assertions, which only recognizes macros matchingassert(,Assert(x, y), orc_assert(— soFW_ASSERTis invisible to them. This causedcpp/jpl-c/use-of-assertions-density("Long function without assertion") to flag every long F´ function even when it containsFW_ASSERTs, and made the other three Rule 16 queries silently skipFW_ASSERTentirely.This PR adds a small in-repo query pack,
.github/codeql/fprime-queries/:FprimeAssertions.qll— extends the standardAssertionclass with anFwAssertclass matchingFW_ASSERTmacro invocations. (FW_ASSERTexpands to(cond ? (void)0 : Fw::SwAssert(...)), so the asserted expression is the conditional's condition.)cpp/fprime/jpl-c/use-of-assertions-*. Per review feedback, the non-boolean query flags any asserted expression whose unspecified type is notbool(stricter than the upstream pointer-only check, appropriate since F´ is C++).The CodeQL configs are updated to swap them in:
jpl-standard-pack-1.yml: adds the custom pack viaqueries:and excludes the three upstream warning-severity assertion queries (constant / non-boolean / side-effect).jpl-standard-pack-2.yml: adds the custom pack and excludes upstreamcpp/jpl-c/use-of-assertions-density.The existing severity filters in each config automatically route the recommendation-severity density query to pack 2 and the warning-severity queries to pack 1.
Rationale
Eliminates persistent false positives from "Long function without assertion" on F´ code (FW_ASSERT was not recognized as an assertion), and enables the constant/non-boolean/side-effect assertion checks to actually analyze
FW_ASSERTconditions (previously false negatives).Testing/Review Recommendations
codeql query compile(CodeQL CLI 2.25.6).FW_ASSERTmacro fromFw/Types/Assert.hpp:FW_ASSERTis no longer flagged by the density query, while one without any assertion still is;FW_ASSERT(x > 0)passes the non-boolean check, whileFW_ASSERT(x)(int),FW_ASSERT(p)(pointer), andFW_ASSERT(1)are flagged;FW_ASSERT(1)andFW_ASSERT(i++ < 5)are correctly flagged by the constant and side-effect queries respectively.Future Work
github/codeql'sAssertions.qll.AI Usage (see policy)
AI (Devin) authored the CodeQL queries, config changes, and testing.
IAMAI