1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "CapabilityFileSystemTest.h"
16 #include <unistd.h>
17 #include "ActsCapabilityTest.h"
18
19 using namespace testing::ext;
20
21 // Preset action of the test suite, which is executed before the first test case
SetUp()22 void CapabilityTestSuite::SetUp()
23 {
24 // Permission mask preset when creating a file
25 umask(ZERO);
26 // Init capabilities
27 CapInit();
28 // Initialize the process and set the uid and gid of the process to zero
29 SetUidGid(UID0, GID0);
30 // Delete the 'TOP_DIR/CAPDIR0' if the directory exists
31 RemoveDir(TOP_DIR "/" CAPDIR0);
32 // Obtain the current working directory of the test code
33 mCurPath = GetCurrentPath();
34 // Modify the current working directory of the test code
35 int ret = chdir(TOP_DIR);
36 if (ret != 0) {
37 LOG("ErrInfo: Failed to chdir to %s, ret=%d, errno=%d", TOP_DIR, ret, errno);
38 }
39 }
40
41 // Test suite cleanup action, which is executed after the last test case
TearDown()42 void CapabilityTestSuite::TearDown()
43 {
44 // Delete the 'TOP_DIR/CAPDIR0' if the directory exists
45 RemoveDir(TOP_DIR "/" CAPDIR0);
46 // Restore the working directory of the test code
47 int ret = chdir(mCurPath);
48 if (ret != 0) {
49 LOG("ErrInfo: Failed to chdir to %s, ret=%d, errno=%d", mCurPath, ret, errno);
50 }
51 }
52
main(int argc,char * argv[])53 int main(int argc, char *argv[])
54 {
55 testing::GTEST_FLAG(output) = "xml:";
56 testing::InitGoogleTest(&argc, argv);
57 if (CheckFsMount(TOP_DIR, TOP_DIR_MOUNT_INFO) != 0) {
58 return 1;
59 }
60 return RUN_ALL_TESTS();
61 }