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 */ |
| 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_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 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 47 | /* cacheflush man page states that cacheflush() is only applicable to |
| 48 | * MIPS architecture -- regardless, it's a good negative test.. */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 49 | |
| 50 | #ifndef ICACHE |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 51 | #define ICACHE (1<<0) /* flush instruction cache */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 52 | #endif |
| 53 | #ifndef DCACHE |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 54 | #define DCACHE (1<<1) /* writeback and flush data cache */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 55 | #endif |
| 56 | #ifndef BCACHE |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 57 | #define BCACHE (ICACHE|DCACHE) /* flush both caches */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | /* Harness Specific Incnude Files. */ |
| 61 | #include "test.h" |
| 62 | #include "usctest.h" |
| 63 | #include "linux_syscall_numbers.h" |
| 64 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 65 | /* 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 Cooper | c9bccfa | 2010-09-16 21:49:00 -0700 | [diff] [blame] | 69 | #ifndef __NR_cacheflush |
| 70 | #define __NR_cacheflush 0 |
| 71 | #endif |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 72 | #else |
| 73 | /* Fake linux_syscall_numbers.h */ |
| 74 | #define __NR_cacheflush 0 |
| 75 | #endif |
| 76 | |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 77 | /* Extern Global Variables */ |
| 78 | extern int Tst_count; /* counter for tst_xxx routines. */ |
| 79 | extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */ |
| 80 | |
| 81 | /* Global Variables */ |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 82 | char *TCID = "cacheflush01"; /* Test program identifier.*/ |
| 83 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 84 | |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 85 | /* 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 | /******************************************************************************/ |
| 103 | extern void cleanup() { |
| 104 | /* Remove tmp dir and all files in it */ |
| 105 | TEST_CLEANUP; |
| 106 | tst_rmdir(); |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 107 | } |
| 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 | /******************************************************************************/ |
| 127 | void setup() { |
| 128 | /* Capture signals if any */ |
| 129 | /* Create temporary directories */ |
| 130 | TEST_PAUSE; |
| 131 | tst_tmpdir(); |
| 132 | } |
| 133 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 134 | int main(int ac, char **av) |
| 135 | { |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 136 | |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 137 | char *addr = NULL; |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 138 | char *msg; /* message returned from parse_opts */ |
| 139 | |
| 140 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 141 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL){ |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame^] | 142 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 143 | tst_exit(); |
| 144 | } |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 145 | |
| 146 | setup(); |
| 147 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 148 | 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_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 154 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 155 | /* Invokes cacheflush() with proper parameters */ |
| 156 | TEST(syscall(__NR_cacheflush, addr, getpagesize(), ICACHE)); |
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"); |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 159 | } else { |
Garrett Cooper | dd59d49 | 2010-08-31 23:09:49 -0700 | [diff] [blame] | 160 | 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 | |
yaberauneya | e70b30b | 2009-11-27 07:40:16 +0000 | [diff] [blame] | 177 | cleanup(); |
subrata_modak | 1d7034b | 2009-04-15 06:32:35 +0000 | [diff] [blame] | 178 | tst_exit(); |
| 179 | } |