Skip to content

Commit 73d275b

Browse files
trupthi1403Truphti
authored andcommitted
RDKEMW-8844: Improve L1 coverage
Reason for change: Changes done to compile newly added test cases Test Procedure: Able to build and run test cases in CI Risks: low Priority: P2
1 parent b405110 commit 73d275b

File tree

8 files changed

+138
-67
lines changed

8 files changed

+138
-67
lines changed

.github/workflows/jsruntime_L1tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
uses: actions/checkout@v3
2727
with:
2828
repository: rdk-e/rdkNativeScript_tests
29-
ref: topic/RDKEMW-5610
29+
ref: topic/RDKEMW-8844
3030
path: rdkNativeScript_tests
3131
token: ${{ secrets.GH_PAT }}
3232

include/EssosInstance.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class EssosInstance
3838
void onKeyRelease(struct JavaScriptKeyDetails& details);
3939
void update();
4040
void registerKeyListener(JavaScriptKeyListener*);
41-
41+
4242
private:
4343
EssosInstance();
4444
static EssosInstance* mInstance;
45-
EssCtx * mEssosContext;
45+
EssCtx * mEssosContext;
4646
bool mUseWayland;
4747
JavaScriptKeyListener* mJavaScriptKeyListener;
4848
};

include/NativeJSRenderer.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <ModuleSettings.h>
3232
#include <condition_variable>
3333
#include <list>
34+
#include <thread>
3435

