Miscellaneous fixes for Android systems
cover Miscellaneous fixes for Android systems
Hello,
We have been running LTP on Android systems and found there are a bunch of tests that don't work. Most common reasons are (but not limited to):
- Lack of tools that LTP tests sometimes expects (e.g. mkfs.extN)
- Different directory structure or location for device nodes (e.g. /dev/block/loopX instead of /dev/loopX)
- Tests depend on Sys V IPC that Android doesn't use / support.
This series fixes some of those tests to make sure they start working on Android systems. I've also clubbed the v2 of a couple of patches in this series that they are clearly annotated as such.
Sandeep Patil (6):
syscalls/cma: Make process_vm_{readv, writev} tests bionic friendly
mm: mallocstress: use safe macros wherever possible
mm: mallocstress: use futexes instead of SysV semaphores
direct_io: diotest4: use getpagesize() for mmap if shm header is
absent
syscalls/mkdir03: convert to new API and use .needsrofs for EROFS
check
lib: mkfs: use 'mke2fs' on android systems for formatting filesystems
configure.ac | 1 + include/lapi/mmap.h | 8 ++ lib/tst_mkfs.c | 16 +++ testcases/kernel/io/direct_io/diotest4.c | 4 +- testcases/kernel/mem/mtest07/mallocstress.c | 101 +++++--------- testcases/kernel/syscalls/cma/process_vm.h | 38 ------ testcases/kernel/syscalls/cma/process_vm_readv02.c | 10 +- testcases/kernel/syscalls/cma/process_vm_readv03.c | 10 +- .../kernel/syscalls/cma/process_vm_writev02.c | 10 +- testcases/kernel/syscalls/mkdir/mkdir03.c | 147 ++++++--------------- 10 files changed, 115 insertions(+), 230 deletions(-)
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH v2 1/6 syscalls/cma: Make process_vm_{readv, writev} tests bionic friendly
All testcases under testcases/kernel/syscalls/cma depend on SysV semaphore to do event notification from parent<->child processes. Since bionic / android doesn't have SysV IPC, the tests can't be built against bionic.
Fix this by using the ltp TST_SAFE_CHECKPOINT APIs taht are based on futexes. The change enables following tests for Android devices.
process_vm01, process_vm_readv0[23], process_vm_writev02
---v1->v2
------
- Use TST_CHECKPOINT APIs instead of eventfd as suggested by Jan
testcases/kernel/syscalls/cma/process_vm.h | 38 ---------------------- testcases/kernel/syscalls/cma/process_vm_readv02.c | 10 +++--- testcases/kernel/syscalls/cma/process_vm_readv03.c | 10 +++--- .../kernel/syscalls/cma/process_vm_writev02.c | 10 +++--- 4 files changed, 15 insertions(+), 53 deletions(-)
testcases/kernel/syscalls/cma/process_vm.h +0 -38
@@ -59,42 +59,4 @@ static inline ssize_t test_process_vm_writev(pid_t pid, #endif } -void safe_semop (int id,unsigned short num,short op) -{ -int ret; -struct sembuf sem_op; - sem_op.sem_num = num, - sem_op.sem_op = op, - sem_op.sem_flg =0 ; - -do { - ret =semop (id, &sem_op,1 ); - }while (ret ==-1 && errno ==EINTR ); -if (ret ==-1 ) -tst_brkm (TBROK |TERRNO ,NULL ,"semop(%d, (%d, %d)) failed" , - id, num, op); -} - -int init_sem (int num) -{ -int id, i; -union semun u; -if ((id =semget (IPC_PRIVATE , num,IPC_CREAT |S_IRWXU )) ==-1 ) -tst_brkm (TBROK |TERRNO ,NULL ,"Couldn't allocate semaphore" ); - -for (i =0 ; i < num; i++) { - u.val =0 ; -if (semctl (id,0 ,SETVAL , u) ==-1 ) -tst_brkm (TBROK |TERRNO ,NULL , -"Couldn't initialize sem %d value" , i); - } -return id; -} - -void clean_sem (int id) -{ -if (semctl (id,0 ,IPC_RMID ) ==-1 ) -tst_brkm (TBROK |TERRNO ,NULL ,"Couldn't remove sem" ); -} -#endif /* _PROCESS_VM_H_ */
testcases/kernel/syscalls/cma/process_vm_readv02.c +5 -5
@@ -38,7 +38,6 @@ static char *tst_string = "THIS IS A TEST";static int len;static int pipe_fd[2 ];static pid_t pids[2 ]; -static int semid;static void child_alloc (void );static void child_invoke (void );
@@ -84,7 +83,7 @@ int main(int argc, char **argv)tst_resm (TFAIL ,"child 1 returns %d" , status);/* child_alloc is free to exit now */ -safe_semop (semid,0 ,1 ); +TST_SAFE_CHECKPOINT_WAKE (cleanup,0 );SAFE_WAITPID (cleanup, pids[0 ], &status,0 );if (!WIFEXITED (status) ||WEXITSTATUS (status) !=0 )
@@ -112,7 +111,7 @@ static void child_alloc(void)SAFE_CLOSE (tst_exit, pipe_fd[1 ]);/* wait until child_invoke is done reading from our VM */ -safe_semop (semid,0 ,-1 ); +TST_SAFE_CHECKPOINT_WAIT (cleanup,0 ); }static void child_invoke (void )
@@ -153,12 +152,13 @@ static void setup(void)tst_brkm (TCONF ,NULL ,"process_vm_readv does not exist " "on your system" );#endif - semid =init_sem (1 ); +tst_tmpdir (); +TST_CHECKPOINT_INIT (cleanup);TEST_PAUSE ; }static void cleanup (void ) { -clean_sem (semid); +tst_rmdir (); }
testcases/kernel/syscalls/cma/process_vm_readv03.c +5 -5
@@ -51,7 +51,6 @@ static int nr_iovecs;static long bufsz;static int pipe_fd[2 ];static pid_t pids[2 ]; -static int semid;static void gen_random_arr (int *arr,int arr_sz);static void child_alloc (int *bufsz_arr);
@@ -103,7 +102,7 @@ int main(int argc, char **argv)tst_resm (TFAIL ,"child 1 returns %d" , status);/* child_alloc is free to exit now */ -safe_semop (semid,0 ,1 ); +TST_SAFE_CHECKPOINT_WAKE (cleanup,0 );SAFE_WAITPID (cleanup, pids[0 ], &status,0 );if (!WIFEXITED (status) ||WEXITSTATUS (status) !=0 )
@@ -157,7 +156,7 @@ static void child_alloc(int *bufsz_arr)SAFE_CLOSE (tst_exit, pipe_fd[1 ]);/* wait until child_invoke is done reading from our VM */ -safe_semop (semid,0 ,-1 ); +TST_SAFE_CHECKPOINT_WAIT (cleanup,0 ); }static long *fetch_remote_addrs (void )
@@ -255,7 +254,8 @@ static void setup(void)tst_brkm (TCONF ,NULL ,"process_vm_readv does not exist " "on your system" );#endif - semid =init_sem (1 ); +tst_tmpdir (); +TST_CHECKPOINT_INIT (cleanup);srand (time (NULL ));TEST_PAUSE ;
@@ -263,7 +263,7 @@ static void setup(void)static void cleanup (void ) { -clean_sem (semid); +tst_rmdir (); }static void help (void )
testcases/kernel/syscalls/cma/process_vm_writev02.c +5 -5
@@ -48,7 +48,6 @@ static option_t options[] = {static long bufsz;static int pipe_fd[2 ];static pid_t pids[2 ]; -static int semid;static void child_init_and_verify (void );static void child_write (void );
@@ -97,7 +96,7 @@ int main(int argc, char **argv)tst_resm (TFAIL ,"child 1 returns %d" , status);/* signal child_init_and_verify to verify its VM now */ -safe_semop (semid,0 ,1 ); +TST_SAFE_CHECKPOINT_WAKE (cleanup,0 );SAFE_WAITPID (cleanup, pids[0 ], &status,0 );if (!WIFEXITED (status) ||WEXITSTATUS (status) !=0 )
@@ -126,7 +125,7 @@ static void child_init_and_verify(void)SAFE_CLOSE (tst_exit, pipe_fd[1 ]);/* wait until child_write() is done writing to our VM */ -safe_semop (semid,0 ,-1 ); +TST_SAFE_CHECKPOINT_WAIT (cleanup,0 ); nr_err =0 ;for (i =0 ; i < bufsz; i++) {
@@ -189,14 +188,15 @@ static void setup(void)tst_brkm (TCONF ,NULL ,"process_vm_writev does not exist " "on your system" );#endif - semid =init_sem (1 ); +tst_tmpdir (); +TST_CHECKPOINT_INIT (cleanup);TEST_PAUSE ; }static void cleanup (void ) { -clean_sem (semid); +tst_rmdir (); }static void help (void )
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH v2 1/6 syscalls/cma: Make process_vm_{readv, writev} tests bionic friendly
----- Original Message -----
Quoted 8 lines
All testcases under testcases/kernel/syscalls/cma depend on SysV semaphore to do event notification from parent<->child processes. Since bionic / android doesn't have SysV IPC, the tests can't be built against bionic.
Fix this by using the ltp
TST_SAFE_CHECKPOINTAPIs taht are based on futexes. The change enables following tests for Android devices.
Quoted 8 lines
process_vm01, process_vm_readv0[23], process_vm_writev02Signed-off-by Sandeep Patil <[email protected]>---
v1->v2
------
- UseTST_CHECKPOINTAPIs instead of eventfd as suggested by Jan
Pushed.
Thanks,
Jan
PATCH 2/6 mm: mallocstress: use safe macros wherever possible
In reply to Sandeep PatilThe test is currently doesn't use the test library at all and instead is a standlone program. While the conversion is being done, there is no reason why the program can't use SAFE_ macros. Make necessary changes to the program for the same, reducing the error check paths a lot.
--- testcases/kernel/mem/mtest07/mallocstress.c | 75 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 40 deletions(-)
testcases/kernel/mem/mtest07/mallocstress.c +35 -40
@@ -73,6 +73,10 @@#include <sys/ipc.h> #include <sys/sem.h> +#include "test.h" +#include "safe_macros.h" +#include "tst_safe_pthread.h" +#define MAXL 100/* default number of loops to do malloc and free */ #define MAXT 60/* default number of threads to create. */
@@ -90,6 +94,8 @@int num_loop =MAXL ;/* number of loops to perform */ int semid; +pthread_t *thrdid;/* the threads */ +int ret;/* program return value, used by main thread */ /* Define SPEW_SIGNALS to tickle thread_create bug (it fails if interrupted). */ #define SPEW_SIGNALS
@@ -272,6 +278,22 @@ void *alloc_mem(void *threadnum)return (void *)(uintptr_t ) (err ?-1 :0 ); } +/* only ever called from main thread */ +static void cleanup (void ) +{ +if (semid >0 ) { +if (semctl (semid,0 ,IPC_RMID ) ==-1 ) { +perror ("semctl\n" ); + ret =-1 ; + } + } + +if (thrdid) { +free (thrdid); + thrdid =NULL ; + } +} +/******************************************************************************/ /* */ /* Function: main */
@@ -294,10 +316,8 @@ int main(int argc, /* number of input parameters */int c;/* command line options */ int num_thrd =MAXT ;/* number of threads to create */ int thrd_ndx;/* index into the array of thread ids */ -pthread_t *thrdid;/* the threads */ extern int optopt;/* options to the program */ struct sembuf sop[1 ]; -int ret =0 ;while ((c =getopt (argc, argv,"hl:t:" )) !=-1 ) {switch (c) {
@@ -330,15 +350,13 @@ int main(int argc, /* number of input parameters */dprt (("number of times to loop in the thread = %d\n" , num_loop)); - thrdid =malloc (sizeof (pthread_t) * num_thrd); -if (thrdid ==NULL ) { -perror ("main(): allocating space for thrdid[] malloc()" ); -return 1 ; - } + thrdid =SAFE_MALLOC (cleanup,sizeof (pthread_t) * num_thrd); semid =semget (IPC_PRIVATE ,1 ,IPC_CREAT |0666 );if (semid <0 ) {perror ("Semaphore creation failed Reason:" ); + ret =-1 ; + goto out; } sop[0 ].sem_num =0 ;
@@ -351,19 +369,8 @@ int main(int argc, /* number of input parameters */ }for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) { -if (pthread_create (&thrdid[thrd_ndx],NULL , alloc_mem, - (void *)(uintptr_t ) thrd_ndx)) { -int err = errno; -if (err ==EINTR ) { -fprintf (stderr, -"main(): pthread_create failed with EINTR!\n" ); - ret =-1 ; - goto out; - } -perror ("main(): pthread_create()" ); - ret =-11 ; - goto out; - } +SAFE_PTHREAD_CREATE (&thrdid[thrd_ndx],NULL , alloc_mem, + (void *)(uintptr_t )thrd_ndx); }my_yield ();
@@ -376,32 +383,20 @@ int main(int argc, /* number of input parameters */for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) {void *th_status;/* exit status of LWP */ -if (pthread_join (thrdid[thrd_ndx], &th_status) !=0 ) { -perror ("main(): pthread_join()" ); +SAFE_PTHREAD_JOIN (thrdid[thrd_ndx], &th_status); +if ((intptr_t )th_status !=0 ) { +fprintf (stderr, +"%s: thread [%d] - exited with errors\n" , + __func__, thrd_ndx); ret =-1 ; goto out; - }else { -if ((intptr_t ) th_status !=0 ) { -fprintf (stderr, -"main(): thread [%d] - exited with errors\n" , - thrd_ndx); - ret =-1 ; - goto out; - } -dprt (("main(): thread [%d]: exited without errors\n" , - thrd_ndx)); } +dprt (("%s: thread [%d]: exited without errors\n" , + __func__, thrd_ndx));my_yield (); }printf ("main(): test passed.\n" ); out: -if (semctl (semid,0 ,IPC_RMID ) ==-1 ) { -perror ("semctl\n" ); - ret =-1 ; - } -if (thrdid) { -free (thrdid); - thrdid =NULL ; - } +cleanup ();exit (ret); }
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH 2/6 mm: mallocstress: use safe macros wherever possible
----- Original Message -----
Quoted 17 lines
The test is currently doesn't use the test library at all and instead is a standlone program. While the conversion is being done, there is no reason why the program can't use
SAFE_macros. Make necessary changes to the program for the same, reducing the error check paths a lot.Signed-off-by Sandeep Patil <[email protected]>--- testcases/kernel/mem/mtest07/mallocstress.c | 75 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 40 deletions(-)testcases/kernel/mem/mtest07/mallocstress.c +0
-0
testcases/kernel/mem/mtest07/mallocstress.c line 78
Quoted 6 lines
testcases/kernel/mem/mtest07/mallocstress.c +3
-0@@ -73,6 +73,10 @@#include <sys/ipc.h> #include <sys/sem.h> +#include "test.h" +#include "safe_macros.h" +#include "tst_safe_pthread.h"
This doesn't look entirely OK, because it's mixing oldlib and newlib. Some SAFE macros won't end up calling cleanup().
Would you care to create patch that converts it all to newlib? Using checkpoints is of course OK and preferred.
Regards,
Jan
PATCH 3/6 mm: mallocstress: use futexes instead of SysV semaphores
In reply to Sandeep PatilStart using TST_SAFE_CHECKPOINT_WAIT/WAKE macros that are based on futexes instead of SysV semaphore. This allows the test to build and run on an Android system.
--- testcases/kernel/mem/mtest07/mallocstress.c | 44 ++++------------------------- 1 file changed, 5 insertions(+), 39 deletions(-)
testcases/kernel/mem/mtest07/mallocstress.c +5 -39
@@ -93,7 +93,6 @@ }while (0 ) int num_loop = MAXL; /* number of loops to perform */ -int semid;pthread_t *thrdid;/* the threads */ int ret;/* program return value, used by main thread */
@@ -258,16 +257,8 @@ int allocate_free(int repeat, /* number of times to repeat allocate/free *//******************************************************************************/ void *alloc_mem (void *threadnum) { -struct sembuf sop[1 ]; - sop[0 ].sem_num =0 ; - sop[0 ].sem_op =0 ; - sop[0 ].sem_flg =0 ;/* waiting for other threads starting */ -if (semop (semid, sop,1 ) ==-1 ) { -if (errno !=EIDRM ) -perror ("semop" ); -return (void *)-1 ; - } +TST_SAFE_CHECKPOINT_WAIT (NULL ,0 );/* thread N will use growth scheme N mod 4 */ int err =allocate_free (num_loop, ((uintptr_t ) threadnum) %4 );
@@ -281,13 +272,6 @@ void *alloc_mem(void *threadnum)/* only ever called from main thread */ static void cleanup (void ) { -if (semid >0 ) { -if (semctl (semid,0 ,IPC_RMID ) ==-1 ) { -perror ("semctl\n" ); - ret =-1 ; - } - } -if (thrdid) {free (thrdid); thrdid =NULL ;
@@ -351,22 +335,8 @@ int main(int argc, /* number of input parameters */dprt (("number of times to loop in the thread = %d\n" , num_loop)); thrdid =SAFE_MALLOC (cleanup,sizeof (pthread_t) * num_thrd); - - semid =semget (IPC_PRIVATE ,1 ,IPC_CREAT |0666 ); -if (semid <0 ) { -perror ("Semaphore creation failed Reason:" ); - ret =-1 ; - goto out; - } - - sop[0 ].sem_num =0 ; - sop[0 ].sem_op =1 ; - sop[0 ].sem_flg =0 ; -if (semop (semid, sop,1 ) ==-1 ) { -perror ("semop" ); - ret =-1 ; - goto out; - } +tst_tmpdir (); +TST_CHECKPOINT_INIT (cleanup);for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) { SAFE_PTHREAD_CREATE(&thrdid[thrd_ndx], NULL, alloc_mem,
@@ -374,12 +344,8 @@ int main(int argc, /* number of input parameters */ }my_yield (); - sop[0 ].sem_op =-1 ; -if (semop (semid, sop,1 ) ==-1 ) { -perror ("semop" ); - ret =-1 ; - goto out; - } +/* Wake up all threads */ +TST_SAFE_CHECKPOINT_WAKE2 (cleanup,0 , num_thrd);for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) {void *th_status;/* exit status of LWP */
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH v2 4/6 direct_io: diotest4: use getpagesize() for mmap if shm header is absent
In reply to Sandeep PatilFor some architectures, mmap(MAP_FIXED) has to be aligned to SHMLBA (instead of getpagesize()) --
https://sourceforge.net/p/ltp/mailman/ltp-list/?viewmonth=200804
This dependency on SHMLBA causes the test to fail building for Android due to absence of sys/shm.h. Make the header dependency configurable and use getpagesize() as mmap granularity if the header is absent allowing the test to work on Android while not breaking the architectures that depend on the shm headers.
---v1->v2
------
- Instead of relying on __BIONIC__, fix by doing a header check for <sys/shm> and if the header doesn't exist, use getpagesize() as mmap granularity, otherwise use SHMBA (as before)
configure.ac | 1 + include/lapi/mmap.h | 8 ++++++++ testcases/kernel/io/direct_io/diotest4.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-)
configure.ac +1 -0
@@ -47,6 +47,7 @@ AC_CHECK_HEADERS([ \ sys/fanotify.h \ sys/inotify.h \ sys/prctl.h \ + sys/shm.h \ sys/ustat.h \ sys/xattr.h \ ])
include/lapi/mmap.h +8 -0
@@ -71,4 +71,12 @@# define MADV_FREE 8#endif +#ifdef HAVE_SYS_SHM_H +# include <sys/shm.h> +# define MMAP_GRANULARITY SHMLBA +#else +# include <unistd.h> +# define MMAP_GRANULARITY getpagesize() +#endif /* HAVE_SYS_SHM_H */ +#endif /* LAPI_MMAP_H__ */
testcases/kernel/io/direct_io/diotest4.c +2 -2
@@ -65,12 +65,12 @@#include <sys/mman.h> #include <sys/syscall.h> #include <errno.h> -#include <sys/shm.h> #include "diotest_routines.h" #include "test.h" #include "safe_macros.h" +#include "lapi/mmap.h" char *TCID ="diotest4" ;/* Test program identifier. */ int TST_TOTAL =17 ;/* Total number of test conditions */
@@ -196,7 +196,7 @@ int main(int argc, char *argv[])int fd, newfd;int i, l_fail =0 , fail_count =0 , total =0 ;int failed =0 ; -int shmsz =SHMLBA ; +int shmsz =MMAP_GRANULARITY ;int pagemask = ~(sysconf (_SC_PAGE_SIZE) -1 );char *buf0, *buf1, *buf2;caddr_t shm_base;
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH v2 4/6 direct_io: diotest4: use getpagesize() for mmap if shm header is absent
----- Original Message -----
Quoted 12 lines
For some architectures,
mmap(MAP_FIXED)has to be aligned to SHMLBA (instead ofgetpagesize()) --https://sourceforge.net/p/ltp/mailman/ltp-list/?viewmonth=200804This dependency on SHMLBA causes the test to fail building for Android due to absence of
sys/shm.h. Make the header dependency configurable and usegetpagesize()as mmap granularity if the header is absent allowing the test to work on Android while not breaking the architectures that depend on the shm headers.Signed-off-by Sandeep Patil <[email protected]>
Quoted 8 lines
---
v1->v2
------
- Instead of relying on__BIONIC__, fix by doing a header check for <sys/shm> and
if the header doesn't exist, usegetpagesize()as mmap granularity, otherwise
use SHMBA (as before)
Pushed.
Thanks,
Jan
PATCH 5/6 syscalls/mkdir03: convert to new API and use .needsrofs for EROFS check
In reply to Sandeep PatilThe mkdir03 test is converted to the new API along with removing the need to manually acquire and mount a loopback devices for EROFS checks. This now makes it possible for the test to run on Android systems as well.
--- testcases/kernel/syscalls/mkdir/mkdir03.c | 147 +++++++++--------------------- 1 file changed, 42 insertions(+), 105 deletions(-)
testcases/kernel/syscalls/mkdir/mkdir03.c +42 -105
@@ -29,19 +29,12 @@#include <fcntl.h> #include <sys/mount.h> -#include "test.h" -#include "safe_macros.h" - -static void setup (void ); -struct test_case_t ; -static void mkdir_verify (struct test_case_t *tc); -static void bad_addr_setup (struct test_case_t *tc); -static void cleanup (void ); -static int mount_flag; +#include "tst_test.h" #define TST_EEXIST "tst_eexist"#define TST_ENOENT "tst_enoent/tst" -#define TST_ENOTDIR "tst_enotdir/tst" +#define TST_ENOTDIR_FILE "tst_enotdir" +#define TST_ENOTDIR_DIR "tst_enotdir/tst"#define MODE 0777#define MNT_POINT "mntpoint"
@@ -49,122 +42,66 @@ static int mount_flag; S_IXGRP|S_IROTH|S_IXOTH)#define TST_EROFS "mntpoint/tst_erofs" -char *TCID ="mkdir03" ; - -static char long_dir[PATH_MAX +2 ]; +static char long_dir[PATH_MAX +2 ] = {[0 ...PATH_MAX +1 ] ='a' };static char loop_dir[PATH_MAX ] ="." ; -static const char *device; -static struct test_case_t { +static struct tcase {char *pathname; -int mode;int exp_errno; -void (*setupfunc) (struct test_case_t *tc); }TC [] = { #if !defined(UCLINUX) - {NULL ,MODE ,EFAULT , bad_addr_setup}, + {NULL ,EFAULT }, #endif - {long_dir,MODE ,ENAMETOOLONG ,NULL }, - {TST_EEXIST ,MODE ,EEXIST ,NULL }, - {TST_ENOENT ,MODE ,ENOENT ,NULL }, - {TST_ENOTDIR ,MODE ,ENOTDIR ,NULL }, - {loop_dir,MODE ,ELOOP ,NULL }, - {TST_EROFS ,MODE ,EROFS ,NULL }, + {long_dir,ENAMETOOLONG }, + {TST_EEXIST ,EEXIST }, + {TST_ENOENT ,ENOENT }, + {TST_ENOTDIR_DIR ,ENOTDIR }, + {loop_dir,ELOOP }, + {TST_EROFS ,EROFS }, }; -int TST_TOTAL =ARRAY_SIZE (TC ); - -int main (int ac,char **av) -{ -int i, lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -for (i =0 ; i <TST_TOTAL ; i++) -mkdir_verify (&TC [i]); - } - -cleanup (); -tst_exit (); -} - -static void setup (void ) -{ -int i; -const char *fs_type; - -tst_require_root (); - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - - fs_type =tst_dev_fs_type (); - device =tst_acquire_device (cleanup); - -if (!device) -tst_brkm (TCONF , cleanup,"Failed to acquire device" ); - -memset (long_dir,'a' ,PATH_MAX +1 ); - -SAFE_TOUCH (cleanup,TST_EEXIST ,MODE ,NULL ); - -SAFE_TOUCH (cleanup,"tst_enotdir" ,MODE ,NULL ); - -SAFE_MKDIR (cleanup,"test_eloop" ,DIR_MODE ); -SAFE_SYMLINK (cleanup,"../test_eloop" ,"test_eloop/test_eloop" ); -for (i =0 ; i <43 ; i++) -strcat (loop_dir,"/test_eloop" ); - -tst_mkfs (cleanup, device, fs_type,NULL ,NULL ); -SAFE_MKDIR (cleanup,MNT_POINT ,DIR_MODE ); -SAFE_MOUNT (cleanup, device,MNT_POINT , fs_type,MS_RDONLY ,NULL ); - mount_flag =1 ; -} - -#if !defined(UCLINUX ) -static void bad_addr_setup (struct test_case_t *tc) -{ - tc->pathname =SAFE_MMAP (cleanup,0 ,1 ,PROT_NONE , -MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); -} -#endif - -static void mkdir_verify (struct test_case_t *tc) +static void verify_mkdir (unsigned int n) { -if (tc->setupfunc !=NULL ) - tc->setupfunc (tc); - -TEST (mkdir (tc->pathname, tc->mode)); +struct tcase *tc =TC + n; +TEST (mkdir (tc->pathname,MODE ));if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"mkdir() returned %ld, expected -1, errno=%d" , -TEST_RETURN , tc->exp_errno); +tst_res (TFAIL ,"mkdir() returned %ld, expected -1, errno=%d" , +TEST_RETURN , tc->exp_errno);return ; }if (TEST_ERRNO == tc->exp_errno) { -tst_resm (TPASS |TTERRNO ,"mkdir() failed as expected" ); +tst_res (TPASS |TTERRNO ,"mkdir() failed as expected" ); }else { -tst_resm (TFAIL |TTERRNO , -"mkdir() failed unexpectedly; expected: %d - %s" , +tst_res (TFAIL |TTERRNO , +"mkdir() failed unexpectedly; expected: %d - %s" , tc->exp_errno,strerror (tc->exp_errno)); } } -static void cleanup (void ) +static void setup (void ) { -if (mount_flag &&tst_umount (MNT_POINT ) <0 ) -tst_resm (TWARN |TERRNO ,"umount device:%s failed" , device); - -if (device) -tst_release_device (device); +int i; +#if !defined(UCLINUX ) +TC [0 ].pathname =SAFE_MMAP (0 ,1 ,PROT_NONE , +MAP_PRIVATE |MAP_ANONYMOUS ,0 ,0 ); +#endif +SAFE_TOUCH (TST_EEXIST ,MODE ,NULL ); +SAFE_TOUCH (TST_ENOTDIR_FILE ,MODE ,NULL ); -tst_rmdir (); +SAFE_MKDIR ("test_eloop" ,DIR_MODE ); +SAFE_SYMLINK ("../test_eloop" ,"test_eloop/test_eloop" ); +for (i =0 ; i <43 ; i++) +strcat (loop_dir,"/test_eloop" ); } + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (TC ), + .needs_tmpdir =1 , + .needs_root =1 , + .needs_rofs =1 , + .mntpoint =MNT_POINT , + .setup = setup, + .test = verify_mkdir, +};
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH 5/6 syscalls/mkdir03: convert to new API and use .needsrofs for EROFS check
----- Original Message -----
Quoted 6 lines
The mkdir03 test is converted to the new API along with removing the need to manually acquire and mount a loopback devices for EROFS checks. This now makes it possible for the test to run on Android systems as well.
Signed-off-by Sandeep Patil <[email protected]>
Pushed with 2 small changes:
- drop UCLINUX support
- keep the setupfunc, so that we don't hardcode indexes into tcase array
Thanks,
Jan
PATCH 6/6 lib: mkfs: use 'mke2fs' on android systems for formatting filesystems
In reply to Sandeep PatilAndroid does not have mkfs.extN symlinks and only extN filesystems images can be created on the device. So, make sure we use 'mke2fs -t <fs_type>' when being built for Android and filter out any non-ext filesystem type requests from tst_mkfs_() when built for Android.
syscalls/mmap16, syscalls/rename11 are the tests the tests currently known to start working after this change on Android systems
--- lib/tst_mkfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
lib/tst_mkfs.c +16 -0
@@ -43,7 +43,23 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),return ; } +#ifdef __ANDROID__ +if (strncmp (fs_type,"ext" ,3 )) { +tst_brkm (TBROK , cleanup_fn, +"%s:%d: \'%s\' fs_type not supported" , file, lineno, fs_type); +return ; + } +strcpy (mkfs,"mke2fs" ); + +/* insert '-t <fs_type> in arguments here */ + argv[pos++] ="-t" ; +strcat (fs_opts_str,"-t " ); + argv[pos++] = fs_type; +strcat (fs_opts_str, fs_type); +strcat (fs_opts_str," " ); +#else snprintf (mkfs,sizeof (mkfs),"mkfs.%s" , fs_type); +#endif if (fs_opts) {for (i =0 ; fs_opts[i]; i++) {
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
PATCH 6/6 lib: mkfs: use 'mke2fs' on android systems for formatting filesystems
----- Original Message -----
Quoted 4 lines
Android does not have mkfs.extN symlinks and only extN filesystems images can be created on the device. So, make sure we use 'mke2fs -t <
fs_type>' when being built for Android and filter out any non-ext filesystem type requests fromtst_mkfs_()when built for Android.
Hi,
So we probably need something similar for:
d1f9382ba7c8 "lib: Add interface to list supported filesystems"
that introduced ".all_filesystems" as it also checks for mkfs.XXX.
Quoted 14 lines
syscalls/mmap16, syscalls/rename11 are the tests the tests currently known to start working after this change on Android systems
Signed-off-by Sandeep Patil <[email protected]>--- lib/tst_mkfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)lib/tst_mkfs.c +0
-0
lib/tst_mkfs.c void tst_mkfs_(const char *file, const int lineno, void · line 50
Quoted 8 lines
lib/tst_mkfs.c +4
-0@@ -43,7 +43,23 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void), return; } +#ifdef __ANDROID__ +if (strncmp (fs_type,"ext" ,3 )) { +tst_brkm (TBROK , cleanup_fn, +"%s:%d: \'%s\' fs_type not supported" , file, lineno, fs_type);
This looks like it should TCONF instead. TBROK suggests there's something broken about the test, but this is more property of the environment where it runs.
We TCONF already if mkfs.XXX can't be found couple lines below. Maybe we could use it for android too, what do you think?
#ifdef __ANDROID__
if (!strncmp(fs_type, "ext", 3)) {
// use mke2fs
}
#endif
if (pos == 1)
// use mkfs.XXX
Regards,
Jan
Quoted 20 lines
lib/tst_mkfs.c +12
-0+ return; + } +strcpy (mkfs,"mke2fs" ); + +/* insert '-t <fs_type> in arguments here */ + argv[pos++] ="-t" ; +strcat (fs_opts_str,"-t " ); + argv[pos++] = fs_type; +strcat (fs_opts_str, fs_type); +strcat (fs_opts_str," " ); +#else snprintf (mkfs,sizeof (mkfs),"mkfs.%s" , fs_type); +#endif if (fs_opts) {for (i = 0; fs_opts[i]; i++) {
--
2.15.0.448.gf294e3d99a-goog
PATCH 6/6 lib: mkfs: use 'mke2fs' on android systems for formatting filesystems
Quoted 8 lines · Jan Stancek
----- Original Message -----
Quoted 4 lines
Android does not have mkfs.extN symlinks and only extN filesystems images can be created on the device. So, make sure we use 'mke2fs -t <
fs_type>' when being built for Android and filter out any non-ext filesystem type requests fromtst_mkfs_()when built for Android.
Quoted 5 lines
Hi,
So we probably need something similar for:
d1f9382ba7c8"lib: Add interface to list supported filesystems"
that introduced ".all_filesystems" as it also checks for mkfs.XXX.
Yes, I saw those changes after. I'll pull and add changes there too.
Quoted 30 lines
Quoted 15 lines
syscalls/mmap16, syscalls/rename11 are the tests the tests currently known to start working after this change on Android systems
Signed-off-by Sandeep Patil <[email protected]>--- lib/tst_mkfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)lib/tst_mkfs.c +0
-0lib/tst_mkfs.c void tst_mkfs_(const char *file, const int lineno, void · line 50
Quoted 8 lines
lib/tst_mkfs.c +4
-0@@ -43,7 +43,23 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void), return; } +#ifdef __ANDROID__ +if (strncmp (fs_type,"ext" ,3 )) { +tst_brkm (TBROK , cleanup_fn, +"%s:%d: \'%s\' fs_type not supported" , file, lineno, fs_type);This looks like it should TCONF instead. TBROK suggests there's something broken about the test, but this is more property of the environment where it runs.
We TCONF already if mkfs.XXX can't be found couple lines below. Maybe we could use it for android too, what do you think?
Quoted 8 lines
#ifdef
__ANDROID__
if (!strncmp(fs_type, "ext", 3)) {
// use mke2fs
}
#endifif (pos == 1)
// use mkfs.XXX
agree, will respin.
- ssp
Quoted 24 lines
Regards,
JanQuoted 20 lines
lib/tst_mkfs.c +12
-0+ return; + } +strcpy (mkfs,"mke2fs" ); + +/* insert '-t <fs_type> in arguments here */ + argv[pos++] ="-t" ; +strcat (fs_opts_str,"-t " ); + argv[pos++] = fs_type; +strcat (fs_opts_str, fs_type); +strcat (fs_opts_str," " ); +#else snprintf (mkfs,sizeof (mkfs),"mkfs.%s" , fs_type); +#endif if (fs_opts) {for (i = 0; fs_opts[i]; i++) {
--
2.15.0.448.gf294e3d99a-goog