aboutsummaryrefslogtreecommitdiff
path: root/engines/testbed
diff options
context:
space:
mode:
authorNeeraj Kumar2010-06-28 12:58:14 +0000
committerNeeraj Kumar2010-06-28 12:58:14 +0000
commitef1ba0ea15435d178da7a834a487caf4ff8ef9e5 (patch)
tree1b0604022f1bf3a8359fe6700de6c8bc2d6c589c /engines/testbed
parentcf3d5c27742bf1591ea91b05eb18e600c6ce332c (diff)
downloadscummvm-rg350-ef1ba0ea15435d178da7a834a487caf4ff8ef9e5.tar.gz
scummvm-rg350-ef1ba0ea15435d178da7a834a487caf4ff8ef9e5.tar.bz2
scummvm-rg350-ef1ba0ea15435d178da7a834a487caf4ff8ef9e5.zip
added code to test timers and mutexes, some issues with mutexes present although
svn-id: r50444
Diffstat (limited to 'engines/testbed')
-rw-r--r--engines/testbed/misc.cpp45
-rw-r--r--engines/testbed/misc.h9
-rw-r--r--engines/testbed/testbed.cpp2
3 files changed, 51 insertions, 5 deletions
diff --git a/engines/testbed/misc.cpp b/engines/testbed/misc.cpp
index 9c722e41a3..11dd7c1510 100644
--- a/engines/testbed/misc.cpp
+++ b/engines/testbed/misc.cpp
@@ -23,6 +23,7 @@
*/
#include "testbed/misc.h"
+#include "common/timer.h"
namespace Testbed {
@@ -34,6 +35,25 @@ void MiscTests::getHumanReadableFormat(TimeDate &td, Common::String &date) {
return;
}
+void MiscTests::timerCallback(void *arg) {
+ // Increment arg which actually points to an int
+ // arg must point to a static data, threads otherwise have their own stack
+ int &ptrToNumTimesExecuted = *((int *) arg);
+ ptrToNumTimesExecuted++;
+ printf("LOG: Inside the timed process!\n");
+}
+
+void MiscTests::criticalSection(void *arg) {
+ SharedVars &sv = *((SharedVars *) arg);
+
+ printf("Before: %d %d\n", sv.first, sv.second);
+ sv.first++;
+ g_system->delayMillis(3000);
+ printf("After waking up: %d %d\n", sv.first, sv.second);
+ sv.second *= sv.first;
+ printf("Finally: %d %d\n", sv.first, sv.second);
+}
+
bool MiscTests::testDateTime() {
TimeDate t1, t2;
g_system->getTimeAndDate(t1);
@@ -70,16 +90,33 @@ bool MiscTests::testDateTime() {
}
bool MiscTests::testTimers() {
- return true;
+ static int numTimesExecuted = 0;
+ if (g_system->getTimerManager()->installTimerProc(timerCallback, 100000, &numTimesExecuted)) {
+ g_system->delayMillis(150);
+ printf("LOG: Timed Process Invoked %d times\n", numTimesExecuted);
+ g_system->getTimerManager()->removeTimerProc(timerCallback);
+
+ if (1 == numTimesExecuted) {
+ return true;
+ }
+ }
+ return false;
}
bool MiscTests::testMutexes() {
- return true;
+ static SharedVars sv = {1, 1, g_system->createMutex()};
+
+ if (g_system->getTimerManager()->installTimerProc(criticalSection, 100000, &sv)) {
+ g_system->delayMillis(150);
+ criticalSection(&sv);
+ g_system->getTimerManager()->removeTimerProc(criticalSection);
+ }
+ return false;
}
MiscTestSuite::MiscTestSuite() {
- addTest("Date/time", &MiscTests::testDateTime);
- addTest("Timers", &MiscTests::testTimers);
+ // addTest("Date/time", &MiscTests::testDateTime);
+ // addTest("Timers", &MiscTests::testTimers);
addTest("Mutexes", &MiscTests::testMutexes);
}
const char *MiscTestSuite::getName() const {
diff --git a/engines/testbed/misc.h b/engines/testbed/misc.h
index 7568ce34f3..596bbcae25 100644
--- a/engines/testbed/misc.h
+++ b/engines/testbed/misc.h
@@ -30,12 +30,21 @@
namespace Testbed {
+// Shared variables used in mutex handling test
+struct SharedVars {
+ int first;
+ int second;
+ OSystem::MutexRef mutex;
+};
+
namespace MiscTests {
// Miscellaneous tests include testing datetime, timers and mutexes
// Helper functions for Misc tests
void getHumanReadableFormat(TimeDate &td, Common::String &date);
+void timerCallback(void *arg);
+void criticalSection(void *arg);
// will contain function declarations for Misc tests
bool testDateTime();
diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp
index 47509ec9fb..5731483c66 100644
--- a/engines/testbed/testbed.cpp
+++ b/engines/testbed/testbed.cpp
@@ -88,7 +88,7 @@ Common::Error TestbedEngine::run() {
// To be set from config file
// By default Interactive tests are enabled
// XXX: disabling these as of now for fastly testing other tests
- // Testsuite::isInteractive = false;
+ Testsuite::isInteractive = false;
if (Testsuite::isInteractive) {
printf("Running Interactive tests as well\n");