• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "DACFileSystemTest.h"
16 #include <unistd.h>
17 #include "ActsCapabilityTest.h"
18 #include "ActsDacTest.h"
19 
20 using namespace testing::ext;
21 
22 // Preset action of the test suite, which is executed before the first test case
SetUp()23 void DacTestSuite::SetUp()
24 {
25     // Permission mask preset when creating a file
26     umask(ZERO);
27     // Init capabilities
28     CapInit();
29     // Initialize the process and set the uid and gid of the process to zero
30     SetUidGid(UID0, GID0);
31     // Delete the the directory if exists
32     RemoveDir(TOP_DIR "/" DACDIR0);
33     RemoveDir(TOP_DIR "/" DACDIR1);
34     RemoveDir("/storage/" DACDIR0);
35     // Obtain the current working directory of the test code
36     mCurPath = GetCurrentPath();
37     // Modify the current working directory of the test code
38     int ret = chdir(TOP_DIR);
39     if (ret != 0) {
40         LOG("ErrInfo: Failed to chdir to %s, ret=%d, errno=%d", TOP_DIR, ret, errno);
41     }
42 }
43 
44 // Test suite cleanup action, which is executed after the last test case
TearDown()45 void DacTestSuite::TearDown()
46 {
47     // Delete the the directory if exists
48     RemoveDir(TOP_DIR "/" DACDIR0);
49     RemoveDir(TOP_DIR "/" DACDIR1);
50     RemoveDir("/storage/" DACDIR0);
51     // Initialize the process and set the uid and gid of the process to zero
52     SetUidGid(UID0, GID0);
53     // Restore the working directory of the test code
54     int ret = chdir(mCurPath);
55     if (ret != 0) {
56         LOG("ErrInfo: Failed to chdir to %s, ret=%d, errno=%d", mCurPath, ret, errno);
57     }
58 }
59 
main(int argc,char * argv[])60 int main(int argc, char *argv[])
61 {
62     testing::GTEST_FLAG(output) = "xml:";
63     testing::InitGoogleTest(&argc, argv);
64     if (CheckFsMount(TOP_DIR, TOP_DIR_MOUNT_INFO) != 0) {
65         return 1;
66     }
67     return RUN_ALL_TESTS();
68 }