blob: 1fa7a12d1759a6358d5e064427d37e2c38475fa2 [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"
Narayan Kamathd1c606f2014-06-09 16:50:19 +010018
Ian Rogerse63db272014-07-15 15:36:11 -070019#include "common_runtime_test.h"
Narayan Kamathd1c606f2014-06-09 16:50:19 +010020
21namespace art {
22
23class ScopedFlockTest : public CommonRuntimeTest {};
24
25TEST_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