Skip to content

Commit

Permalink
Add option to save Logic Tests logs to a directory
Browse files Browse the repository at this point in the history
Summary: As title

Reviewed By: fgasperij

Differential Revision: D27367976

fbshipit-source-id: 62ef5134721fdb54e474cbd41cafda1a4726f5c9
  • Loading branch information
jbardini authored and facebook-github-bot committed Apr 14, 2021
1 parent 26204f2 commit d5d04f9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
7 changes: 7 additions & 0 deletions idb/cli/commands/xctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ def add_parser_arguments(self, parser: ArgumentParser) -> None:
"--coverage-output-path",
help="Outputs coverage information in the llvm json format",
)
parser.add_argument(
"--log-directory-path",
default=None,
type=str,
help="Path to save the test logs collected",
)
parser.add_argument(
"--install",
help="When this option is provided bundle_ids are assumed "
Expand Down Expand Up @@ -206,6 +212,7 @@ async def run_with_client(self, args: Namespace, client: Client) -> None:
report_attachments=args.report_attachments,
activities_output_path=args.activities_output_path,
coverage_output_path=args.coverage_output_path,
log_directory_path=args.log_directory_path,
):
print(formatter(test_result))
crashed_outside_test_case = (
Expand Down
1 change: 1 addition & 0 deletions idb/cli/tests/parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def xctest_run_namespace(self, command: str, test_bundle_id: str) -> Namespace:
namespace.report_attachments = False
namespace.activities_output_path = None
namespace.coverage_output_path = None
namespace.log_directory_path = None
namespace.install = False
return namespace

Expand Down
1 change: 1 addition & 0 deletions idb/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ async def run_xctest(
report_attachments: bool = False,
activities_output_path: Optional[str] = None,
coverage_output_path: Optional[str] = None,
log_directory_path: Optional[str] = None,
) -> AsyncIterator[TestRunInfo]:
yield

Expand Down
16 changes: 13 additions & 3 deletions idb/grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
make_request,
make_results,
save_attachments,
write_result_bundle,
untar_into_path,
)
from idb.grpc.xctest_log_parser import XCTestLogParser
from idb.grpc.xctrace import (
Expand Down Expand Up @@ -952,6 +952,7 @@ async def run_xctest(
report_attachments: bool = False,
activities_output_path: Optional[str] = None,
coverage_output_path: Optional[str] = None,
log_directory_path: Optional[str] = None,
) -> AsyncIterator[TestRunInfo]:
async with self.stub.xctest_run.open() as stream:
request = make_request(
Expand All @@ -973,6 +974,7 @@ async def run_xctest(
),
report_attachments=report_attachments,
collect_coverage=coverage_output_path is not None,
collect_logs=log_directory_path is not None,
)
log_parser = XCTestLogParser()
await stream.send_message(request)
Expand All @@ -991,11 +993,19 @@ async def run_xctest(
idb_log_buffer.write(line)

if result_bundle_path:
await write_result_bundle(
response=response,
await untar_into_path(
payload=response.result_bundle,
description="result bundle",
output_path=result_bundle_path,
logger=self.logger,
)
if log_directory_path:
await untar_into_path(
payload=response.log_directory,
description="log directory",
output_path=log_directory_path,
logger=self.logger,
)
if response.coverage_json and coverage_output_path:
with open(coverage_output_path, "w") as f:
f.write(response.coverage_json)
Expand Down
13 changes: 7 additions & 6 deletions idb/grpc/xctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
TestRunFailureInfo,
TestRunInfo,
)
from idb.grpc.idb_pb2 import XctestRunRequest, XctestRunResponse
from idb.grpc.idb_pb2 import XctestRunRequest, XctestRunResponse, Payload
from idb.grpc.xctest_log_parser import XCTestLogParser


Expand Down Expand Up @@ -103,6 +103,7 @@ def make_request(
report_activities: bool,
report_attachments: bool,
collect_coverage: bool,
collect_logs: bool,
) -> XctestRunRequest:
if is_logic_test:
mode = Mode(logic=Logic())
Expand All @@ -127,21 +128,21 @@ def make_request(
tests_to_run=list(tests_to_run or []),
tests_to_skip=list(tests_to_skip or []),
timeout=(timeout if timeout is not None else 0),
collect_logs=collect_logs,
)


async def write_result_bundle(
response: XctestRunResponse, output_path: str, logger: Logger
async def untar_into_path(
payload: Payload, description: str, output_path: str, logger: Logger
) -> None:
payload = response.result_bundle
if not payload:
return
data = payload.data
if not len(data):
return
logger.info(f"Writing result bundle to {output_path}")
logger.info(f"Writing {description} to {output_path}")
await untar(data=data, output_path=output_path)
logger.info(f"Finished writing result bundle to {output_path}")
logger.info(f"Finished writing {description} to {output_path}")


def make_results(
Expand Down

0 comments on commit d5d04f9

Please sign in to comment.