Skip to content

Development/ com and json rpc functional tests#248

Open
smanes0213 wants to merge 40 commits intomasterfrom
development/json-rpc-functional-tests
Open

Development/ com and json rpc functional tests#248
smanes0213 wants to merge 40 commits intomasterfrom
development/json-rpc-functional-tests

Conversation

@smanes0213
Copy link
Copy Markdown
Contributor

No description provided.

bramoosterhuis and others added 13 commits March 4, 2026 09:16
…tor fix

The ProxyStubGenerator does not forward the caller's IsSet() state for
@out OptionalType<T> parameters. The stub always constructs an unset
optional, so the implementation never receives the caller's intent and
the value is never written back.

Affected: Divide_WithRemainder, ParseInt_ValidNumber,
          ParseInt_NegativeNumber, ParseInt_InvalidString
Signed-off-by: smanes0213 <sankalpmaneshwar46@outlook.com>
Copilot AI review requested due to automatic review settings March 24, 2026 11:07
@rdkcmf-jenkins
Copy link
Copy Markdown
Contributor

b'## Blackduck scan failure details

Summary: 0 violations, 0 files pending approval, 3 files pending identification.

  • Protex Server Path: /home/blackduck/github/ThunderTools/248/rdkcentral/ThunderTools

  • Commit: cf7b33b

Report detail: gist'

@smanes0213 smanes0213 marked this pull request as draft March 24, 2026 11:10
@smanes0213 smanes0213 review requested due to automatic review settings March 24, 2026 11:10
@rdkcmf-jenkins
Copy link
Copy Markdown
Contributor

b'## Blackduck scan failure details

Summary: 0 violations, 0 files pending approval, 3 files pending identification.

  • Protex Server Path: /home/blackduck/github/ThunderTools/248/rdkcentral/ThunderTools

  • Commit: 377a3b0

Report detail: gist'

Comment thread tests/src/tests/TestStructsJsonRpc.cpp Outdated
EXPECT_NE(response.find("20"), string::npos) << "Response: " << response;
}

// NOTE: SetGetColor test removed - setColor/getColor methods fail with error 30 (not found)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove tests that expose known or possible issues — instead keep them and prefix the test name with DISABLED_ so the gap stays visible.

class TestPrimitivesJsonRpc : public JsonRpcTesting::JsonRpcTestHarness<ITestPrimitives> {};

// ===== Signed integers =====
// NOTE: Signed integer boundary tests fail due to JsonGenerator bug (overflow validation)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove tests that expose known or possible issues — instead keep them and prefix the test name with DISABLED_ so the gap stays visible.

Comment thread tests/src/tests/TestEnumsJsonRpc.cpp Outdated

class TestEnumsJsonRpc : public JsonRpcTesting::JsonRpcTestHarness<ITestEnums> {};

// Keep only tests for methods that actually work
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove tests that expose known or possible issues — instead keep them and prefix the test name with DISABLED_ so the gap stays visible.

Comment thread tests/CMakeLists.txt Outdated
endmacro()

# Helper macro to also add interface to JSON-RPC generation
macro(AddTestInterfaceWithJsonRpc TestName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose to use extra macros creating an inheritance chain? In cmake cmake_parse_arguments works fine for macros. If you would add JSON_RPC and HAS_ENUMS the call sites become self-documenting:

AddTestInterface("Primitives"    JSON_RPC)
AddTestInterface("Enums"         JSON_RPC HAS_ENUMS)
AddTestInterface("Structs"       JSON_RPC)
AddTestInterface("Restrictions"  JSON_RPC)
AddTestInterface("Buffers")               # COM-RPC only — known generator bug
AddTestInterface("Iterators")             # COM-RPC only — no JSON mapping

Adding a new flag later (say NO_INSTALL or SKIP) touches one macro instead of the whole inheritance chain, and there's no risk of forgetting to call the base macro from a derived one.

Comment thread tests/src/Module.h Outdated

#include <core/core.h>
#include <com/com.h>
#include <plugins/JSONRPC.h> // Only need JSONRPC (includes IPlugin, IShell, IDispatcher)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unconditional #include <plugins/JSONRPC.h> is included in every translation unit including the COM-RPC binary. external/thunder/CMakeLists.txt only builds PLUGINS when INCLUDE_JSON_RPC_INTERFACES is ON, so a plain COM-RPC build will fail to find the header. Needs a guard:

#ifdef BUILD_JSON_RPC_TESTS
#include <plugins/JSONRPC.h>
#endif

EXPECT_NE(Core::ERROR_NONE, result) << "Should reject zero";
}

