(root)/
strace-6.5/
tests/
swap.c
       1  /*
       2   * Check decoding of swapon and swapoff tests.
       3   *
       4   * Copyright (c) 2016-2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  
      13  #include <stdio.h>
      14  #include <sys/swap.h>
      15  #include <unistd.h>
      16  
      17  int
      18  main(void)
      19  {
      20  	static const char sample[] = "swap.sample";
      21  	long rc;
      22  
      23  	rc = syscall(__NR_swapon, sample, 0);
      24  	printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
      25  	       sample, "0", rc, errno2name());
      26  
      27  	rc = syscall(__NR_swapon, sample, 42);
      28  	printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
      29  	       sample, "42", rc, errno2name());
      30  
      31  	rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER);
      32  	printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
      33  	       sample, "SWAP_FLAG_PREFER|0", rc, errno2name());
      34  
      35  	rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER | 42);
      36  	printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
      37  	       sample, "SWAP_FLAG_PREFER|42", rc, errno2name());
      38  
      39  	rc = syscall(__NR_swapon, sample, -1L);
      40  	printf("swapon(\"%s\", %s) = %ld %s (%m)\n",
      41  	       sample,
      42  	       "SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE"
      43  	       "|SWAP_FLAG_DISCARD_PAGES|0xfff80000|32767",
      44  	       rc, errno2name());
      45  
      46  	rc = syscall(__NR_swapoff, sample);
      47  	printf("swapoff(\"%s\") = %ld %s (%m)\n",
      48  	       sample, rc, errno2name());
      49  
      50  	puts("+++ exited with 0 +++");
      51  	return 0;
      52  }