blob: 3b85cea1755221c97bcb808777fee25b1629b7dc [file] [log] [blame]
subrata_modak1d7034b2009-04-15 06:32:35 +00001/******************************************************************************/
2/* Copyright (c) Maxin John <maxin.john@gmail.com>, 2009 */
3/* LKML Reference: http://lkml.org/lkml/2009/4/9/203 */
4/* This program is free software; you can redistribute it and/or modify */
5/* it under the terms of the GNU General Public License as published by */
6/* the Free Software Foundation; either version 2 of the License, or */
7/* (at your option) any later version. */
8/* */
9/* This program is distributed in the hope that it will be useful, */
10/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
12/* the GNU General Public License for more details. */
13/* */
14/* You should have received a copy of the GNU General Public License */
15/* along with this program; if not, write to the Free Software */
16/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: cacheflush01.c */
22/* */
23/* Description: The cacheflush_check() syscall */
24/* Tests EINVAL error of cacheflush system call. */
25/* Its expected behaviour is cacheflush() should return -EINVAL */
26/* when cache parameter is not one of ICACHE, DCACHE, or BCACHE. */
27/* */
28/* Usage: <for command-line> */
29/* cacheflush01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
30/* where, -c n : Run n copies concurrently. */
31/* -e : Turn on errno logging. */
32/* -i n : Execute test n times. */
33/* -I x : Execute test for x seconds. */
34/* -P x : Pause for x seconds between iterations. */
35/* -t : Turn on syscall timing. */
36/* */
37/* Total Tests: 1 */
38/* */
39/* Test Name: cacheflush01 */
40/******************************************************************************/
41
subrata_modak1d7034b2009-04-15 06:32:35 +000042#include <unistd.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <errno.h>
46
yaberauneyae70b30b2009-11-27 07:40:16 +000047/* cacheflush man page states that cacheflush() is only applicable to
48 * MIPS architecture -- regardless, it's a good negative test.. */
subrata_modak1d7034b2009-04-15 06:32:35 +000049
50#ifndef ICACHE
yaberauneyae70b30b2009-11-27 07:40:16 +000051#define ICACHE (1<<0) /* flush instruction cache */
subrata_modak1d7034b2009-04-15 06:32:35 +000052#endif
53#ifndef DCACHE
yaberauneyae70b30b2009-11-27 07:40:16 +000054#define DCACHE (1<<1) /* writeback and flush data cache */
subrata_modak1d7034b2009-04-15 06:32:35 +000055#endif
56#ifndef BCACHE
yaberauneyae70b30b2009-11-27 07:40:16 +000057#define BCACHE (ICACHE|DCACHE) /* flush both caches */
subrata_modak1d7034b2009-04-15 06:32:35 +000058#endif
59
60/* Harness Specific Incnude Files. */
61#include "test.h"
62#include "usctest.h"
63#include "linux_syscall_numbers.h"
64
yaberauneyae70b30b2009-11-27 07:40:16 +000065/* cacheflush man page states that cacheflush() is only applicable to
66 * MIPS architecture -- regardless, it's a good negative test.. */
67#if defined __mips__
68#include <asm/cachectl.h>
Garrett Cooperc9bccfa2010-09-16 21:49:00 -070069#ifndef __NR_cacheflush
70#define __NR_cacheflush 0
71#endif
yaberauneyae70b30b2009-11-27 07:40:16 +000072#else
73/* Fake linux_syscall_numbers.h */
74#define __NR_cacheflush 0
75#endif
76
subrata_modak1d7034b2009-04-15 06:32:35 +000077/* Extern Global Variables */
78extern int Tst_count; /* counter for tst_xxx routines. */
79extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */
80
81/* Global Variables */
yaberauneyae70b30b2009-11-27 07:40:16 +000082char *TCID = "cacheflush01"; /* Test program identifier.*/
83int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modak1d7034b2009-04-15 06:32:35 +000084
subrata_modak1d7034b2009-04-15 06:32:35 +000085/* Extern Global Functions */
86/******************************************************************************/
87/* */
88/* Function: cleanup */
89/* */
90/* Description: Performs all one time clean up for this test on successful */
91/* completion, premature exit or failure. Closes all temporary */
92/* files, removes all temporary directories exits the test with */
93/* appropriate return code by calling tst_exit() function. */
94/* */
95/* Input: None. */
96/* */
97/* Output: None. */
98/* */
99/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
100/* On success - Exits calling tst_exit(). With '0' return code. */
101/* */
102/******************************************************************************/
103extern void cleanup() {
104 /* Remove tmp dir and all files in it */
105 TEST_CLEANUP;
106 tst_rmdir();
subrata_modak1d7034b2009-04-15 06:32:35 +0000107}
108
109/* Local Functions */
110/******************************************************************************/
111/* */
112/* Function: setup */
113/* */
114/* Description: Performs all one time setup for this test. This function is */
115/* typically used to capture signals, create temporary dirs */
116/* and temporary files that may be used in the course of this */
117/* test. */
118/* */
119/* Input: None. */
120/* */
121/* Output: None. */
122/* */
123/* Return: On failure - Exits by calling cleanup(). */
124/* On success - returns 0. */
125/* */
126/******************************************************************************/
127void setup() {
128 /* Capture signals if any */
129 /* Create temporary directories */
130 TEST_PAUSE;
131 tst_tmpdir();
132}
133
yaberauneyae70b30b2009-11-27 07:40:16 +0000134int main(int ac, char **av)
135{
subrata_modak1d7034b2009-04-15 06:32:35 +0000136
subrata_modak1d7034b2009-04-15 06:32:35 +0000137 char *addr = NULL;
subrata_modak1d7034b2009-04-15 06:32:35 +0000138 char *msg; /* message returned from parse_opts */
139
140 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -0800141 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL){
Garrett Cooper60fa8012010-11-22 13:50:58 -0800142 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
yaberauneyae70b30b2009-11-27 07:40:16 +0000143 tst_exit();
144 }
subrata_modak1d7034b2009-04-15 06:32:35 +0000145
146 setup();
147
yaberauneyae70b30b2009-11-27 07:40:16 +0000148 Tst_count = 0;
149 /* Create some user address range */
150 addr = malloc(getpagesize());
151 if (addr == NULL) {
152 tst_brkm(TFAIL | TTERRNO, cleanup, "malloc failed");
153 }
subrata_modak1d7034b2009-04-15 06:32:35 +0000154
yaberauneyae70b30b2009-11-27 07:40:16 +0000155 /* Invokes cacheflush() with proper parameters */
156 TEST(syscall(__NR_cacheflush, addr, getpagesize(), ICACHE));
Garrett Cooperdd59d492010-08-31 23:09:49 -0700157 if (TEST_RETURN == 0) {
158 tst_resm(TPASS, "passed with no errno");
yaberauneyae70b30b2009-11-27 07:40:16 +0000159 } else {
Garrett Cooperdd59d492010-08-31 23:09:49 -0700160 tst_resm(TFAIL, "failed with unexpected errno");
161 }
162
163 TEST(syscall(__NR_cacheflush, addr, getpagesize(), DCACHE));
164 if (TEST_RETURN == 0) {
165 tst_resm(TPASS, "passed with no errno");
166 } else {
167 tst_resm(TFAIL, "failed with unexpected errno");
168 }
169
170 TEST(syscall(__NR_cacheflush, addr, getpagesize(), BCACHE));
171 if (TEST_RETURN == 0) {
172 tst_resm(TPASS, "passed with no errno");
173 } else {
174 tst_resm(TFAIL, "failed with unexpected errno");
175 }
176
yaberauneyae70b30b2009-11-27 07:40:16 +0000177 cleanup();
subrata_modak1d7034b2009-04-15 06:32:35 +0000178 tst_exit();
179}