2017-02-13 17:15:28 +00:00
/*
2019-05-28 10:29:49 +01:00
* SPDX - License - Identifier : MIT
2017-02-13 17:15:28 +00:00
*
2019-05-28 10:29:49 +01:00
* Copyright © 2016 Intel Corporation
2017-02-13 17:15:28 +00:00
*/
2019-05-28 10:29:49 +01:00
# include "i915_selftest.h"
2017-02-13 17:15:28 +00:00
2017-02-13 17:15:31 +00:00
# include "huge_gem_object.h"
2019-05-28 10:29:49 +01:00
# include "selftests/igt_flush_test.h"
# include "selftests/mock_gem_device.h"
2017-02-13 17:15:28 +00:00
static int igt_gem_object ( void * arg )
{
struct drm_i915_private * i915 = arg ;
struct drm_i915_gem_object * obj ;
2020-04-09 14:31:07 +01:00
int err ;
2017-02-13 17:15:28 +00:00
/* Basic test to ensure we can create an object */
2019-05-28 10:29:45 +01:00
obj = i915_gem_object_create_shmem ( i915 , PAGE_SIZE ) ;
2017-02-13 17:15:28 +00:00
if ( IS_ERR ( obj ) ) {
err = PTR_ERR ( obj ) ;
pr_err ( " i915_gem_object_create failed, err=%d \n " , err ) ;
goto out ;
}
err = 0 ;
i915_gem_object_put ( obj ) ;
out :
return err ;
}
2017-02-13 17:15:29 +00:00
static int igt_gem_huge ( void * arg )
{
const unsigned int nreal = 509 ; /* just to be awkward */
struct drm_i915_private * i915 = arg ;
struct drm_i915_gem_object * obj ;
unsigned int n ;
int err ;
/* Basic sanitycheck of our huge fake object allocation */
obj = huge_gem_object ( i915 ,
nreal * PAGE_SIZE ,
2018-06-05 16:37:58 +01:00
i915 - > ggtt . vm . total + PAGE_SIZE ) ;
2017-02-13 17:15:29 +00:00
if ( IS_ERR ( obj ) )
return PTR_ERR ( obj ) ;
err = i915_gem_object_pin_pages ( obj ) ;
if ( err ) {
pr_err ( " Failed to allocate %u pages (%lu total), err=%d \n " ,
nreal , obj - > base . size / PAGE_SIZE , err ) ;
goto out ;
}
for ( n = 0 ; n < obj - > base . size / PAGE_SIZE ; n + + ) {
if ( i915_gem_object_get_page ( obj , n ) ! =
i915_gem_object_get_page ( obj , n % nreal ) ) {
pr_err ( " Page lookup mismatch at index %u [%u] \n " ,
n , n % nreal ) ;
err = - EINVAL ;
goto out_unpin ;
}
}
out_unpin :
i915_gem_object_unpin_pages ( obj ) ;
out :
i915_gem_object_put ( obj ) ;
return err ;
}
2017-02-13 17:15:28 +00:00
int i915_gem_object_mock_selftests ( void )
{
static const struct i915_subtest tests [ ] = {
SUBTEST ( igt_gem_object ) ,
} ;
struct drm_i915_private * i915 ;
int err ;
i915 = mock_gem_device ( ) ;
if ( ! i915 )
return - ENOMEM ;
err = i915_subtests ( tests , i915 ) ;
2018-06-18 13:01:54 +02:00
drm_dev_put ( & i915 - > drm ) ;
2017-02-13 17:15:28 +00:00
return err ;
}
2017-02-13 17:15:29 +00:00
int i915_gem_object_live_selftests ( struct drm_i915_private * i915 )
{
static const struct i915_subtest tests [ ] = {
SUBTEST ( igt_gem_huge ) ,
} ;
return i915_subtests ( tests , i915 ) ;
}