blob: d4d353fd156f69dcf3b1bff5d856b595607e9d9e [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 */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modak1d7034b2009-04-15 06:32:35 +000017/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: cacheflush01.c */
22/* */
Garrett Cooper2c282152010-12-16 00:55:50 -080023/* Description: The cacheflush_check() syscall */
24/* Tests EINVAL error of cacheflush system call. */
subrata_modak1d7034b2009-04-15 06:32:35 +000025/* 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
Francesco Rundo8255dcc2012-01-18 16:04:18 +010047#include "test.h"
48#include "usctest.h"
49#include "linux_syscall_numbers.h"
subrata_modak1d7034b2009-04-15 06:32:35 +000050
Francesco Rundo8255dcc2012-01-18 16:04:18 +010051#if defined __NR_cacheflush && __NR_cacheflush > 0
52#include <asm/cachectl.h>
53#else
54/* Fake linux_syscall_numbers.h */
55#define __NR_cacheflush 0
subrata_modak1d7034b2009-04-15 06:32:35 +000056#ifndef ICACHE
Wanlong Gao354ebb42012-12-07 10:10:04 +080057#define ICACHE (1<<0) /* flush instruction cache */
subrata_modak1d7034b2009-04-15 06:32:35 +000058#endif
59#ifndef DCACHE
Wanlong Gao354ebb42012-12-07 10:10:04 +080060#define DCACHE (1<<1) /* writeback and flush data cache */
subrata_modak1d7034b2009-04-15 06:32:35 +000061#endif
62#ifndef BCACHE
yaberauneyae70b30b2009-11-27 07:40:16 +000063#define BCACHE (ICACHE|DCACHE) /* flush both caches */
subrata_modak1d7034b2009-04-15 06:32:35 +000064#endif
yaberauneyae70b30b2009-11-27 07:40:16 +000065#endif
66
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020067char *TCID = "cacheflush01";
68int TST_TOTAL = 1;
subrata_modak1d7034b2009-04-15 06:32:35 +000069
subrata_modak1d7034b2009-04-15 06:32:35 +000070/* Extern Global Functions */
71/******************************************************************************/
72/* */
73/* Function: cleanup */
74/* */
75/* Description: Performs all one time clean up for this test on successful */
76/* completion, premature exit or failure. Closes all temporary */
77/* files, removes all temporary directories exits the test with */
78/* appropriate return code by calling tst_exit() function. */
79/* */
80/* Input: None. */
81/* */
82/* Output: None. */
83/* */
84/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
85/* On success - Exits calling tst_exit(). With '0' return code. */
86/* */
87/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080088extern void cleanup()
89{
Garrett Cooper2c282152010-12-16 00:55:50 -080090
Wanlong Gao354ebb42012-12-07 10:10:04 +080091 TEST_CLEANUP;
92 tst_rmdir();
subrata_modak1d7034b2009-04-15 06:32:35 +000093}
94
95/* Local Functions */
96/******************************************************************************/
97/* */
98/* Function: setup */
99/* */
100/* Description: Performs all one time setup for this test. This function is */
101/* typically used to capture signals, create temporary dirs */
102/* and temporary files that may be used in the course of this */
103/* test. */
104/* */
105/* Input: None. */
106/* */
107/* Output: None. */
108/* */
109/* Return: On failure - Exits by calling cleanup(). */
110/* On success - returns 0. */
111/* */
112/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800113void setup()
114{
115 /* Capture signals if any */
116 /* Create temporary directories */
117 TEST_PAUSE;
118 tst_tmpdir();
subrata_modak1d7034b2009-04-15 06:32:35 +0000119}
120
yaberauneyae70b30b2009-11-27 07:40:16 +0000121int main(int ac, char **av)
122{
subrata_modak1d7034b2009-04-15 06:32:35 +0000123
subrata_modak1d7034b2009-04-15 06:32:35 +0000124 char *addr = NULL;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200125 char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800126
Wanlong Gao354ebb42012-12-07 10:10:04 +0800127 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -0800128 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
yaberauneyae70b30b2009-11-27 07:40:16 +0000129 tst_exit();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800130 }
subrata_modak1d7034b2009-04-15 06:32:35 +0000131
Wanlong Gao354ebb42012-12-07 10:10:04 +0800132 setup();
subrata_modak1d7034b2009-04-15 06:32:35 +0000133
Caspar Zhangd59a6592013-03-07 14:59:12 +0800134 tst_count = 0;
yaberauneyae70b30b2009-11-27 07:40:16 +0000135 /* Create some user address range */
136 addr = malloc(getpagesize());
137 if (addr == NULL) {
138 tst_brkm(TFAIL | TTERRNO, cleanup, "malloc failed");
139 }
subrata_modak1d7034b2009-04-15 06:32:35 +0000140
yaberauneyae70b30b2009-11-27 07:40:16 +0000141 /* Invokes cacheflush() with proper parameters */
Jan Stancek359980f2013-02-15 10:16:05 +0100142 TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), ICACHE));
Garrett Cooperdd59d492010-08-31 23:09:49 -0700143 if (TEST_RETURN == 0) {
144 tst_resm(TPASS, "passed with no errno");
yaberauneyae70b30b2009-11-27 07:40:16 +0000145 } else {
Garrett Cooperdd59d492010-08-31 23:09:49 -0700146 tst_resm(TFAIL, "failed with unexpected errno");
Garrett Cooper2c282152010-12-16 00:55:50 -0800147 }
148
Jan Stancek359980f2013-02-15 10:16:05 +0100149 TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), DCACHE));
Garrett Cooperdd59d492010-08-31 23:09:49 -0700150 if (TEST_RETURN == 0) {
151 tst_resm(TPASS, "passed with no errno");
152 } else {
153 tst_resm(TFAIL, "failed with unexpected errno");
Garrett Cooper2c282152010-12-16 00:55:50 -0800154 }
155
Jan Stancek359980f2013-02-15 10:16:05 +0100156 TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), BCACHE));
Garrett Cooperdd59d492010-08-31 23:09:49 -0700157 if (TEST_RETURN == 0) {
158 tst_resm(TPASS, "passed with no errno");
159 } else {
160 tst_resm(TFAIL, "failed with unexpected errno");
Garrett Cooper2c282152010-12-16 00:55:50 -0800161 }
Garrett Cooperdd59d492010-08-31 23:09:49 -0700162
Garrett Cooper2c282152010-12-16 00:55:50 -0800163 cleanup();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800164 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700165}