Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1 | // Copyright 2021 Google LLC |
| 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 main |
| 16 | |
| 17 | import ( |
| 18 | "bytes" |
| 19 | "fmt" |
Colin Cross | d0f05c9 | 2022-01-27 15:40:29 -0800 | [diff] [blame] | 20 | "os" |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
Colin Cross | d0f05c9 | 2022-01-27 15:40:29 -0800 | [diff] [blame] | 25 | func TestMain(m *testing.M) { |
| 26 | // Change into the parent directory before running the tests |
| 27 | // so they can find the testdata directory. |
| 28 | if err := os.Chdir(".."); err != nil { |
| 29 | fmt.Printf("failed to change to testdata directory: %s\n", err) |
| 30 | os.Exit(1) |
| 31 | } |
| 32 | os.Exit(m.Run()) |
| 33 | } |
| 34 | |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 35 | func Test_plaintext(t *testing.T) { |
| 36 | tests := []struct { |
| 37 | condition string |
| 38 | name string |
| 39 | roots []string |
| 40 | ctx context |
| 41 | expectedOut []string |
| 42 | }{ |
| 43 | { |
| 44 | condition: "firstparty", |
| 45 | name: "apex", |
| 46 | roots: []string{"highest.apex.meta_lic"}, |
| 47 | expectedOut: []string{ |
| 48 | "testdata/firstparty/bin/bin1.meta_lic testdata/firstparty/lib/liba.so.meta_lic static", |
| 49 | "testdata/firstparty/bin/bin1.meta_lic testdata/firstparty/lib/libc.a.meta_lic static", |
| 50 | "testdata/firstparty/bin/bin2.meta_lic testdata/firstparty/lib/libb.so.meta_lic dynamic", |
| 51 | "testdata/firstparty/bin/bin2.meta_lic testdata/firstparty/lib/libd.so.meta_lic dynamic", |
| 52 | "testdata/firstparty/highest.apex.meta_lic testdata/firstparty/bin/bin1.meta_lic static", |
| 53 | "testdata/firstparty/highest.apex.meta_lic testdata/firstparty/bin/bin2.meta_lic static", |
| 54 | "testdata/firstparty/highest.apex.meta_lic testdata/firstparty/lib/liba.so.meta_lic static", |
| 55 | "testdata/firstparty/highest.apex.meta_lic testdata/firstparty/lib/libb.so.meta_lic static", |
| 56 | }, |
| 57 | }, |
| 58 | { |
| 59 | condition: "firstparty", |
| 60 | name: "apex_trimmed", |
| 61 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 62 | ctx: context{stripPrefix: []string{"testdata/firstparty/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 63 | expectedOut: []string{ |
| 64 | "bin/bin1.meta_lic lib/liba.so.meta_lic static", |
| 65 | "bin/bin1.meta_lic lib/libc.a.meta_lic static", |
| 66 | "bin/bin2.meta_lic lib/libb.so.meta_lic dynamic", |
| 67 | "bin/bin2.meta_lic lib/libd.so.meta_lic dynamic", |
| 68 | "highest.apex.meta_lic bin/bin1.meta_lic static", |
| 69 | "highest.apex.meta_lic bin/bin2.meta_lic static", |
| 70 | "highest.apex.meta_lic lib/liba.so.meta_lic static", |
| 71 | "highest.apex.meta_lic lib/libb.so.meta_lic static", |
| 72 | }, |
| 73 | }, |
| 74 | { |
| 75 | condition: "firstparty", |
| 76 | name: "apex_trimmed_labelled", |
| 77 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 78 | ctx: context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 79 | expectedOut: []string{ |
| 80 | "bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice static", |
| 81 | "bin/bin1.meta_lic:notice lib/libc.a.meta_lic:notice static", |
| 82 | "bin/bin2.meta_lic:notice lib/libb.so.meta_lic:notice dynamic", |
| 83 | "bin/bin2.meta_lic:notice lib/libd.so.meta_lic:notice dynamic", |
| 84 | "highest.apex.meta_lic:notice bin/bin1.meta_lic:notice static", |
| 85 | "highest.apex.meta_lic:notice bin/bin2.meta_lic:notice static", |
| 86 | "highest.apex.meta_lic:notice lib/liba.so.meta_lic:notice static", |
| 87 | "highest.apex.meta_lic:notice lib/libb.so.meta_lic:notice static", |
| 88 | }, |
| 89 | }, |
| 90 | { |
| 91 | condition: "firstparty", |
| 92 | name: "container", |
| 93 | roots: []string{"container.zip.meta_lic"}, |
| 94 | expectedOut: []string{ |
| 95 | "testdata/firstparty/bin/bin1.meta_lic testdata/firstparty/lib/liba.so.meta_lic static", |
| 96 | "testdata/firstparty/bin/bin1.meta_lic testdata/firstparty/lib/libc.a.meta_lic static", |
| 97 | "testdata/firstparty/bin/bin2.meta_lic testdata/firstparty/lib/libb.so.meta_lic dynamic", |
| 98 | "testdata/firstparty/bin/bin2.meta_lic testdata/firstparty/lib/libd.so.meta_lic dynamic", |
| 99 | "testdata/firstparty/container.zip.meta_lic testdata/firstparty/bin/bin1.meta_lic static", |
| 100 | "testdata/firstparty/container.zip.meta_lic testdata/firstparty/bin/bin2.meta_lic static", |
| 101 | "testdata/firstparty/container.zip.meta_lic testdata/firstparty/lib/liba.so.meta_lic static", |
| 102 | "testdata/firstparty/container.zip.meta_lic testdata/firstparty/lib/libb.so.meta_lic static", |
| 103 | }, |
| 104 | }, |
| 105 | { |
| 106 | condition: "firstparty", |
| 107 | name: "application", |
| 108 | roots: []string{"application.meta_lic"}, |
| 109 | expectedOut: []string{ |
| 110 | "testdata/firstparty/application.meta_lic testdata/firstparty/bin/bin3.meta_lic toolchain", |
| 111 | "testdata/firstparty/application.meta_lic testdata/firstparty/lib/liba.so.meta_lic static", |
| 112 | "testdata/firstparty/application.meta_lic testdata/firstparty/lib/libb.so.meta_lic dynamic", |
| 113 | }, |
| 114 | }, |
| 115 | { |
| 116 | condition: "firstparty", |
| 117 | name: "binary", |
| 118 | roots: []string{"bin/bin1.meta_lic"}, |
| 119 | expectedOut: []string{ |
| 120 | "testdata/firstparty/bin/bin1.meta_lic testdata/firstparty/lib/liba.so.meta_lic static", |
| 121 | "testdata/firstparty/bin/bin1.meta_lic testdata/firstparty/lib/libc.a.meta_lic static", |
| 122 | }, |
| 123 | }, |
| 124 | { |
| 125 | condition: "firstparty", |
| 126 | name: "library", |
| 127 | roots: []string{"lib/libd.so.meta_lic"}, |
| 128 | expectedOut: []string{}, |
| 129 | }, |
| 130 | { |
| 131 | condition: "notice", |
| 132 | name: "apex", |
| 133 | roots: []string{"highest.apex.meta_lic"}, |
| 134 | expectedOut: []string{ |
| 135 | "testdata/notice/bin/bin1.meta_lic testdata/notice/lib/liba.so.meta_lic static", |
| 136 | "testdata/notice/bin/bin1.meta_lic testdata/notice/lib/libc.a.meta_lic static", |
| 137 | "testdata/notice/bin/bin2.meta_lic testdata/notice/lib/libb.so.meta_lic dynamic", |
| 138 | "testdata/notice/bin/bin2.meta_lic testdata/notice/lib/libd.so.meta_lic dynamic", |
| 139 | "testdata/notice/highest.apex.meta_lic testdata/notice/bin/bin1.meta_lic static", |
| 140 | "testdata/notice/highest.apex.meta_lic testdata/notice/bin/bin2.meta_lic static", |
| 141 | "testdata/notice/highest.apex.meta_lic testdata/notice/lib/liba.so.meta_lic static", |
| 142 | "testdata/notice/highest.apex.meta_lic testdata/notice/lib/libb.so.meta_lic static", |
| 143 | }, |
| 144 | }, |
| 145 | { |
| 146 | condition: "notice", |
| 147 | name: "apex_trimmed", |
| 148 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 149 | ctx: context{stripPrefix: []string{"testdata/notice/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 150 | expectedOut: []string{ |
| 151 | "bin/bin1.meta_lic lib/liba.so.meta_lic static", |
| 152 | "bin/bin1.meta_lic lib/libc.a.meta_lic static", |
| 153 | "bin/bin2.meta_lic lib/libb.so.meta_lic dynamic", |
| 154 | "bin/bin2.meta_lic lib/libd.so.meta_lic dynamic", |
| 155 | "highest.apex.meta_lic bin/bin1.meta_lic static", |
| 156 | "highest.apex.meta_lic bin/bin2.meta_lic static", |
| 157 | "highest.apex.meta_lic lib/liba.so.meta_lic static", |
| 158 | "highest.apex.meta_lic lib/libb.so.meta_lic static", |
| 159 | }, |
| 160 | }, |
| 161 | { |
| 162 | condition: "notice", |
| 163 | name: "apex_trimmed_labelled", |
| 164 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 165 | ctx: context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 166 | expectedOut: []string{ |
| 167 | "bin/bin1.meta_lic:notice lib/liba.so.meta_lic:notice static", |
| 168 | "bin/bin1.meta_lic:notice lib/libc.a.meta_lic:notice static", |
| 169 | "bin/bin2.meta_lic:notice lib/libb.so.meta_lic:notice dynamic", |
| 170 | "bin/bin2.meta_lic:notice lib/libd.so.meta_lic:notice dynamic", |
| 171 | "highest.apex.meta_lic:notice bin/bin1.meta_lic:notice static", |
| 172 | "highest.apex.meta_lic:notice bin/bin2.meta_lic:notice static", |
| 173 | "highest.apex.meta_lic:notice lib/liba.so.meta_lic:notice static", |
| 174 | "highest.apex.meta_lic:notice lib/libb.so.meta_lic:notice static", |
| 175 | }, |
| 176 | }, |
| 177 | { |
| 178 | condition: "notice", |
| 179 | name: "container", |
| 180 | roots: []string{"container.zip.meta_lic"}, |
| 181 | expectedOut: []string{ |
| 182 | "testdata/notice/bin/bin1.meta_lic testdata/notice/lib/liba.so.meta_lic static", |
| 183 | "testdata/notice/bin/bin1.meta_lic testdata/notice/lib/libc.a.meta_lic static", |
| 184 | "testdata/notice/bin/bin2.meta_lic testdata/notice/lib/libb.so.meta_lic dynamic", |
| 185 | "testdata/notice/bin/bin2.meta_lic testdata/notice/lib/libd.so.meta_lic dynamic", |
| 186 | "testdata/notice/container.zip.meta_lic testdata/notice/bin/bin1.meta_lic static", |
| 187 | "testdata/notice/container.zip.meta_lic testdata/notice/bin/bin2.meta_lic static", |
| 188 | "testdata/notice/container.zip.meta_lic testdata/notice/lib/liba.so.meta_lic static", |
| 189 | "testdata/notice/container.zip.meta_lic testdata/notice/lib/libb.so.meta_lic static", |
| 190 | }, |
| 191 | }, |
| 192 | { |
| 193 | condition: "notice", |
| 194 | name: "application", |
| 195 | roots: []string{"application.meta_lic"}, |
| 196 | expectedOut: []string{ |
| 197 | "testdata/notice/application.meta_lic testdata/notice/bin/bin3.meta_lic toolchain", |
| 198 | "testdata/notice/application.meta_lic testdata/notice/lib/liba.so.meta_lic static", |
| 199 | "testdata/notice/application.meta_lic testdata/notice/lib/libb.so.meta_lic dynamic", |
| 200 | }, |
| 201 | }, |
| 202 | { |
| 203 | condition: "notice", |
| 204 | name: "binary", |
| 205 | roots: []string{"bin/bin1.meta_lic"}, |
| 206 | expectedOut: []string{ |
| 207 | "testdata/notice/bin/bin1.meta_lic testdata/notice/lib/liba.so.meta_lic static", |
| 208 | "testdata/notice/bin/bin1.meta_lic testdata/notice/lib/libc.a.meta_lic static", |
| 209 | }, |
| 210 | }, |
| 211 | { |
| 212 | condition: "notice", |
| 213 | name: "library", |
| 214 | roots: []string{"lib/libd.so.meta_lic"}, |
| 215 | expectedOut: []string{}, |
| 216 | }, |
| 217 | { |
| 218 | condition: "reciprocal", |
| 219 | name: "apex", |
| 220 | roots: []string{"highest.apex.meta_lic"}, |
| 221 | expectedOut: []string{ |
| 222 | "testdata/reciprocal/bin/bin1.meta_lic testdata/reciprocal/lib/liba.so.meta_lic static", |
| 223 | "testdata/reciprocal/bin/bin1.meta_lic testdata/reciprocal/lib/libc.a.meta_lic static", |
| 224 | "testdata/reciprocal/bin/bin2.meta_lic testdata/reciprocal/lib/libb.so.meta_lic dynamic", |
| 225 | "testdata/reciprocal/bin/bin2.meta_lic testdata/reciprocal/lib/libd.so.meta_lic dynamic", |
| 226 | "testdata/reciprocal/highest.apex.meta_lic testdata/reciprocal/bin/bin1.meta_lic static", |
| 227 | "testdata/reciprocal/highest.apex.meta_lic testdata/reciprocal/bin/bin2.meta_lic static", |
| 228 | "testdata/reciprocal/highest.apex.meta_lic testdata/reciprocal/lib/liba.so.meta_lic static", |
| 229 | "testdata/reciprocal/highest.apex.meta_lic testdata/reciprocal/lib/libb.so.meta_lic static", |
| 230 | }, |
| 231 | }, |
| 232 | { |
| 233 | condition: "reciprocal", |
| 234 | name: "apex_trimmed", |
| 235 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 236 | ctx: context{stripPrefix: []string{"testdata/reciprocal/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 237 | expectedOut: []string{ |
| 238 | "bin/bin1.meta_lic lib/liba.so.meta_lic static", |
| 239 | "bin/bin1.meta_lic lib/libc.a.meta_lic static", |
| 240 | "bin/bin2.meta_lic lib/libb.so.meta_lic dynamic", |
| 241 | "bin/bin2.meta_lic lib/libd.so.meta_lic dynamic", |
| 242 | "highest.apex.meta_lic bin/bin1.meta_lic static", |
| 243 | "highest.apex.meta_lic bin/bin2.meta_lic static", |
| 244 | "highest.apex.meta_lic lib/liba.so.meta_lic static", |
| 245 | "highest.apex.meta_lic lib/libb.so.meta_lic static", |
| 246 | }, |
| 247 | }, |
| 248 | { |
| 249 | condition: "reciprocal", |
| 250 | name: "apex_trimmed_labelled", |
| 251 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 252 | ctx: context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 253 | expectedOut: []string{ |
| 254 | "bin/bin1.meta_lic:notice lib/liba.so.meta_lic:reciprocal static", |
| 255 | "bin/bin1.meta_lic:notice lib/libc.a.meta_lic:reciprocal static", |
| 256 | "bin/bin2.meta_lic:notice lib/libb.so.meta_lic:notice dynamic", |
| 257 | "bin/bin2.meta_lic:notice lib/libd.so.meta_lic:notice dynamic", |
| 258 | "highest.apex.meta_lic:notice bin/bin1.meta_lic:notice static", |
| 259 | "highest.apex.meta_lic:notice bin/bin2.meta_lic:notice static", |
| 260 | "highest.apex.meta_lic:notice lib/liba.so.meta_lic:reciprocal static", |
| 261 | "highest.apex.meta_lic:notice lib/libb.so.meta_lic:notice static", |
| 262 | }, |
| 263 | }, |
| 264 | { |
| 265 | condition: "reciprocal", |
| 266 | name: "container", |
| 267 | roots: []string{"container.zip.meta_lic"}, |
| 268 | expectedOut: []string{ |
| 269 | "testdata/reciprocal/bin/bin1.meta_lic testdata/reciprocal/lib/liba.so.meta_lic static", |
| 270 | "testdata/reciprocal/bin/bin1.meta_lic testdata/reciprocal/lib/libc.a.meta_lic static", |
| 271 | "testdata/reciprocal/bin/bin2.meta_lic testdata/reciprocal/lib/libb.so.meta_lic dynamic", |
| 272 | "testdata/reciprocal/bin/bin2.meta_lic testdata/reciprocal/lib/libd.so.meta_lic dynamic", |
| 273 | "testdata/reciprocal/container.zip.meta_lic testdata/reciprocal/bin/bin1.meta_lic static", |
| 274 | "testdata/reciprocal/container.zip.meta_lic testdata/reciprocal/bin/bin2.meta_lic static", |
| 275 | "testdata/reciprocal/container.zip.meta_lic testdata/reciprocal/lib/liba.so.meta_lic static", |
| 276 | "testdata/reciprocal/container.zip.meta_lic testdata/reciprocal/lib/libb.so.meta_lic static", |
| 277 | }, |
| 278 | }, |
| 279 | { |
| 280 | condition: "reciprocal", |
| 281 | name: "application", |
| 282 | roots: []string{"application.meta_lic"}, |
| 283 | expectedOut: []string{ |
| 284 | "testdata/reciprocal/application.meta_lic testdata/reciprocal/bin/bin3.meta_lic toolchain", |
| 285 | "testdata/reciprocal/application.meta_lic testdata/reciprocal/lib/liba.so.meta_lic static", |
| 286 | "testdata/reciprocal/application.meta_lic testdata/reciprocal/lib/libb.so.meta_lic dynamic", |
| 287 | }, |
| 288 | }, |
| 289 | { |
| 290 | condition: "reciprocal", |
| 291 | name: "binary", |
| 292 | roots: []string{"bin/bin1.meta_lic"}, |
| 293 | expectedOut: []string{ |
| 294 | "testdata/reciprocal/bin/bin1.meta_lic testdata/reciprocal/lib/liba.so.meta_lic static", |
| 295 | "testdata/reciprocal/bin/bin1.meta_lic testdata/reciprocal/lib/libc.a.meta_lic static", |
| 296 | }, |
| 297 | }, |
| 298 | { |
| 299 | condition: "reciprocal", |
| 300 | name: "library", |
| 301 | roots: []string{"lib/libd.so.meta_lic"}, |
| 302 | expectedOut: []string{}, |
| 303 | }, |
| 304 | { |
| 305 | condition: "restricted", |
| 306 | name: "apex", |
| 307 | roots: []string{"highest.apex.meta_lic"}, |
| 308 | expectedOut: []string{ |
| 309 | "testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/liba.so.meta_lic static", |
| 310 | "testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/libc.a.meta_lic static", |
| 311 | "testdata/restricted/bin/bin2.meta_lic testdata/restricted/lib/libb.so.meta_lic dynamic", |
| 312 | "testdata/restricted/bin/bin2.meta_lic testdata/restricted/lib/libd.so.meta_lic dynamic", |
| 313 | "testdata/restricted/highest.apex.meta_lic testdata/restricted/bin/bin1.meta_lic static", |
| 314 | "testdata/restricted/highest.apex.meta_lic testdata/restricted/bin/bin2.meta_lic static", |
| 315 | "testdata/restricted/highest.apex.meta_lic testdata/restricted/lib/liba.so.meta_lic static", |
| 316 | "testdata/restricted/highest.apex.meta_lic testdata/restricted/lib/libb.so.meta_lic static", |
| 317 | }, |
| 318 | }, |
| 319 | { |
| 320 | condition: "restricted", |
| 321 | name: "apex_trimmed", |
| 322 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 323 | ctx: context{stripPrefix: []string{"testdata/restricted/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 324 | expectedOut: []string{ |
| 325 | "bin/bin1.meta_lic lib/liba.so.meta_lic static", |
| 326 | "bin/bin1.meta_lic lib/libc.a.meta_lic static", |
| 327 | "bin/bin2.meta_lic lib/libb.so.meta_lic dynamic", |
| 328 | "bin/bin2.meta_lic lib/libd.so.meta_lic dynamic", |
| 329 | "highest.apex.meta_lic bin/bin1.meta_lic static", |
| 330 | "highest.apex.meta_lic bin/bin2.meta_lic static", |
| 331 | "highest.apex.meta_lic lib/liba.so.meta_lic static", |
| 332 | "highest.apex.meta_lic lib/libb.so.meta_lic static", |
| 333 | }, |
| 334 | }, |
| 335 | { |
| 336 | condition: "restricted", |
| 337 | name: "apex_trimmed_labelled", |
| 338 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 339 | ctx: context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 340 | expectedOut: []string{ |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 341 | "bin/bin1.meta_lic:notice lib/liba.so.meta_lic:restricted_allows_dynamic_linking static", |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 342 | "bin/bin1.meta_lic:notice lib/libc.a.meta_lic:reciprocal static", |
| 343 | "bin/bin2.meta_lic:notice lib/libb.so.meta_lic:restricted dynamic", |
| 344 | "bin/bin2.meta_lic:notice lib/libd.so.meta_lic:notice dynamic", |
| 345 | "highest.apex.meta_lic:notice bin/bin1.meta_lic:notice static", |
| 346 | "highest.apex.meta_lic:notice bin/bin2.meta_lic:notice static", |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 347 | "highest.apex.meta_lic:notice lib/liba.so.meta_lic:restricted_allows_dynamic_linking static", |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 348 | "highest.apex.meta_lic:notice lib/libb.so.meta_lic:restricted static", |
| 349 | }, |
| 350 | }, |
| 351 | { |
| 352 | condition: "restricted", |
| 353 | name: "container", |
| 354 | roots: []string{"container.zip.meta_lic"}, |
| 355 | expectedOut: []string{ |
| 356 | "testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/liba.so.meta_lic static", |
| 357 | "testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/libc.a.meta_lic static", |
| 358 | "testdata/restricted/bin/bin2.meta_lic testdata/restricted/lib/libb.so.meta_lic dynamic", |
| 359 | "testdata/restricted/bin/bin2.meta_lic testdata/restricted/lib/libd.so.meta_lic dynamic", |
| 360 | "testdata/restricted/container.zip.meta_lic testdata/restricted/bin/bin1.meta_lic static", |
| 361 | "testdata/restricted/container.zip.meta_lic testdata/restricted/bin/bin2.meta_lic static", |
| 362 | "testdata/restricted/container.zip.meta_lic testdata/restricted/lib/liba.so.meta_lic static", |
| 363 | "testdata/restricted/container.zip.meta_lic testdata/restricted/lib/libb.so.meta_lic static", |
| 364 | }, |
| 365 | }, |
| 366 | { |
| 367 | condition: "restricted", |
| 368 | name: "application", |
| 369 | roots: []string{"application.meta_lic"}, |
| 370 | expectedOut: []string{ |
| 371 | "testdata/restricted/application.meta_lic testdata/restricted/bin/bin3.meta_lic toolchain", |
| 372 | "testdata/restricted/application.meta_lic testdata/restricted/lib/liba.so.meta_lic static", |
| 373 | "testdata/restricted/application.meta_lic testdata/restricted/lib/libb.so.meta_lic dynamic", |
| 374 | }, |
| 375 | }, |
| 376 | { |
| 377 | condition: "restricted", |
| 378 | name: "binary", |
| 379 | roots: []string{"bin/bin1.meta_lic"}, |
| 380 | expectedOut: []string{ |
| 381 | "testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/liba.so.meta_lic static", |
| 382 | "testdata/restricted/bin/bin1.meta_lic testdata/restricted/lib/libc.a.meta_lic static", |
| 383 | }, |
| 384 | }, |
| 385 | { |
| 386 | condition: "restricted", |
| 387 | name: "library", |
| 388 | roots: []string{"lib/libd.so.meta_lic"}, |
| 389 | expectedOut: []string{}, |
| 390 | }, |
| 391 | { |
| 392 | condition: "proprietary", |
| 393 | name: "apex", |
| 394 | roots: []string{"highest.apex.meta_lic"}, |
| 395 | expectedOut: []string{ |
| 396 | "testdata/proprietary/bin/bin1.meta_lic testdata/proprietary/lib/liba.so.meta_lic static", |
| 397 | "testdata/proprietary/bin/bin1.meta_lic testdata/proprietary/lib/libc.a.meta_lic static", |
| 398 | "testdata/proprietary/bin/bin2.meta_lic testdata/proprietary/lib/libb.so.meta_lic dynamic", |
| 399 | "testdata/proprietary/bin/bin2.meta_lic testdata/proprietary/lib/libd.so.meta_lic dynamic", |
| 400 | "testdata/proprietary/highest.apex.meta_lic testdata/proprietary/bin/bin1.meta_lic static", |
| 401 | "testdata/proprietary/highest.apex.meta_lic testdata/proprietary/bin/bin2.meta_lic static", |
| 402 | "testdata/proprietary/highest.apex.meta_lic testdata/proprietary/lib/liba.so.meta_lic static", |
| 403 | "testdata/proprietary/highest.apex.meta_lic testdata/proprietary/lib/libb.so.meta_lic static", |
| 404 | }, |
| 405 | }, |
| 406 | { |
| 407 | condition: "proprietary", |
| 408 | name: "apex_trimmed", |
| 409 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 410 | ctx: context{stripPrefix: []string{"testdata/proprietary/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 411 | expectedOut: []string{ |
| 412 | "bin/bin1.meta_lic lib/liba.so.meta_lic static", |
| 413 | "bin/bin1.meta_lic lib/libc.a.meta_lic static", |
| 414 | "bin/bin2.meta_lic lib/libb.so.meta_lic dynamic", |
| 415 | "bin/bin2.meta_lic lib/libd.so.meta_lic dynamic", |
| 416 | "highest.apex.meta_lic bin/bin1.meta_lic static", |
| 417 | "highest.apex.meta_lic bin/bin2.meta_lic static", |
| 418 | "highest.apex.meta_lic lib/liba.so.meta_lic static", |
| 419 | "highest.apex.meta_lic lib/libb.so.meta_lic static", |
| 420 | }, |
| 421 | }, |
| 422 | { |
| 423 | condition: "proprietary", |
| 424 | name: "apex_trimmed_labelled", |
| 425 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 426 | ctx: context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 427 | expectedOut: []string{ |
| 428 | "bin/bin1.meta_lic:notice lib/liba.so.meta_lic:by_exception_only:proprietary static", |
| 429 | "bin/bin1.meta_lic:notice lib/libc.a.meta_lic:by_exception_only:proprietary static", |
| 430 | "bin/bin2.meta_lic:by_exception_only:proprietary lib/libb.so.meta_lic:restricted dynamic", |
| 431 | "bin/bin2.meta_lic:by_exception_only:proprietary lib/libd.so.meta_lic:notice dynamic", |
| 432 | "highest.apex.meta_lic:notice bin/bin1.meta_lic:notice static", |
| 433 | "highest.apex.meta_lic:notice bin/bin2.meta_lic:by_exception_only:proprietary static", |
| 434 | "highest.apex.meta_lic:notice lib/liba.so.meta_lic:by_exception_only:proprietary static", |
| 435 | "highest.apex.meta_lic:notice lib/libb.so.meta_lic:restricted static", |
| 436 | }, |
| 437 | }, |
| 438 | { |
| 439 | condition: "proprietary", |
| 440 | name: "container", |
| 441 | roots: []string{"container.zip.meta_lic"}, |
| 442 | expectedOut: []string{ |
| 443 | "testdata/proprietary/bin/bin1.meta_lic testdata/proprietary/lib/liba.so.meta_lic static", |
| 444 | "testdata/proprietary/bin/bin1.meta_lic testdata/proprietary/lib/libc.a.meta_lic static", |
| 445 | "testdata/proprietary/bin/bin2.meta_lic testdata/proprietary/lib/libb.so.meta_lic dynamic", |
| 446 | "testdata/proprietary/bin/bin2.meta_lic testdata/proprietary/lib/libd.so.meta_lic dynamic", |
| 447 | "testdata/proprietary/container.zip.meta_lic testdata/proprietary/bin/bin1.meta_lic static", |
| 448 | "testdata/proprietary/container.zip.meta_lic testdata/proprietary/bin/bin2.meta_lic static", |
| 449 | "testdata/proprietary/container.zip.meta_lic testdata/proprietary/lib/liba.so.meta_lic static", |
| 450 | "testdata/proprietary/container.zip.meta_lic testdata/proprietary/lib/libb.so.meta_lic static", |
| 451 | }, |
| 452 | }, |
| 453 | { |
| 454 | condition: "proprietary", |
| 455 | name: "application", |
| 456 | roots: []string{"application.meta_lic"}, |
| 457 | expectedOut: []string{ |
| 458 | "testdata/proprietary/application.meta_lic testdata/proprietary/bin/bin3.meta_lic toolchain", |
| 459 | "testdata/proprietary/application.meta_lic testdata/proprietary/lib/liba.so.meta_lic static", |
| 460 | "testdata/proprietary/application.meta_lic testdata/proprietary/lib/libb.so.meta_lic dynamic", |
| 461 | }, |
| 462 | }, |
| 463 | { |
| 464 | condition: "proprietary", |
| 465 | name: "binary", |
| 466 | roots: []string{"bin/bin1.meta_lic"}, |
| 467 | expectedOut: []string{ |
| 468 | "testdata/proprietary/bin/bin1.meta_lic testdata/proprietary/lib/liba.so.meta_lic static", |
| 469 | "testdata/proprietary/bin/bin1.meta_lic testdata/proprietary/lib/libc.a.meta_lic static", |
| 470 | }, |
| 471 | }, |
| 472 | { |
| 473 | condition: "proprietary", |
| 474 | name: "library", |
| 475 | roots: []string{"lib/libd.so.meta_lic"}, |
| 476 | expectedOut: []string{}, |
| 477 | }, |
| 478 | } |
| 479 | for _, tt := range tests { |
| 480 | t.Run(tt.condition+" "+tt.name, func(t *testing.T) { |
| 481 | expectedOut := &bytes.Buffer{} |
| 482 | for _, eo := range tt.expectedOut { |
| 483 | expectedOut.WriteString(eo) |
| 484 | expectedOut.WriteString("\n") |
| 485 | } |
| 486 | |
| 487 | stdout := &bytes.Buffer{} |
| 488 | stderr := &bytes.Buffer{} |
| 489 | |
| 490 | rootFiles := make([]string, 0, len(tt.roots)) |
| 491 | for _, r := range tt.roots { |
| 492 | rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r) |
| 493 | } |
| 494 | err := dumpGraph(&tt.ctx, stdout, stderr, rootFiles...) |
| 495 | if err != nil { |
| 496 | t.Fatalf("dumpgraph: error = %v, stderr = %v", err, stderr) |
| 497 | return |
| 498 | } |
| 499 | if stderr.Len() > 0 { |
| 500 | t.Errorf("dumpgraph: gotStderr = %v, want none", stderr) |
| 501 | } |
| 502 | out := stdout.String() |
| 503 | expected := expectedOut.String() |
| 504 | if out != expected { |
| 505 | outList := strings.Split(out, "\n") |
| 506 | expectedList := strings.Split(expected, "\n") |
| 507 | startLine := 0 |
| 508 | for len(outList) > startLine && len(expectedList) > startLine && outList[startLine] == expectedList[startLine] { |
| 509 | startLine++ |
| 510 | } |
| 511 | t.Errorf("listshare: gotStdout = %v, want %v, somewhere near line %d Stdout = %v, want %v", |
| 512 | out, expected, startLine+1, outList[startLine], expectedList[startLine]) |
| 513 | } |
| 514 | }) |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | type testContext struct { |
| 519 | nextNode int |
| 520 | nodes map[string]string |
| 521 | } |
| 522 | |
| 523 | type matcher interface { |
| 524 | matchString(*testContext) string |
| 525 | typeString() string |
| 526 | } |
| 527 | |
| 528 | type targetMatcher struct { |
| 529 | target string |
| 530 | conditions []string |
| 531 | } |
| 532 | |
| 533 | func (tm *targetMatcher) matchString(ctx *testContext) string { |
| 534 | m := tm.target |
| 535 | if len(tm.conditions) > 0 { |
| 536 | m += "\\n" + strings.Join(tm.conditions, "\\n") |
| 537 | } |
| 538 | m = ctx.nodes[tm.target] + " [label=\"" + m + "\"];" |
| 539 | return m |
| 540 | } |
| 541 | |
| 542 | func (tm *targetMatcher) typeString() string { |
| 543 | return "target" |
| 544 | } |
| 545 | |
| 546 | type edgeMatcher struct { |
| 547 | target string |
| 548 | dep string |
| 549 | annotations []string |
| 550 | } |
| 551 | |
| 552 | func (em *edgeMatcher) matchString(ctx *testContext) string { |
| 553 | return ctx.nodes[em.dep] + " -> " + ctx.nodes[em.target] + " [label=\"" + strings.Join(em.annotations, "\\n") + "\"];" |
| 554 | } |
| 555 | |
| 556 | func (tm *edgeMatcher) typeString() string { |
| 557 | return "edge" |
| 558 | } |
| 559 | |
| 560 | type getMatcher func(*testContext) matcher |
| 561 | |
| 562 | func matchTarget(target string, conditions ...string) getMatcher { |
| 563 | return func(ctx *testContext) matcher { |
| 564 | ctx.nodes[target] = fmt.Sprintf("n%d", ctx.nextNode) |
| 565 | ctx.nextNode++ |
| 566 | return &targetMatcher{target, append([]string{}, conditions...)} |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | func matchEdge(target, dep string, annotations ...string) getMatcher { |
| 571 | return func(ctx *testContext) matcher { |
| 572 | if _, ok := ctx.nodes[target]; !ok { |
| 573 | panic(fmt.Errorf("no node for target %v in %v -> %v [label=\"%s\"];", target, dep, target, strings.Join(annotations, "\\n"))) |
| 574 | } |
| 575 | if _, ok := ctx.nodes[dep]; !ok { |
| 576 | panic(fmt.Errorf("no node for dep %v in %v -> %v [label=\"%s\"];", target, dep, target, strings.Join(annotations, "\\n"))) |
| 577 | } |
| 578 | return &edgeMatcher{target, dep, append([]string{}, annotations...)} |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | func Test_graphviz(t *testing.T) { |
| 583 | tests := []struct { |
| 584 | condition string |
| 585 | name string |
| 586 | roots []string |
| 587 | ctx context |
| 588 | expectedOut []getMatcher |
| 589 | }{ |
| 590 | { |
| 591 | condition: "firstparty", |
| 592 | name: "apex", |
| 593 | roots: []string{"highest.apex.meta_lic"}, |
| 594 | expectedOut: []getMatcher{ |
| 595 | matchTarget("testdata/firstparty/bin/bin1.meta_lic"), |
| 596 | matchTarget("testdata/firstparty/bin/bin2.meta_lic"), |
| 597 | matchTarget("testdata/firstparty/highest.apex.meta_lic"), |
| 598 | matchTarget("testdata/firstparty/lib/liba.so.meta_lic"), |
| 599 | matchTarget("testdata/firstparty/lib/libb.so.meta_lic"), |
| 600 | matchTarget("testdata/firstparty/lib/libc.a.meta_lic"), |
| 601 | matchTarget("testdata/firstparty/lib/libd.so.meta_lic"), |
| 602 | matchEdge("testdata/firstparty/bin/bin1.meta_lic", "testdata/firstparty/lib/liba.so.meta_lic", "static"), |
| 603 | matchEdge("testdata/firstparty/bin/bin1.meta_lic", "testdata/firstparty/lib/libc.a.meta_lic", "static"), |
| 604 | matchEdge("testdata/firstparty/bin/bin2.meta_lic", "testdata/firstparty/lib/libb.so.meta_lic", "dynamic"), |
| 605 | matchEdge("testdata/firstparty/bin/bin2.meta_lic", "testdata/firstparty/lib/libd.so.meta_lic", "dynamic"), |
| 606 | matchEdge("testdata/firstparty/highest.apex.meta_lic", "testdata/firstparty/bin/bin1.meta_lic", "static"), |
| 607 | matchEdge("testdata/firstparty/highest.apex.meta_lic", "testdata/firstparty/bin/bin2.meta_lic", "static"), |
| 608 | matchEdge("testdata/firstparty/highest.apex.meta_lic", "testdata/firstparty/lib/liba.so.meta_lic", "static"), |
| 609 | matchEdge("testdata/firstparty/highest.apex.meta_lic", "testdata/firstparty/lib/libb.so.meta_lic", "static"), |
| 610 | }, |
| 611 | }, |
| 612 | { |
| 613 | condition: "firstparty", |
| 614 | name: "apex_trimmed", |
| 615 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 616 | ctx: context{stripPrefix: []string{"testdata/firstparty/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 617 | expectedOut: []getMatcher{ |
| 618 | matchTarget("bin/bin1.meta_lic"), |
| 619 | matchTarget("bin/bin2.meta_lic"), |
| 620 | matchTarget("highest.apex.meta_lic"), |
| 621 | matchTarget("lib/liba.so.meta_lic"), |
| 622 | matchTarget("lib/libb.so.meta_lic"), |
| 623 | matchTarget("lib/libc.a.meta_lic"), |
| 624 | matchTarget("lib/libd.so.meta_lic"), |
| 625 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 626 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 627 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 628 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 629 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 630 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 631 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 632 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 633 | }, |
| 634 | }, |
| 635 | { |
| 636 | condition: "firstparty", |
| 637 | name: "apex_trimmed_labelled", |
| 638 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 639 | ctx: context{stripPrefix: []string{"testdata/firstparty/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 640 | expectedOut: []getMatcher{ |
| 641 | matchTarget("bin/bin1.meta_lic", "notice"), |
| 642 | matchTarget("bin/bin2.meta_lic", "notice"), |
| 643 | matchTarget("highest.apex.meta_lic", "notice"), |
| 644 | matchTarget("lib/liba.so.meta_lic", "notice"), |
| 645 | matchTarget("lib/libb.so.meta_lic", "notice"), |
| 646 | matchTarget("lib/libc.a.meta_lic", "notice"), |
| 647 | matchTarget("lib/libd.so.meta_lic", "notice"), |
| 648 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 649 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 650 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 651 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 652 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 653 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 654 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 655 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 656 | }, |
| 657 | }, |
| 658 | { |
| 659 | condition: "firstparty", |
| 660 | name: "container", |
| 661 | roots: []string{"container.zip.meta_lic"}, |
| 662 | expectedOut: []getMatcher{ |
| 663 | matchTarget("testdata/firstparty/bin/bin1.meta_lic"), |
| 664 | matchTarget("testdata/firstparty/bin/bin2.meta_lic"), |
| 665 | matchTarget("testdata/firstparty/container.zip.meta_lic"), |
| 666 | matchTarget("testdata/firstparty/lib/liba.so.meta_lic"), |
| 667 | matchTarget("testdata/firstparty/lib/libb.so.meta_lic"), |
| 668 | matchTarget("testdata/firstparty/lib/libc.a.meta_lic"), |
| 669 | matchTarget("testdata/firstparty/lib/libd.so.meta_lic"), |
| 670 | matchEdge("testdata/firstparty/bin/bin1.meta_lic", "testdata/firstparty/lib/liba.so.meta_lic", "static"), |
| 671 | matchEdge("testdata/firstparty/bin/bin1.meta_lic", "testdata/firstparty/lib/libc.a.meta_lic", "static"), |
| 672 | matchEdge("testdata/firstparty/bin/bin2.meta_lic", "testdata/firstparty/lib/libb.so.meta_lic", "dynamic"), |
| 673 | matchEdge("testdata/firstparty/bin/bin2.meta_lic", "testdata/firstparty/lib/libd.so.meta_lic", "dynamic"), |
| 674 | matchEdge("testdata/firstparty/container.zip.meta_lic", "testdata/firstparty/bin/bin1.meta_lic", "static"), |
| 675 | matchEdge("testdata/firstparty/container.zip.meta_lic", "testdata/firstparty/bin/bin2.meta_lic", "static"), |
| 676 | matchEdge("testdata/firstparty/container.zip.meta_lic", "testdata/firstparty/lib/liba.so.meta_lic", "static"), |
| 677 | matchEdge("testdata/firstparty/container.zip.meta_lic", "testdata/firstparty/lib/libb.so.meta_lic", "static"), |
| 678 | }, |
| 679 | }, |
| 680 | { |
| 681 | condition: "firstparty", |
| 682 | name: "application", |
| 683 | roots: []string{"application.meta_lic"}, |
| 684 | expectedOut: []getMatcher{ |
| 685 | matchTarget("testdata/firstparty/application.meta_lic"), |
| 686 | matchTarget("testdata/firstparty/bin/bin3.meta_lic"), |
| 687 | matchTarget("testdata/firstparty/lib/liba.so.meta_lic"), |
| 688 | matchTarget("testdata/firstparty/lib/libb.so.meta_lic"), |
| 689 | matchEdge("testdata/firstparty/application.meta_lic", "testdata/firstparty/bin/bin3.meta_lic", "toolchain"), |
| 690 | matchEdge("testdata/firstparty/application.meta_lic", "testdata/firstparty/lib/liba.so.meta_lic", "static"), |
| 691 | matchEdge("testdata/firstparty/application.meta_lic", "testdata/firstparty/lib/libb.so.meta_lic", "dynamic"), |
| 692 | }, |
| 693 | }, |
| 694 | { |
| 695 | condition: "firstparty", |
| 696 | name: "binary", |
| 697 | roots: []string{"bin/bin1.meta_lic"}, |
| 698 | expectedOut: []getMatcher{ |
| 699 | matchTarget("testdata/firstparty/bin/bin1.meta_lic"), |
| 700 | matchTarget("testdata/firstparty/lib/liba.so.meta_lic"), |
| 701 | matchTarget("testdata/firstparty/lib/libc.a.meta_lic"), |
| 702 | matchEdge("testdata/firstparty/bin/bin1.meta_lic", "testdata/firstparty/lib/liba.so.meta_lic", "static"), |
| 703 | matchEdge("testdata/firstparty/bin/bin1.meta_lic", "testdata/firstparty/lib/libc.a.meta_lic", "static"), |
| 704 | }, |
| 705 | }, |
| 706 | { |
| 707 | condition: "firstparty", |
| 708 | name: "library", |
| 709 | roots: []string{"lib/libd.so.meta_lic"}, |
| 710 | expectedOut: []getMatcher{matchTarget("testdata/firstparty/lib/libd.so.meta_lic")}, |
| 711 | }, |
| 712 | { |
| 713 | condition: "notice", |
| 714 | name: "apex", |
| 715 | roots: []string{"highest.apex.meta_lic"}, |
| 716 | expectedOut: []getMatcher{ |
| 717 | matchTarget("testdata/notice/bin/bin1.meta_lic"), |
| 718 | matchTarget("testdata/notice/bin/bin2.meta_lic"), |
| 719 | matchTarget("testdata/notice/highest.apex.meta_lic"), |
| 720 | matchTarget("testdata/notice/lib/liba.so.meta_lic"), |
| 721 | matchTarget("testdata/notice/lib/libb.so.meta_lic"), |
| 722 | matchTarget("testdata/notice/lib/libc.a.meta_lic"), |
| 723 | matchTarget("testdata/notice/lib/libd.so.meta_lic"), |
| 724 | matchEdge("testdata/notice/bin/bin1.meta_lic", "testdata/notice/lib/liba.so.meta_lic", "static"), |
| 725 | matchEdge("testdata/notice/bin/bin1.meta_lic", "testdata/notice/lib/libc.a.meta_lic", "static"), |
| 726 | matchEdge("testdata/notice/bin/bin2.meta_lic", "testdata/notice/lib/libb.so.meta_lic", "dynamic"), |
| 727 | matchEdge("testdata/notice/bin/bin2.meta_lic", "testdata/notice/lib/libd.so.meta_lic", "dynamic"), |
| 728 | matchEdge("testdata/notice/highest.apex.meta_lic", "testdata/notice/bin/bin1.meta_lic", "static"), |
| 729 | matchEdge("testdata/notice/highest.apex.meta_lic", "testdata/notice/bin/bin2.meta_lic", "static"), |
| 730 | matchEdge("testdata/notice/highest.apex.meta_lic", "testdata/notice/lib/liba.so.meta_lic", "static"), |
| 731 | matchEdge("testdata/notice/highest.apex.meta_lic", "testdata/notice/lib/libb.so.meta_lic", "static"), |
| 732 | }, |
| 733 | }, |
| 734 | { |
| 735 | condition: "notice", |
| 736 | name: "apex_trimmed", |
| 737 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 738 | ctx: context{stripPrefix: []string{"testdata/notice/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 739 | expectedOut: []getMatcher{ |
| 740 | matchTarget("bin/bin1.meta_lic"), |
| 741 | matchTarget("bin/bin2.meta_lic"), |
| 742 | matchTarget("highest.apex.meta_lic"), |
| 743 | matchTarget("lib/liba.so.meta_lic"), |
| 744 | matchTarget("lib/libb.so.meta_lic"), |
| 745 | matchTarget("lib/libc.a.meta_lic"), |
| 746 | matchTarget("lib/libd.so.meta_lic"), |
| 747 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 748 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 749 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 750 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 751 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 752 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 753 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 754 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 755 | }, |
| 756 | }, |
| 757 | { |
| 758 | condition: "notice", |
| 759 | name: "apex_trimmed_labelled", |
| 760 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 761 | ctx: context{stripPrefix: []string{"testdata/notice/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 762 | expectedOut: []getMatcher{ |
| 763 | matchTarget("bin/bin1.meta_lic", "notice"), |
| 764 | matchTarget("bin/bin2.meta_lic", "notice"), |
| 765 | matchTarget("highest.apex.meta_lic", "notice"), |
| 766 | matchTarget("lib/liba.so.meta_lic", "notice"), |
| 767 | matchTarget("lib/libb.so.meta_lic", "notice"), |
| 768 | matchTarget("lib/libc.a.meta_lic", "notice"), |
| 769 | matchTarget("lib/libd.so.meta_lic", "notice"), |
| 770 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 771 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 772 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 773 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 774 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 775 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 776 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 777 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 778 | }, |
| 779 | }, |
| 780 | { |
| 781 | condition: "notice", |
| 782 | name: "container", |
| 783 | roots: []string{"container.zip.meta_lic"}, |
| 784 | expectedOut: []getMatcher{ |
| 785 | matchTarget("testdata/notice/bin/bin1.meta_lic"), |
| 786 | matchTarget("testdata/notice/bin/bin2.meta_lic"), |
| 787 | matchTarget("testdata/notice/container.zip.meta_lic"), |
| 788 | matchTarget("testdata/notice/lib/liba.so.meta_lic"), |
| 789 | matchTarget("testdata/notice/lib/libb.so.meta_lic"), |
| 790 | matchTarget("testdata/notice/lib/libc.a.meta_lic"), |
| 791 | matchTarget("testdata/notice/lib/libd.so.meta_lic"), |
| 792 | matchEdge("testdata/notice/bin/bin1.meta_lic", "testdata/notice/lib/liba.so.meta_lic", "static"), |
| 793 | matchEdge("testdata/notice/bin/bin1.meta_lic", "testdata/notice/lib/libc.a.meta_lic", "static"), |
| 794 | matchEdge("testdata/notice/bin/bin2.meta_lic", "testdata/notice/lib/libb.so.meta_lic", "dynamic"), |
| 795 | matchEdge("testdata/notice/bin/bin2.meta_lic", "testdata/notice/lib/libd.so.meta_lic", "dynamic"), |
| 796 | matchEdge("testdata/notice/container.zip.meta_lic", "testdata/notice/bin/bin1.meta_lic", "static"), |
| 797 | matchEdge("testdata/notice/container.zip.meta_lic", "testdata/notice/bin/bin2.meta_lic", "static"), |
| 798 | matchEdge("testdata/notice/container.zip.meta_lic", "testdata/notice/lib/liba.so.meta_lic", "static"), |
| 799 | matchEdge("testdata/notice/container.zip.meta_lic", "testdata/notice/lib/libb.so.meta_lic", "static"), |
| 800 | }, |
| 801 | }, |
| 802 | { |
| 803 | condition: "notice", |
| 804 | name: "application", |
| 805 | roots: []string{"application.meta_lic"}, |
| 806 | expectedOut: []getMatcher{ |
| 807 | matchTarget("testdata/notice/application.meta_lic"), |
| 808 | matchTarget("testdata/notice/bin/bin3.meta_lic"), |
| 809 | matchTarget("testdata/notice/lib/liba.so.meta_lic"), |
| 810 | matchTarget("testdata/notice/lib/libb.so.meta_lic"), |
| 811 | matchEdge("testdata/notice/application.meta_lic", "testdata/notice/bin/bin3.meta_lic", "toolchain"), |
| 812 | matchEdge("testdata/notice/application.meta_lic", "testdata/notice/lib/liba.so.meta_lic", "static"), |
| 813 | matchEdge("testdata/notice/application.meta_lic", "testdata/notice/lib/libb.so.meta_lic", "dynamic"), |
| 814 | }, |
| 815 | }, |
| 816 | { |
| 817 | condition: "notice", |
| 818 | name: "binary", |
| 819 | roots: []string{"bin/bin1.meta_lic"}, |
| 820 | expectedOut: []getMatcher{ |
| 821 | matchTarget("testdata/notice/bin/bin1.meta_lic"), |
| 822 | matchTarget("testdata/notice/lib/liba.so.meta_lic"), |
| 823 | matchTarget("testdata/notice/lib/libc.a.meta_lic"), |
| 824 | matchEdge("testdata/notice/bin/bin1.meta_lic", "testdata/notice/lib/liba.so.meta_lic", "static"), |
| 825 | matchEdge("testdata/notice/bin/bin1.meta_lic", "testdata/notice/lib/libc.a.meta_lic", "static"), |
| 826 | }, |
| 827 | }, |
| 828 | { |
| 829 | condition: "notice", |
| 830 | name: "library", |
| 831 | roots: []string{"lib/libd.so.meta_lic"}, |
| 832 | expectedOut: []getMatcher{matchTarget("testdata/notice/lib/libd.so.meta_lic")}, |
| 833 | }, |
| 834 | { |
| 835 | condition: "reciprocal", |
| 836 | name: "apex", |
| 837 | roots: []string{"highest.apex.meta_lic"}, |
| 838 | expectedOut: []getMatcher{ |
| 839 | matchTarget("testdata/reciprocal/bin/bin1.meta_lic"), |
| 840 | matchTarget("testdata/reciprocal/bin/bin2.meta_lic"), |
| 841 | matchTarget("testdata/reciprocal/highest.apex.meta_lic"), |
| 842 | matchTarget("testdata/reciprocal/lib/liba.so.meta_lic"), |
| 843 | matchTarget("testdata/reciprocal/lib/libb.so.meta_lic"), |
| 844 | matchTarget("testdata/reciprocal/lib/libc.a.meta_lic"), |
| 845 | matchTarget("testdata/reciprocal/lib/libd.so.meta_lic"), |
| 846 | matchEdge("testdata/reciprocal/bin/bin1.meta_lic", "testdata/reciprocal/lib/liba.so.meta_lic", "static"), |
| 847 | matchEdge("testdata/reciprocal/bin/bin1.meta_lic", "testdata/reciprocal/lib/libc.a.meta_lic", "static"), |
| 848 | matchEdge("testdata/reciprocal/bin/bin2.meta_lic", "testdata/reciprocal/lib/libb.so.meta_lic", "dynamic"), |
| 849 | matchEdge("testdata/reciprocal/bin/bin2.meta_lic", "testdata/reciprocal/lib/libd.so.meta_lic", "dynamic"), |
| 850 | matchEdge("testdata/reciprocal/highest.apex.meta_lic", "testdata/reciprocal/bin/bin1.meta_lic", "static"), |
| 851 | matchEdge("testdata/reciprocal/highest.apex.meta_lic", "testdata/reciprocal/bin/bin2.meta_lic", "static"), |
| 852 | matchEdge("testdata/reciprocal/highest.apex.meta_lic", "testdata/reciprocal/lib/liba.so.meta_lic", "static"), |
| 853 | matchEdge("testdata/reciprocal/highest.apex.meta_lic", "testdata/reciprocal/lib/libb.so.meta_lic", "static"), |
| 854 | }, |
| 855 | }, |
| 856 | { |
| 857 | condition: "reciprocal", |
| 858 | name: "apex_trimmed", |
| 859 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 860 | ctx: context{stripPrefix: []string{"testdata/reciprocal/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 861 | expectedOut: []getMatcher{ |
| 862 | matchTarget("bin/bin1.meta_lic"), |
| 863 | matchTarget("bin/bin2.meta_lic"), |
| 864 | matchTarget("highest.apex.meta_lic"), |
| 865 | matchTarget("lib/liba.so.meta_lic"), |
| 866 | matchTarget("lib/libb.so.meta_lic"), |
| 867 | matchTarget("lib/libc.a.meta_lic"), |
| 868 | matchTarget("lib/libd.so.meta_lic"), |
| 869 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 870 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 871 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 872 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 873 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 874 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 875 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 876 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 877 | }, |
| 878 | }, |
| 879 | { |
| 880 | condition: "reciprocal", |
| 881 | name: "apex_trimmed_labelled", |
| 882 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 883 | ctx: context{stripPrefix: []string{"testdata/reciprocal/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 884 | expectedOut: []getMatcher{ |
| 885 | matchTarget("bin/bin1.meta_lic", "notice"), |
| 886 | matchTarget("bin/bin2.meta_lic", "notice"), |
| 887 | matchTarget("highest.apex.meta_lic", "notice"), |
| 888 | matchTarget("lib/liba.so.meta_lic", "reciprocal"), |
| 889 | matchTarget("lib/libb.so.meta_lic", "notice"), |
| 890 | matchTarget("lib/libc.a.meta_lic", "reciprocal"), |
| 891 | matchTarget("lib/libd.so.meta_lic", "notice"), |
| 892 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 893 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 894 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 895 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 896 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 897 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 898 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 899 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 900 | }, |
| 901 | }, |
| 902 | { |
| 903 | condition: "reciprocal", |
| 904 | name: "container", |
| 905 | roots: []string{"container.zip.meta_lic"}, |
| 906 | expectedOut: []getMatcher{ |
| 907 | matchTarget("testdata/reciprocal/bin/bin1.meta_lic"), |
| 908 | matchTarget("testdata/reciprocal/bin/bin2.meta_lic"), |
| 909 | matchTarget("testdata/reciprocal/container.zip.meta_lic"), |
| 910 | matchTarget("testdata/reciprocal/lib/liba.so.meta_lic"), |
| 911 | matchTarget("testdata/reciprocal/lib/libb.so.meta_lic"), |
| 912 | matchTarget("testdata/reciprocal/lib/libc.a.meta_lic"), |
| 913 | matchTarget("testdata/reciprocal/lib/libd.so.meta_lic"), |
| 914 | matchEdge("testdata/reciprocal/bin/bin1.meta_lic", "testdata/reciprocal/lib/liba.so.meta_lic", "static"), |
| 915 | matchEdge("testdata/reciprocal/bin/bin1.meta_lic", "testdata/reciprocal/lib/libc.a.meta_lic", "static"), |
| 916 | matchEdge("testdata/reciprocal/bin/bin2.meta_lic", "testdata/reciprocal/lib/libb.so.meta_lic", "dynamic"), |
| 917 | matchEdge("testdata/reciprocal/bin/bin2.meta_lic", "testdata/reciprocal/lib/libd.so.meta_lic", "dynamic"), |
| 918 | matchEdge("testdata/reciprocal/container.zip.meta_lic", "testdata/reciprocal/bin/bin1.meta_lic", "static"), |
| 919 | matchEdge("testdata/reciprocal/container.zip.meta_lic", "testdata/reciprocal/bin/bin2.meta_lic", "static"), |
| 920 | matchEdge("testdata/reciprocal/container.zip.meta_lic", "testdata/reciprocal/lib/liba.so.meta_lic", "static"), |
| 921 | matchEdge("testdata/reciprocal/container.zip.meta_lic", "testdata/reciprocal/lib/libb.so.meta_lic", "static"), |
| 922 | }, |
| 923 | }, |
| 924 | { |
| 925 | condition: "reciprocal", |
| 926 | name: "application", |
| 927 | roots: []string{"application.meta_lic"}, |
| 928 | expectedOut: []getMatcher{ |
| 929 | matchTarget("testdata/reciprocal/application.meta_lic"), |
| 930 | matchTarget("testdata/reciprocal/bin/bin3.meta_lic"), |
| 931 | matchTarget("testdata/reciprocal/lib/liba.so.meta_lic"), |
| 932 | matchTarget("testdata/reciprocal/lib/libb.so.meta_lic"), |
| 933 | matchEdge("testdata/reciprocal/application.meta_lic", "testdata/reciprocal/bin/bin3.meta_lic", "toolchain"), |
| 934 | matchEdge("testdata/reciprocal/application.meta_lic", "testdata/reciprocal/lib/liba.so.meta_lic", "static"), |
| 935 | matchEdge("testdata/reciprocal/application.meta_lic", "testdata/reciprocal/lib/libb.so.meta_lic", "dynamic"), |
| 936 | }, |
| 937 | }, |
| 938 | { |
| 939 | condition: "reciprocal", |
| 940 | name: "binary", |
| 941 | roots: []string{"bin/bin1.meta_lic"}, |
| 942 | expectedOut: []getMatcher{ |
| 943 | matchTarget("testdata/reciprocal/bin/bin1.meta_lic"), |
| 944 | matchTarget("testdata/reciprocal/lib/liba.so.meta_lic"), |
| 945 | matchTarget("testdata/reciprocal/lib/libc.a.meta_lic"), |
| 946 | matchEdge("testdata/reciprocal/bin/bin1.meta_lic", "testdata/reciprocal/lib/liba.so.meta_lic", "static"), |
| 947 | matchEdge("testdata/reciprocal/bin/bin1.meta_lic", "testdata/reciprocal/lib/libc.a.meta_lic", "static"), |
| 948 | }, |
| 949 | }, |
| 950 | { |
| 951 | condition: "reciprocal", |
| 952 | name: "library", |
| 953 | roots: []string{"lib/libd.so.meta_lic"}, |
| 954 | expectedOut: []getMatcher{matchTarget("testdata/reciprocal/lib/libd.so.meta_lic")}, |
| 955 | }, |
| 956 | { |
| 957 | condition: "restricted", |
| 958 | name: "apex", |
| 959 | roots: []string{"highest.apex.meta_lic"}, |
| 960 | expectedOut: []getMatcher{ |
| 961 | matchTarget("testdata/restricted/bin/bin1.meta_lic"), |
| 962 | matchTarget("testdata/restricted/bin/bin2.meta_lic"), |
| 963 | matchTarget("testdata/restricted/highest.apex.meta_lic"), |
| 964 | matchTarget("testdata/restricted/lib/liba.so.meta_lic"), |
| 965 | matchTarget("testdata/restricted/lib/libb.so.meta_lic"), |
| 966 | matchTarget("testdata/restricted/lib/libc.a.meta_lic"), |
| 967 | matchTarget("testdata/restricted/lib/libd.so.meta_lic"), |
| 968 | matchEdge("testdata/restricted/bin/bin1.meta_lic", "testdata/restricted/lib/liba.so.meta_lic", "static"), |
| 969 | matchEdge("testdata/restricted/bin/bin1.meta_lic", "testdata/restricted/lib/libc.a.meta_lic", "static"), |
| 970 | matchEdge("testdata/restricted/bin/bin2.meta_lic", "testdata/restricted/lib/libb.so.meta_lic", "dynamic"), |
| 971 | matchEdge("testdata/restricted/bin/bin2.meta_lic", "testdata/restricted/lib/libd.so.meta_lic", "dynamic"), |
| 972 | matchEdge("testdata/restricted/highest.apex.meta_lic", "testdata/restricted/bin/bin1.meta_lic", "static"), |
| 973 | matchEdge("testdata/restricted/highest.apex.meta_lic", "testdata/restricted/bin/bin2.meta_lic", "static"), |
| 974 | matchEdge("testdata/restricted/highest.apex.meta_lic", "testdata/restricted/lib/liba.so.meta_lic", "static"), |
| 975 | matchEdge("testdata/restricted/highest.apex.meta_lic", "testdata/restricted/lib/libb.so.meta_lic", "static"), |
| 976 | }, |
| 977 | }, |
| 978 | { |
| 979 | condition: "restricted", |
| 980 | name: "apex_trimmed", |
| 981 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 982 | ctx: context{stripPrefix: []string{"testdata/restricted/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 983 | expectedOut: []getMatcher{ |
| 984 | matchTarget("bin/bin1.meta_lic"), |
| 985 | matchTarget("bin/bin2.meta_lic"), |
| 986 | matchTarget("highest.apex.meta_lic"), |
| 987 | matchTarget("lib/liba.so.meta_lic"), |
| 988 | matchTarget("lib/libb.so.meta_lic"), |
| 989 | matchTarget("lib/libc.a.meta_lic"), |
| 990 | matchTarget("lib/libd.so.meta_lic"), |
| 991 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 992 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 993 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 994 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 995 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 996 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 997 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 998 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 999 | }, |
| 1000 | }, |
| 1001 | { |
| 1002 | condition: "restricted", |
| 1003 | name: "apex_trimmed_labelled", |
| 1004 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 1005 | ctx: context{stripPrefix: []string{"testdata/restricted/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1006 | expectedOut: []getMatcher{ |
| 1007 | matchTarget("bin/bin1.meta_lic", "notice"), |
| 1008 | matchTarget("bin/bin2.meta_lic", "notice"), |
| 1009 | matchTarget("highest.apex.meta_lic", "notice"), |
Bob Badour | 103eb0f | 2022-01-10 13:50:57 -0800 | [diff] [blame] | 1010 | matchTarget("lib/liba.so.meta_lic", "restricted_allows_dynamic_linking"), |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1011 | matchTarget("lib/libb.so.meta_lic", "restricted"), |
| 1012 | matchTarget("lib/libc.a.meta_lic", "reciprocal"), |
| 1013 | matchTarget("lib/libd.so.meta_lic", "notice"), |
| 1014 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 1015 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 1016 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 1017 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 1018 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 1019 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 1020 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 1021 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 1022 | }, |
| 1023 | }, |
| 1024 | { |
| 1025 | condition: "restricted", |
| 1026 | name: "container", |
| 1027 | roots: []string{"container.zip.meta_lic"}, |
| 1028 | expectedOut: []getMatcher{ |
| 1029 | matchTarget("testdata/restricted/bin/bin1.meta_lic"), |
| 1030 | matchTarget("testdata/restricted/bin/bin2.meta_lic"), |
| 1031 | matchTarget("testdata/restricted/container.zip.meta_lic"), |
| 1032 | matchTarget("testdata/restricted/lib/liba.so.meta_lic"), |
| 1033 | matchTarget("testdata/restricted/lib/libb.so.meta_lic"), |
| 1034 | matchTarget("testdata/restricted/lib/libc.a.meta_lic"), |
| 1035 | matchTarget("testdata/restricted/lib/libd.so.meta_lic"), |
| 1036 | matchEdge("testdata/restricted/bin/bin1.meta_lic", "testdata/restricted/lib/liba.so.meta_lic", "static"), |
| 1037 | matchEdge("testdata/restricted/bin/bin1.meta_lic", "testdata/restricted/lib/libc.a.meta_lic", "static"), |
| 1038 | matchEdge("testdata/restricted/bin/bin2.meta_lic", "testdata/restricted/lib/libb.so.meta_lic", "dynamic"), |
| 1039 | matchEdge("testdata/restricted/bin/bin2.meta_lic", "testdata/restricted/lib/libd.so.meta_lic", "dynamic"), |
| 1040 | matchEdge("testdata/restricted/container.zip.meta_lic", "testdata/restricted/bin/bin1.meta_lic", "static"), |
| 1041 | matchEdge("testdata/restricted/container.zip.meta_lic", "testdata/restricted/bin/bin2.meta_lic", "static"), |
| 1042 | matchEdge("testdata/restricted/container.zip.meta_lic", "testdata/restricted/lib/liba.so.meta_lic", "static"), |
| 1043 | matchEdge("testdata/restricted/container.zip.meta_lic", "testdata/restricted/lib/libb.so.meta_lic", "static"), |
| 1044 | }, |
| 1045 | }, |
| 1046 | { |
| 1047 | condition: "restricted", |
| 1048 | name: "application", |
| 1049 | roots: []string{"application.meta_lic"}, |
| 1050 | expectedOut: []getMatcher{ |
| 1051 | matchTarget("testdata/restricted/application.meta_lic"), |
| 1052 | matchTarget("testdata/restricted/bin/bin3.meta_lic"), |
| 1053 | matchTarget("testdata/restricted/lib/liba.so.meta_lic"), |
| 1054 | matchTarget("testdata/restricted/lib/libb.so.meta_lic"), |
| 1055 | matchEdge("testdata/restricted/application.meta_lic", "testdata/restricted/bin/bin3.meta_lic", "toolchain"), |
| 1056 | matchEdge("testdata/restricted/application.meta_lic", "testdata/restricted/lib/liba.so.meta_lic", "static"), |
| 1057 | matchEdge("testdata/restricted/application.meta_lic", "testdata/restricted/lib/libb.so.meta_lic", "dynamic"), |
| 1058 | }, |
| 1059 | }, |
| 1060 | { |
| 1061 | condition: "restricted", |
| 1062 | name: "binary", |
| 1063 | roots: []string{"bin/bin1.meta_lic"}, |
| 1064 | expectedOut: []getMatcher{ |
| 1065 | matchTarget("testdata/restricted/bin/bin1.meta_lic"), |
| 1066 | matchTarget("testdata/restricted/lib/liba.so.meta_lic"), |
| 1067 | matchTarget("testdata/restricted/lib/libc.a.meta_lic"), |
| 1068 | matchEdge("testdata/restricted/bin/bin1.meta_lic", "testdata/restricted/lib/liba.so.meta_lic", "static"), |
| 1069 | matchEdge("testdata/restricted/bin/bin1.meta_lic", "testdata/restricted/lib/libc.a.meta_lic", "static"), |
| 1070 | }, |
| 1071 | }, |
| 1072 | { |
| 1073 | condition: "restricted", |
| 1074 | name: "library", |
| 1075 | roots: []string{"lib/libd.so.meta_lic"}, |
| 1076 | expectedOut: []getMatcher{matchTarget("testdata/restricted/lib/libd.so.meta_lic")}, |
| 1077 | }, |
| 1078 | { |
| 1079 | condition: "proprietary", |
| 1080 | name: "apex", |
| 1081 | roots: []string{"highest.apex.meta_lic"}, |
| 1082 | expectedOut: []getMatcher{ |
| 1083 | matchTarget("testdata/proprietary/bin/bin1.meta_lic"), |
| 1084 | matchTarget("testdata/proprietary/bin/bin2.meta_lic"), |
| 1085 | matchTarget("testdata/proprietary/highest.apex.meta_lic"), |
| 1086 | matchTarget("testdata/proprietary/lib/liba.so.meta_lic"), |
| 1087 | matchTarget("testdata/proprietary/lib/libb.so.meta_lic"), |
| 1088 | matchTarget("testdata/proprietary/lib/libc.a.meta_lic"), |
| 1089 | matchTarget("testdata/proprietary/lib/libd.so.meta_lic"), |
| 1090 | matchEdge("testdata/proprietary/bin/bin1.meta_lic", "testdata/proprietary/lib/liba.so.meta_lic", "static"), |
| 1091 | matchEdge("testdata/proprietary/bin/bin1.meta_lic", "testdata/proprietary/lib/libc.a.meta_lic", "static"), |
| 1092 | matchEdge("testdata/proprietary/bin/bin2.meta_lic", "testdata/proprietary/lib/libb.so.meta_lic", "dynamic"), |
| 1093 | matchEdge("testdata/proprietary/bin/bin2.meta_lic", "testdata/proprietary/lib/libd.so.meta_lic", "dynamic"), |
| 1094 | matchEdge("testdata/proprietary/highest.apex.meta_lic", "testdata/proprietary/bin/bin1.meta_lic", "static"), |
| 1095 | matchEdge("testdata/proprietary/highest.apex.meta_lic", "testdata/proprietary/bin/bin2.meta_lic", "static"), |
| 1096 | matchEdge("testdata/proprietary/highest.apex.meta_lic", "testdata/proprietary/lib/liba.so.meta_lic", "static"), |
| 1097 | matchEdge("testdata/proprietary/highest.apex.meta_lic", "testdata/proprietary/lib/libb.so.meta_lic", "static"), |
| 1098 | }, |
| 1099 | }, |
| 1100 | { |
| 1101 | condition: "proprietary", |
| 1102 | name: "apex_trimmed", |
| 1103 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 1104 | ctx: context{stripPrefix: []string{"testdata/proprietary/"}}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1105 | expectedOut: []getMatcher{ |
| 1106 | matchTarget("bin/bin1.meta_lic"), |
| 1107 | matchTarget("bin/bin2.meta_lic"), |
| 1108 | matchTarget("highest.apex.meta_lic"), |
| 1109 | matchTarget("lib/liba.so.meta_lic"), |
| 1110 | matchTarget("lib/libb.so.meta_lic"), |
| 1111 | matchTarget("lib/libc.a.meta_lic"), |
| 1112 | matchTarget("lib/libd.so.meta_lic"), |
| 1113 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 1114 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 1115 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 1116 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 1117 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 1118 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 1119 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 1120 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 1121 | }, |
| 1122 | }, |
| 1123 | { |
| 1124 | condition: "proprietary", |
| 1125 | name: "apex_trimmed_labelled", |
| 1126 | roots: []string{"highest.apex.meta_lic"}, |
Bob Badour | 682e1ba | 2022-02-02 15:15:56 -0800 | [diff] [blame^] | 1127 | ctx: context{stripPrefix: []string{"testdata/proprietary/"}, labelConditions: true}, |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1128 | expectedOut: []getMatcher{ |
| 1129 | matchTarget("bin/bin1.meta_lic", "notice"), |
| 1130 | matchTarget("bin/bin2.meta_lic", "by_exception_only", "proprietary"), |
| 1131 | matchTarget("highest.apex.meta_lic", "notice"), |
| 1132 | matchTarget("lib/liba.so.meta_lic", "by_exception_only", "proprietary"), |
| 1133 | matchTarget("lib/libb.so.meta_lic", "restricted"), |
| 1134 | matchTarget("lib/libc.a.meta_lic", "by_exception_only", "proprietary"), |
| 1135 | matchTarget("lib/libd.so.meta_lic", "notice"), |
| 1136 | matchEdge("bin/bin1.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 1137 | matchEdge("bin/bin1.meta_lic", "lib/libc.a.meta_lic", "static"), |
| 1138 | matchEdge("bin/bin2.meta_lic", "lib/libb.so.meta_lic", "dynamic"), |
| 1139 | matchEdge("bin/bin2.meta_lic", "lib/libd.so.meta_lic", "dynamic"), |
| 1140 | matchEdge("highest.apex.meta_lic", "bin/bin1.meta_lic", "static"), |
| 1141 | matchEdge("highest.apex.meta_lic", "bin/bin2.meta_lic", "static"), |
| 1142 | matchEdge("highest.apex.meta_lic", "lib/liba.so.meta_lic", "static"), |
| 1143 | matchEdge("highest.apex.meta_lic", "lib/libb.so.meta_lic", "static"), |
| 1144 | }, |
| 1145 | }, |
| 1146 | { |
| 1147 | condition: "proprietary", |
| 1148 | name: "container", |
| 1149 | roots: []string{"container.zip.meta_lic"}, |
| 1150 | expectedOut: []getMatcher{ |
| 1151 | matchTarget("testdata/proprietary/bin/bin1.meta_lic"), |
| 1152 | matchTarget("testdata/proprietary/bin/bin2.meta_lic"), |
| 1153 | matchTarget("testdata/proprietary/container.zip.meta_lic"), |
| 1154 | matchTarget("testdata/proprietary/lib/liba.so.meta_lic"), |
| 1155 | matchTarget("testdata/proprietary/lib/libb.so.meta_lic"), |
| 1156 | matchTarget("testdata/proprietary/lib/libc.a.meta_lic"), |
| 1157 | matchTarget("testdata/proprietary/lib/libd.so.meta_lic"), |
| 1158 | matchEdge("testdata/proprietary/bin/bin1.meta_lic", "testdata/proprietary/lib/liba.so.meta_lic", "static"), |
| 1159 | matchEdge("testdata/proprietary/bin/bin1.meta_lic", "testdata/proprietary/lib/libc.a.meta_lic", "static"), |
| 1160 | matchEdge("testdata/proprietary/bin/bin2.meta_lic", "testdata/proprietary/lib/libb.so.meta_lic", "dynamic"), |
| 1161 | matchEdge("testdata/proprietary/bin/bin2.meta_lic", "testdata/proprietary/lib/libd.so.meta_lic", "dynamic"), |
| 1162 | matchEdge("testdata/proprietary/container.zip.meta_lic", "testdata/proprietary/bin/bin1.meta_lic", "static"), |
| 1163 | matchEdge("testdata/proprietary/container.zip.meta_lic", "testdata/proprietary/bin/bin2.meta_lic", "static"), |
| 1164 | matchEdge("testdata/proprietary/container.zip.meta_lic", "testdata/proprietary/lib/liba.so.meta_lic", "static"), |
| 1165 | matchEdge("testdata/proprietary/container.zip.meta_lic", "testdata/proprietary/lib/libb.so.meta_lic", "static"), |
| 1166 | }, |
| 1167 | }, |
| 1168 | { |
| 1169 | condition: "proprietary", |
| 1170 | name: "application", |
| 1171 | roots: []string{"application.meta_lic"}, |
| 1172 | expectedOut: []getMatcher{ |
| 1173 | matchTarget("testdata/proprietary/application.meta_lic"), |
| 1174 | matchTarget("testdata/proprietary/bin/bin3.meta_lic"), |
| 1175 | matchTarget("testdata/proprietary/lib/liba.so.meta_lic"), |
| 1176 | matchTarget("testdata/proprietary/lib/libb.so.meta_lic"), |
| 1177 | matchEdge("testdata/proprietary/application.meta_lic", "testdata/proprietary/bin/bin3.meta_lic", "toolchain"), |
| 1178 | matchEdge("testdata/proprietary/application.meta_lic", "testdata/proprietary/lib/liba.so.meta_lic", "static"), |
| 1179 | matchEdge("testdata/proprietary/application.meta_lic", "testdata/proprietary/lib/libb.so.meta_lic", "dynamic"), |
| 1180 | }, |
| 1181 | }, |
| 1182 | { |
| 1183 | condition: "proprietary", |
| 1184 | name: "binary", |
| 1185 | roots: []string{"bin/bin1.meta_lic"}, |
| 1186 | expectedOut: []getMatcher{ |
| 1187 | matchTarget("testdata/proprietary/bin/bin1.meta_lic"), |
| 1188 | matchTarget("testdata/proprietary/lib/liba.so.meta_lic"), |
| 1189 | matchTarget("testdata/proprietary/lib/libc.a.meta_lic"), |
| 1190 | matchEdge("testdata/proprietary/bin/bin1.meta_lic", "testdata/proprietary/lib/liba.so.meta_lic", "static"), |
| 1191 | matchEdge("testdata/proprietary/bin/bin1.meta_lic", "testdata/proprietary/lib/libc.a.meta_lic", "static"), |
| 1192 | }, |
| 1193 | }, |
| 1194 | { |
| 1195 | condition: "proprietary", |
| 1196 | name: "library", |
| 1197 | roots: []string{"lib/libd.so.meta_lic"}, |
| 1198 | expectedOut: []getMatcher{matchTarget("testdata/proprietary/lib/libd.so.meta_lic")}, |
| 1199 | }, |
| 1200 | } |
| 1201 | for _, tt := range tests { |
| 1202 | t.Run(tt.condition+" "+tt.name, func(t *testing.T) { |
| 1203 | ctx := &testContext{0, make(map[string]string)} |
| 1204 | |
| 1205 | expectedOut := &bytes.Buffer{} |
| 1206 | for _, eo := range tt.expectedOut { |
| 1207 | m := eo(ctx) |
| 1208 | expectedOut.WriteString(m.matchString(ctx)) |
| 1209 | expectedOut.WriteString("\n") |
| 1210 | } |
| 1211 | |
| 1212 | stdout := &bytes.Buffer{} |
| 1213 | stderr := &bytes.Buffer{} |
| 1214 | |
| 1215 | rootFiles := make([]string, 0, len(tt.roots)) |
| 1216 | for _, r := range tt.roots { |
| 1217 | rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r) |
| 1218 | } |
| 1219 | tt.ctx.graphViz = true |
| 1220 | err := dumpGraph(&tt.ctx, stdout, stderr, rootFiles...) |
| 1221 | if err != nil { |
| 1222 | t.Fatalf("dumpgraph: error = %v, stderr = %v", err, stderr) |
| 1223 | return |
| 1224 | } |
| 1225 | if stderr.Len() > 0 { |
| 1226 | t.Errorf("dumpgraph: gotStderr = %v, want none", stderr) |
| 1227 | } |
| 1228 | outList := strings.Split(stdout.String(), "\n") |
| 1229 | outLine := 0 |
| 1230 | if outList[outLine] != "strict digraph {" { |
Colin Cross | 179ec3e | 2022-01-27 15:47:09 -0800 | [diff] [blame] | 1231 | t.Errorf("dumpgraph: got 1st line %v, want strict digraph {", outList[outLine]) |
Bob Badour | fa739da | 2021-10-25 16:21:00 -0700 | [diff] [blame] | 1232 | } |
| 1233 | outLine++ |
| 1234 | if strings.HasPrefix(strings.TrimLeft(outList[outLine], " \t"), "rankdir") { |
| 1235 | outLine++ |
| 1236 | } |
| 1237 | endOut := len(outList) |
| 1238 | for endOut > 0 && strings.TrimLeft(outList[endOut-1], " \t") == "" { |
| 1239 | endOut-- |
| 1240 | } |
| 1241 | if outList[endOut-1] != "}" { |
| 1242 | t.Errorf("dumpgraph: got last line %v, want }", outList[endOut-1]) |
| 1243 | } |
| 1244 | endOut-- |
| 1245 | if strings.HasPrefix(strings.TrimLeft(outList[endOut-1], " \t"), "{rank=same") { |
| 1246 | endOut-- |
| 1247 | } |
| 1248 | expectedList := strings.Split(expectedOut.String(), "\n") |
| 1249 | for len(expectedList) > 0 && expectedList[len(expectedList)-1] == "" { |
| 1250 | expectedList = expectedList[0 : len(expectedList)-1] |
| 1251 | } |
| 1252 | matchLine := 0 |
| 1253 | |
| 1254 | for outLine < endOut && matchLine < len(expectedList) && strings.TrimLeft(outList[outLine], " \t") == expectedList[matchLine] { |
| 1255 | outLine++ |
| 1256 | matchLine++ |
| 1257 | } |
| 1258 | if outLine < endOut || matchLine < len(expectedList) { |
| 1259 | if outLine >= endOut { |
| 1260 | t.Errorf("dumpgraph: missing lines at end of graph, want %d lines %v", len(expectedList)-matchLine, strings.Join(expectedList[matchLine:], "\n")) |
| 1261 | } else if matchLine >= len(expectedList) { |
| 1262 | t.Errorf("dumpgraph: unexpected lines at end of graph starting line %d, got %v, want nothing", outLine+1, strings.Join(outList[outLine:], "\n")) |
| 1263 | } else { |
| 1264 | t.Errorf("dumpgraph: at line %d, got %v, want %v", outLine+1, strings.Join(outList[outLine:], "\n"), strings.Join(expectedList[matchLine:], "\n")) |
| 1265 | } |
| 1266 | } |
| 1267 | }) |
| 1268 | } |
| 1269 | } |