Updated "TestNative" as JNI

Dirk Grunwald grunwald at pa.dec.com
Sun Jan 3 17:25:07 PST 1999


Btw, I modified the "TestNative" method in the tests/regression
directory to be a seperable JNI library. I also modified the test case
to report more meaningful messages (like "SUCCESS" and "FAILURE").

Here's some sample output showing the problem I'm having on the ARM,
even with my floating point retun fix.

Following test results should be 305419888
a = 11111111
b = 22222222
c = 33333333
d = 44444444
e = 55555555
f = 66666666
g = 77777777
h = 88888888
i = 99999999
j = aaaaaaaa
k = bbbbbbbb
l = cccccccc
m = dddddddd
n = eeeeeeee
o = ffffffff
p = 12345678
test16int returned 305419888...SUCCESS
Following test results should be 305419888
a = 0000000011111111
b = 0000000022222222
c = 0000000033333333
d = 0000000044444444
e = 0000000055555555
f = 0000000066666666
g = 0000000077777777
h = eeeeeeee88888888
i = ffffffff99999999
j = ffffffffaaaaaaaa
k = ffffffffbbbbbbbb
l = ffffffffcccccccc
m = ffffffffdddddddd
n = ffffffffeeeeeeee
o = ffffffffffffffff
p = 0000000012345678
test16long returned -1229782937655552400...FALIURE
a = 00000001
b = ffffffffffffffff
c = 0000000000000002
d = fffffffffffffffe
e = 0000000000000003
f = fffffffffffffffd
g = 0000000000000004
h = fffffffffffffffc
i = 0000000b77777777
j = fffffff5
k = bffff6fc
l = aaaaaaaaffffffea
m = 0000000000000021
n = ffffffffffffffdf
o = 000000000000002c
p = ffffffffffffffd4
test16intlong returned -6148914641629647278...FALIURE
Following test results should be 133.4
a = -1.20
b = 0.20
c = 3.30
d = 4.50
e = 5.60
f = 6.00
g = 7.00
h = 8.00
i = 9.00
j = 10.00
k = 11.00
l = 12.00
m = 13.00
n = 14.00
o = 15.00
p = 16.00
test16float returned 133.4...SUCCESS
Following test results should be 133.4
a = -1.20
b = 0.20
c = 3.30
d = 4.50
e = 5.60
f = 6.00
g = 7.00
h = 8.00
i = 9.00
j = 10.00
k = 11.00
l = 12.00
m = 13.00
n = 14.00
o = 15.00
p = 16.00
test16double returned 133.40000195...FALIURE
a = -1.20
b = 0.20
c = 3.30
d = 4.50
e = 5.60
f = 6.00
g = 7.00
h = 8.00
i = 7.00
j = 10.00
k = 0.00
l = 12.00
m = 13.00
n = 14.00
o = 15.00
p = 16.00
test16floatdouble returned 120.40000282...FALIURE


#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-01-03 17:24 PST by <grunwald at hood.pa.dec.com>.
# Source directory was `/tmp_mnt/n/wrl-nfs2/wrl/proj/itsy/grunwald/Kaffe/TestCases'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   2764 -rw-r--r-- TestArgs.c
#   4939 -rw-rw-r-- TestArgs.java
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh15046; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= TestArgs.c ==============
if test -f 'TestArgs.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'TestArgs.c' '(file already exists)'
else
  $echo 'x -' extracting 'TestArgs.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'TestArgs.c' &&
