summaryrefslogtreecommitdiffstats
path: root/fastos/src/tests/thread_sleep_test.cpp
blob: 4e84d9fef804c6ecb0a3a69949bc3570a0d6b978 (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
53
54
55
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <stdlib.h>

#include <vespa/fastos/fastos.h>
#include "tests.h"
#include "jobs.h"
#include "base_thread.hpp"

class Thread_Sleep_Test : public BaseForThreadTest
{
   int Main ();

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

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

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

         Progress(true, "Sleeping 3 seconds");
         FastOS_Thread::Sleep(3000);
      }

      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 0;
}

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