api: crchcecker ignore version < 1.0.0 and outside of src directory
[vpp.git] / extras / scripts / tests / test_crcchecker.sh
1 #!/bin/sh
2 set -eux
3
4 TMPDIR=$(mktemp -d /tmp/vpp-crccheck-test-XXXXX)
5
6 CURR_ROOT=$(git rev-parse --show-toplevel)
7 CURR_DIR=$(pwd)
8
9 verify_check_patchset_fails() {
10         if (extras/scripts/crcchecker.py --check-patchset); then
11                 echo "ERROR - check succeeded, it should have failed!"
12                 exit 1;
13         fi
14 }
15
16 finish() {
17         if [ -e "$TMPDIR" ]; then
18                 echo "Temporary directory is: $TMPDIR"
19         fi
20 }
21 trap finish EXIT
22
23
24 # make a copy of the current repo that we can play with
25 cd ${TMPDIR}
26 mkdir misc-files
27 git clone ${CURR_ROOT} vpp-uut
28 cd vpp-uut
29
30 # maybe grab the CRC checker
31 # git fetch "https://gerrit.fd.io/r/vpp" refs/changes/81/26881/14 && git cherry-pick FETCH_HEAD || echo "Already there"
32
33
34 echo "TEST 1: Check the current patchset..."
35 extras/scripts/crcchecker.py --check-patchset
36
37 echo "TEST 2: Dumping the current manifest..."
38 extras/scripts/crcchecker.py --dump-manifest >${TMPDIR}/misc-files/manifest.txt
39
40 echo "TEST 3: Checking the 20.01 version of acl.api...."
41 extras/scripts/crcchecker.py --git-revision v20.01 src/plugins/acl/acl.api
42
43 echo "TEST 4: Add a new field into a message in acl.api, and check patchset - must fail..."
44 sed -i -e 's#vpe_pid;#vpe_pid; u32 sneaky_new_field;#' src/plugins/acl/acl.api
45 verify_check_patchset_fails
46
47 echo "TEST 5: Rename the changed acl.api file and not add it to git... must fail (due to deletion of the APIs)..."
48 mv src/plugins/acl/acl.api src/plugins/acl/acl_new.api
49 verify_check_patchset_fails
50
51 echo "TEST 6: Add the renamed file to git commit... must fail (due to addition of the fields)..."
52 git add src/plugins/acl/acl_new.api
53 git commit -m "added acl_new.api"
54 verify_check_patchset_fails
55
56 echo "TEST 7: Verify we can delete deprecated message"
57 git commit -a -m "reset"
58 cat >src/crccheck.api <<EOL
59 option version="1.0.0";
60 autoreply define crccheck
61 {
62   option deprecated;
63   bool foo;
64 };
65 EOL
66 git add src/crccheck.api
67 git commit -m "deprecated api";
68 # delete API
69 cat >src/crccheck.api <<EOL
70 option version="1.0.0";
71 autoreply define crccheck_2
72 {
73   bool foo;
74 };
75 EOL
76 git add src/crccheck.api
77 git commit -m "deprecated api";
78 extras/scripts/crcchecker.py --check-patchset
79
80 echo "TEST 7.1: Verify we can delete deprecated message (old/confused style)"
81 cat >src/crccheck_dep.api <<EOL
82 option version="1.0.0";
83 autoreply define crccheck
84 {
85   option status="deprecated";
86   bool foo;
87 };
88 EOL
89 git add src/crccheck_dep.api
90 git commit -m "deprecated api";
91 # delete API
92 cat >src/crccheck_dep.api <<EOL
93 option version="1.0.0";
94 autoreply define crccheck_2
95 {
96   bool foo;
97 };
98 EOL
99 git add src/crccheck_dep.api
100 git commit -m "deprecated api";
101 extras/scripts/crcchecker.py --check-patchset
102
103 echo "TEST 8: Verify that we can not rename a non-deprecated message"
104 sed -i -e 's/crccheck_2/crccheck_3/g' src/crccheck.api
105 git add src/crccheck.api
106 git commit -m "renamed api";
107 verify_check_patchset_fails
108 # fix it.
109 sed -i -e 's/crccheck_3/crccheck_2/g' src/crccheck.api
110 git commit -a --amend -m "empty commit after we renamed api back" --allow-empty
111
112 echo "TEST 9: Verify that the check fails if the changes are not committed"
113 cat >>src/crccheck.api <<EOL
114 autoreply define crc_new_check_in_progress
115 {
116   option status="in_progress";
117   bool foobar;
118 };
119 EOL
120 verify_check_patchset_fails
121
122 echo "TEST10: Verify that the in-progress message can be added"
123 git add src/crccheck.api
124 git commit -m "added a new in-progress api";
125 extras/scripts/crcchecker.py --check-patchset
126
127 echo "TEST11: Verify we can rename an in-progress API"
128 sed -i -e 's/crc_new_check_in_progress/crc_new_check_in_progress_2/g' src/crccheck.api
129 git add src/crccheck.api
130 git commit -m "renamed in-progress api";
131 extras/scripts/crcchecker.py --check-patchset
132
133 echo "TEST11.1: Switch to new designation of in-progress API"
134 sed -i -e 's/status="in_progress"/in_progress/g' src/crccheck.api
135 git add src/crccheck.api
136 git commit -m "new designation of in-progress api";
137 extras/scripts/crcchecker.py --check-patchset
138
139
140 echo "TEST12: Verify we can add a field to an in-progress API"
141 sed -i -e 's/foobar;/foobar; bool new_baz;/g' src/crccheck.api
142 git add src/crccheck.api
143 git commit -m "new field added in in-progress api";
144 extras/scripts/crcchecker.py --check-patchset
145
146 echo "TEST13: Verify we fail the check if the file can not be compiled"
147 cat >src/crccheck2.api <<EOL
148 option version="0.0.1";
149 autoreply define spot_the_error
150 {
151   option status="in_progress"
152   bool something_important;
153 };
154 EOL
155 git add src/crccheck2.api
156 git commit -m "a new message with a syntax error";
157 verify_check_patchset_fails
158
159 # get rid of the "erroneous" commit in the previous test
160 git reset --hard HEAD~1
161
162 echo "TEST14: Verify we handle new .api file"
163 cat >src/crccheck3.api <<EOL
164 autoreply define foo
165 {
166   bool bar;
167 };
168 EOL
169 git add src/crccheck3.api
170 git commit -m "a new message in new file";
171 extras/scripts/crcchecker.py --check-patchset
172
173 echo "TEST: All tests got the expected result, cleaning up."
174
175 # done with all the tests - clean up
176 cd ${CURR_DIR}
177
178 # beware of empty variables, careful with deletion
179 rm -rf ${TMPDIR}/vpp-uut
180 rm -rf ${TMPDIR}/misc-files
181 rmdir ${TMPDIR}