Anton Hansson | c02eb52 | 2020-12-30 11:33:31 +0000 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | # |
| 3 | # Copyright (C) 2021 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Anton Hansson | 2848c68 | 2021-03-08 12:54:32 +0000 | [diff] [blame] | 17 | # To access gen_sdk |
| 18 | PATH=.:$PATH |
| 19 | |
Anton Hansson | c02eb52 | 2020-12-30 11:33:31 +0000 | [diff] [blame] | 20 | # Verifies the tool correctly prints the binary representation of a db. |
| 21 | function test_print_binary() { |
| 22 | # Golden binary rep generated with: |
| 23 | # $ gqui from textproto:testdata/test_extensions_db.textpb \ |
| 24 | # proto extensions_db.proto:ExtensionDatabase \ |
| 25 | # --outfile rawproto:- | xxd -p |
| 26 | cat > golden_binary << EOF |
| 27 | 0a0a080112060803120208010a1a08021206080312020801120608021202 |
| 28 | 080212060801120208020a1a080312060803120208031206080212020802 |
| 29 | 12060801120208020a220804120608031202080312060802120208021206 |
| 30 | 0801120208041206080512020804 |
| 31 | EOF |
| 32 | |
| 33 | diff golden_binary <(gen_sdk --action print_binary --database testdata/test_extensions_db.textpb | xxd -p) |
| 34 | } |
| 35 | test_print_binary |
Anton Hansson | c6328fe | 2020-12-30 11:33:31 +0000 | [diff] [blame] | 36 | |
| 37 | # Verifies the tool is able to re-create the test DB correctly. |
| 38 | function test_new_sdk() { |
| 39 | rm -f extensions_db.textpb && touch extensions_db.textpb |
| 40 | gen_sdk --action new_sdk --sdk 1 --modules MEDIA_PROVIDER |
| 41 | gen_sdk --action new_sdk --sdk 2 --modules MEDIA,IPSEC |
| 42 | gen_sdk --action new_sdk --sdk 3 --modules MEDIA_PROVIDER |
| 43 | gen_sdk --action new_sdk --sdk 4 --modules SDK_EXTENSIONS,IPSEC |
| 44 | |
| 45 | diff -u0 testdata/test_extensions_db.textpb extensions_db.textpb |
| 46 | } |
| 47 | test_new_sdk |
Anton Hansson | e810652 | 2020-12-30 11:33:31 +0000 | [diff] [blame] | 48 | |
| 49 | # Verifies the tool won't allow bogus SDK updates |
| 50 | function test_validate() { |
| 51 | set +e |
| 52 | |
| 53 | rm -f extensions_db.textpb && echo bogus > extensions_db.textpb |
| 54 | if gen_sdk --action validate; then |
| 55 | echo "expected validate to fail on bogus db" |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | rm -f extensions_db.textpb && touch extensions_db.textpb |
| 60 | gen_sdk --action new_sdk --sdk 1 --modules MEDIA_PROVIDER |
| 61 | if gen_sdk --action new_sdk --sdk 1 --modules SDK_EXTENSIONS; then |
| 62 | echo "FAILED: expected duplicate sdk numbers to fail" |
| 63 | echo "DB:" |
| 64 | cat extensions_db.textpb |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | if gen_sdk --action validate --database testdata/dupe_req.textpb; then |
| 69 | echo "FAILED: expected duplicate module in one sdk level to fail" |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
| 73 | if gen_sdk --action validate --database testdata/backward_req.textpb; then |
| 74 | echo "FAILED: expect version requirement going backward to fail" |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
| 78 | set -e |
| 79 | } |
| 80 | test_validate |
| 81 | |
| 82 | function test_checked_in_db() { |
| 83 | gen_sdk --action validate --database extensions_db.textpb |
| 84 | } |
| 85 | test_checked_in_db |