Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 1 | // Copyright 2020 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package remoteexec |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func TestTemplate(t *testing.T) { |
| 23 | tests := []struct { |
| 24 | name string |
| 25 | params *REParams |
| 26 | want string |
| 27 | }{ |
| 28 | { |
| 29 | name: "basic", |
| 30 | params: &REParams{ |
| 31 | Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"}, |
| 32 | Inputs: []string{"$in"}, |
| 33 | OutputFiles: []string{"$out"}, |
| 34 | Platform: map[string]string{ |
| 35 | ContainerImageKey: DefaultImage, |
| 36 | PoolKey: "default", |
| 37 | }, |
| 38 | }, |
Colin Cross | 95fad7a | 2021-06-09 12:48:53 -0700 | [diff] [blame] | 39 | want: fmt.Sprintf("${android.RBEWrapper} --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=local --inputs=$in --output_files=$out --env_var_allowlist=LANG,LC_MESSAGES,PYTHONDONTWRITEBYTECODE -- ", DefaultImage), |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 40 | }, |
| 41 | { |
| 42 | name: "all params", |
| 43 | params: &REParams{ |
| 44 | Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"}, |
| 45 | Inputs: []string{"$in"}, |
| 46 | OutputFiles: []string{"$out"}, |
| 47 | ExecStrategy: "remote", |
Colin Cross | a4eafdd | 2021-03-24 14:09:28 -0700 | [diff] [blame] | 48 | RSPFiles: []string{"$out.rsp", "out2.rsp"}, |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 49 | ToolchainInputs: []string{"clang++"}, |
| 50 | Platform: map[string]string{ |
| 51 | ContainerImageKey: DefaultImage, |
| 52 | PoolKey: "default", |
| 53 | }, |
| 54 | }, |
Colin Cross | 95fad7a | 2021-06-09 12:48:53 -0700 | [diff] [blame] | 55 | want: fmt.Sprintf("${android.RBEWrapper} --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=remote --inputs=$in --input_list_paths=$out.rsp,out2.rsp --output_files=$out --toolchain_inputs=clang++ --env_var_allowlist=LANG,LC_MESSAGES,PYTHONDONTWRITEBYTECODE -- ", DefaultImage), |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 56 | }, |
| 57 | } |
| 58 | for _, test := range tests { |
| 59 | t.Run(test.name, func(t *testing.T) { |
| 60 | if got := test.params.Template(); got != test.want { |
| 61 | t.Errorf("Template() returned\n%s\nwant\n%s", got, test.want) |
| 62 | } |
| 63 | }) |
| 64 | } |
| 65 | } |
| 66 | |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 67 | func TestNoVarTemplate(t *testing.T) { |
| 68 | params := &REParams{ |
| 69 | Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"}, |
| 70 | Inputs: []string{"$in"}, |
| 71 | OutputFiles: []string{"$out"}, |
| 72 | Platform: map[string]string{ |
| 73 | ContainerImageKey: DefaultImage, |
| 74 | PoolKey: "default", |
| 75 | }, |
| 76 | } |
Colin Cross | 95fad7a | 2021-06-09 12:48:53 -0700 | [diff] [blame] | 77 | want := fmt.Sprintf("prebuilts/remoteexecution-client/live/rewrapper --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=local --inputs=$in --output_files=$out --env_var_allowlist=LANG,LC_MESSAGES,PYTHONDONTWRITEBYTECODE -- ", DefaultImage) |
Colin Cross | 77cdcfd | 2021-03-12 11:28:25 -0800 | [diff] [blame] | 78 | if got := params.NoVarTemplate(DefaultWrapperPath); got != want { |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 79 | t.Errorf("NoVarTemplate() returned\n%s\nwant\n%s", got, want) |
| 80 | } |
| 81 | } |
| 82 | |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 83 | func TestTemplateDeterminism(t *testing.T) { |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 84 | r := &REParams{ |
| 85 | Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"}, |
| 86 | Inputs: []string{"$in"}, |
| 87 | OutputFiles: []string{"$out"}, |
| 88 | Platform: map[string]string{ |
| 89 | ContainerImageKey: DefaultImage, |
| 90 | PoolKey: "default", |
| 91 | }, |
| 92 | } |
Colin Cross | 95fad7a | 2021-06-09 12:48:53 -0700 | [diff] [blame] | 93 | want := fmt.Sprintf("${android.RBEWrapper} --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=local --inputs=$in --output_files=$out --env_var_allowlist=LANG,LC_MESSAGES,PYTHONDONTWRITEBYTECODE -- ", DefaultImage) |
Ramy Medhat | 9a90fe5 | 2020-04-13 13:21:23 -0400 | [diff] [blame] | 94 | for i := 0; i < 1000; i++ { |
| 95 | if got := r.Template(); got != want { |
| 96 | t.Fatalf("Template() returned\n%s\nwant\n%s", got, want) |
| 97 | } |
| 98 | } |
| 99 | } |