• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
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 #include "scoped_flock.h"
18 
19 #include "common_runtime_test.h"
20 
21 namespace art {
22 
23 class ScopedFlockTest : public CommonRuntimeTest {};
24 
TEST_F(ScopedFlockTest,TestLocking)25 TEST_F(ScopedFlockTest, TestLocking) {
26   ScratchFile scratch_file;
27   std::string error_msg;
28 
29   // NOTE: Locks applied using flock(2) and fcntl(2) are oblivious
30   // to each other, so attempting to query locks set by flock using
31   // using fcntl(,F_GETLK,) will not work. see kernel doc at
32   // Documentation/filesystems/locks.txt.
33   ScopedFlock file_lock;
34   ASSERT_TRUE(file_lock.Init(scratch_file.GetFilename().c_str(),
35                              &error_msg));
36 
37   ASSERT_FALSE(file_lock.Init("/guaranteed/not/to/exist", &error_msg));
38 }
39 
40 }  // namespace art
41