1 # Copyright (C) 2013-2016, 2019 Free Software Foundation, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # DejaGnu is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu. If not, see <http://www.gnu.org/licenses/>.
18 process_multilib_options ""
20 load_generic_config "adb"
22 # We need this for find_gcc and *_include_flags/*_link_flags.
23 load_base_board_description "adb"
25 # We may need -mandroid.
26 set_board_info cflags "-mandroid"
27 set_board_info ldflags "-mandroid"
30 # load PROG to DEST and run it with ARGS using adb
32 proc adb_load { dest prog args } {
33 # Default directory uses tmpfs, so it is the best place to run
34 # tests to avoid excessive wear of flash.
35 global android_tmp_dir
36 if { $android_tmp_dir ne "" } {
37 verbose -log "android temporary directory is set to $android_tmp_dir" 3
39 set android_tmp_dir "/mnt/sdcard/.android_secure"
40 verbose -log "android temporary directory will be used by default $android_tmp_dir" 3
43 if { [llength $args] > 0 } {
44 set pargs [lindex $args 0]
49 if { [llength $args] > 1 } {
50 set inp "[lindex $args 1]"
55 if {![file exists $prog]} then {
56 # We call both here because this should never happen.
57 perror "$prog does not exist in standard_load."
58 verbose -log "$prog does not exist." 3
62 if {[isremote $dest]} {
63 set localfile "./[file tail $prog].[pid]"
64 set remotefile "$android_tmp_dir/[file tail $prog].[pid]"
65 set remotefile [remote_download $dest $prog $remotefile]
66 if { $remotefile eq "" } {
67 verbose -log "Download of $prog to [board_info $dest name] failed." 3
70 set retval [remote_exec $dest "test -x $remotefile"]
71 if { $retval ne "0 {}" } {
72 # Android doesn't support symbolic input for chmod, therefore set executable permission by number
73 set retval [remote_exec $dest "chmod 755 $remotefile"]
74 if { $retval ne "0 {}" } {
75 verbose -log "Setting executable permissions of $prog on [board_info $dest name] failed." 3
79 if {[board_info $dest exists remote_link]} {
80 if {[[board_info $dest remote_link] $remotefile]} {
81 verbose -log "Couldn't do remote link"
82 # Can't use remote_file delete since /system/bin/rm does not
83 # support -f on Android.
84 remote_exec $dest rm $remotefile
88 set status [remote_exec $dest $localfile $pargs $inp]
89 remote_exec $dest rm $remotefile
91 set status [remote_exec $dest $prog $pargs $inp]
93 if { [lindex $status 0] < 0 } {
94 verbose -log "Couldn't execute $prog, [lindex $status 1]" 3
97 set output [lindex $status 1]
98 set status [lindex $status 0]
100 verbose -log "Executed $prog, status $status" 2
102 verbose -log -- $output 2
104 if { $status == 0 } {
105 return [list "pass" $output]
107 return [list "fail" $output]