NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Teststand crashes when unloading dll

I have crated a dll using Delphi.

When i try to "unload all modules" or close the sequence editor teststand crashes.

Can this be related to bug#189528?

 

TestStand engine ver. 4.2.1.83

 

DLL sourcecode:

library Test;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  ShareMem,
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

Procedure TestProcedure(parStr : pChar);  safecall; export;
begin
  ShowMessage(TestProcedure called with parameter: '+pchar(parStr));
  StrPCopy(parStr,'String from TestProcedure);
end;

exports TestProcedure;

begin
end.

0 Kudos
Message 1 of 9
(5,925 Views)

Hi Allan,

 

The issue you are refering to is related to Perforce 2009.1 client. If you are using Perforce a solution would be to run a client of a different version.

 

Do you see the same behavior when unloading other DLLs, or when you do not have you Delphi DLL loaded?

 

Do you get any error messages when TestStand crashes? In that case, can you post screenshots of them?

Regards,
Eirikur Runarsson
0 Kudos
Message 2 of 9
(5,877 Views)

In the attached sequence file, I have copied "IdentifyUUT" step from preuut into mainsequence.

After running the sequence "unload all modules" makes testsatand crash.

 

Regards,

 

Allan

0 Kudos
Message 3 of 9
(5,861 Views)

Hi Allan,

 

I can see in you sequence file that the Sequence sub-sequence contains a step that preloads TNBTools.dll. Is that the name of the dll you have developed?

What happens if you set the Load Option on the Action step to Preload when execution begins instead of Preload when opening sequence file and then try to run he main sequence and then unload modules? Another way to test this was to create a new sequence file that does not contain any form for reference to the TNBTools.dll at all.

 

I presume that the TNBTools.dll is the one you have developed in Delphi. If TestStand still crashes when you have done the above, are you willing to share the dll so I can test it out at my side?

Regards,
Eirikur Runarsson
0 Kudos
Message 4 of 9
(5,856 Views)

Hi, Eirikur

 

Sorry, I wasn't aware of the subsequense was preloading a dll.

I have attached a simple dll (in test.zip) which contains the procedure below and a seq file that are failing when unloading the dll

 

Procedure TestProcedure(parStr : pChar);  safecall; export;
begin
  ShowMessage('Testfunction called with parameter: '+String(parStr));
  StrPCopy(parStr,'String from testfunction');
end;

 

Regards,

 

Allan

Download All
0 Kudos
Message 5 of 9
(5,847 Views)

Hi Allan,

 

Well, no success this time either. I can't recreate the crash. On the other hand the module is probably not loading properly since I am receiving this error when I execute:

 

Error: Could not load DLL or external library 'E:\Work\965968 - Allan Laursen\New folder\Test.dll'.

This DLL requires the following DLLs which could not be found or loaded:
borlndmm.dll (Not Found)
[Error Code: -17004, Could not load DLL or library.]

 

See this.

 

I presume that the crash is only occurring with custom dlls created in Delphi?


Regards,
Eirikur Runarsson
0 Kudos
Message 6 of 9
(5,843 Views)

It's possible the delphi runtime engine or at least the borlandmm.dll component of it does not properly handle being dynamically unloaded. If that is the case, you either need a bugfix from borland or you need to make it so that your dll and/or the delphi runtime engine dll never get dynamically unloaded. One way to do this is to call LoadLibrary on your dll and never call FreeLibrary on it. This will ensure that it never gets unloaded until the process exits. The downside of this is that you will need to restart teststand whenever you rebuild your dll. You might also try calling loadlibrary on the borland dll instead (i.e. call LoadLibrary with "borlandmm.dll" after it's first loaded), that way your dll will still be unloadable, however this might not address the problem, depending on where the issue is.

 

Hope this helps,

-Doug

0 Kudos
Message 7 of 9
(5,831 Views)

Hi Allan,

 

Did any of Doug's suggestions help, or are you still having the issue?

Regards,
Eirikur Runarsson
0 Kudos
Message 8 of 9
(5,780 Views)

Hi,

 

I looks like that it was the borlndmm.dll that was causing me the trouble.

I have removed references to this in my project and now it seems more stable.

 

Regards,

 

Allan

0 Kudos
Message 9 of 9
(5,599 Views)