Kaydet (Commit) b122aae8 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Fix rtl_DoubleLocking::getValue_002 test

At least <https://ci.libreoffice.org//job/lo_tb_master_win/20394/> once failed
with

> Value in Thread #1 is 0
> Value in Thread #2 is 5
> C:/cygwin/home/tdf/lode/jenkins/workspace/lo_tb_master_win/sal/qa/rtl/doublelock/rtl_doublelocking.cxx:202:rtl_DoubleLocking::getValue::getValue_002
> assertion failed
> - Expression: nValueOK != 0
> - getValue() failed, wrong value expected.

and there is indeed no guarantee that either of the OGetThreads has already been
through its while loop by the time the main thread calls terminate().  So make
execution of the threads deterministic (and take out the sleeps that are no
longer necessary, and use the now-deterministic expected values in the result
checks).

Change-Id: I61726906f646ffae7a21b1e08b1d973a4e51265b
Reviewed-on: https://gerrit.libreoffice.org/66494
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst eb5f725c
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <sal/types.h> #include <sal/types.h>
#include <osl/thread.hxx> #include <osl/thread.hxx>
#include <osl/time.h>
#include <rtl/instance.hxx> #include <rtl/instance.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
...@@ -53,28 +52,6 @@ struct Gregorian : public rtl::StaticWithInit<OUString, Gregorian> { ...@@ -53,28 +52,6 @@ struct Gregorian : public rtl::StaticWithInit<OUString, Gregorian> {
}; };
} }
namespace ThreadHelper
{
// typedef enum {
// QUIET=1,
// VERBOSE
// } eSleepVerboseMode;
static void thread_sleep_tenth_sec(sal_Int32 _nTenthSec/*, eSleepVerboseMode nVerbose = VERBOSE*/)
{
// if (nVerbose == VERBOSE)
// {
// printf("wait %d tenth seconds. ", _nTenthSec );
// fflush(stdout);
// }
osl::Thread::wait(std::chrono::milliseconds(_nTenthSec * 100));
// if (nVerbose == VERBOSE)
// {
// printf("done\n");
// }
}
}
/** Simple thread for testing Thread-create. /** Simple thread for testing Thread-create.
* Just add 1 of value 0, and after running, result is 1. * Just add 1 of value 0, and after running, result is 1.
*/ */
...@@ -104,7 +81,7 @@ protected: ...@@ -104,7 +81,7 @@ protected:
*/ */
void SAL_CALL run() override void SAL_CALL run() override
{ {
while(schedule()) for (int i = 0; i != 5; ++i)
{ {
OUString aStr = Gregorian::get(); OUString aStr = Gregorian::get();
if (aStr == m_sConstStr) if (aStr == m_sConstStr)
...@@ -117,7 +94,6 @@ protected: ...@@ -117,7 +94,6 @@ protected:
osl::MutexGuard g(m_mutex); osl::MutexGuard g(m_mutex);
m_nFails++; m_nFails++;
} }
ThreadHelper::thread_sleep_tenth_sec(1);
} }
} }
...@@ -171,11 +147,6 @@ namespace rtl_DoubleLocking ...@@ -171,11 +147,6 @@ namespace rtl_DoubleLocking
pThread->create(); pThread->create();
p2Thread->create(); p2Thread->create();
ThreadHelper::thread_sleep_tenth_sec(5);
pThread->terminate();
p2Thread->terminate();
pThread->join(); pThread->join();
p2Thread->join(); p2Thread->join();
...@@ -196,10 +167,8 @@ namespace rtl_DoubleLocking ...@@ -196,10 +167,8 @@ namespace rtl_DoubleLocking
delete pThread; delete pThread;
delete p2Thread; delete p2Thread;
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nValueOK);
"getValue() failed, wrong value expected.", CPPUNIT_ASSERT_EQUAL(sal_Int32(5), nValueOK2);
nValueOK != 0
);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nValueFails); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nValueFails);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nValueFails2); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nValueFails2);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment