Skip to content

Commit 02561ba

Browse files
committed
Remove: Shared state in FrameTestStrategy
Fix: Use just one handler bundle per pacing tests Fix: Change required timings for pacing
1 parent 5ee2cdd commit 02561ba

24 files changed

+204
-310
lines changed

tests/integration_tests/noctx/core/constants.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
4+
25
#pragma once
36

47
#ifndef SESSION_SKIP_PORT

tests/integration_tests/noctx/core/handler_base.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
24

35
#include "handler_base.hpp"
46

@@ -14,9 +16,9 @@ Handlers::~Handlers() {
1416
}
1517

1618
void Handlers::startSession(
17-
std::vector<std::function<void(std::atomic<bool>&)>> threadFunctions) {
19+
std::vector<std::function<void(std::atomic<bool>&)>> threadFunctions, bool isRx) {
1820
for (auto& func : threadFunctions) {
19-
session.addThread(func);
21+
session.addThread(func, isRx);
2022
}
2123
}
2224

tests/integration_tests/noctx/core/handler_base.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
4+
25
#pragma once
36

4-
#include <atomic>
57
#include <functional>
68
#include <vector>
79

@@ -15,8 +17,8 @@ class Handlers {
1517
FrameTestStrategy* frameTestStrategy = nullptr);
1618
virtual ~Handlers();
1719

18-
void startSession(
19-
std::vector<std::function<void(std::atomic<bool>&)>> threadFunctions = {});
20+
void startSession(std::vector<std::function<void(std::atomic<bool>&)>> threadFunctions,
21+
bool isRx);
2022
void stopSession();
2123

2224
void setSessionPortsRx(struct st_rx_port* port, int rxPortIdx, int rxPortRedundantIdx);

tests/integration_tests/noctx/core/session.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
24

35
#include "session.hpp"
46

