Skip to content
Browse files

Added p5test which test various stages of linking in a perl5 interpre…

…ter to mono.
  • Loading branch information...
1 parent 301a891 commit e99322344acaa935ce65d07c9e896c76f2d8c4d7 @pmurias pmurias committed Jan 27, 2012
Showing with 162 additions and 0 deletions.
  1. +59 −0 p5test/p5test.pl
  2. +4 −0 p5test/test1.c
  3. +35 −0 p5test/test2.c
  4. +6 −0 p5test/test3.cs
  5. +9 −0 p5test/test4.cs
  6. +4 −0 p5test/test4lib.c
  7. +9 −0 p5test/test5.cs
  8. +36 −0 p5test/test5lib.c
View
59 p5test/p5test.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More;
+use Config;
+use ExtUtils::Embed;
+use File::Spec::Functions qw(rel2abs);
+
+my $cc = $Config{cc};
+my $csc = "gmcs";
+
+diag($Config{osname});
+system($cc,"test1.c","-o","test1");
+my $ok1 = `./test1`;
+
+is $ok1,"OK 1\n","We have a working C compiler.";
+
+my $ccopts = `perl -MExtUtils::Embed -e ccopts`;
+my $ldopts = `perl -MExtUtils::Embed -e ldopts`;
+chomp($ccopts);
+chomp($ldopts);
+system("$cc test2.c -o test2 $ccopts $ldopts");
+my $ok2 = `./test2`;
+
+is $ok2,"OK 2\n","We can embed p5.";
+
+system($csc,"test3.cs");
+my $ok3 = `mono test3.exe`;
+is $ok3,"OK 3\n","We can run programs under mono";
+
+my $lib_path4 = rel2abs("test4lib.$Config{so}");
+open(my $test4_config,">test4.exe.config");
+print $test4_config <<END;
+ <configuration>
+ <dllmap dll="test4lib" target="$lib_path4" />
+</configuration>
+END
+
+system($csc,"test4.cs");
+system("$cc -shared -o test4lib.so test4lib.c");
+my $ok4 = `mono test4.exe`;
+is $ok4,"OK 4\n","We call C code from mono";
+
+my $lib_path5 = rel2abs("test5lib.$Config{so}");
+open(my $test5_config,">test5.exe.config");
+print $test5_config <<END;
+ <configuration>
+ <dllmap dll="test5lib" target="$lib_path5" />
+</configuration>
+END
+
+system($csc,"test5.cs");
+system("$cc -shared -o test5lib.so test5lib.c $ccopts $ldopts");
+my $ok5 = `mono test5.exe`;
+is $ok5,"OK 5\n","We call C code from mono";
+
+
+done_testing;
+
View
4 p5test/test1.c
@@ -0,0 +1,4 @@
+#include <stdio.h>
+int main() {
+ printf("OK 1\n");
+}
View
35 p5test/test2.c
@@ -0,0 +1,35 @@
+#include <EXTERN.h>
+#include <perl.h>
+
+/* So that we can load XS using modules from our perl */
+EXTERN_C void xs_init (pTHX);
+
+EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
+
+EXTERN_C void
+xs_init(pTHX)
+{
+ char *file = __FILE__;
+ dXSUB_SYS;
+
+ /* DynaLoader is a special case */
+ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+}
+
+static PerlInterpreter *my_perl;
+int main()
+{
+ int argc = 1;
+ char *argv0[] = { "perl", NULL, 0 };
+ char **argv = argv0;
+ PERL_SYS_INIT(&argc,&argv);
+ my_perl = perl_alloc();
+ perl_construct(my_perl);
+ char *embedding[] = { "", "-e", "0" };
+ perl_parse(my_perl, xs_init, 3, embedding, NULL);
+ PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+ eval_pv("print \"OK 2\\n\"",TRUE);
+ perl_destruct(my_perl);
+ perl_free(my_perl);
+ PERL_SYS_TERM();
+}
View
6 p5test/test3.cs
@@ -0,0 +1,6 @@
+public class Test3 {
+ public static void Main() {
+ System.Console.WriteLine("OK 3");
+ }
+}
+
View
9 p5test/test4.cs
@@ -0,0 +1,9 @@
+using System.Runtime.InteropServices;
+public class Test4 {
+ [DllImport("test4lib", EntryPoint="run_test")]
+ public static extern void RunTest();
+ public static void Main() {
+ RunTest();
+ }
+}
+
View
4 p5test/test4lib.c
@@ -0,0 +1,4 @@
+#include <stdio.h>
+void run_test(void) {
+ printf("OK 4\n");
+}
View
9 p5test/test5.cs
@@ -0,0 +1,9 @@
+using System.Runtime.InteropServices;
+public class Test4 {
+ [DllImport("test5lib", EntryPoint="run_test")]
+ public static extern void RunTest();
+ public static void Main() {
+ RunTest();
+ }
+}
+
View
36 p5test/test5lib.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <EXTERN.h>
+#include <perl.h>
+
+/* So that we can load XS using modules from our perl */
+EXTERN_C void xs_init (pTHX);
+
+EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
+
+EXTERN_C void
+xs_init(pTHX)
+{
+ char *file = __FILE__;
+ dXSUB_SYS;
+
+ /* DynaLoader is a special case */
+ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+}
+
+static PerlInterpreter *my_perl;
+int run_test()
+{
+ int argc = 1;
+ char *argv0[] = { "perl", NULL, 0 };
+ char **argv = argv0;
+ PERL_SYS_INIT(&argc,&argv);
+ my_perl = perl_alloc();
+ perl_construct(my_perl);
+ char *embedding[] = { "", "-e", "0" };
+ perl_parse(my_perl, xs_init, 3, embedding, NULL);
+ PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+ eval_pv("print \"OK 5\\n\"",TRUE);
+ perl_destruct(my_perl);
+ perl_free(my_perl);
+ PERL_SYS_TERM();
+}

0 comments on commit e993223

Please sign in to comment.
Something went wrong with that request. Please try again.