1

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?

Community
  • 1
  • 1
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178

1 Answers1

1

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.

Community
  • 1
  • 1
MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • That's a great answer, but I tried that already. I have changed the Teamcity build agent and the service to run as user, enabled 'Allow local desktop interaction' and restarted the server. I then ran the teamcity job while logged in (as remote desktop). Tests failed :/ – Dr. Andrew Burnett-Thompson Oct 04 '16 at 12:46
  • You cannot login with remote desktop, as DirectX apps cannot run in a remote desktop session, it must be a local login. If you don't have physical access to the machine, you should consider the automatic login that I mentioned in my answer (which is a local login). – MuertoExcobito Oct 05 '16 at 03:39
  • That's actually partly untrue. As I mentioned in my question, I can log in to the server, run the tests locally (inside visual studio) and they pass. So the Visual Studio instance running on the build server is able to grab a DirectX device when logged in via Remote Desktop. Just teamcity agent can't (even though its login as user, with desktop interaction) :? – Dr. Andrew Burnett-Thompson Oct 05 '16 at 11:10
  • 1
    It appears there are some versions of Windows that do support DirectX through remote desktop, although, I've never had it work successfully. Perhaps your server and agent are running different versions, the server one is compatible, and the agent one is not? – MuertoExcobito Oct 07 '16 at 05:14
  • No, remote desktop to server and build agent are on the same physical machine. It's a strange one I'll give you that! – Dr. Andrew Burnett-Thompson Oct 07 '16 at 07:08