1 /**
2  * Copyright 2020 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 <jni.h>
18 #include <string>
19 #include <iomanip>
20 #include <sstream>
21 #include <fcntl.h>
22 
23 #include <android/log.h>
24 
25 #define LOG_TAG "CrashTest"
26 
27 extern "C" JNIEXPORT void JNICALL
Java_com_android_nn_crashtest_core_test_CrashingCrashTest_nativeSegViolation(JNIEnv * env,jobject)28 Java_com_android_nn_crashtest_core_test_CrashingCrashTest_nativeSegViolation(
29     JNIEnv* env, jobject /* this */) {
30   __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Causing NATIVE crash");
31 
32   char* bad_array = nullptr;
33 
34   bad_array[10] = 'x';
35 
36   __android_log_print(ANDROID_LOG_FATAL, LOG_TAG,
37                       "Looks like it didn't crash!!!");
38 }
39