[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-harness.h
1 #ifndef TEST_HARNESS_H
2 #define TEST_HARNESS_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <testcase.h>
22
23 #include <chrono>
24 #include <cstdint>
25
26 namespace TestHarness
27 {
28 enum ExitStatus
29 {
30   EXIT_STATUS_TESTCASE_SUCCEEDED, // 0
31   EXIT_STATUS_TESTCASE_FAILED,    // 1
32   EXIT_STATUS_TESTCASE_ABORTED,   // 2
33   EXIT_STATUS_FORK_FAILED,        // 3
34   EXIT_STATUS_WAITPID_FAILED,     // 4
35   EXIT_STATUS_BAD_ARGUMENT,       // 5
36   EXIT_STATUS_TESTCASE_NOT_FOUND  // 6
37 };
38
39 const int32_t MAX_NUM_CHILDREN(16);
40
41 struct TestCase
42 {
43   int32_t                               testCase;
44   const char*                           name;
45   std::chrono::steady_clock::time_point startTime;
46   std::chrono::system_clock::time_point startSystemTime;
47   int32_t                               result{0};
48   pid_t                                 childPid{0};
49   testcase*                             tctPtr;
50   bool                                  finished{false};
51
52   TestCase(int32_t index, testcase* testCase)
53   : testCase(index),
54     name(testCase->name),
55     startTime(),
56     startSystemTime(),
57     result(0),
58     childPid(0),
59     tctPtr(testCase)
60   {
61   }
62   TestCase()
63   : testCase(0),
64     name(NULL),
65     startTime(),
66     startSystemTime(),
67     result(0),
68     childPid(0),
69     tctPtr(nullptr)
70   {
71   }
72
73   TestCase(int32_t tc, const char* name)
74   : testCase(tc),
75     name(name),
76     startTime(),
77     startSystemTime(),
78     result(0),
79     childPid(0),
80     tctPtr(nullptr)
81   {
82   }
83   TestCase(const TestCase& rhs)
84   : testCase(rhs.testCase),
85     name(rhs.name),
86     startTime(rhs.startTime),
87     startSystemTime(rhs.startSystemTime),
88     result(rhs.result),
89     childPid(rhs.childPid),
90     tctPtr(rhs.tctPtr)
91   {
92   }
93   TestCase& operator=(const TestCase& rhs)
94   {
95     testCase        = rhs.testCase;
96     name            = rhs.name;
97     startTime       = rhs.startTime;
98     startSystemTime = rhs.startSystemTime;
99     result          = rhs.result;
100     childPid        = rhs.childPid;
101     tctPtr          = rhs.tctPtr;
102     return *this;
103   }
104 };
105
106 /**
107  * Run a test case
108  * @param[in] testCase The Testkit-lite test case to run
109  */
110 int32_t RunTestCase(struct testcase_s& testCase);
111
112 /**
113  * Run all test cases in parallel
114  * @param[in] processName The name of this process
115  * @param[in] tc_array The array of auto-generated testkit-lite test cases
116  * @param[in] reRunFailed True if failed test cases should be re-run
117  * @return 0 on success
118  */
119 int32_t RunAllInParallel(const char* processName, testcase tc_array[], bool reRunFailed);
120
121 /**
122  * Run all test cases in serial
123  * @param[in] processName The name of this process
124  * @param[in] tc_array The array of auto-generated testkit-lite test cases
125  * @return 0 on success
126  */
127 int32_t RunAll(const char* processName, testcase tc_array[]);
128
129 /**
130  * Find the named test case in the given array, and run it
131  * @param[in] tc_array The array of auto-generated testkit-lite test cases
132  * @param[in] testCaseName the name of the test case to run
133  * @return 0 on success
134  */
135 int32_t FindAndRunTestCase(::testcase tc_array[], const char* testCaseName);
136
137 /**
138  * Display usage instructions for this program
139  * @param[in] program The name of this program
140  */
141 void Usage(const char* program);
142
143 /**
144  * Main function.
145  * @param[in] argc Argument count
146  * @param[in] argv Argument vector
147  * @param[in] tc_array Array of test cases
148  */
149 int RunTests(int argc, char* const argv[], ::testcase tc_array[]);
150
151 } // namespace TestHarness
152
153 #endif