Add test case macros for different environments
[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
31 int smack_runtime_check(void);
32 int smack_check(void);
33
34 #define RUNNER_TEST_SMACK(Proc)                                                     \
35     void Proc();                                                                    \
36     static int Static##Proc##Init()                                                 \
37     {                                                                               \
38         if(smack_check())                                                           \
39             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);  \
40                                                                                     \
41         return 0;                                                                   \
42     }                                                                               \
43     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();              \
44     void Proc()
45
46 #define RUNNER_TEST_NOSMACK(Proc)                                                   \
47     void Proc();                                                                    \
48     static int Static##Proc##Init()                                                 \
49     {                                                                               \
50         if(!(smack_check()))                                                        \
51             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);  \
52                                                                                     \
53         return 0;                                                                   \
54     }                                                                               \
55     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();              \
56     void Proc()
57
58 #define RUNNER_CHILD_TEST_SMACK(Proc)                                                \
59     void Proc();                                                                     \
60     void Proc##Child();                                                              \
61     static int Static##Proc##Init()                                                  \
62     {                                                                                \
63         if(smack_check())                                                            \
64             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);   \
65         return 0;                                                                    \
66     }                                                                                \
67     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();               \
68     void Proc(){                                                                     \
69             DPL::Test::RunChildProc(&Proc##Child);                                   \
70     }                                                                                \
71     void Proc##Child()
72
73 #define RUNNER_CHILD_TEST_NOSMACK(Proc)                                              \
74     void Proc();                                                                     \
75     void Proc##Child();                                                              \
76     static int Static##Proc##Init()                                                  \
77     {                                                                                \
78         if(!(smack_check()))                                                         \
79             DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc);   \
80         return 0;                                                                    \
81     }                                                                                \
82     const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init();               \
83     void Proc(){                                                                     \
84             DPL::Test::RunChildProc(&Proc##Child);                                   \
85     }                                                                                \
86     void Proc##Child()
87
88 #endif