/*
X * TestArgs.c
X *
X * Copyright (c) 1996, 1997
X *	Transvirtual Technologies, Inc.  All rights reserved.
X *
X * See the file "lib-license.terms" for information on usage and redistribution 
X * of this file. 
X */
X
#include <jni.h>
#include <stdio.h>
#include <unistd.h>
X
#define DEBUG
X
#if defined(DEBUG)
jint
Java_TestArgs_test16int(JNIEnv* env, jclass clazz,
X			  jint a, jint b, jint c, jint d, 
X	jint e, jint f, jint g, jint h, 
X	jint i, jint j, jint k, jint l, 
X	jint m, jint n, jint o, jint p)
{
#define A(x)	printf("%s = %08x\n", #x, x), fflush(stdout)
X	A(a); A(b); A(c); A(d);
X	A(e); A(f); A(g); A(h);
X	A(i); A(j); A(k); A(l);
X	A(m); A(n); A(o); A(p);
X	return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
}
X
jlong
Java_TestArgs_test16long(JNIEnv* env, jclass clazz,
X			   jlong a, jlong b, jlong c, jlong d, 
X	jlong e, jlong f, jlong g, jlong h, 
X	jlong i, jlong j, jlong k, jlong l, 
X	jlong m, jlong n, jlong o, jlong p)
{
#define B(x)	printf("%s = %08x%08x\n", #x, (int)(x >> 32), (int)x), \
X	fflush(stdout)
X	B(a); B(b); B(c); B(d);
X	B(e); B(f); B(g); B(h);
X	B(i); B(j); B(k); B(l);
X	B(m); B(n); B(o); B(p);
X	return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
}
X
jlong
Java_TestArgs_test16intlong(JNIEnv* env, jclass clazz,
X			      jint a, jlong b, jlong c, jlong d, 
X	jlong e, jlong f, jlong g, jlong h, 
X	jlong i, jint j, jint k, jlong l, 
X	jlong m, jlong n, jlong o, jlong p)
{
X	A(a); B(b); B(c); B(d);
X	B(e); B(f); B(g); B(h);
X	B(i); A(j); A(k); B(l);
X	B(m); B(n); B(o); B(p);
X	return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
}
X
jfloat
Java_TestArgs_test16float(JNIEnv* env, jclass clazz,
X			    jfloat a, jfloat b, jfloat c, jfloat d, 
X	jfloat e, jfloat f, jfloat g, jfloat h, 
X	jfloat i, jfloat j, jfloat k, jfloat l, 
X	jfloat m, jfloat n, jfloat o, jfloat p)
{
#define C(x)	printf("%s = %4.2f\n", #x, x), fflush(stdout)
X	C(a); C(b); C(c); C(d);
X	C(e); C(f); C(g); C(h);
X	C(i); C(j); C(k); C(l);
X	C(m); C(n); C(o); C(p);
X	return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
}
X
jdouble
Java_TestArgs_test16double(JNIEnv* env, jclass clazz,
X			     jdouble a, jdouble b, jdouble c, jdouble d, 
X	jdouble e, jdouble f, jdouble g, jdouble h, 
X	jdouble i, jdouble j, jdouble k, jdouble l, 
X	jdouble m, jdouble n, jdouble o, jdouble p)
{
X	C(a); C(b); C(c); C(d);
X	C(e); C(f); C(g); C(h);
X	C(i); C(j); C(k); C(l);
X	C(m); C(n); C(o); C(p);
X	return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
}
X
jdouble
Java_TestArgs_test16floatdouble(JNIEnv* env, jclass clazz,
X				  jfloat a, jdouble b, jdouble c, jdouble d, 
X	jdouble e, jdouble f, jdouble g, jdouble h, 
X	jdouble i, jfloat j, jfloat k, jdouble l, 
X	jdouble m, jdouble n, jdouble o, jdouble p)
{
X	C(a); C(b); C(c); C(d);
X	C(e); C(f); C(g); C(h);
X	C(i); C(j); C(k); C(l);
X	C(m); C(n); C(o); C(p);
X	return a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
}
X
#endif /* DEBUG */
SHAR_EOF
  $shar_touch -am 0103154599 'TestArgs.c' &&
  chmod 0644 'TestArgs.c' ||
  $echo 'restore of' 'TestArgs.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'TestArgs.c:' 'MD5 check failed'
