Dave Allison | f4b80bc | 2014-05-14 15:41:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Andreas Gampe | 1c83cbc | 2014-07-22 18:52:29 -0700 | [diff] [blame] | 17 | public class Main { |
Dave Allison | f4b80bc | 2014-05-14 15:41:25 -0700 | [diff] [blame] | 18 | private static native void initSignalTest(); |
| 19 | private static native void terminateSignalTest(); |
| 20 | private static native int testSignal(); |
| 21 | |
| 22 | private static void stackOverflow() { |
Mathieu Chartier | 50c138f | 2015-01-07 16:00:03 -0800 | [diff] [blame] | 23 | stackOverflow(); |
Dave Allison | f4b80bc | 2014-05-14 15:41:25 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | public static void main(String[] args) { |
Mathieu Chartier | 031768a | 2015-08-27 10:25:02 -0700 | [diff] [blame] | 27 | System.loadLibrary(args[0]); |
Dave Allison | f4b80bc | 2014-05-14 15:41:25 -0700 | [diff] [blame] | 28 | System.out.println("init signal test"); |
| 29 | initSignalTest(); |
| 30 | try { |
| 31 | Object o = null; |
| 32 | int hash = o.hashCode(); |
| 33 | |
| 34 | // Should never get here. |
| 35 | System.out.println("hash: " + hash); |
| 36 | throw new AssertionError(); |
| 37 | } catch (NullPointerException e) { |
| 38 | System.out.println("Caught NullPointerException"); |
| 39 | } |
| 40 | try { |
| 41 | stackOverflow(); |
Dave Allison | f4b80bc | 2014-05-14 15:41:25 -0700 | [diff] [blame] | 42 | // Should never get here. |
| 43 | throw new AssertionError(); |
| 44 | } catch (StackOverflowError e) { |
| 45 | System.out.println("Caught StackOverflowError"); |
| 46 | } |
| 47 | |
| 48 | // Test that a signal in native code works. This will return |
| 49 | // the value 1234 if the signal is caught. |
| 50 | int x = testSignal(); |
| 51 | if (x != 1234) { |
| 52 | throw new AssertionError(); |
| 53 | } |
| 54 | |
| 55 | terminateSignalTest(); |
| 56 | System.out.println("Signal test OK"); |
| 57 | } |
| 58 | } |