summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2023-10-02 13:09:02 -0400
committerNat Goodspeed <nat@lindenlab.com>2023-10-02 13:09:02 -0400
commitbd20c548dd02778a2c7a6c318e2b8df6b2fc36c3 (patch)
tree22f7be2715442845e917b74e7f8d30fc3a3dcb20
parentde61551df3219dae2238591bae5fa7b6c857e6b0 (diff)
DRTVWR-589: Add initial integration test for LLLUAmanager.
The first test runs a Lua script that calls post_on(), listen_events() and await_event() to engage in LLEventPump handshakes with the test program. Make llluamanager.cpp testable by putting LL_TEST conditionals around lots of viewer-internals headers and the lua_function definitions that engage them. Since LuaListener::connect() is called by its constructor, make it a static method that explicitly accepts the lua_State* (instead of finding it as mState). Add that parameter to its two existing calls. Add a debug log message when LuaListener is destroyed. This surfaced the need to pass a no-op deleter when listen_events() constructs a LuaListener::ptr_t. When compiled for LL_TEST, make LuaListener::mReplyPump an LLEventLogProxyFor<LLEventStream> instead of a plain LLEventStream. For debugging purposes, add a type string "LLEventLogProxy" for LLEventPumps::make(). A make() call with this type will return an LLEventLogProxyFor<LLEventStream>.
-rw-r--r--indra/llcommon/llevents.cpp9
-rw-r--r--indra/newview/CMakeLists.txt5
-rw-r--r--indra/newview/llluamanager.cpp63
-rw-r--r--indra/newview/llluamanager.h3
-rw-r--r--indra/newview/tests/llluamanager_test.cpp101
5 files changed, 158 insertions, 23 deletions
diff --git a/indra/llcommon/llevents.cpp b/indra/llcommon/llevents.cpp
index 0a213bddef..241b8cf463 100644
--- a/indra/llcommon/llevents.cpp
+++ b/indra/llcommon/llevents.cpp
@@ -54,10 +54,11 @@
#pragma warning (pop)
#endif
// other Linden headers
-#include "stringize.h"
#include "llerror.h"
-#include "llsdutil.h"
+#include "lleventfilter.h"
#include "llexception.h"
+#include "llsdutil.h"
+#include "stringize.h"
#if LL_MSVC
#pragma warning (disable : 4702)
#endif
@@ -71,7 +72,9 @@ LLEventPumps::LLEventPumps():
{ "LLEventStream", [](const std::string& name, bool tweak)
{ return new LLEventStream(name, tweak); } },
{ "LLEventMailDrop", [](const std::string& name, bool tweak)
- { return new LLEventMailDrop(name, tweak); } }
+ { return new LLEventMailDrop(name, tweak); } },
+ { "LLEventLogProxy", [](const std::string& name, bool tweak)
+ { return new LLEventLogProxyFor<LLEventStream>(name, tweak); } }
},
mTypes
{
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index ca0b7692c4..22ee2fd295 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -2291,6 +2291,11 @@ if (LL_TESTS)
"${test_libs}"
)
+ LL_ADD_INTEGRATION_TEST(llluamanager
+ "llluamanager.cpp"
+ "${test_libs}"
+ )
+
LL_ADD_INTEGRATION_TEST(llsechandler_basic
llsechandler_basic.cpp
"${test_libs}"
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index 2cc809ff0f..2244fa32f6 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -28,19 +28,24 @@
#include "llviewerprecompiledheaders.h"
#include "llluamanager.h"
-#include "llagent.h"
-#include "llappearancemgr.h"
-#include "llcallbacklist.h"
#include "llerror.h"
#include "lleventcoro.h"
+#include "lleventfilter.h"
#include "llevents.h"
+#include "llinstancetracker.h"
+#include "llleaplistener.h"
+#include "lluuid.h"
+#include "stringize.h"
+
+// skip all these link dependencies for integration testing
+#ifndef LL_TEST
+#include "llagent.h"
+#include "llappearancemgr.h"
+#include "llcallbacklist.h"
#include "llfloaterreg.h"
#include "llfloaterimnearbychat.h"
#include "llfloatersidepanelcontainer.h"
-#include "llinstancetracker.h"
-#include "llleaplistener.h"
#include "llnotificationsutil.h"
-#include "lluuid.h"
#include "llvoavatarself.h"
#include "llviewermenu.h"
#include "llviewermenufile.h"
@@ -48,10 +53,14 @@
#include "lluilistener.h"
#include "llanimationstates.h"
#include "llinventoryfunctions.h"
-#include "stringize.h"
#include "lltoolplacer.h"
#include "llviewerregion.h"
+// FIXME extremely hacky way to get to the UI Listener framework. There's
+// a cleaner way.
+extern LLUIListener sUIListener;
+#endif // ! LL_TEST
+
#include <boost/algorithm/string/replace.hpp>
extern "C"
@@ -79,9 +88,6 @@ void lua_pushstdstring(lua_State* L, const std::string& str);
LLSD lua_tollsd(lua_State* L, int index);
void lua_pushllsd(lua_State* L, const LLSD& data);
-// FIXME extremely hacky way to get to the UI Listener framework. There's almost certainly a cleaner way.
-extern LLUIListener sUIListener;
-
/**
* LuaListener is based on LLLeap. It serves an analogous function.
*
@@ -109,13 +115,20 @@ public:
LuaListener(lua_State* L):
super(getUniqueKey()),
mState(L),
- mReplyPump(LLUUID::generateNewID().asString()),
mListener(
new LLLeapListener(
- [this](LLEventPump& pump, const std::string& listener)
- { return connect(pump, listener); }))
+ [L](LLEventPump& pump, const std::string& listener)
+ { return connect(L, pump, listener); }))
+ {
+ mReplyConnection = connect(L, mReplyPump, "LuaListener");
+ }
+
+ LuaListener(const LuaListener&) = delete;
+ LuaListener& operator=(const LuaListener&) = delete;
+
+ ~LuaListener()
{
- mReplyConnection = connect(mReplyPump, "LuaListener");
+ LL_DEBUGS("Lua") << "~LuaListener('" << mReplyPump.getName() << "')" << LL_ENDL;
}
std::string getReplyName() const { return mReplyPump.getName(); }
@@ -137,12 +150,12 @@ private:
return key;
}
- LLBoundListener connect(LLEventPump& pump, const std::string& listener)
+ static LLBoundListener connect(lua_State* L, LLEventPump& pump, const std::string& listener)
{
return pump.listen(
listener,
- [mState=mState, pumpname=pump.getName()](const LLSD& data)
- { return call_lua(mState, pumpname, data); });
+ [L, pumpname=pump.getName()](const LLSD& data)
+ { return call_lua(L, pumpname, data); });
}
static bool call_lua(lua_State* L, const std::string& pump, const LLSD& data)
@@ -181,7 +194,11 @@ private:
}
lua_State* mState;
- LLEventStream mReplyPump;
+#ifndef LL_TEST
+ LLEventStream mReplyPump{ LLUUID::generateNewID().asString() };
+#else
+ LLEventLogProxyFor<LLEventStream> mReplyPump{ "luapump", false };
+#endif
LLTempBoundListener mReplyConnection;
std::unique_ptr<LLLeapListener> mListener;
};
@@ -340,6 +357,7 @@ lua_function(print_warning)
return 0;
}
+#ifndef LL_TEST
lua_function(avatar_sit)
{
gAgent.sitDown();
@@ -759,6 +777,7 @@ lua_function(run_ui_command)
lua_settop(L, 0);
return 0;
}
+#endif // ! LL_TEST
lua_function(post_on)
{
@@ -812,8 +831,10 @@ lua_function(listen_events)
{
// pop the nil "event.listener" key
lua_pop(mainthread, 1);
- // instantiate a new LuaListener, binding the mainthread state
- listener.reset(new LuaListener(mainthread));
+ // instantiate a new LuaListener, binding the mainthread state -- but
+ // use a no-op deleter: we do NOT want to delete this new LuaListener
+ // on return from listen_events()!
+ listener.reset(new LuaListener(mainthread), [](LuaListener*){});
// set its key in the field where we'll look for it later
lua_pushinteger(mainthread, listener->getKey());
lua_setfield(mainthread, LUA_REGISTRYINDEX, "event.listener");
@@ -983,6 +1004,7 @@ void LLLUAmanager::runScriptLine(const std::string& cmd, script_finished_fn cb)
void LLLUAmanager::runScriptOnLogin()
{
+#ifndef LL_TEST
std::string filename = gSavedSettings.getString("AutorunLuaScriptName");
if (filename.empty())
{
@@ -998,6 +1020,7 @@ void LLLUAmanager::runScriptOnLogin()
}
runScriptFile(filename);
+#endif // ! LL_TEST
}
std::string lua_tostdstring(lua_State* L, int index)
diff --git a/indra/newview/llluamanager.h b/indra/newview/llluamanager.h
index 4581c33ff2..08d9876ce2 100644
--- a/indra/newview/llluamanager.h
+++ b/indra/newview/llluamanager.h
@@ -27,6 +27,9 @@
#ifndef LL_LLLUAMANAGER_H
#define LL_LLLUAMANAGER_H
+#include <functional>
+#include <string>
+
class LLLUAmanager
{
public:
diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp
new file mode 100644
index 0000000000..e5e06b095c
--- /dev/null
+++ b/indra/newview/tests/llluamanager_test.cpp
@@ -0,0 +1,101 @@
+/**
+ * @file llluamanager_test.cpp
+ * @author Nat Goodspeed
+ * @date 2023-09-28
+ * @brief Test for llluamanager.
+ *
+ * $LicenseInfo:firstyear=2023&license=viewerlgpl$
+ * Copyright (c) 2023, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+// Precompiled header
+//#include "llviewerprecompiledheaders.h"
+// associated header
+#include "../newview/llluamanager.h"
+// STL headers
+// std headers
+// external library headers
+// other Linden headers
+#include "../test/lltut.h"
+#include "llapp.h"
+#include "llevents.h"
+#include "lleventcoro.h"
+#include "stringize.h"
+#include "../llcommon/tests/StringVec.h"
+
+class LLTestApp : public LLApp
+{
+public:
+ bool init() override { return true; }
+ bool cleanup() override { return true; }
+ bool frame() override { return true; }
+};
+
+/*****************************************************************************
+* TUT
+*****************************************************************************/
+namespace tut
+{
+ struct llluamanager_data
+ {
+ // We need an LLApp instance because LLLUAmanager uses coroutines,
+ // which suspend, and when a coroutine suspends it checks LLApp state,
+ // and if it's not APP_STATUS_RUNNING the coroutine terminates.
+ LLTestApp mApp;
+ };
+ typedef test_group<llluamanager_data> llluamanager_group;
+ typedef llluamanager_group::object object;
+ llluamanager_group llluamanagergrp("llluamanager");
+
+ template<> template<>
+ void object::test<1>()
+ {
+ set_test_name("test post_on(), listen_events(), await_event()");
+ StringVec posts;
+ LLEventStream replypump("testpump");
+ LLTempBoundListener conn(
+ replypump.listen("test<1>",
+ [&posts](const LLSD& post)
+ {
+ posts.push_back(post.asString());
+ return false;
+ }));
+ const std::string lua(
+ "-- test post_on,listen_events,await_event\n"
+ "post_on('testpump', 'entry')\n"
+ "callback = function(pump, data)\n"
+ " -- just echo the data we received\n"
+ " post_on('testpump', data)\n"
+ "end\n"
+ "post_on('testpump', 'listen_events()')\n"
+ "replypump, cmdpump = listen_events(callback)\n"
+ "post_on('testpump', replypump)\n"
+ "post_on('testpump', 'await_event()')\n"
+ "await_event(replypump)\n"
+ "post_on('testpump', 'exit')\n"
+ );
+ LLLUAmanager::runScriptLine(lua);
+ StringVec expected{
+ "entry",
+ "listen_events()",
+ "",
+ "await_event()",
+ "message",
+ "exit"
+ };
+ for (int i = 0; i < 10 && posts.size() <= 2 && posts[2].empty(); ++i)
+ {
+ llcoro::suspend();
+ }
+ expected[2] = posts.at(2);
+ LL_DEBUGS() << "Found pumpname '" << expected[2] << "'" << LL_ENDL;
+ LLEventPump& luapump{ LLEventPumps::instance().obtain(expected[2]) };
+ LL_DEBUGS() << "Found pump '" << luapump.getName() << "', type '"
+ << LLError::Log::classname(luapump)
+ << "': post('" << expected[4] << "')" << LL_ENDL;
+ luapump.post(expected[4]);
+ llcoro::suspend();
+ ensure_equals("post_on() sequence", posts, expected);
+ }
+} // namespace tut