remoteexec_test.go 3.6 KB

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