r300g/tests: Added missing fclose for FILE resource.
[mesa.git] / src / gallium / drivers / r300 / compiler / tests / radeon_compiler_regalloc_tests.c
1 /*
2 * Copyright 2013 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Tom Stellard <thomas.stellard@amd.com>
24 */
25
26 #include "radeon_program_pair.h"
27
28 #include "r300_compiler_tests.h"
29 #include "rc_test_helpers.h"
30 #include "unit_test.h"
31
32 static void dummy_allocate_hw_inputs(
33 struct r300_fragment_program_compiler * c,
34 void (*allocate)(void * data, unsigned input, unsigned hwreg),
35 void * mydata)
36 {
37 unsigned i;
38 for (i = 0; i < 10; i++) {
39 allocate(mydata, i, i);
40 }
41 }
42
43 static void test_runner_rc_regalloc(
44 struct test_result *result,
45 struct radeon_compiler *c,
46 const char *filename)
47 {
48 struct rc_test_file test_file;
49 unsigned optimizations = 1;
50 unsigned do_full_regalloc = 1;
51 struct rc_instruction *inst;
52 unsigned pass = 1;
53
54 test_begin(result);
55
56 if (!load_program(c, &test_file, filename)) {
57 fprintf(stderr, "Failed to load program\n");
58 }
59
60 rc_pair_translate(c, NULL);
61 rc_pair_schedule(c, &optimizations);
62 rc_pair_remove_dead_sources(c, NULL);
63 rc_pair_regalloc(c, &do_full_regalloc);
64
65 for(inst = c->Program.Instructions.Next;
66 inst != &c->Program.Instructions;
67 inst = inst->Next) {
68 if (inst->Type == RC_INSTRUCTION_NORMAL &&
69 inst->U.I.Opcode != RC_OPCODE_BEGIN_TEX) {
70 if (GET_SWZ(inst->U.I.SrcReg[0].Swizzle, 0)
71 != RC_SWIZZLE_X) {
72 pass = 0;
73 }
74 }
75 }
76
77 test_check(result, pass);
78 }
79
80 static void tex_1d_swizzle(struct test_result *result)
81 {
82 struct r300_fragment_program_compiler c;
83
84 memset(&c, 0, sizeof(c));
85 init_compiler(&c.Base, RC_FRAGMENT_PROGRAM, 0, 0);
86 c.AllocateHwInputs = dummy_allocate_hw_inputs;
87
88 test_runner_rc_regalloc(result, &c.Base, "regalloc_tex_1d_swizzle.test");
89 }
90
91 unsigned radeon_compiler_regalloc_run_tests()
92 {
93 static struct test tests[] = {
94 {"rc_pair_regalloc() => TEX 1D Swizzle - r300", tex_1d_swizzle },
95 {NULL, NULL}
96 };
97 return run_tests(tests);
98 }