TEST_F(TestRestrictionsJsonRpc, SetRatio_OutOfRange) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetRatio_OutOfRange uses {"value":1.5} but IsValidRatio correctly uses {"ratio":0.5} — the interface parameter is ratio, so SetRatio should also use {"ratio":1.5}.

EXPECT_NE(Core::ERROR_NONE, result) << "Should reject value > 1.0";
}

TEST_F(TestRestrictionsJsonRpc, SetName_EmptyRejected) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetName_EmptyRejected and SetName_TooLongRejected use {"value":"..."} but the parameter is name.

Comment thread tests/src/tests/TestEnumsJsonRpc.cpp Outdated
string response;
// Read-only property
EXPECT_EQ(Core::ERROR_NONE, CallMethod("currentState", "{}", response));
// Should return current state value (IDLE, RUNNING, etc.)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to assert the expected state in the response and mark the test DISABLED_ if it doesn't work yet — a disabled test with a failing assertion is more useful than a passing test with no assertion.

Comment thread tests/src/tests/TestEnumsJsonRpc.cpp Outdated
string response;
EXPECT_EQ(Core::ERROR_NONE, CallMethod("computeState",
R"({"current":"RUNNING","desired":"STOPPED"})", response));
// Should return derived state
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to assert the expected state in the response and mark the test DISABLED_ if it doesn't work yet — a disabled test with a failing assertion is more useful than a passing test with no assertion.

Comment thread tests/src/JsonRpcTestHarness.h Outdated

// JSON-RPC test harness that invokes JSON-RPC methods directly via PluginHost::JSONRPC
// Tests the generated JSON stubs by sending JSON strings and validating responses
template <typename INTERFACE>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The INTERFACE template parameter is never used anywhere in the class body. Every fixture gets the exact same g_server singleton regardless of which interface type is passed. TestPrimitivesJsonRpc, TestEnumsJsonRp etc. all resolve to identical classes at compile time — the type parameter is purely decorative.

Two directions to consider:

Either drop the template entirely and name it JsonRpcTestHarness, which is honest about what it does.

Or actually use INTERFACE to make it meaningful — for example using INTERFACE::ID to look up the right impl instance from g_implementations, so each fixture is genuinely scoped to its interface. This would also be the right foundation for per-test state reset once that issue is addressed.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@bramoosterhuis
Copy link
Copy Markdown
Contributor

Refactor functional test infrastructure

The previous test setup had grown organically into a single monolithic tests/CMakeLists.txt
(349 lines) that mixed COM-RPC and JSON-RPC concerns, used #ifdef BUILD_JSON_RPC_TESTS guards
throughout the implementation files, and registered implementations through two separate parallel
mechanisms (TestRegistry::ImplementationRegistrar for COM-RPC and JsonRpcServer::JsonRpcRegistrar
for JSON-RPC).

Structure

The tests are reorganised into tests/FunctionalTests/ with three subtrees: common/ holds the
interfaces, implementations, and generated code; comrpc/ and jsonrpc/ each build their own
executable. This makes the scope of each component clear and removes the need for conditional
compilation in implementation files.

Unified factory

TestRegistry and ComRpcServer::ImplementationProvider are replaced by a single
TestImplementation::Factory in common/. Both COM-RPC (Acquire()) and JSON-RPC
(RegisterJsonRpcInterfaces) pull from the same factory. Implementation files register once via a
static Factory::Registrar<INTERFACE, IMPL> and have no knowledge of which transport will use them.

JSON-RPC dispatch

