Changing tests to run properly on RUNNER_MULTIPROCESS_TEST macro.
[platform/core/test/security-tests.git] / tests / common / tests_common.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        tests_common.h
19  * @author      Lukasz Kostyra (l.kostyra@partner.samsung.com)
20  * @version     1.0
21  * @brief       Common functions and macros used in security-tests package.
22  */
23
24 #ifndef _TESTS_COMMON_H_
25 #define _TESTS_COMMON_H_
26
27 #include <sys/smack.h>
28 #include <dpl/test/test_runner.h>
29 #include <dpl/test/test_runner_child.h>
30 #include <dpl/test/test_runner_multiprocess.h>
31
32 int smack_runtime_check(void);
33 int smack_check(void);
34
35 #define RUNNER_TEST_SMACK(Proc)                                                     \
36     void Proc();                                                                    \
37     static int Static##Proc##Init()                                                 \
38     {                                                                               \
39         if(smack_check())                                                           \
40             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);  \
41                                                                                     \
42         return 0;                                                                   \
43     }                                                                               \
44     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();              \
45     void Proc()
46
47 #define RUNNER_TEST_NOSMACK(Proc)                                                   \
48     void Proc();                                                                    \
49     static int Static##Proc##Init()                                                 \
50     {                                                                               \
51         if(!(smack_check()))                                                        \
52             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);  \
53                                                                                     \
54         return 0;                                                                   \
55     }                                                                               \
56     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();              \
57     void Proc()
58
59 #define RUNNER_CHILD_TEST_SMACK(Proc)                                                \
60     void Proc();                                                                     \
61     void Proc##Child();                                                              \
62     static int Static##Proc##Init()                                                  \
63     {                                                                                \
64         if(smack_check())                                                            \
65             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);   \
66         return 0;                                                                    \
67     }                                                                                \
68     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();               \
69     void Proc(){                                                                     \
70             DPL::Test::RunChildProc(&Proc##Child);                                   \
71     }                                                                                \
72     void Proc##Child()
73
74 #define RUNNER_CHILD_TEST_NOSMACK(Proc)                                              \
75     void Proc();                                                                     \
76     void Proc##Child();                                                              \
77     static int Static##Proc##Init()                                                  \
78     {                                                                                \
79         if(!(smack_check()))                                                         \
80             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);   \
81         return 0;                                                                    \
82     }                                                                                \
83     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();               \
84     void Proc(){                                                                     \
85             DPL::Test::RunChildProc(&Proc##Child);                                   \
86     }                                                                                \
87     void Proc##Child()
88
89 #define RUNNER_MULTIPROCESS_TEST_SMACK(Proc)                                         \
90     void Proc();                                                                     \
91     void Proc##Multi();                                                              \
92     static int Static##Proc##Init()                                                  \
93     {                                                                                \
94         if(smack_check())                                                            \
95             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);   \
96         return 0;                                                                    \
97     }                                                                                \
98     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();               \
99     void Proc(){                                                                     \
100             DPL::Test::RunMultiProc(&Proc##Multi);                                   \
101     }                                                                                \
102     void Proc##Multi()
103
104 #define RUNNER_MULTIPROCESS_TEST_NOSMACK(Proc)                                       \
105     void Proc();                                                                     \
106     void Proc##Multi();                                                              \
107     static int Static##Proc##Init()                                                  \
108     {                                                                                \
109         if(!(smack_check()))                                                         \
110             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);   \
111         return 0;                                                                    \
112     }                                                                                \
113     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();               \
114     void Proc(){                                                                     \
115             DPL::Test::RunMultiProc(&Proc##Multi);                                   \
116     }                                                                                \
117     void Proc##Multi()
118
119
120 #endif