summaryrefslogtreecommitdiff
path: root/kernel/testcases/dma/user-space/dma.c
blob: 97b857266525bd53a405e5dcabe8387d5e885c94 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (C) 2010 ST-Ericsson
 * License terms: GNU General Public License (GPL) version 2
 *
 * Author: 2010, Martin Persson <martin.persson@stericsson.com>,
 * Jonas Aaberg <jonas.aberg@stericsson.com>
 */

#include "test.h"
#include "usctest.h"

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

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

#include <linux/input.h>



/* Extern Global Variables */
extern int Tst_count;		/* counter for tst_xxx routines.         */
extern char *TESTDIR;		/* temporary dir created by tst_tmpdir() */

/* Global Variables */
char *TCID = "dma";

int test_cases[] = {
	22, 23, 24, 25, 1, 2, 3, 4, 6, 7, 8,
	21, 15, 16, 17, 18, 19, 20, 21, 55, 56,
	57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
	67, 68,

	/* run long tests near the end */
	26, 7, 32, 33, 5, 34, 27, 28, 29,

	/*
	 * The following fail:
	 *
	 * This due to hardware error V1, should be fixed in V2:
	 * 30, 31, 35, 51
	 *
	 * These fail due to unknown reason:
	 * 9
	 */
};

/* total number of tests in this file. */
int TST_TOTAL = sizeof(test_cases);

static int dma_test(int id)
{
	int fd = 0, size, err = 0;
	char fname[256], buff[256], answer[256];

	sprintf(fname, "/sys/kernel/debug/ste_dma40_test/test_%d", id);

	fd = open(fname, O_RDONLY);

	if (fd < 0) {
		err = -1;
		goto _exit;
	}
	memset(buff, 0, 256);
	size = read(fd, buff, 255);
	if (size <= 0) {
		err = -2;
		goto _exit;
	}

	sprintf(answer, "Finished test %d: OK\n", id);
	if (size != strlen(answer)) {
		printf("DMA testcase %d failed\n", id);
		err = -3;
		goto _exit;
	}

	if (strncmp(buff, answer, strlen(answer))) {
		printf("DMA testcase %d failed\n", id);
		err = -4;
	}

_exit:
	if (fd > 0)
		close(fd);

	return err;
}

static int n_opt;
static char *n_copt;
static int testnum;

static option_t options[] = {
	{ "n:", &n_opt, &n_copt },
	{ },
};

int main(int argc, char **argv)
{

	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
    int count;      /* test case loop counter */

	/***************************************************************
	 * parse standard options
	 ***************************************************************/
	if ((msg = parse_opts(argc, argv, options, NULL)) != (char *) NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();
	}

	if (n_opt) {
		testnum = atoi(n_copt);
		TST_TOTAL = 1;
	}

	system("modprobe stedma40_test");

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/***************************************************************
		 * only perform functional verification if flag set (-f not given)
		 ***************************************************************/
		if (STD_FUNCTIONAL_TEST) {

			for (count = 0; count < TST_TOTAL; count++) {
				int num;

				num = TST_TOTAL == 1 ?
				      testnum : test_cases[Tst_count];

                # tst_xxx will use Tst_count as test nr
                Tst_count = num -1;

				TEST(dma_test(num));

				if (TEST_RETURN == 0)
					tst_resm(TPASS, "Functional test %d OK\n", num);
				else
					tst_resm(TFAIL, "Return value: %d. TCID: %s (%d) File: %s Line: %d. errno=%d : %s \n",
						 TEST_RETURN, TCID, num, __FILE__, __LINE__,
						 TEST_ERRNO, strerror(TEST_ERRNO));

			}
		}
	}

	system("modprobe -r stedma40_test");

	tst_exit();
	return 0;
}