The old JsonRpcServer inherited from both PluginHost::IPlugin and PluginHost::JSONRPC and
wired registration through a separate JsonRpcRegistrationProvider. The new server inherits directly
from JsonRPCRegister (a thin JSONRPCSupportsEventStatus subclass) and calls
RegisterJsonRpcInterfaces from its constructor. Registration code is generated from
JsonRpcRegistrations.cpp.in via configure_file, driven by the AddTestInterface(... JSON_RPC)
flag in CMake. Tests call Invoke() directly on the server — no socket, no process boundary.

COM-RPC connection sharing

Each test previously opened and closed a socket connection in SetUp/TearDown, causing ~15s
runtime for 136 tests. The harness now uses SetUpTestSuite/TearDownTestSuite to share a single
engine, client, and proxy per test suite. Runtime dropped to ~2s. Tests that assumed a fresh impl
per connection (GetPoint_BeforeSet_ReturnsError) are removed as they are not testing serialisation
behaviour.

1 similar comment
@bramoosterhuis
Copy link
Copy Markdown
Contributor

Refactor functional test infrastructure

The previous test setup had grown organically into a single monolithic tests/CMakeLists.txt
(349 lines) that mixed COM-RPC and JSON-RPC concerns, used #ifdef BUILD_JSON_RPC_TESTS guards
throughout the implementation files, and registered implementations through two separate parallel
mechanisms (TestRegistry::ImplementationRegistrar for COM-RPC and JsonRpcServer::JsonRpcRegistrar
for JSON-RPC).

Structure

The tests are reorganised into tests/FunctionalTests/ with three subtrees: common/ holds the
interfaces, implementations, and generated code; comrpc/ and jsonrpc/ each build their own
executable. This makes the scope of each component clear and removes the need for conditional
compilation in implementation files.

Unified factory

TestRegistry and ComRpcServer::ImplementationProvider are replaced by a single
TestImplementation::Factory in common/. Both COM-RPC (Acquire()) and JSON-RPC
(RegisterJsonRpcInterfaces) pull from the same factory. Implementation files register once via a
static Factory::Registrar<INTERFACE, IMPL> and have no knowledge of which transport will use them.

JSON-RPC dispatch

The old JsonRpcServer inherited from both PluginHost::IPlugin and PluginHost::JSONRPC and
wired registration through a separate JsonRpcRegistrationProvider. The new server inherits directly
from JsonRPCRegister (a thin JSONRPCSupportsEventStatus subclass) and calls
RegisterJsonRpcInterfaces from its constructor. Registration code is generated from
JsonRpcRegistrations.cpp.in via configure_file, driven by the AddTestInterface(... JSON_RPC)
flag in CMake. Tests call Invoke() directly on the server — no socket, no process boundary.

COM-RPC connection sharing

Each test previously opened and closed a socket connection in SetUp/TearDown, causing ~15s
runtime for 136 tests. The harness now uses SetUpTestSuite/TearDownTestSuite to share a single
engine, client, and proxy per test suite. Runtime dropped to ~2s. Tests that assumed a fresh impl
per connection (GetPoint_BeforeSet_ReturnsError) are removed as they are not testing serialisation
behaviour.

@bramoosterhuis bramoosterhuis marked this pull request as ready for review April 24, 2026 09:52
@rdkcmf-jenkins
Copy link
Copy Markdown
Contributor

b'## Blackduck scan failure details

Summary: 0 violations, 0 files pending approval, 3 files pending identification.

  • Protex Server Path: /home/blackduck/github/ThunderTools/248/rdkcentral/ThunderTools

  • Commit: 10f7e72

Report detail: gist'

@bramoosterhuis
Copy link
Copy Markdown
Contributor

@smanes0213 I took the liberty of refactoring the tests to have a common base and removed some complexity from the JSON-RPC side, while keeping the focus on exercising the generated code. Could you take a look and make sure I haven't stepped on anything you had in mind?

@mhughesacn
Copy link
Copy Markdown

Hi @smanes0213 : Please add proper (i.e. full, not one-line) apache-2.0 headers to the new files.

Copilot AI review requested due to automatic review settings April 24, 2026 17:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

@github-actions
Copy link
Copy Markdown

JsonGenerator Results

View Results

Changes detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants