2017-10-31 19:09:21 +03:00
#if ! MONOMAC
using System ;
2016-05-26 16:06:52 +03:00
using System.Runtime.InteropServices ;
using Foundation ;
using ObjCRuntime ;
using NUnit.Framework ;
namespace MonoTouchFixtures {
[TestFixture]
[Preserve (AllMembers = true)]
public partial class Symbols {
string [ ] symbols ;
[Test]
public void FunctionNames ( )
{
2021-12-16 00:32:14 +03:00
TestRuntime . AssertDevice ( ) ;
2016-05-26 16:06:52 +03:00
Collect ( ) ;
2018-10-16 18:25:35 +03:00
bool aot = symbols [ 1 ] . Contains ( "MonoTouchFixtures_Symbols_Collect" ) ;
2019-02-04 13:04:06 +03:00
bool llvmonly = symbols [ 1 ] . Contains ( "mono_llvmonly_runtime_invoke" ) ; // LLVM inlines the Collect function, so 'Collect' doesn't show up in the stack trace :/
2018-12-13 16:52:02 +03:00
bool interp = false ;
if ( ! aot ) {
2019-01-14 19:58:08 +03:00
for ( int i = 0 ; i < 5 & & ! interp ; i + + ) {
2018-12-13 16:52:02 +03:00
/ * ves_pinvoke_method ( slow path ) and do_icall ( fast path ) are
* MONO_NEVER_INLINE , so they should show up in the backtrace
* reliably * /
interp | = symbols [ i ] . Contains ( "ves_pinvoke_method" ) | | symbols [ i ] . Contains ( "do_icall" ) ;
}
}
2018-10-16 18:25:35 +03:00
2019-02-04 13:04:06 +03:00
Assert . IsTrue ( aot | | interp | | llvmonly , $"#1\n\t{string.Join (" \ n \ t ", symbols)}" ) ;
2016-05-26 16:06:52 +03:00
}
void Collect ( )
{
var array = new IntPtr [ 50 ] ;
var size = backtrace ( array , array . Length ) ;
var symbols = backtrace_symbols ( array , size ) ;
this . symbols = new string [ size ] ;
for ( int i = 0 ; i < size ; i + + ) {
this . symbols [ i ] = Marshal . PtrToStringAuto ( Marshal . ReadIntPtr ( symbols , i * IntPtr . Size ) ) ;
// Console.WriteLine (" #{0}: {1}", i, this.symbols [i]);
}
free ( symbols ) ;
}
[DllImport (Constants.libcLibrary)]
static extern int backtrace ( IntPtr [ ] array , int size ) ;
[DllImport (Constants.libcLibrary)]
static extern IntPtr backtrace_symbols ( IntPtr [ ] array , int size ) ;
[DllImport (Constants.libcLibrary)]
static extern void free ( IntPtr ptr ) ;
}
}
2021-08-11 11:06:46 +03:00
#endif