• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
19  *
20  */
21 
22 #include "test.h"
23 #include "libswapon.h"
24 
25 /*
26  * Make a swap file
27  */
make_swapfile(void (cleanup)(void),const char * swapfile)28 void make_swapfile(void (cleanup)(void), const char *swapfile)
29 {
30 	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
31 	    TST_BYTES)) {
32 		tst_brkm(TBROK, cleanup,
33 			"Insufficient disk space to create swap file");
34 	}
35 
36 	/* create file */
37 	if (tst_fill_file(swapfile, 0,
38 			sysconf(_SC_PAGESIZE), 10) != 0) {
39 		tst_brkm(TBROK, cleanup, "Failed to create swapfile");
40 	}
41 
42 	/* make the file swapfile */
43 	const char *argv[2 + 1];
44 	argv[0] = "mkswap";
45 	argv[1] = swapfile;
46 	argv[2] = NULL;
47 
48 	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
49 }
50