2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
24 static volatile bool signaled;
25 static void signal_handler(int) {
29 TEST(workload, success) {
31 SignalHandlerRegister signal_handler_register({SIGCHLD}, signal_handler);
32 auto workload = Workload::CreateWorkload({"sleep", "1"});
33 ASSERT_TRUE(workload != nullptr);
34 ASSERT_TRUE(workload->GetPid() != 0);
35 ASSERT_TRUE(workload->Start());
40 TEST(workload, execvp_failure) {
41 auto workload = Workload::CreateWorkload({"/dev/null"});
42 ASSERT_TRUE(workload != nullptr);
43 ASSERT_FALSE(workload->Start());
46 static void run_signaled_workload() {
49 SignalHandlerRegister signal_handler_register({SIGCHLD}, signal_handler);
50 auto workload = Workload::CreateWorkload({"sleep", "10"});
51 ASSERT_TRUE(workload != nullptr);
52 ASSERT_TRUE(workload->Start());
53 ASSERT_EQ(0, kill(workload->GetPid(), SIGABRT));
57 // Make sure all destructors are called before exit().
61 TEST(workload, signaled_warning) {
62 ASSERT_EXIT(run_signaled_workload(), testing::ExitedWithCode(0),
63 "child process was terminated by signal");
66 static void run_exit_nonzero_workload() {
69 SignalHandlerRegister signal_handler_register({SIGCHLD}, signal_handler);
70 auto workload = Workload::CreateWorkload({"ls", "nonexistdir"});
71 ASSERT_TRUE(workload != nullptr);
72 ASSERT_TRUE(workload->Start());
76 // Make sure all destructors are called before exit().
80 TEST(workload, exit_nonzero_warning) {
81 ASSERT_EXIT(run_exit_nonzero_workload(), testing::ExitedWithCode(0),
82 "child process exited with exit code");