3536
namespace JsRuntime {
3637

@@ -125,7 +126,10 @@ namespace JsRuntime {
125126
bool terminate();
126127
void run();
127128
void setEnvForConsoleMode(ModuleSettings& moduleSettings);
128-
bool runApplication(uint32_t id, std::string url);
129+
static bool consoleLoop;
130+
std::atomic_bool mShutdownConsole{false};
131+
std::thread mConsoleThread;
132+
bool runApplication(uint32_t id, std::string url);
129133
bool runJavaScript(uint32_t id, std::string code);
130134
uint32_t createApplication(ModuleSettings& moduleSettings, std::string userAgent = DEFAULT_USER_AGENT) ;
131135
bool terminateApplication(uint32_t id);
@@ -134,18 +138,18 @@ namespace JsRuntime {
134138
std::string getBaseUserAgent();
135139
private:
136140
bool downloadFile(std::string& url, MemoryStruct& chunk);
137-
void processDevConsoleRequests();
141+
void processDevConsoleRequests();
138142
void runDeveloperConsole(ModuleSettings moduleSettings);
139-
void createApplicationInternal(ApplicationRequest& appRequest);
143+
void createApplicationInternal(ApplicationRequest& appRequest);
140144
void runApplicationInternal(ApplicationRequest& appRequest);
141145
void terminateApplicationInternal(ApplicationRequest& appRequest);
142146
void runJavaScriptInternal(ApplicationRequest& appRequest);
143147
uint32_t createApplicationIdentifier();
144148
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
145-
IJavaScriptEngine* mEngine;
149+
IJavaScriptEngine* mEngine;
146150
bool mRunning;
147151
std::string mTestFileName;
148-
std::unique_ptr<ConsoleState> mConsoleState;
152+
std::unique_ptr<ConsoleState> mConsoleState;
149153
bool mEnableTestFileDOMSupport;
150154
bool mEmbedThunderJS;
151155
bool mEmbedRdkWebBridge;

include/jsc/JavaScriptContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
8686

8787
void setCreateApplicationStartTime(double time);
8888
void setCreateApplicationEndTime(double time,uint32_t id);
89-
void setPlaybackStartTime(double time);
89+
virtual void setPlaybackStartTime(double time);
9090
void setAppdata(uint32_t id, const std::string& url);
9191
double getExecutionDuration() const;
9292

include/jsc/JavaScriptUtils.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define JAVASCRIPTMISC_H
2222

2323
#include <JavaScriptCore/JavaScript.h>
24+
#include "rtHttpRequest.h"
2425
#include "rtString.h"
2526
#include "rtAtomic.h"
2627
#include <rtError.h>
@@ -31,6 +32,10 @@
3132
#include <functional>
3233
#include <vector>
3334
#include <thread>
35+
#include <queue>
36+
#include <chrono>
37+
#include <cstdint>
38+
3439
namespace jsruntime
3540
{
3641
template<typename T>
@@ -51,6 +56,42 @@ class RefCounted: public T
5156
virtual ~RefCounted() {}
5257
};
5358
}
59+
60+
class rtHttpRequestEx : public rtHttpRequest
61+
{
62+
public:
63+
rtDeclareObject(rtHttpRequestEx, rtHttpRequest);
64+
rtHttpRequestEx(const rtString& url);
65+
rtHttpRequestEx(const rtObjectRef& options);
66+
void onDownloadProgressImpl(double progress) final;
67+
void onDownloadCompleteImpl(rtFileDownloadRequest* downloadRequest) final;
68+
};
69+
70+
struct TimeoutInfo
71+
{
72+
std::function<int ()> callback;
73+
std::chrono::time_point<std::chrono::steady_clock> fireTime;
74+
std::chrono::milliseconds interval;
75+
bool repeat;
76+
uint32_t tag;
77+
bool canceled;
78+
};
79+
80+
struct TimeoutInfoComparator
81+
{
82+
constexpr bool operator()(const TimeoutInfo *lhs, const TimeoutInfo *rhs) const {
83+
return !((lhs->fireTime < rhs->fireTime) ||
84+
((lhs->fireTime == rhs->fireTime) && (lhs->tag < rhs->tag)));
85+
}
86+
};
87+
88+
class TimeoutQueue : public std::priority_queue<TimeoutInfo*, std::vector<TimeoutInfo*>, TimeoutInfoComparator>
89+
{
90+
public:
91+
void pushTimeouts(const std::vector<TimeoutInfo*>& timerVec);
92+
bool updateForInfo(const TimeoutInfo* info);
93+
};
94+
5495
void dispatchOnMainLoop(std::function<void ()>&& fun);
5596
void dispatchPending();
5697
void dispatchTimeouts();
@@ -73,6 +114,7 @@ rtError rtSetVideoStartTimeBinding(int numArgs, const rtValue* args, rtValue* re
73114
rtError rtJSRuntimeDownloadMetrics(int numArgs, const rtValue* args, rtValue* result, void* context);
74115
rtError rtSetExternalAppHandlerBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
75116
rtError rtGetRandomValuesBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
117+
rtError rtInstallTimeout(int numArgs, const rtValue* args, rtValue* result, bool repeat);
76118
JSValueRef requireCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception);
77119

78120
#endif /* JAVASCRIPTMISC_H */

src/NativeJSRenderer.cpp

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,32 @@ NativeJSRenderer::NativeJSRenderer(std::string waylandDisplay): mEngine(nullptr)
179179

180180
NativeJSRenderer::~NativeJSRenderer()
181181
{
182-
gPendingRequests.clear();
183-
if (mEngine)
184-
{
185-
delete mEngine;
186-
mEngine = nullptr;
182+
mShutdownConsole = true;
183+
if (mConsoleThread.joinable()) {
184+
mConsoleThread.join();
187185
}
186+
gPendingRequests.clear();
187+
188188
if (mConsoleState && mConsoleState->consoleContext) {
189189
delete mConsoleState->consoleContext;
190+
mConsoleState->consoleContext = nullptr;
191+
}
192+
if (mEngine){
193+
delete mEngine;
194+
mEngine = nullptr;
190195
}
196+
191197
}
192198

193199
void NativeJSRenderer::setEnvForConsoleMode(ModuleSettings& moduleSettings)
194200
{
201+
202+
if (mConsoleThread.joinable()) {
203+
mShutdownConsole = true;
204+
mConsoleThread.join();
205+
}
206+
207+
mShutdownConsole = false;
195208
mConsoleState = std::make_unique<ConsoleState>();
196209
mConsoleState->moduleSettings = moduleSettings;
197210

@@ -205,8 +218,7 @@ void NativeJSRenderer::setEnvForConsoleMode(ModuleSettings& moduleSettings)
205218
mConsoleState->consoleContext = context;
206219

207220
NativeJSLogger::log(INFO, "Running developer console...\n");
208-
std::thread consoleThread(&JsRuntime::NativeJSRenderer::runDeveloperConsole, this, std::ref(mConsoleState->moduleSettings));
209-
consoleThread.detach();
221+
mConsoleThread = std::thread(&JsRuntime::NativeJSRenderer::runDeveloperConsole, this, std::ref(mConsoleState->moduleSettings));
210222

211223
mConsoleMode = true;
212224
}
@@ -542,12 +554,10 @@ void NativeJSRenderer::processDevConsoleRequests()
542554
mConsoleState->inputMutex.unlock();
543555
}
544556

545-
namespace {
546-
bool consoleLoop = true;
547-
void handleDevConsoleSigInt(int /*sig*/){
548-
consoleLoop = false;
549-
}
550-
} // namespace
557+
bool NativeJSRenderer::consoleLoop = true;
558+
void handleDevConsoleSigInt(int /*sig*/) {
559+
NativeJSRenderer::consoleLoop = false;
560+
}
551561

552562
void NativeJSRenderer::runDeveloperConsole(ModuleSettings moduleSettings)
553563
{
@@ -557,7 +567,17 @@ void NativeJSRenderer::runDeveloperConsole(ModuleSettings moduleSettings)
557567
NativeJSLogger::log(INFO, "Type 'exit' or press CTRL+C and ENTER to quit.\n");
558568

559569
signal(SIGINT, handleDevConsoleSigInt);
560-
while (consoleLoop) {
570+
571+
#ifdef UNIT_TEST_BUILD
572+
input = "exit";
573+
NativeJSLogger::log(INFO, "[UNIT_TEST_BUILD] Auto-exiting developer console");
574+
delete mConsoleState->consoleContext;
575+
mConsoleState->consoleContext = nullptr;
576+
signal(SIGINT, SIG_DFL);
577+
return;
578+
#else
579+
580+
while (consoleLoop && !mShutdownConsole) {
561581
// Don't display another input prompt until previous code is processed (prevents)
562582
{
563583
std::unique_lock<std::mutex> lk(mConsoleState->isProcessing_cv_m);
@@ -566,11 +586,14 @@ void NativeJSRenderer::runDeveloperConsole(ModuleSettings moduleSettings)
566586
mConsoleState->isProcessing = true;
567587
}
568588

589+
if (mShutdownConsole) break;
569590
std::getline(std::cin, input);
591+
if (mShutdownConsole) break;
570592

571593
// Short-cirtuit: in case consoleLoop was altered by signal handler we shouldn't execute lines below
572594
if (!consoleLoop || input == "exit") {
573595
delete mConsoleState->consoleContext;
596+
mConsoleState->consoleContext = nullptr;
574597
break;
575598
}
576599

src/jsc/JavaScriptUtils.cpp

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,25 @@ static std::list<std::function<void ()>> gPendingFun;
7070
static std::mutex gDispatchMutex;
7171
static const char* envValue = std::getenv("NATIVEJS_DUMP_NETWORKMETRIC");
7272

73-
struct TimeoutInfo
73+
void TimeoutQueue::pushTimeouts(const std::vector<TimeoutInfo*>& timerVec)
7474
{
75-
std::function<int ()> callback;
76-
std::chrono::time_point<std::chrono::steady_clock> fireTime;
77-
std::chrono::milliseconds interval;
78-
bool repeat;
79-
uint32_t tag;
80-
bool canceled;
81-
};
82-
83-
struct TimeoutInfoComparator
84-
{
85-
constexpr bool operator()(const TimeoutInfo *lhs, const TimeoutInfo *rhs) const {
86-
return !((lhs->fireTime < rhs->fireTime) ||
87-
((lhs->fireTime == rhs->fireTime) && (lhs->tag < rhs->tag)));
88-
}
89-
};
75+
if (!timerVec.size())
76+
return;
77+
this->c.reserve(this->c.size() + timerVec.size());
78+
this->c.insert(this->c.end(), timerVec.begin(), timerVec.end());
79+
std::make_heap(this->c.begin(), this->c.end(), this->comp);
80+
}
9081

91-
class TimeoutQueue : public std::priority_queue<TimeoutInfo*, std::vector<TimeoutInfo*>, TimeoutInfoComparator>
82+
bool TimeoutQueue::updateForInfo(const TimeoutInfo* info)
9283
{
93-
public:
94-
void pushTimeouts(const std::vector<TimeoutInfo*>& timerVec)
95-
{
96-
if (!timerVec.size())
97-
return;
98-
c.reserve(c.size() + timerVec.size());
99-
c.insert(c.end(),timerVec.begin(), timerVec.end());
100-
std::make_heap(c.begin(), c.end(), comp);
101-
}
102-
bool updateForInfo(const TimeoutInfo* info)
103-
{
104-
auto it = std::find(c.begin(), c.end(), info);
105-
if (it != c.end()) {
106-
std::make_heap(c.begin(), c.end(), comp);
107-
return true;
84+
auto it = std::find(this->c.begin(), this->c.end(), info);
85+
if (it != this->c.end()) {
86+
std::make_heap(this->c.begin(), this->c.end(), this->comp);
87+
return true;
10888
}
10989
return false;
110-
}
111-
};
90+
}
91+
11292
static std::map<uint32_t, TimeoutInfo*> gTimeoutMap;
11393
static uint32_t gTimeoutIdx = 0;
11494
static TimeoutQueue gTimeoutQueue;
@@ -179,22 +159,17 @@ void assertIsMainThread()
179159
assert(std::this_thread::get_id() == gMainThreadId);
180160
}
181161

182-
class rtHttpRequestEx : public rtHttpRequest
183-
{
184-
public:
185-
rtDeclareObject(rtHttpRequestEx, rtHttpRequest);
186-
187-
rtHttpRequestEx(const rtString& url)
162+
rtHttpRequestEx::rtHttpRequestEx(const rtString& url)
188163
: rtHttpRequest(url)
189164
{
190165
}
191166

192-
rtHttpRequestEx(const rtObjectRef& options)
167+
rtHttpRequestEx::rtHttpRequestEx(const rtObjectRef& options)
193168
: rtHttpRequest(options)
194169
{
195170
}
196171

197-
void onDownloadProgressImpl(double progress) final
172+
void rtHttpRequestEx::onDownloadProgressImpl(double progress)
198173
{
199174

200175
AddRef();
@@ -209,7 +184,7 @@ class rtHttpRequestEx : public rtHttpRequest
209184
});
210185
}
211186

212-
void onDownloadCompleteImpl(rtFileDownloadRequest* downloadRequest) final
187+
void rtHttpRequestEx::onDownloadCompleteImpl(rtFileDownloadRequest* downloadRequest)
213188
{
214189
AddRef();
215190
if (!downloadRequest->errorString().isEmpty()) {
@@ -275,7 +250,6 @@ class rtHttpRequestEx : public rtHttpRequest
275250
});
276251
}
277252
}
278-
};
279253

