@@ -79,23 +79,6 @@ static void check_loop_value(int set_flag, int get_flag, int autoclear_field)
7979
8080static void verify_ioctl_loop (void )
8181{
82- int ret ;
83- const char * const cmd_parted [] = {"parted" , "-s" , dev_path , "mklabel" , "msdos" , "mkpart" ,
84- "primary" , "ext4" , "1M" , "10M" , NULL };
85-
86- tst_fill_file ("test.img" , 0 , 1024 * 1024 , 10 );
87- tst_attach_device (dev_path , "test.img" );
88-
89- ret = tst_cmd (cmd_parted , NULL , NULL , TST_CMD_PASS_RETVAL );
90- if (!ret )
91- parted_sup = 1 ;
92- else if (ret == 255 )
93- tst_res (TCONF , "parted binary not installed or failed" );
94- else
95- tst_res (TCONF , "parted exited with %i" , ret );
96-
97- attach_flag = 1 ;
98-
9982 TST_ASSERT_INT (partscan_path , 0 );
10083 TST_ASSERT_INT (autoclear_path , 0 );
10184 TST_ASSERT_STR (backing_path , backing_file_path );
@@ -114,10 +97,23 @@ static void verify_ioctl_loop(void)
11497
11598static void setup (void )
11699{
100+ parted_sup = tst_cmd_present ("parted" );
101+
102+ const char * const cmd_parted [] = {"parted" , "-s" , dev_path , "mklabel" , "msdos" , "mkpart" ,
103+ "primary" , "ext4" , "1M" , "10M" , NULL };
104+
117105 dev_num = tst_find_free_loopdev (dev_path , sizeof (dev_path ));
118106 if (dev_num < 0 )
119107 tst_brk (TBROK , "Failed to find free loop device" );
120108
109+ tst_fill_file ("test.img" , 0 , 1024 * 1024 , 10 );
110+
111+ tst_attach_device (dev_path , "test.img" );
112+ attach_flag = 1 ;
113+
114+ if (parted_sup )
115+ SAFE_CMD (cmd_parted , NULL , NULL );
116+
121117 sprintf (partscan_path , "/sys/block/loop%d/loop/partscan" , dev_num );
122118 sprintf (autoclear_path , "/sys/block/loop%d/loop/autoclear" , dev_num );
123119 sprintf (backing_path , "/sys/block/loop%d/loop/backing_file" , dev_num );
@@ -149,5 +145,9 @@ static struct tst_test test = {
149145 {"linux-git" , "6ac92fb5cdff" },
150146 {}
151147 },
148+ .needs_cmds = (struct tst_cmd []) {
149+ {.cmd = "parted" , .optional = 1 },
150+ {}
151+ },
152152 .needs_tmpdir = 1 ,
153153};
0 commit comments