summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2019-07-18 17:32:08 +0200
committerNat Goodspeed <nat@lindenlab.com>2020-03-25 18:44:04 -0400
commit9a3afe96063635de28ebb56b633ca4e75eea2180 (patch)
treebec11f6cef1acfa983f4b53187fe1f408ede8633 /indra/llcommon
parent3810145c1d8e21fc0819d71bbc42dcecced1f7e4 (diff)
DRTVWR-476: Add basic tests for LLCond.
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/CMakeLists.txt2
-rw-r--r--indra/llcommon/tests/llcond_test.cpp67
2 files changed, 69 insertions, 0 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 2f263cd830..d237985b04 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -145,6 +145,7 @@ set(llcommon_HEADER_FILES
llcleanup.h
llcommon.h
llcommonutils.h
+ llcond.h
llcoros.h
llcrc.h
llcriticaldamp.h
@@ -327,6 +328,7 @@ if (LL_TESTS)
LL_ADD_INTEGRATION_TEST(commonmisc "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(bitpack "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llbase64 "" "${test_libs}")
+ LL_ADD_INTEGRATION_TEST(llcond "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lldate "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lldeadmantimer "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(lldependencies "" "${test_libs}")
diff --git a/indra/llcommon/tests/llcond_test.cpp b/indra/llcommon/tests/llcond_test.cpp
new file mode 100644
index 0000000000..478149eacf
--- /dev/null
+++ b/indra/llcommon/tests/llcond_test.cpp
@@ -0,0 +1,67 @@
+/**
+ * @file llcond_test.cpp
+ * @author Nat Goodspeed
+ * @date 2019-07-18
+ * @brief Test for llcond.
+ *
+ * $LicenseInfo:firstyear=2019&license=viewerlgpl$
+ * Copyright (c) 2019, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+// Precompiled header
+#include "linden_common.h"
+// associated header
+#include "llcond.h"
+// STL headers
+// std headers
+// external library headers
+// other Linden headers
+#include "../test/lltut.h"
+#include "llcoros.h"
+
+/*****************************************************************************
+* TUT
+*****************************************************************************/
+namespace tut
+{
+ struct llcond_data
+ {
+ LLScalarCond<int> cond{0};
+ };
+ typedef test_group<llcond_data> llcond_group;
+ typedef llcond_group::object object;
+ llcond_group llcondgrp("llcond");
+
+ template<> template<>
+ void object::test<1>()
+ {
+ set_test_name("Immediate gratification");
+ cond.set_one(1);
+ ensure("wait_for_equal() failed",
+ cond.wait_for_equal(F32Milliseconds(1), 1));
+ ensure("wait_for_unequal() should have failed",
+ ! cond.wait_for_unequal(F32Milliseconds(1), 1));
+ }
+
+ template<> template<>
+ void object::test<2>()
+ {
+ set_test_name("Simple two-coroutine test");
+ LLCoros::instance().launch(
+ "test<2>",
+ [this]()
+ {
+ // Lambda immediately entered -- control comes here first.
+ ensure_equals(cond.get(), 0);
+ cond.set_all(1);
+ cond.wait_equal(2);
+ ensure_equals(cond.get(), 2);
+ cond.set_all(3);
+ });
+ // Main coroutine is resumed only when the lambda waits.
+ ensure_equals(cond.get(), 1);
+ cond.set_all(2);
+ cond.wait_equal(3);
+ }
+} // namespace tut