Elliott Hughes | 53bfdae | 2013-10-18 19:39:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <sched.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/wait.h> |
| 23 | |
Christopher Ferris | 1361313 | 2013-10-28 15:24:04 -0700 | [diff] [blame] | 24 | #ifdef __BIONIC__ |
Elliott Hughes | 53bfdae | 2013-10-18 19:39:09 -0700 | [diff] [blame] | 25 | static int child_fn(void* i_ptr) { |
| 26 | *reinterpret_cast<int*>(i_ptr) = 42; |
| 27 | return 123; |
| 28 | } |
| 29 | |
| 30 | TEST(sched, clone) { |
| 31 | void* child_stack[1024]; |
| 32 | |
| 33 | int i = 0; |
Christopher Ferris | 1361313 | 2013-10-28 15:24:04 -0700 | [diff] [blame] | 34 | pid_t tid = clone(child_fn, &child_stack[1024], CLONE_VM, &i); |
Elliott Hughes | 53bfdae | 2013-10-18 19:39:09 -0700 | [diff] [blame] | 35 | |
| 36 | int status; |
| 37 | ASSERT_EQ(tid, TEMP_FAILURE_RETRY(waitpid(tid, &status, __WCLONE))); |
| 38 | |
| 39 | ASSERT_EQ(42, i); |
| 40 | |
| 41 | ASSERT_TRUE(WIFEXITED(status)); |
| 42 | ASSERT_EQ(123, WEXITSTATUS(status)); |
| 43 | } |
Christopher Ferris | 1361313 | 2013-10-28 15:24:04 -0700 | [diff] [blame] | 44 | #else |
| 45 | // For glibc, any call to clone with CLONE_VM set will cause later pthread |
| 46 | // calls in the same process to misbehave. |
| 47 | // See https://sourceware.org/bugzilla/show_bug.cgi?id=10311 for more details. |
| 48 | TEST(sched, clone) { |
| 49 | // In order to enumerate all possible tests for CTS, create an empty test. |
| 50 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 51 | } |
| 52 | #endif |