1#!/bin/bash
2
3# Run hidl-gen against interfaces in errors/ to ensure it detects as many
4# errors as possible.
5
6if [ ! -d system/tools/hidl/test/errors/ ]; then
7    echo "Where is system/tools/hidl/test/errors?";
8    exit 1;
9fi
10
11# TODO(b/33276472)
12if [ ! -d system/libhidl/transport ]; then
13    echo "Where is system/libhidl/transport?";
14    exit 1;
15fi
16
17if [[ "$@" == *"-h"* ]]; then
18    echo "$0 [-h|-u|-a]"
19    echo "    (No options)  Run and diff against expected output"
20    echo "    -u            Update expected output"
21    echo "    -a            Run and show actual output"
22    echo "    -h            Show help text"
23    exit 1
24fi
25
26if [[ "$@" == *"-u"* ]]; then update_files=true; fi
27if [[ "$@" == *"-a"* ]]; then show_output=true; fi
28
29function check() {
30    local "${@}"
31    COMMAND="hidl-gen -Lc++ -rtests:system/tools/hidl/test -randroid.hidl:system/libhidl/transport -o /tmp $package"
32
33    if [ $show_output ]; then
34        echo "Running: $COMMAND"
35        $COMMAND
36        echo
37        return
38    fi
39
40    if [[ ! -z "$contains" ]]; then
41        if [ $update_files ]; then
42            # no files to update
43            return
44        fi
45        $COMMAND 2>&1 | grep "$contains" -q
46        if [ $? -eq 0 ]; then
47            echo "Success for $package."
48        else
49            echo "Fail for $package; output doesn't contain '$contains'"
50        fi
51        return
52    fi
53
54    EXPECTED="system/tools/hidl/test/$filename"
55    if [ $update_files ]; then
56        $COMMAND 2>$EXPECTED;
57        echo "Updated $filename."
58    else
59        $COMMAND 2>&1 | diff $EXPECTED -
60        if [ $? -eq 0 ]; then
61            echo "Success for $package."
62        fi
63    fi
64}
65
66check package="tests.errors.syntax@1.0" filename="errors/syntax.output"
67
68check package="tests.errors.versioning@2.2" \
69    contains="Cannot enforce minor version uprevs for tests.errors.versioning@2.2"
70
71check package="tests.errors.versioning@3.3" \
72    contains="Cannot enforce minor version uprevs for tests.errors.versioning@3.3"
73