forked from DeviceFarmer/stf
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Di/ios provider/file and logs/qa 16207 #119
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38fed00
add log parsing by tags
5c5f9fc
remake install
f58f3d1
implement storage navigation
b58d961
beatify
3e24c6f
Merge remote-tracking branch 'github/master' into di/ios-provider/fil…
976e6a0
fix name in log
b85bc6e
Update lib/units/ios-device/plugins/filesystem.js
DaniilSmirnov 9cd7343
Merge remote-tracking branch 'github/di/ios-provider/file-and-logs/QA…
e32d87e
review fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,14 @@ import push from '../../base-device/support/push.js' | |
import router from '../../base-device/support/router.js' | ||
import sub from '../../base-device/support/sub.js' | ||
import group from './group.js' | ||
import {IncompleteJsonParser} from 'incomplete-json-parser' | ||
|
||
export default syrup | ||
.serial() | ||
export default syrup.serial() | ||
.dependency(push) | ||
.dependency(router) | ||
.dependency(sub) | ||
.dependency(group) | ||
.define(function(options, push, router, group) { | ||
.define(function(options, push, router, sub, group) { | ||
const log = logger.createLogger('device:plugins:devicelog') | ||
|
||
let DeviceLogger = { | ||
|
@@ -31,17 +31,79 @@ export default syrup | |
, startLogging: async function(channel) { | ||
DeviceLogger.setChannel(channel) | ||
try { | ||
DeviceLogger.stream = spawn('idb logs --udid ' + options.serial, {shell: true}) | ||
const realGroup = await group.get() | ||
const parser = new IncompleteJsonParser() | ||
|
||
DeviceLogger.stream = spawn('idb', ['log', '--udid', options.serial, '--', '--style', 'json']) | ||
|
||
DeviceLogger.stream.stdout.on('data', data => { | ||
push.send([ | ||
this.channel | ||
, wireutil.envelope(new wire.DeviceLogcatEntryMessage(options.serial, new Date().getTime() / 1000, DeviceLogger.stream.pid, DeviceLogger.stream.pid, 1, 'device:log:cat', data.toString())) | ||
]) | ||
parser.write(data.toString()) | ||
let logs = parser.getObjects() | ||
let threadId = 0 | ||
let processId = 0 | ||
let subsystem = '*' | ||
let timestamp = new Date().getTime() / 1000 | ||
let message | ||
logs.forEach(log => { | ||
let logLevel = 2 | ||
switch (log.messageType) { | ||
case 'Fatal': { logLevel = 7; break } | ||
case 'Error': { logLevel = 6; break } | ||
case 'Warning': { logLevel = 5; break } | ||
case 'Default': { logLevel = 4; break } | ||
case 'Activity': { logLevel = 3; break } | ||
} | ||
|
||
if (log.eventMessage) { | ||
message = log.eventMessage | ||
} | ||
else if (log.formatString) { | ||
message = log.formatString | ||
} | ||
else { | ||
return | ||
} | ||
|
||
if (log.threadID) { | ||
threadId = log.threadID | ||
} | ||
|
||
if (log.processID) { | ||
processId = log.processID | ||
} | ||
|
||
if (log.timestamp) { | ||
timestamp = log.timestamp | ||
} | ||
|
||
if (log.subsystem) { | ||
subsystem = log.subsystem | ||
} | ||
else { | ||
subsystem = '*' | ||
} | ||
|
||
push.send([ | ||
realGroup.group | ||
, wireutil.envelope(new wire.DeviceLogcatEntryMessage( | ||
options.serial | ||
, Date.parse(timestamp) / 1000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
, processId | ||
, threadId | ||
, logLevel | ||
, subsystem | ||
, message | ||
)) | ||
]) | ||
}) | ||
}) | ||
|
||
DeviceLogger.stream.stderr.on('data', data => { | ||
console.log(data.toString()) | ||
}) | ||
|
||
DeviceLogger.stream.on('close', err => { | ||
log.fatal('Unable to get devicelog', err) | ||
log.warn('Stream is closed', err) | ||
DeviceLogger.killLoggingProcess() | ||
}) | ||
} | ||
|
@@ -52,7 +114,6 @@ export default syrup | |
|
||
, killLoggingProcess: () => { | ||
if (DeviceLogger.stream) { | ||
process.kill(-DeviceLogger.stream.pid) | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DeviceLogger.stream.kill() | ||
DeviceLogger.stream = null | ||
DeviceLogger.channel = '' | ||
|
@@ -76,7 +137,9 @@ export default syrup | |
} | ||
}) | ||
.on(wire.LogcatStopMessage, function(channel, data) { | ||
const reply = wireutil.reply(options.serial) | ||
DeviceLogger.killLoggingProcess() | ||
push.send([channel, reply.okay('success')]) | ||
}) | ||
.on(wire.GroupMessage, function(channel, data) { | ||
DeviceLogger.channel = channel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import syrup from '@devicefarmer/stf-syrup' | ||
import logger from '../../../util/logger.js' | ||
import wire from '../../../wire/index.js' | ||
import wireutil from '../../../wire/util.js' | ||
import router from '../../base-device/support/router.js' | ||
import push from '../../base-device/support/push.js' | ||
import storage from '../../base-device/support/storage.js' | ||
import {execFile} from 'child_process' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import {v4 as uuidv4} from 'uuid' | ||
export default syrup.serial() | ||
.dependency(router) | ||
.dependency(push) | ||
.dependency(storage) | ||
.define(function(options, router, push, storage) { | ||
const log = logger.createLogger('device:plugins:filesystem') | ||
let plugin = Object.create(null) | ||
|
||
const getIdbTarget = dir => { | ||
let currentPath = dir.split('/') | ||
let rootDir = currentPath[1] | ||
if (['root', 'application', 'crashes'].indexOf(rootDir) !== -1) { | ||
return rootDir | ||
} | ||
else { | ||
return 'media' | ||
} | ||
} | ||
|
||
router.on(wire.FileSystemGetMessage, function(channel, message) { | ||
let reply = wireutil.reply(options.serial) | ||
let file = message.file | ||
log.info('Retrieving file "%s"', file) | ||
let currentPath = file.split('/') | ||
let target = getIdbTarget(file) | ||
let tempFileName = `tmp_${uuidv4()}` | ||
|
||
if (currentPath.length === 2) { | ||
currentPath = '' | ||
} | ||
else { | ||
currentPath = currentPath.slice(2).join('/').replace(' ', '\\ ') | ||
} | ||
|
||
execFile('idb', ['file', 'pull', `--${target}`, currentPath, `/tmp/${tempFileName}`, '--json', '--udid', options.serial], | ||
(error, stdout, stderr) => { | ||
if (error) { | ||
log.warn('Unable to list directory "%s"', file, stderr) | ||
} | ||
|
||
storage.store('blob', path.basename(file), { | ||
filename: path.basename(file) | ||
, contentType: 'application/octet-stream' | ||
}).then((file) => { | ||
try { | ||
push.send([ | ||
channel | ||
, reply.okay('success', file) | ||
]) | ||
} | ||
catch (e) { | ||
push.send([ | ||
channel | ||
, reply.fail('error', e) | ||
]) | ||
} | ||
fs.unlink(`/tmp/${tempFileName}`, (err) => { | ||
log.warn('Error while deleting file "%s"', file, err) | ||
}) | ||
}) | ||
} | ||
) | ||
}) | ||
router.on(wire.FileSystemListMessage, function(channel, message) { | ||
let reply = wireutil.reply(options.serial) | ||
let dirs = [] | ||
let rootDir = message.dir | ||
if (rootDir === '/') { | ||
dirs = [ | ||
{name: 'root', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
, {name: 'application', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
, {name: 'crashes', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
, {name: 'media', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
] | ||
push.send([ | ||
channel | ||
, reply.okay('success', dirs) | ||
]) | ||
} | ||
let currentPath = message.dir.split('/') | ||
let target = getIdbTarget(message.dir) | ||
|
||
if (currentPath.length === 2) { | ||
currentPath = '' | ||
} | ||
else { | ||
currentPath = currentPath.slice(2).join('/').replace(' ', '\\ ') | ||
} | ||
|
||
execFile('idb', ['file', 'list', `--${target}`, currentPath, '--json', '--udid', options.serial], | ||
(error, stdout, stderr) => { | ||
if (error) { | ||
log.warn('Unable to list directory "%s"', message.dir, stderr) | ||
push.send([ | ||
channel | ||
, reply.fail(error.message) | ||
]) | ||
return | ||
} | ||
|
||
let rawDirs = JSON.parse(stdout) | ||
let entries = [] | ||
rawDirs.forEach(dir => { | ||
let name = dir.path | ||
let mode = 0o40365 | ||
if (name.includes('.')) { | ||
mode = 0o555 | ||
} | ||
entries.push({ | ||
name: name, mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: mode, size: 0 | ||
}) | ||
}) | ||
|
||
push.send([ | ||
channel | ||
, reply.okay('success', entries) | ||
]) | ||
} | ||
) | ||
}) | ||
return plugin | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--style json
is unrecognized on an iphone with ios 18.1.1 and idb-companion 1.1.8