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