5-
void Session::addThread(std::function<void(std::atomic<bool>&)> func) {
7+
void Session::addThread(std::function<void(std::atomic<bool>&)> func, bool isRx) {
68
if (!func) {
79
return;
810
}
11+
std::atomic<bool>& stopFlag = isRx ? stopFlagRx : stopFlagTx;
912

1013
if (threads_.empty()) {
11-
stopFlag_.store(false);
14+
stopFlag.store(false);
1215
}
1316

14-
threads_.emplace_back(func, std::ref(stopFlag_));
17+
threads_.emplace_back(func, std::ref(stopFlag));
1518
}
1619

1720
bool Session::isRunning() const {
@@ -29,7 +32,9 @@ bool Session::isRunning() const {
2932
}
3033

3134
void Session::stop() {
32-
stopFlag_ = true;
35+
stopFlagTx.store(true);
36+
std::this_thread::sleep_for(std::chrono::milliseconds(500));
37+
stopFlagRx.store(true);
3338
for (auto& thread : threads_) {
3439
if (thread.joinable()) {
3540
thread.join();

tests/integration_tests/noctx/core/session.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
4+
25
#pragma once
36

47
#include <atomic>
@@ -11,12 +14,13 @@
1114
*/
1215
class Session {
1316
public:
14-
void addThread(std::function<void(std::atomic<bool>&)> func);
17+
void addThread(std::function<void(std::atomic<bool>&)> func, bool isRx);
1518
bool isRunning() const;
1619
void stop();
1720
~Session();
1821

1922
private:
2023
std::vector<std::thread> threads_;
21-
std::atomic<bool> stopFlag_{false};
24+
std::atomic<bool> stopFlagRx{false};
25+
std::atomic<bool> stopFlagTx{false};
2226
};
Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,19 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
24

35
#include "strategy.hpp"
46

5-
#include <utility>
6-
7-
void StrategySharedState::setPacingParameters(double tr_offset_ns, double trs_ns,
8-
uint32_t vrx_pkts) {
9-
std::lock_guard<std::mutex> lock(pacing_mutex_);
10-
pacing_.tr_offset_ns = tr_offset_ns;
11-
pacing_.trs_ns = trs_ns;
12-
pacing_.vrx_pkts = vrx_pkts;
13-
pacing_.has_value = true;
14-
}
15-
16-
StrategySharedState::PacingParameters StrategySharedState::getPacingParameters() const {
17-
std::lock_guard<std::mutex> lock(pacing_mutex_);
18-
return pacing_;
19-
}
20-
217
FrameTestStrategy::FrameTestStrategy(Handlers* parent, bool enable_tx_modifier,
228
bool enable_rx_modifier)
239
: parent(parent),
2410
idx_tx(0),
2511
idx_rx(0),
2612
expect_fps(0.0),
2713
enable_tx_modifier(enable_tx_modifier),
28-
enable_rx_modifier(enable_rx_modifier),
29-
shared_state_(nullptr) {
14+
enable_rx_modifier(enable_rx_modifier) {
3015
}
3116

3217
FrameTestStrategy::~FrameTestStrategy() {
3318
parent = nullptr;
3419
}
35-
36-
void FrameTestStrategy::setSharedState(std::shared_ptr<StrategySharedState> state) {
37-
shared_state_ = std::move(state);
38-
}
39-
40-
std::shared_ptr<StrategySharedState> FrameTestStrategy::sharedState() const {
41-
return shared_state_;
42-
}
Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
4+
25
#pragma once
36

47
#include <cstddef>
@@ -8,32 +11,12 @@
811

912
class Handlers;
1013

11-
class StrategySharedState {
12-
public:
13-
struct PacingParameters {
14-
double tr_offset_ns = 0.0;
15-
double trs_ns = 0.0;
16-
uint32_t vrx_pkts = 0;
17-
bool has_value = false;
18-
};
19-
20-
void setPacingParameters(double tr_offset_ns, double trs_ns, uint32_t vrx_pkts);
21-
PacingParameters getPacingParameters() const;
22-
23-
private:
24-
mutable std::mutex pacing_mutex_;
25-
PacingParameters pacing_;
26-
};
27-
2814
class FrameTestStrategy {
2915
public:
3016
FrameTestStrategy(Handlers* parent = nullptr, bool enable_tx_modifier = false,
3117
bool enable_rx_modifier = false);
3218
virtual ~FrameTestStrategy();
3319

34-
void setSharedState(std::shared_ptr<StrategySharedState> state);
35-
std::shared_ptr<StrategySharedState> sharedState() const;
36-
3720
virtual void txTestFrameModifier(void* frame, size_t frame_size) {
3821
}
3922
virtual void rxTestFrameModifier(void* frame, size_t frame_size) {
@@ -45,7 +28,4 @@ class FrameTestStrategy {
4528
double expect_fps;
4629
bool enable_tx_modifier;
4730
bool enable_rx_modifier;
48-
49-
private:
50-
std::shared_ptr<StrategySharedState> shared_state_;
5131
};

tests/integration_tests/noctx/core/test_fixture.cpp

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
24

35
#include "test_fixture.hpp"
46

@@ -46,7 +48,7 @@ void NoCtxTest::SetUp() {
4648
void NoCtxTest::TearDown() {
4749
st30pHandlers.clear();
4850
st20pHandlers.clear();
49-
frameTestStrategys.clear();
51+
frameTestStrategies.clear();
5052

5153
if (ctx) {
5254
if (ctx->handle) {
@@ -93,15 +95,11 @@ void NoCtxTest::sleepUntilFailure(int sleep_duration) {
9395
NoCtxTest::St20pHandlerBundle NoCtxTest::createSt20pHandlerBundle(
9496
bool createTx, bool createRx,
9597
std::function<FrameTestStrategy*(St20pHandler*)> strategyFactory,
96-
std::function<void(St20pHandler*)> configure,
97-
std::shared_ptr<StrategySharedState> sharedState) {
98+
std::function<void(St20pHandler*)> configure) {
9899
if (!ctx) {
99100
throw std::runtime_error("createSt20pHandlerBundle expects initialized ctx");
100101
}
101102

102-
auto bundleSharedState =
103-
sharedState ? sharedState : std::make_shared<StrategySharedState>();
104-
105103
auto handlerOwned = std::make_unique<St20pHandler>(ctx);
106104
auto* handler = handlerOwned.get();
107105
if (configure) {
@@ -114,7 +112,6 @@ NoCtxTest::St20pHandlerBundle NoCtxTest::createSt20pHandlerBundle(
114112
strategyOwned.reset(strategyFactory(handler));
115113
strategy = strategyOwned.get();
116114
handler->setFrameTestStrategy(strategy);
117-
strategy->setSharedState(bundleSharedState);
118115
}
119116

120117
if (createRx) {
@@ -125,7 +122,6 @@ NoCtxTest::St20pHandlerBundle NoCtxTest::createSt20pHandlerBundle(
125122
}
126123

127124
auto bundle = registerSt20pResources(std::move(handlerOwned), std::move(strategyOwned));
128-
bundle.sharedState = bundleSharedState;
129125
return bundle;
130126
}
131127

@@ -138,7 +134,7 @@ NoCtxTest::St20pHandlerBundle NoCtxTest::registerSt20pResources(
138134
}
139135
if (strategy) {
140136
bundle.strategy = strategy.get();
141-
frameTestStrategys.emplace_back(std::move(strategy));
137+
frameTestStrategies.emplace_back(std::move(strategy));
142138
}
143139
return bundle;
144140
}
@@ -165,33 +161,3 @@ bool NoCtxTest::waitForSession(Session& session, std::chrono::milliseconds timeo
165161
}
166162
return session.isRunning();
167163
}
168-
169-
bool NoCtxTest::startRxThenTx(St20pHandlerBundle& rxBundle, St20pHandlerBundle& txBundle,
170-
std::chrono::milliseconds warmup) {
171-
if (!rxBundle.handler || !txBundle.handler) {
172-
return false;
173-
}
174-
175-
rxBundle.handler->startSessionRx();
176-
if (!waitForSession(rxBundle.handler->session, warmup)) {
177-
return false;
178-
}
179-
180-
txBundle.handler->startSessionTx();
181-
return waitForSession(txBundle.handler->session, warmup);
182-
}
183-
184-
void NoCtxTest::stopTxThenRx(St20pHandlerBundle& txBundle, St20pHandlerBundle& rxBundle,
185-
std::chrono::milliseconds rxDelay) {
186-
if (txBundle.handler) {
187-
txBundle.handler->session.stop();
188-
}
189-
190-
if (rxDelay.count() > 0) {
191-
std::this_thread::sleep_for(rxDelay);
192-
}
193-
194-
if (rxBundle.handler) {
195-
rxBundle.handler->session.stop();
196-
}
197-
}
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
* Copyright(c) 2025 Intel Corporation
3+
*/
4+
25
#pragma once
36

47
#include <gtest/gtest.h>
@@ -8,18 +11,15 @@
811
#include <memory>
912
#include <vector>
1013

14+
#include "handlers/st20p_handler.hpp"
15+
#include "handlers/st30p_handler.hpp"
1116
#include "tests.hpp"
1217

1318
class Session;
1419
class FrameTestStrategy;
15-
class St20pHandler;
16-
class St30pHandler;
17-
class StrategySharedState;
18-
1920
class NoCtxTest : public ::testing::Test {
2021
protected:
2122
static constexpr int SessionStartTimeoutMs = 1500;
22-
static constexpr int TxRxDelayMs = 200;
2323

2424
struct st_tests_context* ctx = nullptr;
2525

@@ -30,7 +30,6 @@ class NoCtxTest : public ::testing::Test {
3030
struct St20pHandlerBundle {
3131
St20pHandler* handler = nullptr;
3232
FrameTestStrategy* strategy = nullptr;
33-
std::shared_ptr<StrategySharedState> sharedState;
3433
};
3534

3635
uint defaultTestDuration = 0;
@@ -41,22 +40,15 @@ class NoCtxTest : public ::testing::Test {
4140
St20pHandlerBundle createSt20pHandlerBundle(
4241
bool createTx, bool createRx,
4342
std::function<FrameTestStrategy*(St20pHandler*)> strategyFactory,
44-
std::function<void(St20pHandler*)> configure = nullptr,
45-
std::shared_ptr<StrategySharedState> sharedState = nullptr);
43+
std::function<void(St20pHandler*)> configure = nullptr);
4644
St20pHandlerBundle registerSt20pResources(std::unique_ptr<St20pHandler> handler,
4745
std::unique_ptr<FrameTestStrategy> strategy);
4846
void initSt20pDefaultContext();
4947
bool waitForSession(Session& session,
5048
std::chrono::milliseconds timeout =
5149
std::chrono::milliseconds(SessionStartTimeoutMs));
52-
bool startRxThenTx(St20pHandlerBundle& rxBundle, St20pHandlerBundle& txBundle,
53-
std::chrono::milliseconds warmup =
54-
std::chrono::milliseconds(SessionStartTimeoutMs));
55-
void stopTxThenRx(
56-
St20pHandlerBundle& txBundle, St20pHandlerBundle& rxBundle,
57-
std::chrono::milliseconds rxDelay = std::chrono::milliseconds(TxRxDelayMs));
5850

5951
std::vector<std::unique_ptr<St30pHandler>> st30pHandlers;
6052
std::vector<std::unique_ptr<St20pHandler>> st20pHandlers;
61-
std::vector<std::unique_ptr<FrameTestStrategy>> frameTestStrategys;
53+
std::vector<std::unique_ptr<FrameTestStrategy>> frameTestStrategies;
6254
};

0 commit comments

Comments
 (0)