• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************/
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 
42 #include <unistd.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 
47 #include "test.h"
48 #include "lapi/syscalls.h"
49 
50 #if __NR_cacheflush != __LTP__NR_INVALID_SYSCALL
51 #include <asm/cachectl.h>
52 #else
53 #ifndef   ICACHE
54 #define   ICACHE   (1<<0)	/* flush instruction cache        */
55 #endif
56 #ifndef   DCACHE
57 #define   DCACHE   (1<<1)	/* writeback and flush data cache */
58 #endif
59 #ifndef   BCACHE
60 #define   BCACHE   (ICACHE|DCACHE)	/* flush both caches              */
61 #endif
62 #endif
63 
64 char *TCID = "cacheflush01";
65 int TST_TOTAL = 1;
66 
67 /* Extern Global Functions */
68 /******************************************************************************/
69 /*                                                                            */
70 /* Function:    cleanup                                                       */
71 /*                                                                            */
72 /* Description: Performs all one time clean up for this test on successful    */
73 /*              completion,  premature exit or  failure. Closes all temporary */
74 /*              files, removes all temporary directories exits the test with  */
75 /*              appropriate return code by calling tst_exit() function.       */
76 /*                                                                            */
77 /* Input:       None.                                                         */
78 /*                                                                            */
79 /* Output:      None.                                                         */
80 /*                                                                            */
81 /* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
82 /*              On success - Exits calling tst_exit(). With '0' return code.  */
83 /*                                                                            */
84 /******************************************************************************/
cleanup(void)85 void cleanup(void)
86 {
87 
88 	tst_rmdir();
89 }
90 
91 /* Local  Functions */
92 /******************************************************************************/
93 /*                                                                            */
94 /* Function:    setup                                                         */
95 /*                                                                            */
96 /* Description: Performs all one time setup for this test. This function is   */
97 /*              typically used to capture signals, create temporary dirs      */
98 /*              and temporary files that may be used in the course of this    */
99 /*              test.                                                         */
100 /*                                                                            */
101 /* Input:       None.                                                         */
102 /*                                                                            */
103 /* Output:      None.                                                         */
104 /*                                                                            */
105 /* Return:      On failure - Exits by calling cleanup().                      */
106 /*              On success - returns 0.                                       */
107 /*                                                                            */
108 /******************************************************************************/
setup(void)109 void setup(void)
110 {
111 	/* Capture signals if any */
112 	/* Create temporary directories */
113 	TEST_PAUSE;
114 	tst_tmpdir();
115 }
116 
main(int ac,char ** av)117 int main(int ac, char **av)
118 {
119 
120 	char *addr = NULL;
121 
122 	tst_parse_opts(ac, av, NULL, NULL);
123 
124 	setup();
125 
126 	tst_count = 0;
127 	/* Create some user address range */
128 	addr = malloc(getpagesize());
129 	if (addr == NULL) {
130 		tst_brkm(TFAIL | TTERRNO, cleanup, "malloc failed");
131 	}
132 
133 	/* Invokes cacheflush() with proper parameters */
134 	TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), ICACHE));
135 	if (TEST_RETURN == 0) {
136 		tst_resm(TPASS, "passed with no errno");
137 	} else {
138 		tst_resm(TFAIL, "failed with unexpected errno");
139 	}
140 
141 	TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), DCACHE));
142 	if (TEST_RETURN == 0) {
143 		tst_resm(TPASS, "passed with no errno");
144 	} else {
145 		tst_resm(TFAIL, "failed with unexpected errno");
146 	}
147 
148 	TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), BCACHE));
149 	if (TEST_RETURN == 0) {
150 		tst_resm(TPASS, "passed with no errno");
151 	} else {
152 		tst_resm(TFAIL, "failed with unexpected errno");
153 	}
154 
155 	cleanup();
156 	tst_exit();
157 }
158