Skip to content

Commit

Permalink
Add test for weak symbols feature.
Browse files Browse the repository at this point in the history
Bugs: android/ndk#837
Test: run_test.py
Change-Id: I8e353a2adc46dfd36bfc289ecb0ac0a7078b515c
  • Loading branch information
ZijunZhaoCCK committed Aug 31, 2022
1 parent a00704b commit f1a4c1e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/device/weak_symbols/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := unconditional
LOCAL_SRC_FILES := unconditional.cpp
LOCAL_STATIC_LIBRARIES := googletest_main
LOCAL_CFLAGS := -D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__
LOCAL_LDLIBS := -landroid
include $(BUILD_EXECUTABLE)

$(call import-module,third_party/googletest)
1 change: 1 addition & 0 deletions tests/device/weak_symbols/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_STL := c++_static
23 changes: 23 additions & 0 deletions tests/device/weak_symbols/jni/unconditional.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <gtest/gtest.h>
#include <android/trace.h>
#include <android/api-level.h>

TEST(weak_symbols, crash_if_call_unavailable) {
if (android_get_device_api_level() >= 29) {
GTEST_SKIP() << "Test only valid for post-API 29 devices";
}
// 4770 is a cookie example from
// http://cs/android/cts/hostsidetests/atrace/AtraceTestApp/jni/CtsTrace.cpp;l=30;rcl=214cc4d8356fdb1ba4a63ae5baf86c6d76074233
ASSERT_DEATH(ATrace_beginAsyncSection("ndk::asyncBeginEndSection", 4770), "");
}

TEST(weak_symbols, pass_if_call_available) {
if (android_get_device_api_level() < 29) {
GTEST_SKIP() << "Test not valid for pre-API 29 devices";
}
// 4770 is a cookie example from
// http://cs/android/cts/hostsidetests/atrace/AtraceTestApp/jni/CtsTrace.cpp;l=30;rcl=214cc4d8356fdb1ba4a63ae5baf86c6d76074233
ATrace_beginAsyncSection("ndk::asyncBeginEndSection", 4770);
}


0 comments on commit f1a4c1e

Please sign in to comment.