1
votes

For the sake of testing a visual WPF control library which uses DirectX, I have created a few Unit Tests which create a DirectX scene, screenshot, then compare vs. expected image.

I'm aware that this is a fragile unit testing technique (visual comparison) however it helps us to cover a large number of possible combinations.

The problem I have is the tests run locally just fine, but fail on the build server with error:

SharpDX.SharpDXException : HRESULT: [0x8876086A], Module: 
[SharpDX.Direct3D9], ApiCode: [D3DERR_NOTAVAILABLE/NotAvailable], Message: Unknown
   at SharpDX.Result.CheckError()
   at SharpDX.Direct3D9.D3D9.Create9Ex(Int32 sDKVersion, Direct3DEx arg1)
   at SharpDX.Direct3D9.Direct3DEx..ctor()

However, if I log in to the build server and run the tests, they pass! (See below)

Unit Tests when run on server - pass!

The build server is Windows Server 2012 R2 and has DirectX10 Warp (software) drivers.

I suspect that related to this issue here that the user profile of the team city build agent does not allow getting a DirectX device. I have changed the Teamcity service, and TeamCity build agents to log on as user but still no luck.

Any ideas?

1
Might be that the service needs to be allowed to interact with the desktop?rene
It's something like that. I don't know if it is a.) possible or not and b.) if possible, how to configure it.Dr. Andrew Burnett-Thompson
oo I just saw the checkbox in services -> Teamcity Build Agent -> Log on as! I will try it ...Dr. Andrew Burnett-Thompson
... No it still fails, same error, but you've given me something to search for ..Dr. Andrew Burnett-Thompson
It is not a 32/64 bit issue? I'm not sure if component registration is influenced by WOW redirection.rene

1 Answers

1
votes

To run tests that use a DirectX driver on a Teamcity agent, you must ensure that the service is running under a user account (eg. not the SYSTEM account that the agent service defaults to). Additionally, that account needs to be currently logged onto the agent computer. Without having the account logged in, there is no active desktop (which is required for DirectX initialization).

From the comments, it sounds like you have already found how to change the account the service runs as (eg. described in How can I change the user identity that runs a build agent in TeamCity?). To have the user account that the service is running as always login, you might consider configuring a Windows Automatic Login. You could also just login the computer manually, depending on your setup.

As an added tip, Remote Desktop can sometimes cause issues with the desktop of the logged in user, causing DirectX initialization failures. If you want to remote-view the agent, you can instead use VNC (or equivalent), which does not cause such issues.