Christopher Ferris | 7fb2287 | 2013-09-27 12:43:15 -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 <stdbool.h> |
| 18 | #include <unistd.h> |
| 19 | |
| 20 | int test_level_four(int one, int two, int three, int four, |
| 21 | bool (*callback_func)(pid_t)) { |
| 22 | if (callback_func != NULL) { |
| 23 | callback_func(-1); |
| 24 | } else { |
| 25 | while (1) { |
| 26 | } |
| 27 | } |
| 28 | return one + two + three + four; |
| 29 | } |
| 30 | |
| 31 | int test_level_three(int one, int two, int three, int four, |
| 32 | bool (*callback_func)(pid_t)) { |
| 33 | return test_level_four(one+3, two+6, three+9, four+12, callback_func) + 3; |
| 34 | } |
| 35 | |
| 36 | int test_level_two(int one, int two, int three, int four, |
| 37 | bool (*callback_func)(pid_t)) { |
| 38 | return test_level_three(one+2, two+4, three+6, four+8, callback_func) + 2; |
| 39 | } |
| 40 | |
| 41 | int test_level_one(int one, int two, int three, int four, |
| 42 | bool (*callback_func)(pid_t)) { |
| 43 | return test_level_two(one+1, two+2, three+3, four+4, callback_func) + 1; |
| 44 | } |
| 45 | |
| 46 | int test_recursive_call(int level, bool (*callback_func)(pid_t)) { |
| 47 | if (level > 0) { |
| 48 | return test_recursive_call(level - 1, callback_func) + level; |
| 49 | } else if (callback_func != NULL) { |
| 50 | callback_func(-1); |
| 51 | } else { |
| 52 | while (1) { |
| 53 | } |
| 54 | } |
| 55 | return 0; |
| 56 | } |