Skip to content

Commit

Permalink
Include image driver tests in merge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Linas Beresna committed Jan 14, 2025
1 parent 9c2a2e1 commit f0a8f9f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/IECoreImage/DisplayDriverServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ IE_CORE_DEFINERUNTIMETYPED( DisplayDriverServer );
namespace
{

static DisplayDriverServer::MergeMap g_mergeMap;
DisplayDriverServer::MergeMap g_mergeMap;

/* Set the FD_CLOEXEC flag for the given socket descriptor, so that it will not exist on child processes.*/
static void fixSocketFlags( int socketDesc )
Expand Down
48 changes: 43 additions & 5 deletions test/IECoreImage/DisplayDriverServerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@

import unittest
import sys
import os
import imath

import IECore
import IECoreImage

class DisplayDriverServerTest( unittest.TestCase ) :

def __prepareBuf( self, buf, width, offset, red, green, blue ):
for i in range( 0, width ):
buf[3*i] = blue[i+offset]
buf[3*i+1] = green[i+offset]
buf[3*i+2] = red[i+offset]

def testPortNumber( self ) :

s1 = IECoreImage.DisplayDriverServer( 1559 )
Expand Down Expand Up @@ -122,22 +129,37 @@ def testPortRangeRegistry( self ) :
def testMergeMap( self ) :
server = IECoreImage.DisplayDriverServer( 45001 )

displayWindow = imath.Box2i( imath.V2i(0,0), imath.V2i(100,100) )
dataWindow = imath.Box2i( imath.V2i(0,0), imath.V2i(100,100) )
img = IECore.Reader.create( os.path.join( "test", "IECoreImage", "data", "tiff", "bluegreen_noise.400x300.tif" ) )()
self.assertEqual( img.keys(), [ 'B', 'G', 'R' ] )
red = img['R']
green = img['G']
blue = img['B']
width = img.dataWindow.max().x - img.dataWindow.min().x + 1

params = IECore.CompoundData()
params['displayHost'] = IECore.StringData('localhost')
params['displayPort'] = IECore.StringData( '45001' )
params['displayDriverServer:mergeId'] = IECore.IntData( 42 )
params['displayDriverServer:mergeClients'] = IECore.IntData( 2 )
params["remoteDisplayType"] = IECore.StringData( "ImageDisplayDriver" )
params["handle"] = IECore.StringData( "myHandle1" )

idd1 = IECoreImage.ClientDisplayDriver( img.displayWindow, img.dataWindow, list( img.channelNames() ), params )

idd1 = IECoreImage.ClientDisplayDriver( displayWindow, dataWindow, list( ["R", "G"] ), params )
idd2 = IECoreImage.ClientDisplayDriver( displayWindow, dataWindow, list( ["R", "G"] ), params )
params["handle"] = IECore.StringData( "myHandle2" )
idd2 = IECoreImage.ClientDisplayDriver( img.displayWindow, img.dataWindow, list( img.channelNames() ), params )

params['displayDriverServer:mergeId'] = IECore.IntData( 666 )
params['displayDriverServer:mergeClients'] = IECore.IntData( 1 )
idd3 = IECoreImage.ClientDisplayDriver( displayWindow, dataWindow, list( ["R", "G"] ), params )
params["handle"] = IECore.StringData( "myHandle3" )
idd3 = IECoreImage.ClientDisplayDriver( img.displayWindow, img.dataWindow, list( img.channelNames() ), params )

buf = IECore.FloatVectorData( width * 3 )
for i in range( 0, img.dataWindow.max().y - img.dataWindow.min().y + 1 ):
self.__prepareBuf( buf, width, i*width, red, green, blue )
idd1.imageData( imath.Box2i( imath.V2i( img.dataWindow.min().x, i + img.dataWindow.min().y ), imath.V2i( img.dataWindow.max().x, i + img.dataWindow.min().y) ), buf )
idd2.imageData( imath.Box2i( imath.V2i( img.dataWindow.min().x, i + img.dataWindow.min().y ), imath.V2i( img.dataWindow.max().x, i + img.dataWindow.min().y) ), buf )
idd3.imageData( imath.Box2i( imath.V2i( img.dataWindow.min().x, i + img.dataWindow.min().y ), imath.V2i( img.dataWindow.max().x, i + img.dataWindow.min().y) ), buf )

# Test that the merge map has merge id 42 and that there are two clients
mergeDriverInfo = IECoreImage.DisplayDriverServer.getMergeDriverInfo( 42 )
Expand All @@ -158,6 +180,22 @@ def testMergeMap( self ) :

idd3.imageClose()

newImg = IECoreImage.ImageDisplayDriver.removeStoredImage( "myHandle1" )
newImg2 = IECoreImage.ImageDisplayDriver.removeStoredImage( "myHandle2" )
newImg3 = IECoreImage.ImageDisplayDriver.removeStoredImage( "myHandle3" )

# merge drivers share the same display driver - so second image should be none,
# as there is no image drivere associated with it.
self.assertIsNone( newImg2 )

# remove blindData for comparison
newImg.blindData().clear()
img.blindData().clear()
self.assertEqual( newImg, img )

newImg3.blindData().clear()
self.assertEqual( newImg3, img )

server = None

if __name__ == "__main__":
Expand Down

0 comments on commit f0a8f9f

Please sign in to comment.