sched_test.cpp revision 13613137bc4266656bffce464e525eb9ae6371f0
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
24#ifdef __BIONIC__
25static int child_fn(void* i_ptr) {
26  *reinterpret_cast<int*>(i_ptr) = 42;
27  return 123;
28}
29
30TEST(sched, clone) {
31  void* child_stack[1024];
32
33  int i = 0;
34  pid_t tid = clone(child_fn, &child_stack[1024], CLONE_VM, &i);
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}
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.
48TEST(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
53