Squish/Hooking into Subprocesses: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Add "cleanup" tag)
m (style)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
[[Category:Squish]]
 
[[Category:Tools::Squish]]
 
= Hooking into slow-launching subprocesses on Windows =


Sometimes when writing Squish tests the application being tested launches a subprocess. In this short tip we'll see how to robustly connect to an externally launched subprocess on Windows.
Sometimes when writing Squish tests the application being tested launches a subprocess. In this short tip we'll see how to robustly connect to an externally launched subprocess on Windows.
Line 11: Line 7:
In any case, once the AUT has been modified to properly launch the subprocess, the squish test still needs to attach to the launching subprocess. If the AUT uses QProcess to launch the subprocess, it is enough to do:
In any case, once the AUT has been modified to properly launch the subprocess, the squish test still needs to attach to the launching subprocess. If the AUT uses QProcess to launch the subprocess, it is enough to do:


<code> subprocess = waitForApplicationLaunch()
<code> subprocess = waitForApplicationLaunch()</code>
</code>
However, if the squish IDE is set up to attach to the AUT manually, the desired call would be:
However, if the squish IDE is set up to attach to the AUT manually, the desired call would be:


<code> subprocess = attachToApplication( "APPNAME" )
<code> subprocess = attachToApplication( "APPNAME" )</code>
</code>
However, the attachToApplication() call will throw an exception if the subprocess is not ready. So, a more robust way to give the subprocess time to launch properly is to try again in a loop for a predetermined amount of time:
However, the attachToApplication() call will throw an exception if the subprocess is not ready. So, a more robust way to give the subprocess time to launch properly is to try again in a loop for a predetermined amount of time:


<code> subprocess = 0
<code>
count = 0
  subprocess = 0
while True:
  count = 0
if count > 30:
  while True:
raise RuntimeError( "Attaching to AUT subprocess failed!" )
    if count > 30:
try:
      raise RuntimeError( "Attaching to AUT subprocess failed!" )
subprocess = attachToApplication("APPNAME")
    try:
break
      subprocess = attachToApplication("APPNAME")
except:
      break
snooze(1)
    except:
count += 1</code>
      snooze(1)
    count += 1
</code>

Latest revision as of 17:23, 12 August 2020


Sometimes when writing Squish tests the application being tested launches a subprocess. In this short tip we'll see how to robustly connect to an externally launched subprocess on Windows.

As the froglogic Squish manual (section 17.7.1) explains, hooking into an AUT's subprocess when on windows is slightly more complex, as Squish is not able to use LD_PRELOAD (or DYLD_INSERT_LIBRARIES on OS X) to insert the squish library hook into the launching executable. Two options to get around this are clear—the AUT sourcecode can be modified to optionally insert "dllpreload.exe" into the subprocess launch (as the squish manual explains), or the AUT can be modified to call an external shell script that does the optional prepending of 'dllpreload.exe'.

In any case, once the AUT has been modified to properly launch the subprocess, the squish test still needs to attach to the launching subprocess. If the AUT uses QProcess to launch the subprocess, it is enough to do:

 subprocess = waitForApplicationLaunch()

However, if the squish IDE is set up to attach to the AUT manually, the desired call would be:

 subprocess = attachToApplication( "APPNAME" )

However, the attachToApplication() call will throw an exception if the subprocess is not ready. So, a more robust way to give the subprocess time to launch properly is to try again in a loop for a predetermined amount of time:

  subprocess = 0
  count = 0
  while True:
    if count > 30:
      raise RuntimeError( "Attaching to AUT subprocess failed!" )
    try:
      subprocess = attachToApplication("APPNAME")
      break
    except:
      snooze(1)
    count += 1