blob: b117b89158d0d7c777c46536d9ac6e3df1ef3c50 [file] [log] [blame]
Ramy Medhat9a90fe52020-04-13 13:21:23 -04001// 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
15package remoteexec
16
17import (
18 "fmt"
19 "testing"
20)
21
22func 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 Cross77cdcfd2021-03-12 11:28:25 -080039 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 -- ", DefaultImage),
Ramy Medhat9a90fe52020-04-13 13:21:23 -040040 },
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 Crossa4eafdd2021-03-24 14:09:28 -070048 RSPFiles: []string{"$out.rsp", "out2.rsp"},
Ramy Medhat9a90fe52020-04-13 13:21:23 -040049 ToolchainInputs: []string{"clang++"},
50 Platform: map[string]string{
51 ContainerImageKey: DefaultImage,
52 PoolKey: "default",
53 },
54 },
Colin Crossa4eafdd2021-03-24 14:09:28 -070055 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++ -- ", DefaultImage),
Ramy Medhat9a90fe52020-04-13 13:21:23 -040056 },
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 Medhat427683c2020-04-30 03:08:37 -040067func 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 }
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 -- ", DefaultImage)
Colin Cross77cdcfd2021-03-12 11:28:25 -080078 if got := params.NoVarTemplate(DefaultWrapperPath); got != want {
Ramy Medhat427683c2020-04-30 03:08:37 -040079 t.Errorf("NoVarTemplate() returned\n%s\nwant\n%s", got, want)
80 }
81}
82
Ramy Medhat9a90fe52020-04-13 13:21:23 -040083func TestTemplateDeterminism(t *testing.T) {
Ramy Medhat9a90fe52020-04-13 13:21:23 -040084 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 Cross77cdcfd2021-03-12 11:28:25 -080093 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 -- ", DefaultImage)
Ramy Medhat9a90fe52020-04-13 13:21:23 -040094 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}