Skip to content

Commit

Permalink
fix some bug when install and run xcuitest & supoort context in forwa…
Browse files Browse the repository at this point in the history
…rd and xcuitestrunner & add fsync (#144)

* fix: install ipa failed below iOS 10

* fix: run xcuitest failed bug

* support context and export StartNewProxyConnection in forward

* support fsync

* fix: house_arrest connection close failed when it is nil

* support context in xcuitestrunner

Co-authored-by: colerwang <colerwang@tencent.com>
  • Loading branch information
wangchaoHZ and colerwang committed Jul 13, 2022
1 parent 89cfb69 commit 94f24f8
Show file tree
Hide file tree
Showing 16 changed files with 1,044 additions and 443 deletions.
438 changes: 141 additions & 297 deletions ios/afc/afc.go

Large diffs are not rendered by default.

408 changes: 408 additions & 0 deletions ios/afc/fsync.go

Large diffs are not rendered by default.

125 changes: 125 additions & 0 deletions ios/afc/fsync_test.go
@@ -0,0 +1,125 @@
package afc

/*
const test_device_udid = "your device udid"
func TestConnection_Remove(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
err = conn.Remove("/DCIM/goios")
if err != nil {
log.Fatalf("remove failed:%v", err)
}
}
func TestConnection_Mkdir(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
err = conn.MkDir("/DCIM/TestDir")
if err != nil {
log.Fatalf("mkdir failed:%v", err)
}
}
func TestConnection_stat(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
si, err := conn.Stat("/DCIM/architecture_diagram.png")
if err != nil {
log.Fatalf("get Stat failed:%v", err)
}
log.Printf("Stat :%+v", si)
}
func TestConnection_listDir(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
flist, err := conn.listDir("/DCIM/")
if err != nil {
log.Fatalf("tree view failed:%v", err)
}
for _, v := range flist {
fmt.Printf("path: %+v\n", v)
}
}
func TestConnection_TreeView(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
err = conn.TreeView("/DCIM/", "", true)
if err != nil {
log.Fatalf("tree view failed:%v", err)
}
}
func TestConnection_pullSingleFile(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
err = conn.PullSingleFile("/DCIM/architecture_diagram.png", "architecture_diagram.png")
if err != nil {
log.Fatalf("pull single file failed:%v", err)
}
}
func TestConnection_Pull(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
srcPath := "/DCIM/"
dstpath := "TempRecv"
dstpath = path.Join(dstpath, srcPath)
err = conn.Pull(srcPath, dstpath)
if err != nil {
log.Fatalf("pull failed:%v", err)
}
}
func TestConnection_Push(t *testing.T) {
deviceEnrty, _ := ios.GetDevice(test_device_udid)
conn, err := New(deviceEnrty)
if err != nil {
log.Fatalf("connect service failed: %v", err)
}
srcPath := "your src path"
dstpath := "your dst path"
err = conn.Push(srcPath, dstpath)
if err != nil {
log.Fatalf("push failed:%v", err)
}
}
*/
88 changes: 0 additions & 88 deletions ios/afc/house_arrest.go

This file was deleted.

16 changes: 4 additions & 12 deletions ios/crashreport/crashreport.go
Expand Up @@ -50,14 +50,14 @@ func copyReports(afc *afc.Connection, cwd string, pattern string, targetDir stri
devicePath := path.Join(cwd, f)
targetFilePath := path.Join(targetDir, f)
log.WithFields(log.Fields{"from": devicePath, "to": targetFilePath}).Info("downloading")
info, err := afc.GetFileInfo(devicePath)
info, err := afc.Stat(devicePath)
if err != nil {
log.Warnf("failed getting info for file: %s, skipping", f)
continue
}
log.Debugf("%+v", info)

if info.IsDir() {
if info.IsDir(){
err := os.Mkdir(targetFilePath, targetDirInfo.Mode().Perm())
if err != nil {
return err
Expand All @@ -69,15 +69,7 @@ func copyReports(afc *afc.Connection, cwd string, pattern string, targetDir stri
continue
}

targetFileHandle, err := os.Create(targetFilePath)
if err != nil {
return err
}
err = afc.DownloadFile(devicePath, targetFileHandle)
if err != nil {
return err
}
err = targetFileHandle.Close()
err = afc.PullSingleFile(devicePath, targetFilePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +101,7 @@ func RemoveReports(device ios.DeviceEntry, cwd string, pattern string) error {
continue
}
log.WithFields(log.Fields{"path": path.Join(cwd, f)}).Info("delete")
err := afc.Delete(path.Join(cwd, f))
err := afc.Remove(path.Join(cwd, f))
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions ios/dtx_codec/channel.go
Expand Up @@ -57,6 +57,7 @@ func (d *Channel) MethodCall(selector string, args ...interface{}) (Message, err
msg, err := d.SendAndAwaitReply(true, Methodinvocation, payload, auxiliary)
if err != nil {
log.WithFields(log.Fields{"channel_id": d.channelName, "error": err, "methodselector": selector}).Info("failed starting invoking method")
return msg, err
}
if msg.HasError() {
return msg, fmt.Errorf("Failed invoking method '%s' with error: %s", selector, msg.Payload[0])
Expand All @@ -73,6 +74,7 @@ func (d *Channel) MethodCallAsync(selector string, args ...interface{}) error {
err := d.Send(false, Methodinvocation, payload, auxiliary)
if err != nil {
log.WithFields(log.Fields{"channel_id": d.channelName, "error": err, "methodselector": selector}).Info("failed starting invoking method")
return err
}
return nil
}
Expand Down
17 changes: 10 additions & 7 deletions ios/dtx_codec/connection.go
Expand Up @@ -18,7 +18,7 @@ type MethodWithResponse func(msg Message) (interface{}, error)
type Connection struct {
deviceConnection ios.DeviceConnectionInterface
channelCodeCounter int
activeChannels map[int]*Channel
activeChannels sync.Map
globalChannel *Channel
capabilities map[string]interface{}
mutex sync.Mutex
Expand Down Expand Up @@ -72,8 +72,10 @@ func (g GlobalDispatcher) Dispatch(msg Message) {
}
//TODO: use the dispatchFunctions map
if "outputReceived:fromProcess:atTime:" == msg.Payload[0] {
msg, _ := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[0].([]byte))
log.Info(msg[0])
msg, err := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[0].([]byte))
if err == nil {
log.Info(msg[0])
}
return
}
}
Expand All @@ -96,7 +98,7 @@ func NewConnection(device ios.DeviceEntry, serviceName string) (*Connection, err
requestChannelMessages := make(chan Message, 5)

//The global channel has channelCode 0, so we need to start with channelCodeCounter==1
dtxConnection := &Connection{deviceConnection: conn, channelCodeCounter: 1, activeChannels: map[int]*Channel{}, requestChannelMessages: requestChannelMessages}
dtxConnection := &Connection{deviceConnection: conn, channelCodeCounter: 1, requestChannelMessages: requestChannelMessages}

//The global channel is automatically present and used for requesting other channels and some other methods like notifyPublishedCapabilities
globalChannel := Channel{channelCode: 0,
Expand Down Expand Up @@ -132,7 +134,8 @@ func reader(dtxConn *Connection) {
return
}

if channel, ok := dtxConn.activeChannels[msg.ChannelCode]; ok {
if _channel, ok := dtxConn.activeChannels.Load(msg.ChannelCode); ok {
channel := _channel.(*Channel)
channel.Dispatch(msg)
} else {
dtxConn.globalChannel.Dispatch(msg)
Expand All @@ -158,7 +161,7 @@ func (dtxConn *Connection) ForChannelRequest(messageDispatcher Dispatcher) *Chan
identifier, _ := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[1].([]byte))
//TODO: Setting the channel code here manually to -1 for making testmanagerd work. For some reason it requests the TestDriver proxy channel with code 1 but sends messages on -1. Should probably be fixed somehow
channel := &Channel{channelCode: -1, channelName: identifier[0].(string), messageIdentifier: 1, connection: dtxConn, messageDispatcher: messageDispatcher, responseWaiters: map[int]chan Message{}, defragmenters: map[int]*FragmentDecoder{}, timeout: 5 * time.Second}
dtxConn.activeChannels[-1] = channel
dtxConn.activeChannels.Store(-1, channel)
return channel
}

Expand All @@ -184,7 +187,7 @@ func (dtxConn *Connection) RequestChannelIdentifier(identifier string, messageDi
}
log.WithFields(log.Fields{"channel_id": identifier}).Debug("Channel open")
channel := &Channel{channelCode: code, channelName: identifier, messageIdentifier: 1, connection: dtxConn, messageDispatcher: messageDispatcher, responseWaiters: map[int]chan Message{}, defragmenters: map[int]*FragmentDecoder{}, timeout: 5 * time.Second}
dtxConn.activeChannels[code] = channel
dtxConn.activeChannels.Store(code, channel)
for _, opt := range opts {
opt(channel)
}
Expand Down

0 comments on commit 94f24f8

Please sign in to comment.