blob: ec48a4b37fa489c9bb6ffb418fb2903769d94567 [file] [log] [blame]
Elliott Hughes53bfdae2013-10-18 19:39:09 -07001/*
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
24static int child_fn(void* i_ptr) {
25 *reinterpret_cast<int*>(i_ptr) = 42;
26 return 123;
27}
28
29TEST(sched, clone) {
30 void* child_stack[1024];
31
32 int i = 0;
33 pid_t tid = clone(child_fn, &child_stack[1024], /*CLONE_FILES | CLONE_FS | */CLONE_VM/* | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM*/, &i);
34
35 int status;
36 ASSERT_EQ(tid, TEMP_FAILURE_RETRY(waitpid(tid, &status, __WCLONE)));
37
38 ASSERT_EQ(42, i);
39
40 ASSERT_TRUE(WIFEXITED(status));
41 ASSERT_EQ(123, WEXITSTATUS(status));
42}