Skip to content

Commit

Permalink
[jnigen] Run Java GC using jcmd in tests (dart-archive/jnigen#371)
Browse files Browse the repository at this point in the history
meta: remove apk builds from windows minimal CI
  • Loading branch information
HosseinYousefi authored Aug 24, 2023
1 parent 95c8375 commit b7cc048
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,6 @@ jobs:
- run: Add-Content $env:GITHUB_PATH "$env:JAVA_HOME\bin\server"
- run: dart pub get
- run: dart run jnigen:setup
- name: build in_app_java APK
run: flutter build apk --target-platform=android-arm64
working-directory: ./pkgs/jnigen/example/in_app_java
- name: build notification_plugin example APK
run: flutter build apk --target-platform=android-arm64
working-directory: ./pkgs/jnigen/example/notification_plugin/example
- name: Build summarizer
run: dart run jnigen:setup
- name: Generate runtime tests
Expand Down
19 changes: 9 additions & 10 deletions pkgs/jnigen/test/descriptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import 'test_util/test_util.dart';

void main() {
checkLocallyBuiltDependencies();
test('Method descriptor generation', timeout: const Timeout.factor(3),
() async {
final configGetters = [
simple_package_test.getConfig,
kotlin_test.getConfig,
jackson_core_test.getConfig
];
for (final getConfig in configGetters) {
for (final (name, getConfig) in [
('simple_package', simple_package_test.getConfig),
('kotlin', kotlin_test.getConfig),
('jackson_core', jackson_core_test.getConfig),
]) {
test('Method descriptor generation for $name',
timeout: const Timeout.factor(3), () async {
final config = getConfig();
config.summarizerOptions =
SummarizerOptions(backend: SummarizerBackend.asm);
Expand All @@ -38,6 +37,6 @@ void main() {
expect(method.descriptor, method.accept(methodDescriptor));
}
}
}
});
});
}
}
12 changes: 10 additions & 2 deletions pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ const fpDelta = 0.001;
const trillion = 1024 * 1024 * 1024 * 1024;

void _runJavaGC() {
final system = Jni.findJClass('java/lang/System');
system.callStaticMethodByName<void>('gc', '()V', []);
final managementFactory =
Jni.findJClass('java/lang/management/ManagementFactory');
final bean = managementFactory.callStaticMethodByName<JObject>(
'getRuntimeMXBean', '()Ljava/lang/management/RuntimeMXBean;', []);
final pid = bean.callMethodByName<int>('getPid', '()J', []);
ProcessResult result;
do {
sleep(const Duration(milliseconds: 100));
result = Process.runSync('jcmd', [pid.toString(), 'GC.run']);
} while (result.exitCode != 0);
}

void registerTests(String groupName, TestRunnerCallback test) {
Expand Down

0 comments on commit b7cc048

Please sign in to comment.