280254
rtDefineObject(rtHttpRequestEx, rtHttpRequest);
281255

src/linux/KeyInput.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ std::map<uint32_t, std::vector<std::string>> keyMappings = {
144144
{ WAYLAND_KEY_MUTE, { "AudioVolumeMute", "AudioVolumeMute", "AudioVolumeMute", "AudioVolumeMute" } },
145145
{ WAYLAND_KEY_VOLUME_DOWN, { "AudioVolumeDown", "AudioVolumeDown", "AudioVolumeDown", "AudioVolumeDown" } },
146146
{ WAYLAND_KEY_VOLUME_UP, { "AudioVolumeUp", "AudioVolumeUp", "AudioVolumeUp", "AudioVolumeUp" } }
147+
148+
#if defined(UNIT_TEST_BUILD)
149+
#ifdef WAYLAND_KEY_PLAYPAUSE
150+
, { WAYLAND_KEY_PLAYPAUSE, { "PlayPause", "PlayPause", "PlayPause", "PlayPause" } }
151+
#endif
152+
#ifdef WAYLAND_KEY_PLAY
153+
, { WAYLAND_KEY_PLAY, { "Play", "Play", "Play", "Play" } }
154+
#endif
155+
#ifdef WAYLAND_KEY_FASTFORWARD
156+
, { WAYLAND_KEY_FASTFORWARD, { "FastForward", "FastForward", "FastForward", "FastForward" } }
157+
#endif
158+
#ifdef WAYLAND_KEY_REWIND
159+
, { WAYLAND_KEY_REWIND, { "Rewind", "Rewind", "Rewind", "Rewind" } }
160+
#endif
161+
#ifdef WAYLAND_KEY_KPENTER
162+
, { WAYLAND_KEY_KPENTER, { "Enter", "Enter", "Enter", "Enter" } }
163+
#endif
164+
#ifdef WAYLAND_KEY_BACK
165+
, { WAYLAND_KEY_BACK, { "Back", "Back", "Back", "Back" } }
166+
#endif
167+
#ifdef WAYLAND_KEY_MENU
168+
, { WAYLAND_KEY_MENU, { "Menu", "Menu", "Menu", "Menu" } }
169+
#endif
170+
#ifdef WAYLAND_KEY_HOMEPAGE
171+
, { WAYLAND_KEY_HOMEPAGE, { "Homepage", "Homepage", "Homepage", "Homepage" } }
172+
#endif
173+
#endif // UNIT_TEST_BUILD
174+
147175
};
148176

149177
static void getJavaScriptKeyCode(uint32_t waylandKeyCode, std::string& keyCode, uint32_t& keyCodeValue)

0 commit comments

Comments
 (0)