blob: 065af4dc4ed7b82e341ecd55b15715151c548660 [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
Fei Jie93faa4c2016-04-06 14:18:50 +08006# include <stdio.h>
7# include <sys/swap.h>
8# include <unistd.h>
9
Fei Jie93faa4c2016-04-06 14:18:50 +080010int
11main(void)
12{
13 static const char sample[] = "swap.sample";
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000014 long rc;
Fei Jie93faa4c2016-04-06 14:18:50 +080015
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000016 rc = syscall(__NR_swapon, sample, 0);
17 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
18 sample, "0", rc, errno2name());
Fei Jie93faa4c2016-04-06 14:18:50 +080019
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000020 rc = syscall(__NR_swapon, sample, 42);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000021 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
22 sample, "42", rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000023
24 rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000025 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
26 sample, "SWAP_FLAG_PREFER", rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000027
28 rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER | 42);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000029 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
30 sample, "SWAP_FLAG_PREFER|42", rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000031
32 rc = syscall(__NR_swapon, sample, -1L);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000033 printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000034 sample,
35 "SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE"
36 "|SWAP_FLAG_DISCARD_PAGES|0xfff80000|32767",
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000037 rc, errno2name());
Dmitry V. Levinfcb94cd2016-04-07 01:15:58 +000038
Fei Jie93faa4c2016-04-06 14:18:50 +080039 rc = syscall(__NR_swapoff, sample);
Dmitry V. Levinf75e0342016-04-21 21:24:43 +000040 printf("swapoff(\"%s\") = %ld %s (%m)\n",
41 sample, rc, errno2name());
Fei Jie93faa4c2016-04-06 14:18:50 +080042
43 puts("+++ exited with 0 +++");
44 return 0;
45}
46
47#else
48
49SKIP_MAIN_UNDEFINED("__NR_swapon && __NR_swapoff")
50
51#endif