Skip to content

Commit

Permalink
Add FFI test for handling crashes (#11266)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Sep 26, 2023
1 parent aae577a commit 31fc8a7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions testsuite/flattening/modelica/ffi/Crash1.mos
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// name: Crash1
// keywords: ffi
// status: correct
// cflags: -d=newInst
//
// Checks that the compiler doesn't crash if the external function crashes.
//

loadFile("FFITest/package.mo"); getErrorString();
instantiateModel(FFITest.ErrorChecking.Crash1); getErrorString();

// Result:
// true
// ""
// ""
// "[flattening/modelica/ffi/FFITest/package.mo:279:7-279:40:writable] Error: Failed to evaluate function: FFITest.ErrorChecking.exception1.
// "
// endResult
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

double real1_ext(double x)
{
Expand Down Expand Up @@ -126,3 +127,8 @@ void record4_ext(const double *arr, struct record4 *r4)
r4->r2.z = arr[3];
r4->y = arr[4];
}

int crash1_ext()
{
abort();
}
10 changes: 10 additions & 0 deletions testsuite/flattening/modelica/ffi/FFITest/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ package FFITest
model Exception1
constant Integer x = exception1();
end Exception1;

function crash1
output Integer x;
external "C" x = crash1_ext()
annotation(Library="FFITestLib");
end crash1;

model Crash1
constant Integer x = crash1();
end Crash1;
end ErrorChecking;

package ExternalC
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/ffi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ StringArray1.mos \
# Run make testfailing
FAILINGTESTFILES=\
Record5.mos \
Crash1.mos

# Dependency files that are not .mo .mos or Makefile
# Add them here or they will be cleaned.
Expand Down

0 comments on commit 31fc8a7

Please sign in to comment.