blob: 8fa181ab6b547f401e6eeb7e2aaa924cba0fe435 [file] [log] [blame]
Narayan Kamathd1c606f2014-06-09 16:50:19 +01001/*
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#include "common_runtime_test.h"
19
20#include "gtest/gtest.h"
21
22namespace art {
23
24class ScopedFlockTest : public CommonRuntimeTest {};
25
26TEST_F(ScopedFlockTest, TestLocking) {
27 ScratchFile scratch_file;
28 std::string error_msg;
29
30 // NOTE: Locks applied using flock(2) and fcntl(2) are oblivious
31 // to each other, so attempting to query locks set by flock using
32 // using fcntl(,F_GETLK,) will not work. see kernel doc at
33 // Documentation/filesystems/locks.txt.
34 ScopedFlock file_lock;
35 ASSERT_TRUE(file_lock.Init(scratch_file.GetFilename().c_str(),
36 &error_msg));
37
38 ASSERT_FALSE(file_lock.Init("/guaranteed/not/to/exist", &error_msg));
39}
40
41} // namespace art