scala / scala-dev

Scala 2 team issues. Not for user-facing bugs or directly actionable user-facing improvements. For build/test/infra and for longer-term planning and idea tracking. Our bug tracker is at https://github.com/scala/bug/issues
Apache License 2.0
130 stars 15 forks source link

Partest test case jvm/natives.scala failed on MacOS M1 platform #833

Closed liang3zy22 closed 1 year ago

liang3zy22 commented 1 year ago

Reproduction steps

sbt> restarrFull
sbt>partest jvm

Problem

jvm/natives.scala test case failed. I checked the codes, the script test/files/jvm/mkLibNatives.sh doesn't generate new natives library for ARM platform.

SethTisue commented 1 year ago

The script uses javah, which isn't present on JDK 10+, as per https://docs.oracle.com/en/java/javase/18/migrate/removed-tools-and-components.html#GUID-12237744-E23B-42F8-8892-26BA1BDD63F2.

We have the option of fixing the script to use javac -h instead (which should work on 8, 11, and 17), or simply leaving it alone and requiring that it be run on Java 8.

SethTisue commented 1 year ago

Even on Java 8, the script fails with Error: Could not find class file for 'Test$'.

What does one have to do for the natives-jvm.obj directory test/files/jvm to exist...? It comes into being briefly, then gets deleted.

I hoped --no-exec (as in partest --no-exec test/files/jvm/natives.scala) would cause the .obj directory to be left behind, but no dice.

Ah, here we go: you need to pass --debug to partest and then the directory stays around :+1:

SethTisue commented 1 year ago

hahaha

commit 9b3b1847ce5c12902ab2b1ba1018208d33ae8c9d
Author: Gilles Dubochet <gilles.dubochet@epfl.ch>
Date:   Wed May 13 16:09:14 2009 +0000

    Disabled "natives" test because its annoyance /...

    Disabled "natives" test because its annoyance / usefulness ratio was
    considered to be too low.

it got re-enabled later (by Toni in 2010)

som-snytt commented 1 year ago

There is a special secret ceremony for when you're using partest --debug, but I see partest --help works.

som-snytt commented 1 year ago

its annoyance / usefulness ratio was considered to be too low.

s/low/high, though arguably if a test is not annoying you, it may not be doing its job.

SethTisue commented 1 year ago

the following changes to mkLibNatives.sh help:

-  CC_OPTIONS="-c -arch ppc -arch i386 -arch x86_64"
-  CC_INCLUDES="-I/System/Library/Frameworks/JavaVM.framework/Headers"
+  CC_OPTIONS="-c -arch i386 -arch x86_64 -arch arm64"
+  CC_INCLUDES="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/darwin"

but then it bombs out because -framework JavaVM doesn't work on recent MacOS

this seems to help

-  LNK_OPTIONS="-dynamiclib -framework JavaVM"
+  LNK_OPTIONS="-L${JAVA_HOME}/jre/lib/server -dynamiclib -ljvm"

I smell success nearby

SethTisue commented 1 year ago

PR: scala/scala#10330

SethTisue commented 1 year ago

@liang3zy22 thanks for reporting

SethTisue commented 1 year ago

(we'll merge the fix forward from 2.12.x to 2.13.x before too much longer)