aboutsummaryrefslogtreecommitdiffstats
path: root/fastos/src/tests/thread_sleep_test.cpp
blob: 209b7d3f8801e0ac09a79b7073611f310e7a83ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "tests.h"
#include "job.h"
#include "thread_test_base.hpp"

class Thread_Sleep_Test : public ThreadTestBase
{
   int Main () override;

   void CreateSingleThread ()
   {
      TestHeader("Create Single Thread Test");

      FastOS_ThreadPool *pool = new FastOS_ThreadPool(128*1024);

      if(Progress(pool != nullptr, "Allocating ThreadPool"))
      {
         bool rc = (nullptr != pool->NewThread(this, nullptr));
         Progress(rc, "Creating Thread");

         Progress(true, "Sleeping 3 seconds");
         std::this_thread::sleep_for(3s);
      }

      Progress(true, "Closing threadpool...");
      pool->Close();

      Progress(true, "Deleting threadpool...");
      delete(pool);
      PrintSeparator();
   }
};

int Thread_Sleep_Test::Main ()
{
   printf("grep for the string '%s' to detect failures.\n\n", failString);
   time_t before = time(0);

   CreateSingleThread();
   { time_t now = time(0); printf("[%ld seconds]\n", now-before); before = now; }

   printf("END OF TEST (%s)\n", _argv[0]);
   return allWasOk() ? 0 : 1;
}

int main (int argc, char **argv)
{
   Thread_Sleep_Test app;
   setvbuf(stdout, nullptr, _IOLBF, 8192);
   return app.Entry(argc, argv);
}