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>
32 #include <sys/smack.h>
37 const uid_t APP_UID = 5000;
38 const gid_t APP_GID = 5000;
39 const uid_t DB_ALARM_UID = 6001;
40 const gid_t DB_ALARM_GID = 6001;
42 int smack_runtime_check(void);
43 int smack_check(void);
44 int drop_root_privileges(uid_t appUid = APP_UID, gid_t appGid = APP_GID);
45 void setLabelForSelf(const int line, const char *label);
46 void add_process_group(const char* group_name);
47 void remove_process_group(const char* group_name);
48 std::string formatCstr(const char *cstr);
50 #define RUNNER_TEST_SMACK(Proc) \
52 static int Static##Proc##Init() \
55 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
59 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
62 #define RUNNER_TEST_NOSMACK(Proc) \
64 static int Static##Proc##Init() \
66 if(!(smack_check())) \
67 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
71 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
74 #define RUNNER_CHILD_TEST_SMACK(Proc) \
77 static int Static##Proc##Init() \
80 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
83 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
85 DPL::Test::RunChildProc(&Proc##Child); \
89 #define RUNNER_CHILD_TEST_NOSMACK(Proc) \
92 static int Static##Proc##Init() \
94 if(!(smack_check())) \
95 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
98 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
100 DPL::Test::RunChildProc(&Proc##Child); \
104 #define RUNNER_MULTIPROCESS_TEST_SMACK(Proc) \
106 void Proc##Multi(); \
107 static int Static##Proc##Init() \
110 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
113 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
115 DPL::Test::RunMultiProc(&Proc##Multi); \
119 #define RUNNER_MULTIPROCESS_TEST_NOSMACK(Proc) \
121 void Proc##Multi(); \
122 static int Static##Proc##Init() \
124 if(!(smack_check())) \
125 DPL::Test::TestRunnerSingleton::Instance().RegisterTest(#Proc, &Proc); \
128 const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \
130 DPL::Test::RunMultiProc(&Proc##Multi); \
140 static int db_result;
143 db_result = perm_begin();
144 RUNNER_ASSERT_MSG(PC_OPERATION_SUCCESS == db_result,
145 "perm_begin returned: " << db_result);
149 db_result = perm_end();
154 // Database Transaction macros
155 // PLEASE NOTE Both DB_BEGIN and DB_END need to be called in the same scope.
156 // They are used to prevent developer from forgetting to close transaction.
157 // Also note that variables defined between these macros will not be visible
161 DB::Transaction db_transaction;
164 RUNNER_ASSERT_MSG(PC_OPERATION_SUCCESS == DB::Transaction::db_result, \
165 "perm_end returned: " << DB::Transaction::db_result);
167 // Common macros and labels used in tests
168 extern const char *WGT_APP_ID;