0001-cacheflush01-Rewrite-into-new-API.patch 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. From 48edd768850825a4d01e5e5e737122333fc55cdf Mon Sep 17 00:00:00 2001
  2. From: Petr Vorel <petr.vorel@gmail.com>
  3. Date: Fri, 2 Oct 2020 21:29:58 +0200
  4. Subject: [PATCH] cacheflush01: Rewrite into new API
  5. This syscall is currently (v5.9) supported on these architectures:
  6. arc, csky, mips, m68k, nds32, sh
  7. constants are missing for m68k, not sure if the testcase is valid for it.
  8. Untested.
  9. Test for __LTP__NR_INVALID_SYSCALL saves adding autotools check for
  10. <asm/cachectl.h>.
  11. Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
  12. ---
  13. [ upstream status: https://patchwork.ozlabs.org/project/ltp/patch/20201002202416.28972-1-petr.vorel@gmail.com/ ]
  14. .../kernel/syscalls/cacheflush/cacheflush01.c | 173 ++++--------------
  15. 1 file changed, 40 insertions(+), 133 deletions(-)
  16. diff --git a/testcases/kernel/syscalls/cacheflush/cacheflush01.c b/testcases/kernel/syscalls/cacheflush/cacheflush01.c
  17. index 29cf2014a..6ad8b953a 100644
  18. --- a/testcases/kernel/syscalls/cacheflush/cacheflush01.c
  19. +++ b/testcases/kernel/syscalls/cacheflush/cacheflush01.c
  20. @@ -1,157 +1,64 @@
  21. -/******************************************************************************/
  22. -/* Copyright (c) Maxin John <maxin.john@gmail.com>, 2009 */
  23. -/* LKML Reference: http://lkml.org/lkml/2009/4/9/203 */
  24. -/* This program is free software; you can redistribute it and/or modify */
  25. -/* it under the terms of the GNU General Public License as published by */
  26. -/* the Free Software Foundation; either version 2 of the License, or */
  27. -/* (at your option) any later version. */
  28. -/* */
  29. -/* This program is distributed in the hope that it will be useful, */
  30. -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  31. -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
  32. -/* the GNU General Public License for more details. */
  33. -/* */
  34. -/* You should have received a copy of the GNU General Public License */
  35. -/* along with this program; if not, write to the Free Software */
  36. -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
  37. -/* */
  38. -/******************************************************************************/
  39. -/******************************************************************************/
  40. -/* */
  41. -/* File: cacheflush01.c */
  42. -/* */
  43. -/* Description: The cacheflush_check() syscall */
  44. -/* Tests EINVAL error of cacheflush system call. */
  45. -/* Its expected behaviour is cacheflush() should return -EINVAL */
  46. -/* when cache parameter is not one of ICACHE, DCACHE, or BCACHE. */
  47. -/* */
  48. -/* Usage: <for command-line> */
  49. -/* cacheflush01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
  50. -/* where, -c n : Run n copies concurrently. */
  51. -/* -e : Turn on errno logging. */
  52. -/* -i n : Execute test n times. */
  53. -/* -I x : Execute test for x seconds. */
  54. -/* -P x : Pause for x seconds between iterations. */
  55. -/* -t : Turn on syscall timing. */
  56. -/* */
  57. -/* Total Tests: 1 */
  58. -/* */
  59. -/* Test Name: cacheflush01 */
  60. -/******************************************************************************/
  61. +// SPDX-License-Identifier: GPL-2.0-or-later
  62. -#include <unistd.h>
  63. -#include <stdio.h>
  64. -#include <stdlib.h>
  65. -#include <errno.h>
  66. -
  67. -#include "test.h"
  68. +#include "tst_test.h"
  69. #include "lapi/syscalls.h"
  70. #if __NR_cacheflush != __LTP__NR_INVALID_SYSCALL
  71. +
  72. #include <asm/cachectl.h>
  73. -#else
  74. +
  75. +/*
  76. + * m68k does not have these constants
  77. + */
  78. +
  79. #ifndef ICACHE
  80. -#define ICACHE (1<<0) /* flush instruction cache */
  81. +# define ICACHE (1<<0)
  82. #endif
  83. +
  84. #ifndef DCACHE
  85. -#define DCACHE (1<<1) /* writeback and flush data cache */
  86. +# define DCACHE (1<<1)
  87. #endif
  88. +
  89. #ifndef BCACHE
  90. -#define BCACHE (ICACHE|DCACHE) /* flush both caches */
  91. -#endif
  92. +# define BCACHE (ICACHE|DCACHE)
  93. #endif
  94. -char *TCID = "cacheflush01";
  95. -int TST_TOTAL = 1;
  96. +#define CACHE_DESC(x) .cache = x, .desc = #x
  97. -/* Extern Global Functions */
  98. -/******************************************************************************/
  99. -/* */
  100. -/* Function: cleanup */
  101. -/* */
  102. -/* Description: Performs all one time clean up for this test on successful */
  103. -/* completion, premature exit or failure. Closes all temporary */
  104. -/* files, removes all temporary directories exits the test with */
  105. -/* appropriate return code by calling tst_exit() function. */
  106. -/* */
  107. -/* Input: None. */
  108. -/* */
  109. -/* Output: None. */
  110. -/* */
  111. -/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
  112. -/* On success - Exits calling tst_exit(). With '0' return code. */
  113. -/* */
  114. -/******************************************************************************/
  115. -void cleanup(void)
  116. -{
  117. +static struct test_case_t {
  118. + int cache;
  119. + const char *desc;
  120. +} test_cases[] = {
  121. + { CACHE_DESC(ICACHE) },
  122. + { CACHE_DESC(DCACHE) },
  123. + { CACHE_DESC(BCACHE) },
  124. +};
  125. - tst_rmdir();
  126. -}
  127. +static char *addr;
  128. -/* Local Functions */
  129. -/******************************************************************************/
  130. -/* */
  131. -/* Function: setup */
  132. -/* */
  133. -/* Description: Performs all one time setup for this test. This function is */
  134. -/* typically used to capture signals, create temporary dirs */
  135. -/* and temporary files that may be used in the course of this */
  136. -/* test. */
  137. -/* */
  138. -/* Input: None. */
  139. -/* */
  140. -/* Output: None. */
  141. -/* */
  142. -/* Return: On failure - Exits by calling cleanup(). */
  143. -/* On success - returns 0. */
  144. -/* */
  145. -/******************************************************************************/
  146. -void setup(void)
  147. +static void setup(void)
  148. {
  149. - /* Capture signals if any */
  150. - /* Create temporary directories */
  151. - TEST_PAUSE;
  152. - tst_tmpdir();
  153. + addr = SAFE_MALLOC(getpagesize());
  154. }
  155. -int main(int ac, char **av)
  156. +static void test_cacheflush(unsigned int i)
  157. {
  158. + struct test_case_t *tc = &test_cases[i];
  159. - char *addr = NULL;
  160. -
  161. - tst_parse_opts(ac, av, NULL, NULL);
  162. -
  163. - setup();
  164. -
  165. - tst_count = 0;
  166. - /* Create some user address range */
  167. - addr = malloc(getpagesize());
  168. - if (addr == NULL) {
  169. - tst_brkm(TFAIL | TTERRNO, cleanup, "malloc failed");
  170. - }
  171. -
  172. - /* Invokes cacheflush() with proper parameters */
  173. - TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), ICACHE));
  174. - if (TEST_RETURN == 0) {
  175. - tst_resm(TPASS, "passed with no errno");
  176. - } else {
  177. - tst_resm(TFAIL, "failed with unexpected errno");
  178. - }
  179. -
  180. - TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), DCACHE));
  181. - if (TEST_RETURN == 0) {
  182. - tst_resm(TPASS, "passed with no errno");
  183. + TEST(tst_syscall(__NR_cacheflush, addr, getpagesize(), tc->cache));
  184. + if (TST_RET == 0) {
  185. + tst_res(TPASS, "%s passed", tc->desc);
  186. } else {
  187. - tst_resm(TFAIL, "failed with unexpected errno");
  188. + tst_res(TFAIL | TTERRNO, "%s failed", tc->desc);
  189. }
  190. +}
  191. - TEST(ltp_syscall(__NR_cacheflush, addr, getpagesize(), BCACHE));
  192. - if (TEST_RETURN == 0) {
  193. - tst_resm(TPASS, "passed with no errno");
  194. - } else {
  195. - tst_resm(TFAIL, "failed with unexpected errno");
  196. - }
  197. +static struct tst_test test = {
  198. + .setup = setup,
  199. + .test = test_cacheflush,
  200. + .tcnt = ARRAY_SIZE(test_cases),
  201. +};
  202. - cleanup();
  203. - tst_exit();
  204. -}
  205. +#else
  206. + TST_TEST_TCONF("system doesn't support cacheflush()");
  207. +#endif
  208. --
  209. 2.28.0