Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame^] | 1 | Index: git/libs/libltpswapon/Makefile |
| 2 | =================================================================== |
| 3 | --- /dev/null |
| 4 | +++ git/libs/libltpswapon/Makefile |
| 5 | @@ -0,0 +1,12 @@ |
| 6 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | +# |
| 8 | +# Copyright (C) Richard Purdie <richard.purdie@linuxfoundation.org> |
| 9 | + |
| 10 | +top_srcdir ?= ../.. |
| 11 | + |
| 12 | +include $(top_srcdir)/include/mk/env_pre.mk |
| 13 | + |
| 14 | +INTERNAL_LIB := libltpswapon.a |
| 15 | + |
| 16 | +include $(top_srcdir)/include/mk/lib.mk |
| 17 | +include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 18 | Index: git/libs/libltpswapon/libswapon.c |
| 19 | =================================================================== |
| 20 | --- /dev/null |
| 21 | +++ git/libs/libltpswapon/libswapon.c |
| 22 | @@ -0,0 +1,90 @@ |
| 23 | +/* |
| 24 | + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. |
| 25 | + * |
| 26 | + * This program is free software; you can redistribute it and/or |
| 27 | + * modify it under the terms of the GNU General Public License as |
| 28 | + * published by the Free Software Foundation; either version 2 of |
| 29 | + * the License, or (at your option) any later version. |
| 30 | + * |
| 31 | + * This program is distributed in the hope that it would be useful, |
| 32 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 34 | + * GNU General Public License for more details. |
| 35 | + * |
| 36 | + * You should have received a copy of the GNU General Public License |
| 37 | + * along with this program; if not, write the Free Software Foundation, |
| 38 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 39 | + * |
| 40 | + * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> |
| 41 | + * |
| 42 | + */ |
| 43 | + |
| 44 | +#include <errno.h> |
| 45 | +#include "lapi/syscalls.h" |
| 46 | +#include "test.h" |
| 47 | +#include "libswapon.h" |
| 48 | + |
| 49 | +/* |
| 50 | + * Make a swap file |
| 51 | + */ |
| 52 | +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe) |
| 53 | +{ |
| 54 | + if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10, |
| 55 | + TST_BYTES)) { |
| 56 | + tst_brkm(TBROK, cleanup, |
| 57 | + "Insufficient disk space to create swap file"); |
| 58 | + } |
| 59 | + |
| 60 | + /* create file */ |
| 61 | + if (tst_fill_file(swapfile, 0, |
| 62 | + sysconf(_SC_PAGESIZE), 10) != 0) { |
| 63 | + tst_brkm(TBROK, cleanup, "Failed to create swapfile"); |
| 64 | + } |
| 65 | + |
| 66 | + /* make the file swapfile */ |
| 67 | + const char *argv[2 + 1]; |
| 68 | + argv[0] = "mkswap"; |
| 69 | + argv[1] = swapfile; |
| 70 | + argv[2] = NULL; |
| 71 | + |
| 72 | + return tst_cmd(cleanup, argv, "/dev/null", "/dev/null", safe); |
| 73 | +} |
| 74 | + |
| 75 | +/* |
| 76 | + * Check swapon/swapoff support status of filesystems or files |
| 77 | + * we are testing on. |
| 78 | + */ |
| 79 | +void is_swap_supported(void (cleanup)(void), const char *filename) |
| 80 | +{ |
| 81 | + int fibmap = tst_fibmap(filename); |
| 82 | + long fs_type = tst_fs_type(cleanup, filename); |
| 83 | + const char *fstype = tst_fs_type_name(fs_type); |
| 84 | + |
| 85 | + int ret = make_swapfile(NULL, filename, 1); |
| 86 | + if (ret != 0) { |
| 87 | + if (fibmap == 1) { |
| 88 | + tst_brkm(TCONF, cleanup, |
| 89 | + "mkswap on %s not supported", fstype); |
| 90 | + } else { |
| 91 | + tst_brkm(TFAIL, cleanup, |
| 92 | + "mkswap on %s failed", fstype); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + TEST(ltp_syscall(__NR_swapon, filename, 0)); |
| 97 | + if (TEST_RETURN == -1) { |
| 98 | + if (fibmap == 1 && errno == EINVAL) { |
| 99 | + tst_brkm(TCONF, cleanup, |
| 100 | + "Swapfile on %s not implemented", fstype); |
| 101 | + } else { |
| 102 | + tst_brkm(TFAIL | TERRNO, cleanup, |
| 103 | + "swapon on %s failed", fstype); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + TEST(ltp_syscall(__NR_swapoff, filename, 0)); |
| 108 | + if (TEST_RETURN == -1) { |
| 109 | + tst_brkm(TFAIL | TERRNO, cleanup, |
| 110 | + "swapoff on %s failed", fstype); |
| 111 | + } |
| 112 | +} |
| 113 | Index: git/testcases/kernel/syscalls/swapoff/Makefile |
| 114 | =================================================================== |
| 115 | --- git.orig/testcases/kernel/syscalls/swapoff/Makefile |
| 116 | +++ git/testcases/kernel/syscalls/swapoff/Makefile |
| 117 | @@ -3,7 +3,11 @@ |
| 118 | |
| 119 | top_srcdir ?= ../../../.. |
| 120 | |
| 121 | +LTPLIBS = ltpswapon |
| 122 | + |
| 123 | include $(top_srcdir)/include/mk/testcases.mk |
| 124 | -include $(abs_srcdir)/./Makefile.inc |
| 125 | + |
| 126 | +LTPLDLIBS = -lltpswapon |
| 127 | + |
| 128 | include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 129 | -$(MAKE_TARGETS): %: ../swapon/libswapon.o |
| 130 | + |
| 131 | Index: git/testcases/kernel/syscalls/swapoff/Makefile.inc |
| 132 | =================================================================== |
| 133 | --- git.orig/testcases/kernel/syscalls/swapoff/Makefile.inc |
| 134 | +++ /dev/null |
| 135 | @@ -1,6 +0,0 @@ |
| 136 | -LIBDIR += ../swapon/ |
| 137 | -LIBSWAPON := $(LIBDIR)/libswapon.o |
| 138 | -$(LIBSWAPON): |
| 139 | - $(MAKE) -C $(LIBDIR) |
| 140 | -CPPFLAGS += -I$(abs_srcdir)/$(LIBDIR) |
| 141 | -LDFLAGS += -L$(abs_builddir)/$(LIBDIR) |
| 142 | Index: git/testcases/kernel/syscalls/swapon/Makefile |
| 143 | =================================================================== |
| 144 | --- git.orig/testcases/kernel/syscalls/swapon/Makefile |
| 145 | +++ git/testcases/kernel/syscalls/swapon/Makefile |
| 146 | @@ -8,10 +8,10 @@ endif |
| 147 | |
| 148 | top_srcdir ?= ../../../.. |
| 149 | |
| 150 | +LTPLIBS = ltpswapon |
| 151 | + |
| 152 | include $(top_srcdir)/include/mk/testcases.mk |
| 153 | |
| 154 | -FILTER_OUT_MAKE_TARGETS := libswapon |
| 155 | +LTPLDLIBS = -lltpswapon |
| 156 | |
| 157 | include $(top_srcdir)/include/mk/generic_leaf_target.mk |
| 158 | - |
| 159 | -$(MAKE_TARGETS): %: libswapon.o |
| 160 | Index: git/testcases/kernel/syscalls/swapon/libswapon.c |
| 161 | =================================================================== |
| 162 | --- git.orig/testcases/kernel/syscalls/swapon/libswapon.c |
| 163 | +++ /dev/null |
| 164 | @@ -1,90 +0,0 @@ |
| 165 | -/* |
| 166 | - * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. |
| 167 | - * |
| 168 | - * This program is free software; you can redistribute it and/or |
| 169 | - * modify it under the terms of the GNU General Public License as |
| 170 | - * published by the Free Software Foundation; either version 2 of |
| 171 | - * the License, or (at your option) any later version. |
| 172 | - * |
| 173 | - * This program is distributed in the hope that it would be useful, |
| 174 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 175 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 176 | - * GNU General Public License for more details. |
| 177 | - * |
| 178 | - * You should have received a copy of the GNU General Public License |
| 179 | - * along with this program; if not, write the Free Software Foundation, |
| 180 | - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 181 | - * |
| 182 | - * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> |
| 183 | - * |
| 184 | - */ |
| 185 | - |
| 186 | -#include <errno.h> |
| 187 | -#include "lapi/syscalls.h" |
| 188 | -#include "test.h" |
| 189 | -#include "libswapon.h" |
| 190 | - |
| 191 | -/* |
| 192 | - * Make a swap file |
| 193 | - */ |
| 194 | -int make_swapfile(void (cleanup)(void), const char *swapfile, int safe) |
| 195 | -{ |
| 196 | - if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10, |
| 197 | - TST_BYTES)) { |
| 198 | - tst_brkm(TBROK, cleanup, |
| 199 | - "Insufficient disk space to create swap file"); |
| 200 | - } |
| 201 | - |
| 202 | - /* create file */ |
| 203 | - if (tst_fill_file(swapfile, 0, |
| 204 | - sysconf(_SC_PAGESIZE), 10) != 0) { |
| 205 | - tst_brkm(TBROK, cleanup, "Failed to create swapfile"); |
| 206 | - } |
| 207 | - |
| 208 | - /* make the file swapfile */ |
| 209 | - const char *argv[2 + 1]; |
| 210 | - argv[0] = "mkswap"; |
| 211 | - argv[1] = swapfile; |
| 212 | - argv[2] = NULL; |
| 213 | - |
| 214 | - return tst_cmd(cleanup, argv, "/dev/null", "/dev/null", safe); |
| 215 | -} |
| 216 | - |
| 217 | -/* |
| 218 | - * Check swapon/swapoff support status of filesystems or files |
| 219 | - * we are testing on. |
| 220 | - */ |
| 221 | -void is_swap_supported(void (cleanup)(void), const char *filename) |
| 222 | -{ |
| 223 | - int fibmap = tst_fibmap(filename); |
| 224 | - long fs_type = tst_fs_type(cleanup, filename); |
| 225 | - const char *fstype = tst_fs_type_name(fs_type); |
| 226 | - |
| 227 | - int ret = make_swapfile(NULL, filename, 1); |
| 228 | - if (ret != 0) { |
| 229 | - if (fibmap == 1) { |
| 230 | - tst_brkm(TCONF, cleanup, |
| 231 | - "mkswap on %s not supported", fstype); |
| 232 | - } else { |
| 233 | - tst_brkm(TFAIL, cleanup, |
| 234 | - "mkswap on %s failed", fstype); |
| 235 | - } |
| 236 | - } |
| 237 | - |
| 238 | - TEST(ltp_syscall(__NR_swapon, filename, 0)); |
| 239 | - if (TEST_RETURN == -1) { |
| 240 | - if (fibmap == 1 && errno == EINVAL) { |
| 241 | - tst_brkm(TCONF, cleanup, |
| 242 | - "Swapfile on %s not implemented", fstype); |
| 243 | - } else { |
| 244 | - tst_brkm(TFAIL | TERRNO, cleanup, |
| 245 | - "swapon on %s failed", fstype); |
| 246 | - } |
| 247 | - } |
| 248 | - |
| 249 | - TEST(ltp_syscall(__NR_swapoff, filename, 0)); |
| 250 | - if (TEST_RETURN == -1) { |
| 251 | - tst_brkm(TFAIL | TERRNO, cleanup, |
| 252 | - "swapoff on %s failed", fstype); |
| 253 | - } |
| 254 | -} |
| 255 | Index: git/testcases/kernel/syscalls/swapon/libswapon.h |
| 256 | =================================================================== |
| 257 | --- git.orig/testcases/kernel/syscalls/swapon/libswapon.h |
| 258 | +++ /dev/null |
| 259 | @@ -1,39 +0,0 @@ |
| 260 | -/* |
| 261 | - * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. |
| 262 | - * |
| 263 | - * This program is free software; you can redistribute it and/or |
| 264 | - * modify it under the terms of the GNU General Public License as |
| 265 | - * published by the Free Software Foundation; either version 2 of |
| 266 | - * the License, or (at your option) any later version. |
| 267 | - * |
| 268 | - * This program is distributed in the hope that it would be useful, |
| 269 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 270 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 271 | - * GNU General Public License for more details. |
| 272 | - * |
| 273 | - * You should have received a copy of the GNU General Public License |
| 274 | - * along with this program; if not, write the Free Software Foundation, |
| 275 | - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 276 | - * |
| 277 | - * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> |
| 278 | - * |
| 279 | - */ |
| 280 | - |
| 281 | -/* |
| 282 | - * Contains common content for all swapon tests |
| 283 | - */ |
| 284 | - |
| 285 | -#ifndef __LIBSWAPON_H__ |
| 286 | -#define __LIBSWAPON_H__ |
| 287 | - |
| 288 | -/* |
| 289 | - * Make a swap file |
| 290 | - */ |
| 291 | -int make_swapfile(void (cleanup)(void), const char *swapfile, int safe); |
| 292 | - |
| 293 | -/* |
| 294 | - * Check swapon/swapoff support status of filesystems or files |
| 295 | - * we are testing on. |
| 296 | - */ |
| 297 | -void is_swap_supported(void (cleanup)(void), const char *filename); |
| 298 | -#endif /* __LIBSWAPON_H__ */ |
| 299 | Index: git/testcases/kernel/syscalls/swapoff/swapoff01.c |
| 300 | =================================================================== |
| 301 | --- git.orig/testcases/kernel/syscalls/swapoff/swapoff01.c |
| 302 | +++ git/testcases/kernel/syscalls/swapoff/swapoff01.c |
| 303 | @@ -25,7 +25,7 @@ |
| 304 | #include <stdlib.h> |
| 305 | #include "config.h" |
| 306 | #include "lapi/syscalls.h" |
| 307 | -#include "../swapon/libswapon.h" |
| 308 | +#include "libswapon.h" |
| 309 | |
| 310 | static void setup(void); |
| 311 | static void cleanup(void); |
| 312 | Index: git/testcases/kernel/syscalls/swapoff/swapoff02.c |
| 313 | =================================================================== |
| 314 | --- git.orig/testcases/kernel/syscalls/swapoff/swapoff02.c |
| 315 | +++ git/testcases/kernel/syscalls/swapoff/swapoff02.c |
| 316 | @@ -33,7 +33,7 @@ |
| 317 | #include "test.h" |
| 318 | #include "lapi/syscalls.h" |
| 319 | #include "safe_macros.h" |
| 320 | -#include "../swapon/libswapon.h" |
| 321 | +#include "libswapon.h" |
| 322 | |
| 323 | static void setup(void); |
| 324 | static void cleanup(void); |
| 325 | Index: git/include/libswapon.h |
| 326 | =================================================================== |
| 327 | --- /dev/null |
| 328 | +++ git/include/libswapon.h |
| 329 | @@ -0,0 +1,39 @@ |
| 330 | +/* |
| 331 | + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. |
| 332 | + * |
| 333 | + * This program is free software; you can redistribute it and/or |
| 334 | + * modify it under the terms of the GNU General Public License as |
| 335 | + * published by the Free Software Foundation; either version 2 of |
| 336 | + * the License, or (at your option) any later version. |
| 337 | + * |
| 338 | + * This program is distributed in the hope that it would be useful, |
| 339 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 340 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 341 | + * GNU General Public License for more details. |
| 342 | + * |
| 343 | + * You should have received a copy of the GNU General Public License |
| 344 | + * along with this program; if not, write the Free Software Foundation, |
| 345 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 346 | + * |
| 347 | + * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com> |
| 348 | + * |
| 349 | + */ |
| 350 | + |
| 351 | +/* |
| 352 | + * Contains common content for all swapon tests |
| 353 | + */ |
| 354 | + |
| 355 | +#ifndef __LIBSWAPON_H__ |
| 356 | +#define __LIBSWAPON_H__ |
| 357 | + |
| 358 | +/* |
| 359 | + * Make a swap file |
| 360 | + */ |
| 361 | +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe); |
| 362 | + |
| 363 | +/* |
| 364 | + * Check swapon/swapoff support status of filesystems or files |
| 365 | + * we are testing on. |
| 366 | + */ |
| 367 | +void is_swap_supported(void (cleanup)(void), const char *filename); |
| 368 | +#endif /* __LIBSWAPON_H__ */ |