remoteexec_test.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. package remoteexec
  15. import (
  16. "fmt"
  17. "testing"
  18. )
  19. func TestTemplate(t *testing.T) {
  20. tests := []struct {
  21. name string
  22. params *REParams
  23. want string
  24. }{
  25. {
  26. name: "basic",
  27. params: &REParams{
  28. Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
  29. Inputs: []string{"$in"},
  30. OutputFiles: []string{"$out"},
  31. Platform: map[string]string{
  32. ContainerImageKey: DefaultImage,
  33. PoolKey: "default",
  34. },
  35. },
  36. 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),
  37. },
  38. {
  39. name: "all params",
  40. params: &REParams{
  41. Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
  42. Inputs: []string{"$in"},
  43. OutputFiles: []string{"$out"},
  44. ExecStrategy: "remote",
  45. RSPFiles: []string{"$out.rsp", "out2.rsp"},
  46. ToolchainInputs: []string{"clang++"},
  47. Platform: map[string]string{
  48. ContainerImageKey: DefaultImage,
  49. PoolKey: "default",
  50. },
  51. },
  52. 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),
  53. },
  54. }
  55. for _, test := range tests {
  56. t.Run(test.name, func(t *testing.T) {
  57. if got := test.params.Template(); got != test.want {
  58. t.Errorf("Template() returned\n%s\nwant\n%s", got, test.want)
  59. }
  60. })
  61. }
  62. }
  63. func TestNoVarTemplate(t *testing.T) {
  64. params := &REParams{
  65. Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
  66. Inputs: []string{"$in"},
  67. OutputFiles: []string{"$out"},
  68. Platform: map[string]string{
  69. ContainerImageKey: DefaultImage,
  70. PoolKey: "default",
  71. },
  72. }
  73. 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)
  74. if got := params.NoVarTemplate(DefaultWrapperPath); got != want {
  75. t.Errorf("NoVarTemplate() returned\n%s\nwant\n%s", got, want)
  76. }
  77. }
  78. func TestTemplateDeterminism(t *testing.T) {
  79. r := &REParams{
  80. Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
  81. Inputs: []string{"$in"},
  82. OutputFiles: []string{"$out"},
  83. Platform: map[string]string{
  84. ContainerImageKey: DefaultImage,
  85. PoolKey: "default",
  86. },
  87. }
  88. 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)
  89. for i := 0; i < 1000; i++ {
  90. if got := r.Template(); got != want {
  91. t.Fatalf("Template() returned\n%s\nwant\n%s", got, want)
  92. }
  93. }
  94. }