@@ -360,6 +360,10 @@ def graalpython_gate_runner(args, tasks):
360
360
if task :
361
361
python_checkcopyrights ([])
362
362
363
+ with Task ('GraalPython GraalVM shared-library build' , tasks , tags = [GraalPythonTags .downstream , GraalPythonTags .graalvm ]) as task :
364
+ if task :
365
+ run_shared_lib_test ()
366
+
363
367
with Task ('GraalPython GraalVM build' , tasks , tags = [GraalPythonTags .downstream , GraalPythonTags .graalvm ]) as task :
364
368
if task :
365
369
mx .run_mx (
@@ -393,6 +397,155 @@ def graalpython_gate_runner(args, tasks):
393
397
mx_gate .add_gate_runner (_suite , graalpython_gate_runner )
394
398
395
399
400
+ def run_shared_lib_test (args = None ):
401
+ mx .run_mx (
402
+ ["--dynamicimports" , "/substratevm,/vm" ,
403
+ "build" , "--force-deprecation-as-warning" , "--dependencies" ,
404
+ "GRAAL_MANAGEMENT,POLYGLOT_NATIVE_API_HEADERS,libpolyglot.so.image" ],
405
+ nonZeroIsFatal = True
406
+ )
407
+ vmdir = os .path .join (mx .suite ("truffle" ).dir , ".." , "vm" )
408
+ svm_lib_path = os .path .join (vmdir , "mxbuild" , "-" .join ([mx .get_os (), mx .get_arch ()]), "libpolyglot.so.image" )
409
+ fd = name = progname = None
410
+ try :
411
+ fd , name = tempfile .mkstemp (suffix = '.c' )
412
+ os .write (fd , """
413
+ #include "stdio.h"
414
+ #include "polyglot_api.h"
415
+
416
+ #define assert_ok(msg, f) { if (!(f)) { \\
417
+ const poly_extended_error_info* error_info; \\
418
+ poly_get_last_error_info(isolate_thread, &error_info); \\
419
+ fprintf(stderr, "%s\\ n", error_info->error_message); \\
420
+ return fprintf(stderr, "%s\\ n", msg); } } while (0)
421
+
422
+ poly_isolate global_isolate;
423
+ poly_thread isolate_thread;
424
+ poly_engine engine;
425
+ poly_context context;
426
+
427
+ static poly_status create_context() {
428
+ poly_status status;
429
+
430
+ if (poly_attach_thread(global_isolate, &isolate_thread)) {
431
+ return poly_generic_failure;
432
+ }
433
+
434
+ poly_engine_builder engine_builder;
435
+ status = poly_create_engine_builder(isolate_thread, &engine_builder);
436
+ if (status != poly_ok) {
437
+ return status;
438
+ }
439
+ status = poly_engine_builder_build(isolate_thread, engine_builder, &engine);
440
+ if (status != poly_ok) {
441
+ return status;
442
+ }
443
+ poly_context_builder builder;
444
+ status = poly_create_context_builder(isolate_thread, NULL, 0, &builder);
445
+ if (status != poly_ok) {
446
+ return status;
447
+ }
448
+ status = poly_context_builder_engine(isolate_thread, builder, engine);
449
+ if (status != poly_ok) {
450
+ return status;
451
+ }
452
+ status = poly_context_builder_option(isolate_thread, builder, "python.VerboseFlag", "true");
453
+ if (status != poly_ok) {
454
+ return status;
455
+ }
456
+ status = poly_context_builder_build(isolate_thread, builder, &context);
457
+ if (status != poly_ok) {
458
+ return status;
459
+ }
460
+
461
+ poly_destroy_handle(isolate_thread, engine_builder);
462
+ poly_destroy_handle(isolate_thread, builder);
463
+
464
+ return poly_ok;
465
+ }
466
+
467
+ static poly_status tear_down_context() {
468
+ poly_status status = poly_context_close(isolate_thread, context, true);
469
+ if (status != poly_ok) {
470
+ return status;
471
+ }
472
+
473
+ status = poly_destroy_handle(isolate_thread, context);
474
+ if (status != poly_ok) {
475
+ return status;
476
+ }
477
+
478
+ status = poly_engine_close(isolate_thread, engine, true);
479
+ if (status != poly_ok) {
480
+ return status;
481
+ }
482
+
483
+ status = poly_destroy_handle(isolate_thread, engine);
484
+ if (status != poly_ok) {
485
+ return status;
486
+ }
487
+
488
+ if (poly_detach_thread(isolate_thread)) {
489
+ return poly_ok;
490
+ }
491
+
492
+ return poly_ok;
493
+ }
494
+
495
+ static int test_basic_python_function() {
496
+ assert_ok("Context creation failed.", create_context() == poly_ok);
497
+
498
+ poly_value func;
499
+ assert_ok("function eval failed", poly_context_eval(isolate_thread, context, "python", "test_func", "def test_func(x):\\ n return x * x\\ ntest_func", &func) == poly_ok);
500
+ int32_t arg_value = 42;
501
+ poly_value primitive_object;
502
+ assert_ok("create argument failed", poly_create_int32(isolate_thread, context, arg_value, &primitive_object) == poly_ok);
503
+ poly_value arg[1] = {primitive_object};
504
+ poly_value value;
505
+ assert_ok("invocation was unsuccessful", poly_value_execute(isolate_thread, func, arg, 1, &value) == poly_ok);
506
+
507
+ int32_t result_value;
508
+ poly_value_as_int32(isolate_thread, value, &result_value);
509
+
510
+ assert_ok("primitive free failed", poly_destroy_handle(isolate_thread, primitive_object) == poly_ok);
511
+ assert_ok("value free failed", poly_destroy_handle(isolate_thread, value) == poly_ok);
512
+ assert_ok("value computation was incorrect", result_value == 42 * 42);
513
+ assert_ok("func free failed", poly_destroy_handle(isolate_thread, func) == poly_ok);
514
+ assert_ok("Context tear down failed.", tear_down_context() == poly_ok);
515
+ return 0;
516
+ }
517
+
518
+ int32_t main(int32_t argc, char **argv) {
519
+ poly_isolate_params isolate_params = {};
520
+ if (poly_create_isolate(&isolate_params, &global_isolate)) {
521
+ return 1;
522
+ }
523
+ return test_basic_python_function();
524
+ }
525
+ """ )
526
+ os .close (fd )
527
+ progname = os .path .join (_suite .dir , "graalpython-embedded-tool" )
528
+ mx .log ("" .join (["Running " , "'clang" , "-I%s" % svm_lib_path , "-L%s" % svm_lib_path , name , "-o" , progname , "-lpolyglot" ]))
529
+ mx .run (["clang" , "-I%s" % svm_lib_path , "-L%s" % svm_lib_path , name , "-o%s" % progname , "-lpolyglot" ], nonZeroIsFatal = True )
530
+ mx .log ("Running " + progname + " with LD_LIBRARY_PATH " + svm_lib_path )
531
+ mx .run (["ls" , "-l" , progname ])
532
+ mx .run (["ls" , "-l" , svm_lib_path ])
533
+ mx .run ([progname ], env = {"LD_LIBRARY_PATH" : svm_lib_path })
534
+ finally :
535
+ try :
536
+ os .unlink (progname )
537
+ except :
538
+ pass
539
+ try :
540
+ os .close (fd )
541
+ except :
542
+ pass
543
+ try :
544
+ os .unlink (name )
545
+ except :
546
+ pass
547
+
548
+
396
549
class ArchiveProject (mx .ArchivableProject ):
397
550
def __init__ (self , suite , name , deps , workingSets , theLicense , ** args ):
398
551
super (ArchiveProject , self ).__init__ (suite , name , deps , workingSets , theLicense )
@@ -595,5 +748,6 @@ def python_checkcopyrights(args):
595
748
'delete-graalpython-if-testdownstream' : [delete_self_if_testdownstream , '' ],
596
749
'python-checkcopyrights' : [python_checkcopyrights , 'Make sure code files have copyright notices' ],
597
750
'punittest' : [punittest , '' ],
598
- 'nativebuild' : [nativebuild , '' ]
751
+ 'nativebuild' : [nativebuild , '' ],
752
+ 'python-so-test' : [run_shared_lib_test , '' ],
599
753
})
0 commit comments