1# Copyright 2017 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5 6DEPS = [ 7 'recipe_engine/context', 8 'recipe_engine/path', 9 'recipe_engine/properties', 10 'recipe_engine/step', 11 'run', 12 'vars', 13] 14 15 16def myfunc(api, i): 17 api.run(api.step, 'run %d' % i, cmd=['echo', str(i)]) 18 19 20def RunSteps(api): 21 api.vars.setup() 22 try: 23 api.run(api.step, 'fail', cmd=['false']) 24 except api.step.StepFailure: 25 pass 26 api.run(api.step, 'fail again', cmd=['false'], abort_on_failure=False) 27 api.run(api.step, 'do a thing', cmd=['echo', 'do the thing']) 28 assert len(api.run.failed_steps) == 2 29 30 # Run once. 31 for i in range(10): 32 api.run.run_once(myfunc, api, i) 33 34 # Read and write files. 35 api.run.readfile('myfile.txt') 36 api.run.writefile('myfile.txt', 'contents') 37 api.run.rmtree('mydir') 38 39 # Merge PATHs. 40 with api.context(env={'PATH': 'mydir:%(PATH)s'}): 41 api.run(api.step, 'env', cmd=['env']) 42 43 # Copy build products. 44 api.run.copy_build_products('src', 'dst') 45 46 def between_attempts_fn(attempt): 47 api.run(api.step, 'between_attempts #%d' % attempt, 48 cmd=['echo', 'between_attempt']) 49 50 # Retries. 51 try: 52 api.run.with_retry(api.step, 'retry fail', 5, cmd=['false'], 53 between_attempts_fn=between_attempts_fn) 54 except api.step.StepFailure: 55 pass 56 assert len(api.run.failed_steps) == 7 57 58 api.run.with_retry(api.step, 'retry success', 3, cmd=['false'], 59 between_attempts_fn=between_attempts_fn) 60 assert len(api.run.failed_steps) == 7 61 62 # Check failure. 63 api.run.check_failure() 64 65 66def GenTests(api): 67 buildername = 'Build-Win-Clang-x86_64-Release-Vulkan' 68 yield ( 69 api.test('test') + 70 api.properties(buildername=buildername, 71 repository='https://skia.googlesource.com/skia.git', 72 revision='abc123', 73 path_config='kitchen', 74 swarm_out_dir='[SWARM_OUT_DIR]') + 75 api.step_data('fail', retcode=1) + 76 api.step_data('fail again', retcode=1) + 77 api.step_data('retry fail', retcode=1) + 78 api.step_data('retry fail (attempt 2)', retcode=1) + 79 api.step_data('retry fail (attempt 3)', retcode=1) + 80 api.step_data('retry fail (attempt 4)', retcode=1) + 81 api.step_data('retry fail (attempt 5)', retcode=1) + 82 api.step_data('retry success', retcode=1) + 83 api.step_data('retry success (attempt 2)', retcode=1) 84 ) 85