Fei Jie | 93faa4c | 2016-04-06 14:18:50 +0800 | [diff] [blame] | 1 | #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 Jie | 93faa4c | 2016-04-06 14:18:50 +0800 | [diff] [blame] | 11 | int |
| 12 | main(void) |
| 13 | { |
| 14 | static const char sample[] = "swap.sample"; |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 15 | long rc; |
Fei Jie | 93faa4c | 2016-04-06 14:18:50 +0800 | [diff] [blame] | 16 | |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 17 | rc = syscall(__NR_swapon, sample, 0); |
| 18 | printf("swapon(\"%s\", %s) = %ld %s (%m)\n", |
| 19 | sample, "0", rc, errno2name()); |
Fei Jie | 93faa4c | 2016-04-06 14:18:50 +0800 | [diff] [blame] | 20 | |
Dmitry V. Levin | fcb94cd | 2016-04-07 01:15:58 +0000 | [diff] [blame] | 21 | rc = syscall(__NR_swapon, sample, 42); |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 22 | printf("swapon(\"%s\", %s) = %ld %s (%m)\n", |
| 23 | sample, "42", rc, errno2name()); |
Dmitry V. Levin | fcb94cd | 2016-04-07 01:15:58 +0000 | [diff] [blame] | 24 | |
| 25 | rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER); |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 26 | printf("swapon(\"%s\", %s) = %ld %s (%m)\n", |
| 27 | sample, "SWAP_FLAG_PREFER", rc, errno2name()); |
Dmitry V. Levin | fcb94cd | 2016-04-07 01:15:58 +0000 | [diff] [blame] | 28 | |
| 29 | rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER | 42); |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 30 | printf("swapon(\"%s\", %s) = %ld %s (%m)\n", |
| 31 | sample, "SWAP_FLAG_PREFER|42", rc, errno2name()); |
Dmitry V. Levin | fcb94cd | 2016-04-07 01:15:58 +0000 | [diff] [blame] | 32 | |
| 33 | rc = syscall(__NR_swapon, sample, -1L); |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 34 | printf("swapon(\"%s\", %s) = %ld %s (%m)\n", |
Dmitry V. Levin | fcb94cd | 2016-04-07 01:15:58 +0000 | [diff] [blame] | 35 | sample, |
| 36 | "SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE" |
| 37 | "|SWAP_FLAG_DISCARD_PAGES|0xfff80000|32767", |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 38 | rc, errno2name()); |
Dmitry V. Levin | fcb94cd | 2016-04-07 01:15:58 +0000 | [diff] [blame] | 39 | |
Fei Jie | 93faa4c | 2016-04-06 14:18:50 +0800 | [diff] [blame] | 40 | rc = syscall(__NR_swapoff, sample); |
Dmitry V. Levin | f75e034 | 2016-04-21 21:24:43 +0000 | [diff] [blame^] | 41 | printf("swapoff(\"%s\") = %ld %s (%m)\n", |
| 42 | sample, rc, errno2name()); |
Fei Jie | 93faa4c | 2016-04-06 14:18:50 +0800 | [diff] [blame] | 43 | |
| 44 | puts("+++ exited with 0 +++"); |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | #else |
| 49 | |
| 50 | SKIP_MAIN_UNDEFINED("__NR_swapon && __NR_swapoff") |
| 51 | |
| 52 | #endif |