cvsuser 03/12/25 04:02:28
Modified: src nci_test.c
t/pmc nci.t
Log:
add another nci struct test
* please run
make libnci.so (or whatever)
to update the test lib
Revision Changes Path
1.13 +8 -3 parrot/src/nci_test.c
Index: nci_test.c
===================================================================
RCS file: /cvs/public/parrot/src/nci_test.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -r1.12 -r1.13
--- nci_test.c 29 Oct 2003 09:18:27 -0000 1.12
+++ nci_test.c 25 Dec 2003 12:02:25 -0000 1.13
@@ -41,12 +41,17 @@
return l1 / l2;
}
-/* test calls this with a string */
int nci_ip(void *p) {
- fprintf(stderr, "%c%c\n", (*(char**) p)[1], (*(char **) p)[0]);
- return 2;
+ typedef struct _dfi {
+ double d;
+ float f;
+ int i;
+ } dfi;
+ dfi *sp = (dfi*) p;
+ return (int) (sp->d + sp->f + sp->i);
}
+/* test calls this with a string */
int nci_it(void *p) {
fprintf(stderr, "%c%c\n", ((char*) p)[1], ((char *) p)[0]);
return 2;
1.20 +38 -11 parrot/t/pmc/nci.t
Index: nci.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/nci.t,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -w -r1.19 -r1.20
--- nci.t 29 Oct 2003 09:18:31 -0000 1.19
+++ nci.t 25 Dec 2003 12:02:28 -0000 1.20
@@ -1,4 +1,4 @@
-use Parrot::Test tests => 17;
+use Parrot::Test tests => 18;
use Parrot::Config;
print STDERR $PConfig{jitcpuarch}, " JIT CPU\n";
@@ -19,7 +19,6 @@
dlfunc P0, P1, "nci_dd", "dd"
print "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set N5, 4.0
invoke
ne N5, 8.0, nok_1
@@ -50,7 +49,6 @@
dlfunc P0, P1, "nci_fff", "fff"
print "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set N5, 12.0
set N6, 3.0
invoke
@@ -82,7 +80,6 @@
dlfunc P0, P1, "nci_isc", "isc"
print "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set I5, 2
set I6, 3
invoke
@@ -115,7 +112,6 @@
dlfunc P0, P1, "nci_ssc", "ssc"
print "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set I5, 2
set I6, 3
invoke
@@ -147,7 +143,6 @@
dlfunc P0, P1, "nci_csc", "csc"
print "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set I5, 64
set I6, 2
invoke
@@ -180,7 +175,6 @@
dlfunc P0, P1, "nci_it", "it"
printerr "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set S5, "ko\n"
invoke
ne I5, 2, nok_1
@@ -210,7 +204,6 @@
dlfunc P0, P1, "nci_tt", "tt"
print "dlfunced\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set S5, "ko\n"
invoke
print S5
@@ -242,7 +235,6 @@
loop:
dlfunc P0, P1, "nci_dd", "dd"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set N5, 4.0
invoke
ne N5, 8.0, nok_1
@@ -277,7 +269,6 @@
clone P2, P0
print "ok 1\n"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set N5, 4.0
invoke
ne N5, 8.0, nok_1
@@ -315,7 +306,6 @@
loadlib P1, "libnci"
dlfunc P0, P1, "nci_iiii", "iiii"
set I0, 1 # prototype used - unchecked
- set I1, 0 # items on stack - unchecked
set I5, 10
set I6, 20
set I7, 30
@@ -439,6 +429,43 @@
42.000000
100.000000
47.110000
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "nci_i_p");
+ loadlib P1, "libnci"
+ dlfunc P0, P1, "nci_ip", "ip"
+ # this test function wants a struct { double d; float f; int i }
+ # and returns the sum of these values
+ new P2, .PerlArray
+.include "datatypes.pasm"
+ push P2, .DATATYPE_DOUBLE
+ push P2, 0
+ push P2, 0
+ push P2, .DATATYPE_FLOAT
+ push P2, 0 # 1 elem array
+ push P2, 0
+ push P2, .DATATYPE_INT
+ push P2, 0 # 1 elem array
+ push P2, 0
+ new P5, .ManagedStruct, P2
+ set I6, 0
+ sizeof I7, .DATATYPE_DOUBLE
+ add I6, I7
+ sizeof I7, .DATATYPE_FLOAT
+ add I6, I7
+ sizeof I7, .DATATYPE_INT
+ add I6, I7
+ set P5, I6
+ set P5[0], 10.0
+ set P5[1], 4.0
+ set P5[2], 17
+ set I5, 1
+ invoke
+ print I5
+ print "\n"
+ end
+CODE
+31
OUTPUT
output_is(<<'CODE', <<'OUTPUT', "nci_v_P");