lib/os: Pust igt_require into memory check function

More in line with the usual igt pattern and simplifies the code -
every called just wrapped it in igt_require.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
This commit is contained in:
Daniel Vetter 2014-11-17 14:43:33 +01:00
parent aa63fc740c
commit a535cdedfb
10 changed files with 27 additions and 34 deletions

View File

@ -82,7 +82,7 @@ uint64_t intel_get_avail_ram_mb(void);
uint64_t intel_get_total_ram_mb(void); uint64_t intel_get_total_ram_mb(void);
uint64_t intel_get_total_swap_mb(void); uint64_t intel_get_total_swap_mb(void);
bool intel_check_memory(uint32_t count, uint32_t size, unsigned mode); void intel_require_memory(uint32_t count, uint32_t size, unsigned mode);
#define CHECK_RAM 0x1 #define CHECK_RAM 0x1
#define CHECK_SWAP 0x2 #define CHECK_SWAP 0x2

View File

@ -193,7 +193,7 @@ intel_get_total_swap_mb(void)
} }
/** /**
* intel_check_memory: * intel_require_memory:
* @count: number of surfaces that will be created * @count: number of surfaces that will be created
* @size: the size in bytes of each surface * @size: the size in bytes of each surface
* @mode: a bitfield declaring whether the test will be run in RAM or in SWAP * @mode: a bitfield declaring whether the test will be run in RAM or in SWAP
@ -209,11 +209,10 @@ intel_get_total_swap_mb(void)
* for their tests. oom-killer tests should only run if this reports that * for their tests. oom-killer tests should only run if this reports that
* there is not enough RAM + SWAP! * there is not enough RAM + SWAP!
* *
* Returns: * If there is not enough RAM this function calls igt_skip with an appropriate
* Whether the estimated amount of memory required for the objects * message. It only ever returns if the requirement is fullfilled.
* fits in the available memory on the system.
*/ */
bool intel_check_memory(uint32_t count, uint32_t size, unsigned mode) void intel_require_memory(uint32_t count, uint32_t size, unsigned mode)
{ {
/* rough estimate of how many bytes the kernel requires to track each object */ /* rough estimate of how many bytes the kernel requires to track each object */
#define KERNEL_BO_OVERHEAD 512 #define KERNEL_BO_OVERHEAD 512
@ -235,19 +234,13 @@ bool intel_check_memory(uint32_t count, uint32_t size, unsigned mode)
total += intel_get_total_swap_mb(); total += intel_get_total_swap_mb();
total *= 1024 * 1024; total *= 1024 * 1024;
if (total <= required) { igt_skip_on_f(total <= required,
igt_log(IGT_LOG_INFO, "Estimated that we need %llu bytes for the test, but only have %llu bytes available (%s%s)\n",
"Estimated that we need %llu bytes for the test, but only have %llu bytes available (%s%s)\n", (long long)required, (long long)total,
(long long)required, (long long)total, mode & (CHECK_RAM | CHECK_SWAP) ? "RAM" : "",
mode & (CHECK_RAM | CHECK_SWAP) ? "RAM" : "", mode & CHECK_SWAP ? " + swap": "");
mode & CHECK_SWAP ? " + swap": "");
return 0;
}
return 1;
} }
void void
intel_purge_vm_caches(void) intel_purge_vm_caches(void)
{ {

View File

@ -77,7 +77,7 @@ static int minor_evictions(int fd, struct igt_eviction_test_ops *ops,
total_surfaces = gem_aperture_size(fd) / surface_size + 1; total_surfaces = gem_aperture_size(fd) / surface_size + 1;
igt_require(nr_surfaces < total_surfaces); igt_require(nr_surfaces < total_surfaces);
igt_require(intel_check_memory(total_surfaces, surface_size, CHECK_RAM)); intel_require_memory(total_surfaces, surface_size, CHECK_RAM);
bo = malloc((nr_surfaces + total_surfaces)*sizeof(*bo)); bo = malloc((nr_surfaces + total_surfaces)*sizeof(*bo));
igt_assert(bo); igt_assert(bo);
@ -112,7 +112,7 @@ static int major_evictions(int fd, struct igt_eviction_test_ops *ops,
uint32_t *bo; uint32_t *bo;
int ret; int ret;
igt_require(intel_check_memory(nr_surfaces, surface_size, CHECK_RAM)); intel_require_memory(nr_surfaces, surface_size, CHECK_RAM);
bo = malloc(nr_surfaces*sizeof(*bo)); bo = malloc(nr_surfaces*sizeof(*bo));
igt_assert(bo); igt_assert(bo);
@ -141,12 +141,12 @@ static int swapping_evictions(int fd, struct igt_eviction_test_ops *ops,
uint32_t *bo; uint32_t *bo;
int i, n, pass, ret; int i, n, pass, ret;
igt_require(intel_check_memory(working_surfaces, surface_size, CHECK_RAM)); intel_require_memory(working_surfaces, surface_size, CHECK_RAM);
if (trash_surfaces < working_surfaces) if (trash_surfaces < working_surfaces)
trash_surfaces = working_surfaces; trash_surfaces = working_surfaces;
igt_require(intel_check_memory(trash_surfaces, surface_size, CHECK_RAM | CHECK_SWAP)); intel_require_memory(trash_surfaces, surface_size, CHECK_RAM | CHECK_SWAP);
bo = malloc(trash_surfaces*sizeof(*bo)); bo = malloc(trash_surfaces*sizeof(*bo));
igt_assert(bo); igt_assert(bo);
@ -179,7 +179,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
int num_threads = sysconf(_SC_NPROCESSORS_ONLN); int num_threads = sysconf(_SC_NPROCESSORS_ONLN);
int bo_count; int bo_count;
igt_require(intel_check_memory(working_surfaces, surface_size, CHECK_RAM)); intel_require_memory(working_surfaces, surface_size, CHECK_RAM);
if (flags & FORKING_EVICTIONS_SWAPPING) { if (flags & FORKING_EVICTIONS_SWAPPING) {
bo_count = trash_surfaces; bo_count = trash_surfaces;
@ -190,7 +190,7 @@ static int forking_evictions(int fd, struct igt_eviction_test_ops *ops,
bo_count = working_surfaces; bo_count = working_surfaces;
igt_assert(working_surfaces <= bo_count); igt_assert(working_surfaces <= bo_count);
igt_require(intel_check_memory(bo_count, surface_size, CHECK_RAM | CHECK_SWAP)); intel_require_memory(bo_count, surface_size, CHECK_RAM | CHECK_SWAP);
bo = malloc(bo_count*sizeof(*bo)); bo = malloc(bo_count*sizeof(*bo));
igt_assert(bo); igt_assert(bo);

View File

@ -183,7 +183,7 @@ igt_simple_main
if (igt_run_in_simulation()) if (igt_run_in_simulation())
count = 10; count = 10;
igt_require(intel_check_memory(1+count, 4096, CHECK_RAM)); intel_require_memory(1+count, 4096, CHECK_RAM);
handles = malloc (count * sizeof(uint32_t)); handles = malloc (count * sizeof(uint32_t));
igt_assert(handles); igt_assert(handles);

View File

@ -134,7 +134,7 @@ static void minor_evictions(int fd, int size, int count)
uint32_t *bo, *sel; uint32_t *bo, *sel;
int n, m, alignment, pass, fail; int n, m, alignment, pass, fail;
igt_require(intel_check_memory(2*count, size, CHECK_RAM)); intel_require_memory(2 * count, size, CHECK_RAM);
bo = malloc(3*count*sizeof(*bo)); bo = malloc(3*count*sizeof(*bo));
igt_assert(bo); igt_assert(bo);
@ -164,7 +164,7 @@ static void major_evictions(int fd, int size, int count)
int n, m, loop, alignment, max; int n, m, loop, alignment, max;
uint32_t *bo; uint32_t *bo;
igt_require(intel_check_memory(count, size, CHECK_RAM)); intel_require_memory(count, size, CHECK_RAM);
bo = malloc(count*sizeof(*bo)); bo = malloc(count*sizeof(*bo));
igt_assert(bo); igt_assert(bo);

View File

@ -151,7 +151,7 @@ static void test_forking_evictions(int fd, int size, int count,
int trash_count; int trash_count;
trash_count = intel_get_total_ram_mb() * 11 / 10; trash_count = intel_get_total_ram_mb() * 11 / 10;
igt_require(intel_check_memory(trash_count, size, CHECK_RAM | CHECK_SWAP)); intel_require_memory(trash_count, size, CHECK_RAM | CHECK_SWAP);
forking_evictions(fd, &fault_ops, size, count, trash_count, flags); forking_evictions(fd, &fault_ops, size, count, trash_count, flags);
} }
@ -161,7 +161,7 @@ static void test_swapping_evictions(int fd, int size, int count)
int trash_count; int trash_count;
trash_count = intel_get_total_ram_mb() * 11 / 10; trash_count = intel_get_total_ram_mb() * 11 / 10;
igt_require(intel_check_memory(trash_count, size, CHECK_RAM | CHECK_SWAP)); intel_require_memory(trash_count, size, CHECK_RAM | CHECK_SWAP);
swapping_evictions(fd, &fault_ops, size, count, trash_count); swapping_evictions(fd, &fault_ops, size, count, trash_count);
} }

View File

@ -268,7 +268,7 @@ int main(int argc, char **argv)
count = 3 * gem_aperture_size(fd) / (1024*1024) / 2; count = 3 * gem_aperture_size(fd) / (1024*1024) / 2;
igt_require(count > 1); igt_require(count > 1);
igt_require(intel_check_memory(count, sizeof(linear), CHECK_RAM)); intel_require_memory(count, sizeof(linear), CHECK_RAM);
run_test(fd, count); run_test(fd, count);
} }
@ -279,7 +279,7 @@ int main(int argc, char **argv)
count = 3 * gem_aperture_size(fd) / (1024*1024) / 2; count = 3 * gem_aperture_size(fd) / (1024*1024) / 2;
igt_require(count > 1); igt_require(count > 1);
igt_require(intel_check_memory(count, sizeof(linear), CHECK_RAM)); intel_require_memory(count, sizeof(linear), CHECK_RAM);
igt_fork_signal_helper(); igt_fork_signal_helper();
run_test(fd, count); run_test(fd, count);
igt_stop_signal_helper(); igt_stop_signal_helper();

View File

@ -218,7 +218,7 @@ int main(int argc, char **argv)
count = 3 * gem_aperture_size(fd) / (1024*1024) / 2; count = 3 * gem_aperture_size(fd) / (1024*1024) / 2;
count += (count & 1) == 0; count += (count & 1) == 0;
igt_require(intel_check_memory(count, 1024*1024, CHECK_RAM)); intel_require_memory(count, 1024*1024, CHECK_RAM);
run_test(count); run_test(count);
} }
@ -230,7 +230,7 @@ int main(int argc, char **argv)
count = 3 * gem_aperture_size(fd) / (1024*1024) / 2; count = 3 * gem_aperture_size(fd) / (1024*1024) / 2;
count += (count & 1) == 0; count += (count & 1) == 0;
igt_require(intel_check_memory(count, 1024*1024, CHECK_RAM)); intel_require_memory(count, 1024*1024, CHECK_RAM);
igt_fork_signal_helper(); igt_fork_signal_helper();
run_test(count); run_test(count);

View File

@ -169,7 +169,7 @@ igt_simple_main
(long)intel_get_avail_ram_mb(), (long)intel_get_avail_ram_mb(),
(long)intel_get_total_ram_mb(), (long)intel_get_total_ram_mb(),
(long)intel_get_total_swap_mb()); (long)intel_get_total_swap_mb());
igt_require(intel_check_memory(count, 1024*1024, CHECK_RAM | CHECK_SWAP)); intel_require_memory(count, 1024*1024, CHECK_RAM | CHECK_SWAP);
for (n = 0; n < count; n++) { for (n = 0; n < count; n++) {
bo_handles[n] = create_bo_and_fill(fd); bo_handles[n] = create_bo_and_fill(fd);

View File

@ -891,7 +891,7 @@ static int test_coherency(int fd, int count)
uint32_t start = 0; uint32_t start = 0;
int i, ret; int i, ret;
igt_require(intel_check_memory(count, sizeof(linear), CHECK_RAM)); intel_require_memory(count, sizeof(linear), CHECK_RAM);
igt_info("Using 2x%d 1MiB buffers\n", count); igt_info("Using 2x%d 1MiB buffers\n", count);
ret = posix_memalign((void **)&memory, PAGE_SIZE, count*sizeof(linear)); ret = posix_memalign((void **)&memory, PAGE_SIZE, count*sizeof(linear));