summaryrefslogtreecommitdiffstats
path: root/tests.c
blob: 6f6f818ac4ade8b3bd12ef58b0b34bcf3eb907f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 *  Run some tests
 *
 *  (C) Copyright 2001-2003 Geert Uytterhoeven
 *
 *  This file is subject to the terms and conditions of the GNU General Public
 *  License. See the file COPYING in the main directory of this archive for
 *  more details.
 */

#include <stdio.h>
#include <string.h>

#include "types.h"
#include "fb.h"
#include "visual.h"
#include "test.h"
#include "util.h"


static const struct test *all_tests[] = {
    &test001,
    &test002,
    &test003,
    &test004,
    &test005,
    &test006,
    &test007,
    &test008,
    &test009,
    &test010,
    &test011,
    &test012,
    &test013,
    NULL
};


    /*
     *  Run one test
     */

#define TEST_REQ_MIN(reqname, varname)				\
    if (test->reqs & REQF_ ## reqname) {			\
	if (varname < test->reqname) {				\
	    Debug("Requirement " #reqname " >= %d not met\n",	\
		  test->reqname);				\
	    return;						\
	}							\
    }

static void run_one_test(const struct test *test)
{
    enum test_res res;

    Debug("Running test %s\n", test->name);

    if (test->visual != VISUAL_NONE && !visual_set(test->visual)) {
	Debug("Visual %d not supported\n", test->visual);
	return;
    }

    TEST_REQ_MIN(bits_per_pixel, fb_var.bits_per_pixel);
    TEST_REQ_MIN(num_colors, idx_len);
    TEST_REQ_MIN(red_length, fb_var.red.length);
    TEST_REQ_MIN(green_length, fb_var.green.length);
    TEST_REQ_MIN(blue_length, fb_var.blue.length);
    TEST_REQ_MIN(transp_length, fb_var.transp.length);
    TEST_REQ_MIN(xres, fb_var.xres);
    TEST_REQ_MIN(yres, fb_var.yres);
    if (test->reqs & REQF_panning) {
	if (!(fb_fix.xpanstep && fb_var.xres_virtual-fb_var.xres) &&
	    !(fb_fix.ypanstep && fb_var.yres_virtual-fb_var.yres)) {
	    Debug("No support for virtual screen and panning\n");
	    return;
	}
    }

    res = test->func();
    switch (res) {
	case TEST_OK:
	    Message("%s: PASSED\n", test->name);
	    break;

	case TEST_FAIL:
	    Error("%s: FAILED\n", test->name);
	    break;

	case TEST_NA:
	    Debug("Not applicable\n");
	    break;

	default:
	    Fatal("%s returned unknown code %d\n", test->name, res);
	    break;
    }
}

#undef TEST_REQ_MIN


    /*
     *  Test run
     */

void test_run(const char *name)
{
    int i;

    for (i = 0; all_tests[i]; i++)
	if (!name || !strcmp(all_tests[i]->name, name))
	    run_one_test(all_tests[i]);
}


    /*
     *  List all tests
     */

void test_list(const char *name, int verbose)
{
    int i;
    const struct test *test;

    for (i = 0; all_tests[i]; i++)
	if (!name || !strcmp(all_tests[i]->name, name)) {
	    test = all_tests[i];
	    printf("%s: %s\n", test->name, test->desc);
	}
}