summaryrefslogtreecommitdiffstats
path: root/fastos/src/tests/usecputest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fastos/src/tests/usecputest.cpp')
-rw-r--r--fastos/src/tests/usecputest.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/fastos/src/tests/usecputest.cpp b/fastos/src/tests/usecputest.cpp
new file mode 100644
index 00000000000..3ddc46aaa7e
--- /dev/null
+++ b/fastos/src/tests/usecputest.cpp
@@ -0,0 +1,68 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include "tests.h"
+
+class ThreadRunJob;
+void UseSomeCpu(int i, ThreadRunJob *threadRunJob);
+
+class ThreadRunJob : public FastOS_Runnable
+{
+public:
+ int64_t UseSomeCpu2(int64_t someNumber)
+ {
+ return someNumber + (someNumber/2 + someNumber*4) +
+ someNumber * someNumber * someNumber;
+ }
+
+ void Run (FastOS_ThreadInterface *thisThread, void *arg)
+ {
+ (void)thisThread;
+ (void)arg;
+
+ FastOS_Time before, current;
+ before.SetNow();
+
+ for(int i=0; i<200000; i++)
+ {
+ if((i % 200) == 0)
+ {
+ current.SetNow();
+ current -= before;
+ if(current.MilliSecs() > 3000)
+ break;
+ }
+ UseSomeCpu(i, this);
+ }
+ delete (this);
+ }
+};
+
+class UseCpuTest : public BaseTest
+{
+public:
+ int Main ()
+ {
+ FastOS_ThreadPool pool(128*1024);
+ pool.NewThread(new ThreadRunJob());
+ pool.NewThread(new ThreadRunJob());
+ pool.NewThread(new ThreadRunJob());
+ pool.NewThread(new ThreadRunJob());
+ pool.Close();
+ return 0;
+ }
+};
+
+void UseSomeCpu (int i, ThreadRunJob *threadRunJob)
+{
+ int64_t lastVal = i;
+ for(int e=0; e<100; e++)
+ lastVal = threadRunJob->UseSomeCpu2(lastVal);
+}
+
+int main (int argc, char **argv)
+{
+ UseCpuTest app;
+ setvbuf(stdout, NULL, _IOLBF, 8192);
+ return app.Entry(argc, argv);
+}
+