Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Thread.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/threading/thread.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 #include <iostream>
24 #include <type_traits>
25
26 using Dali::Thread;
27
28 namespace
29 {
30 volatile bool gRunThreadEntryFunc = false;
31
32 class TestThread : public Thread
33 {
34   virtual void Run()
35   {
36     gRunThreadEntryFunc = true;
37   }
38 };
39 } // namespace
40
41 int UtcDaliThreadP(void)
42 {
43   tet_infoline("Testing Dali::Thread");
44
45   gRunThreadEntryFunc = false;
46
47   TestThread thread;
48
49   thread.Start();
50   // wait till the thread is terminated
51   while(!gRunThreadEntryFunc)
52   {
53     usleep(1); // 1 microsecond
54   }
55   DALI_TEST_EQUALS(true, gRunThreadEntryFunc, TEST_LOCATION);
56
57   thread.Join();
58
59   // Restart the thread after joined
60   gRunThreadEntryFunc = false;
61   thread.Start();
62   thread.Join();
63   // wait till the thread is terminated
64   while(!gRunThreadEntryFunc)
65   {
66     usleep(1); // 1 microsecond
67   }
68   DALI_TEST_EQUALS(true, gRunThreadEntryFunc, TEST_LOCATION);
69
70   END_TEST;
71 }
72
73 int UtcDaliThreadNonCopyable(void)
74 {
75   // we want to make sure that mutex is not copyable (its copy constructor is not defined)
76   // this test will stop compiling if Mutex has compiler generated copy constructor
77   static_assert(!__has_trivial_copy(Thread), "Thread should NOT be copyable");
78
79   DALI_TEST_CHECK(true);
80   END_TEST;
81 }