From 3cd2caad2bd4717c7087519639f4b52b1105943a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 23 Jan 2018 10:53:40 +1000 Subject: [PATCH] tests: refactor caps getting code out. This just makes getting caps be common code. Signed-off-by: Dave Airlie --- tests/testvirgl.c | 55 +++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/tests/testvirgl.c b/tests/testvirgl.c index f610c33..b1f77f0 100644 --- a/tests/testvirgl.c +++ b/tests/testvirgl.c @@ -267,47 +267,42 @@ int testvirgl_create_backed_simple_buffer(struct virgl_resource *res, return 0; } -uint32_t testvirgl_get_glsl_level_from_caps(void) +static void *get_caps(void) { - uint32_t max_ver, max_size, glsl_level; - void *caps; - - virgl_renderer_get_cap_set(1, &max_ver, &max_size); - ck_assert_int_eq(max_ver, 1); - ck_assert_int_ne(max_size, 0); - ck_assert_int_eq(max_size, sizeof(struct virgl_caps_v1)); + uint32_t max_ver, max_size, glsl_level; + void *caps; - caps = malloc(max_size); + virgl_renderer_get_cap_set(1, &max_ver, &max_size); + ck_assert_int_eq(max_ver, 1); + ck_assert_int_ne(max_size, 0); + ck_assert_int_eq(max_size, sizeof(struct virgl_caps_v1)); + caps = malloc(max_size); - virgl_renderer_fill_caps(0, 0, caps); + virgl_renderer_fill_caps(0, 0, caps); + return caps; +} - struct virgl_caps_v1 *v1 = (struct virgl_caps_v1*) caps; - glsl_level = v1->glsl_level; +uint32_t testvirgl_get_glsl_level_from_caps(void) +{ + uint32_t glsl_level; + void *caps = get_caps(); + struct virgl_caps_v1 *v1 = (struct virgl_caps_v1*) caps; + glsl_level = v1->glsl_level; - free(caps); + free(caps); - return glsl_level; + return glsl_level; } unsigned testvirgl_get_multisample_from_caps(void) { - uint32_t max_ver, max_size; - unsigned multisample; - void *caps; - - virgl_renderer_get_cap_set(1, &max_ver, &max_size); - ck_assert_int_eq(max_ver, 1); - ck_assert_int_ne(max_size, 0); - ck_assert_int_eq(max_size, sizeof(struct virgl_caps_v1)); - - caps = malloc(max_size); - - virgl_renderer_fill_caps(0, 0, caps); + void *caps = get_caps(); + unsigned multisample; - struct virgl_caps_v1 *v1 = (struct virgl_caps_v1*) caps; - multisample = v1->bset.texture_multisample; + struct virgl_caps_v1 *v1 = (struct virgl_caps_v1*) caps; + multisample = v1->bset.texture_multisample; - free(caps); + free(caps); - return multisample; + return multisample; }