blob: 3ab916359e233672a3adaeca9cc40e4e05989735 [file] [log] [blame]
Fei Jie93faa4c2016-04-06 14:18:50 +08001#include "tests.h"
2#include <sys/syscall.h>
3
4#if defined __NR_swapon && defined __NR_swapoff
5
6# include <errno.h>
7# include <stdio.h>
8# include <sys/swap.h>
9# include <unistd.h>
10
Fei Jie93faa4c2016-04-06 14:18:50 +080011int
12main(void)
13{
14 static const char sample[] = "swap.sample";
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000015 long rc;
Fei Jie93faa4c2016-04-06 14:18:50 +080016
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000017 rc = syscall(__NR_swapon, sample, 0);
18 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
19 sample, "0", rc, errno2name());
Fei Jie93faa4c2016-04-06 14:18:50 +080020
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000021 rc = syscall(__NR_swapon, sample, 42);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000022 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
23 sample, "42", rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000024
25 rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000026 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
27 sample, "SWAP_FLAG_PREFER", rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000028
29 rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER | 42);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000030 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
31 sample, "SWAP_FLAG_PREFER|42", rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000032
33 rc = syscall(__NR_swapon, sample, -1L);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000034 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000035 sample,
36 "SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE"
37 "|SWAP_FLAG_DISCARD_PAGES|0xfff80000|32767",
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000038 rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000039
Fei Jie93faa4c2016-04-06 14:18:50 +080040 rc = syscall(__NR_swapoff, sample);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000041 printf("swapoff(\"%s\") = %ld %s (%m)\n",
42 sample, rc, errno2name());
Fei Jie93faa4c2016-04-06 14:18:50 +080043
44 puts("+++ exited with 0 +++");
45 return 0;
46}
47
48#else
49
50SKIP_MAIN_UNDEFINED("__NR_swapon && __NR_swapoff")
51
52#endif