subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 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 */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 17 | /* */ |
| 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
| 20 | /* */ |
| 21 | /* File: cacheflush01.c */ |
| 22 | /* */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 23 | /* Description: The cacheflush_check() syscall */ |
| 24 | /* Tests EINVAL error of cacheflush system call. */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 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_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 42 | #include <unistd.h> |
| 43 | #include <stdio.h> |
| 44 | #include <stdlib.h> |
| 45 | #include <errno.h> |
| 46 | |
Francesco Rundo | 8255dcc | 2012-01-18 16:04:18 +0100 | [diff] [blame] | 47 | #include "test.h" |
| 48 | #include "usctest.h" |
| 49 | #include "linux_syscall_numbers.h" |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 50 | |
Francesco Rundo | 8255dcc | 2012-01-18 16:04:18 +0100 | [diff] [blame] | 51 | #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_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 56 | #ifndef ICACHE |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 57 | #define ICACHE (1<<0) /* flush instruction cache */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 58 | #endif |
| 59 | #ifndef DCACHE |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | #define DCACHE (1<<1) /* writeback and flush data cache */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 61 | #endif |
| 62 | #ifndef BCACHE |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 63 | #define BCACHE (ICACHE|DCACHE) /* flush both caches */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 64 | #endif |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 65 | #endif |
| 66 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame^] | 67 | char *TCID = "cacheflush01"; |
| 68 | int TST_TOTAL = 1; |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 69 | |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 70 | /* 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 88 | extern void cleanup() |
| 89 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 90 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 91 | TEST_CLEANUP; |
| 92 | tst_rmdir(); |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 93 | } |
| 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 113 | void setup() |
| 114 | { |
| 115 | /* Capture signals if any */ |
| 116 | /* Create temporary directories */ |
| 117 | TEST_PAUSE; |
| 118 | tst_tmpdir(); |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 119 | } |
| 120 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 121 | int main(int ac, char **av) |
| 122 | { |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 123 | |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 124 | char *addr = NULL; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 125 | char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 126 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 128 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 129 | tst_exit(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 130 | } |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 131 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 132 | setup(); |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 133 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 134 | tst_count = 0; |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 135 | /* Create some user address range */ |
| 136 | addr = malloc(getpagesize()); |
| 137 | if (addr == NULL) { |
| 138 | tst_brkm(TFAIL | TTERRNO, cleanup, "malloc failed"); |
| 139 | } |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 140 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 141 | /* Invokes cacheflush() with proper parameters */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 142 | TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), ICACHE)); |
Garrett Cooper | dd59d49 | 2010-08-31 23:09:49 -0700 | [diff] [blame] | 143 | if (TEST_RETURN == 0) { |
| 144 | tst_resm(TPASS, "passed with no errno"); |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 145 | } else { |
Garrett Cooper | dd59d49 | 2010-08-31 23:09:49 -0700 | [diff] [blame] | 146 | tst_resm(TFAIL, "failed with unexpected errno"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 149 | TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), DCACHE)); |
Garrett Cooper | dd59d49 | 2010-08-31 23:09:49 -0700 | [diff] [blame] | 150 | if (TEST_RETURN == 0) { |
| 151 | tst_resm(TPASS, "passed with no errno"); |
| 152 | } else { |
| 153 | tst_resm(TFAIL, "failed with unexpected errno"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 156 | TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), BCACHE)); |
Garrett Cooper | dd59d49 | 2010-08-31 23:09:49 -0700 | [diff] [blame] | 157 | if (TEST_RETURN == 0) { |
| 158 | tst_resm(TPASS, "passed with no errno"); |
| 159 | } else { |
| 160 | tst_resm(TFAIL, "failed with unexpected errno"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 161 | } |
Garrett Cooper | dd59d49 | 2010-08-31 23:09:49 -0700 | [diff] [blame] | 162 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 163 | cleanup(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 164 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 165 | } |