Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
update_spreadsheet.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5#
6"""Tool to automatically update the DartFuzzStats spreadsheet
7
8Requires a one-time authentication step with a @google account.
9"""
10from __future__ import print_function
11import pickle
12import os.path
13import subprocess
14from googleapiclient.discovery import build
15from google_auth_oauthlib.flow import InstalledAppFlow
16from google.auth.transport.requests import Request
17
18# This script may require a one time install of Google API libraries:
19# pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
20
21# If modifying these scopes, delete the file token.pickle.
22SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
23
24# The ID and range of a spreadsheet.
25SPREADSHEET_ID = '1nDoK-dCuEmf6yo55a303UClRd7AwjbzPkRr37ijWcC8'
26RANGE_NAME = 'Sheet1!A3:H'
27
28VERIFY_CURRENT_ROW_FORMULA = '=B:B-C:C-D:D-E:E-F:F'
29
30
32 dir_path = os.path.dirname(os.path.realpath(__file__))
33 creds = None
34 # The file token.pickle stores the user's access and refresh tokens, and is
35 # created automatically when the authorization flow completes for the first
36 # time.
37 pickle_path = os.path.join(dir_path, 'token.pickle')
38 if os.path.exists(pickle_path):
39 with open(pickle_path, 'rb') as token:
40 creds = pickle.load(token)
41 # If there are no (valid) credentials available, let the user log in.
42 if not creds or not creds.valid:
43 if creds and creds.expired and creds.refresh_token:
44 creds.refresh(Request())
45 else:
46 flow = InstalledAppFlow.from_client_secrets_file(
47 os.path.join(dir_path, 'credentials.json'), SCOPES)
48 creds = flow.run_local_server(port=0)
49 # Save the credentials for the next run
50 with open(pickle_path, 'wb') as token:
51 pickle.dump(creds, token)
52 return build('sheets', 'v4', credentials=creds)
53
54
55# Returns the next run ID based on the last run ID found in the fuzzing
56# spreadsheet.
57def get_next_run_id(sheet):
58 result = sheet.values().get(
59 spreadsheetId=SPREADSHEET_ID, range=RANGE_NAME).execute()
60 values = result.get('values', [])
61 return int(values[-1][0]) + 1
62
63
64# Inserts a new entry into the fuzzing spreadsheet.
65def add_new_fuzzing_entry(sheet, run, tests, success, rerun, skipped, timeout,
66 divergences):
67
68 entry = [run, tests, success, skipped, timeout, divergences, rerun]
69 print(
70 'Adding entry for run %d. Tests: %d Successes: %d Skipped: %d Timeouts: %d, Divergences: %d Re-runs: %d'
71 % tuple(entry))
72
73 values = {'values': [entry + [VERIFY_CURRENT_ROW_FORMULA]]}
74 sheet.values().append(
75 spreadsheetId=SPREADSHEET_ID,
76 range=RANGE_NAME,
77 body=values,
78 valueInputOption='USER_ENTERED').execute()
79
80
81# Scrapes the fuzzing shards for fuzzing run statistics.
82#
83# Returns a list of statistics in the following order:
84#
85# - # of tests
86# - # of successes
87# - # of re-runs
88# - # of skipped runs
89# - # of timeouts
90# - # of divergences
91#
93 dir_path = os.path.dirname(os.path.realpath(__file__))
94 output = subprocess.check_output([
95 'python3',
96 os.path.join(dir_path, 'collect_data.py'), '--output-csv', '--type=sum',
97 'https://ci.chromium.org/p/dart/builders/ci.sandbox/fuzz-linux/%d' % run
98 ])
99 return list(map(int, output.decode('UTF-8').rstrip().split(',')))
100
101
102def main():
103 service = authenticate()
104 # Call the Sheets API
105 sheet = service.spreadsheets()
106 while True:
107 try:
108 next_id = get_next_run_id(sheet)
109 summary = get_run_statistic_summary(next_id)
110 add_new_fuzzing_entry(sheet, next_id, *summary)
111 except:
112 # get_run_statistic_summary exits with non-zero exit code if we're out
113 # of runs to check.
114 print('No more runs to process. Exiting.')
115 break
116
117
118if __name__ == '__main__':
119 main()
Type::kYUV Type::kRGBA() int(0.7 *637)
void print(void *str)
Definition bridge.cpp:126
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition editor.cpp:211
Definition build.py:1
Definition main.py:1
add_new_fuzzing_entry(sheet, run, tests, success, rerun, skipped, timeout, divergences)