2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file tests_common.h
19 * @author Lukasz Kostyra (l.kostyra@partner.samsung.com)
21 * @brief Common functions and macros used in security-tests package.
24 #ifndef _TESTS_COMMON_H_
25 #define _TESTS_COMMON_H_
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 #include <privilege-control.h>
33 int smack_runtime_check(void);
34 int smack_check(void);
35 int drop_root_privileges(void);
37 const uid_t APP_UID = 5000;
38 const gid_t APP_GID = 5000;
40 const uid_t DB_ALARM_UID = 6001;
41 const gid_t DB_ALARM_GID = 6001;
43 #define RUNNER_TEST_SMACK(Proc) \
45 static int Static##Proc##Init() \
48 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
52 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
55 #define RUNNER_TEST_NOSMACK(Proc) \
57 static int Static##Proc##Init() \
59 if(!(smack_check())) \
60 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
64 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
67 #define RUNNER_CHILD_TEST_SMACK(Proc) \
70 static int Static##Proc##Init() \
73 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
76 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
78 DPL::Test::RunChildProc(&Proc##Child); \
82 #define RUNNER_CHILD_TEST_NOSMACK(Proc) \
85 static int Static##Proc##Init() \
87 if(!(smack_check())) \
88 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
91 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
93 DPL::Test::RunChildProc(&Proc##Child); \
97 #define RUNNER_MULTIPROCESS_TEST_SMACK(Proc) \
100 static int Static##Proc##Init() \
103 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
106 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
108 DPL::Test::RunMultiProc(&Proc##Multi); \
112 #define RUNNER_MULTIPROCESS_TEST_NOSMACK(Proc) \
114 void Proc##Multi(); \
115 static int Static##Proc##Init() \
117 if(!(smack_check())) \
118 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
121 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
123 DPL::Test::RunMultiProc(&Proc##Multi); \
133 static int db_result;
136 db_result = perm_begin();
137 RUNNER_ASSERT_MSG(PC_OPERATION_SUCCESS == db_result,
138 "perm_begin returned: " << db_result);
142 db_result = perm_end();
147 // Database Transaction macros
148 // PLEASE NOTE Both DB_BEGIN and DB_END need to be called in the same scope.
149 // They are used to prevent developer from forgetting to close transaction.
150 // Also note that variables defined between these macros will not be visible
154 DB::Transaction db_transaction;
157 RUNNER_ASSERT_MSG(PC_OPERATION_SUCCESS == DB::Transaction::db_result, \
158 "perm_end returned: " << DB::Transaction::db_result);
161 typedef std::unique_ptr<smack_accesses,std::function<void (smack_accesses*)> > SmackUniquePtr;
163 // Common macros and labels used in tests
164 extern const char *WGT_APP_ID;