ecfbb6510a6f6cd36e26699bc5cc5f2b  TestArgs.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'TestArgs.c'`"
    test 2764 -eq "$shar_count" ||
    $echo 'TestArgs.c:' 'original size' '2764,' 'current size' "$shar_count!"
  fi
fi
# ============= TestArgs.java ==============
if test -f 'TestArgs.java' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'TestArgs.java' '(file already exists)'
else
  $echo 'x -' extracting 'TestArgs.java' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'TestArgs.java' &&
/**
X * This test requires native functions.
X * It tests that passing int, long, float, and double parameters works
X * properly.  See libraries/clib/native/TestArgs.c
X *
X * This should be very helpful for porters to new architectures who want
X * to debug the sysdepCallMethod macro
X */
public class TestArgs
{
X    static {
X    System.loadLibrary("TestArgs");
X  }
X
X  public native int test16int(int a, int b, int c, int d,
X				     int e, int f, int g, int h,
X				     int i, int j, int k, int l,
X				     int m, int n, int o, int p);
X
X  public native long test16long(long a, long b, long c, long d,
X				       long e, long f, long g, long h,
X				       long i, long j, long k, long l,
X				       long m, long n, long o, long p);
X
X  public native long test16intlong(int a, long b, long c, long d,
X					  long e, long f, long g, long h,
X					  long i, int j, int k, long l,
X					  long m, long n, long o, long p);
X
X  public native float test16float(float a, float b, float c, float d,
X					 float e, float f, float g, float h,
X					 float i, float j, float k, float l,
X					 float m, float n, float o, float p);
X
X  public native double test16double(
X					   double a, double b, double c, double d,
X					   double e, double f, double g, double h,
X					   double i, double j, double k, double l,
X					   double m, double n, double o, double p);
X
X  public native double test16floatdouble(
X						float a, double b, double c, double d,
X						double e, double f, double g, double h,
X						double i, float j, float k, double l,
X						double m, double n, double o, double p);
X
X  public static double fabs(double x)
X  {
X    if ( x < 0 ) {
X      return -x;
X    } else {
X      return x;
X    }
X  }
X
X  public static void main(String av[])
X  {
X    TestArgs me = new TestArgs();
X
X    int i_should_be = 0x11111111 + 0x22222222 + 0x33333333 + 0x44444444 +
X      0x55555555 + 0x66666666 + 0x77777777 + 0x88888888 +
X      0x99999999 + 0xAAAAAAAA + 0xBBBBBBBB + 0xCCCCCCCC +
X      0xDDDDDDDD + 0xEEEEEEEE + 0xFFFFFFFF + 0x12345678;
X    System.out.println("Following test results should be " + i_should_be);
X
X    int i = me.test16int(0x11111111, 0x22222222, 0x33333333, 0x44444444,
X		      0x55555555, 0x66666666, 0x77777777, 0x88888888,
X		      0x99999999, 0xAAAAAAAA, 0xBBBBBBBB, 0xCCCCCCCC,
X		      0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF, 0x12345678
X		      );
X    System.out.print("test16int returned " + i);
X    if ( i == i_should_be ) {
X      System.out.println("...SUCCESS");
X    } else {
X      System.out.println("...FALIURE");
X    }
X
X
X    long l_should_be = 0x11111111 + 0x22222222 + 0x33333333 + 0x44444444 +
X      0x55555555 + 0x66666666 + 0x77777777 + 0x88888888 +
X      0x99999999 + 0xAAAAAAAA + 0xBBBBBBBB + 0xCCCCCCCC +
X      0xDDDDDDDD + 0xEEEEEEEE + 0xFFFFFFFF + 0x12345678;
X    System.out.println("Following test results should be " + l_should_be);
X
X    long l = me.test16long(0x11111111, 0x22222222, 0x33333333, 0x44444444,
X			0x55555555, 0x66666666, 0x77777777, 0x88888888,
X			0x99999999, 0xAAAAAAAA, 0xBBBBBBBB, 0xCCCCCCCC,
X			0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF, 0x12345678
X			);
X    System.out.print("test16long returned " + l);
X    if ( l == l_should_be ) {
X      System.out.println("...SUCCESS");
X    } else {
X      System.out.println("...FALIURE");
X    }
X
X    long l2_should_be = 1 +(-1) + 2 + (-2) + 3 + (-3) + 4 + (-4) +
X      11 +(-11) + 22 + (-22) + 33 + (-33) + 44 + (-44);
X
X    l = me.test16intlong(1 ,(-1) , 2 , (-2) , 3 , (-3) , 4 , (-4) ,
X      11 ,(-11) , 22 , (-22) , 33 , (-33) , 44 , (-44));
X
X    System.out.print("test16intlong returned " + l);
X    if ( l == l2_should_be ) {
X      System.out.println("...SUCCESS");
X    } else {
X      System.out.println("...FALIURE");
X    }
X
X    float f_should_be =  -1.2f + 0.2f + 3.3f + 4.5f + 5.6f + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16;
X    System.out.println("Following test results should be " + f_should_be);
X
X    float f = me.test16float(-1.2f, 0.2f, 3.3f, 4.5f, 5.6f, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
X    System.out.print("test16float returned " + f);
X    if ( f == f_should_be ) {
X      System.out.println("...SUCCESS");
X    } else {
X      System.out.println("...FALIURE");
X    }
X
X    double d_should_be =  -1.2 + 0.2 + 3.3 + 4.5 + 5.6 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16;
X    System.out.println("Following test results should be " + d_should_be);
X
X    double d = me.test16double(-1.2, 0.2, 3.3, 4.5, 5.6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
X    System.out.print("test16double returned " + d);
X    if ( d == d_should_be ) {
X      System.out.println("...SUCCESS");
X    } else {
X      System.out.println("...FALIURE");
X    }
X
X    d = me.test16floatdouble(-1.2f, 0.2, 3.3, 4.5,
X			  5.6, 6, 7, 8,
X			  9, 10f, 11f, 12,
X			  13, 14, 15, 16);
X    System.out.print("test16floatdouble returned " + d);
X    if ( fabs(d - d_should_be) < 0.001 ) {
X      System.out.println("...SUCCESS");
X    } else {
X      System.out.println("...FALIURE");
X    }
X  }
}
SHAR_EOF
  $shar_touch -am 0103172199 'TestArgs.java' &&
  chmod 0664 'TestArgs.java' ||
  $echo 'restore of' 'TestArgs.java' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'TestArgs.java:' 'MD5 check failed'
bc65c7783f2b5c25a587e48ec654ff73  TestArgs.java
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'TestArgs.java'`"
    test 4939 -eq "$shar_count" ||
    $echo 'TestArgs.java:' 'original size' '4939,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh15046
exit 0


More information about the kaffe mailing list