blob: 4caffe28e0d76a153b1db3f658d90bfd7e1ea924 [file] [log] [blame]
Ole Troan5c318c72020-05-05 12:23:47 +02001#!/bin/sh
2set -eux
3
4TMPDIR=$(mktemp -d /tmp/vpp-crccheck-test-XXXXX)
5
6CURR_ROOT=$(git rev-parse --show-toplevel)
7CURR_DIR=$(pwd)
8
9verify_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
16finish() {
17 if [ -e "$TMPDIR" ]; then
18 echo "Temporary directory is: $TMPDIR"
19 fi
20}
21trap finish EXIT
22
23
24# make a copy of the current repo that we can play with
25cd ${TMPDIR}
26mkdir misc-files
27git clone ${CURR_ROOT} vpp-uut
28cd 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
34echo "TEST 1: Check the current patchset..."
35extras/scripts/crcchecker.py --check-patchset
36
37echo "TEST 2: Dumping the current manifest..."
38extras/scripts/crcchecker.py --dump-manifest >${TMPDIR}/misc-files/manifest.txt
39
40echo "TEST 3: Checking the 20.01 version of acl.api...."
41extras/scripts/crcchecker.py --git-revision v20.01 src/plugins/acl/acl.api
42
43echo "TEST 4: Add a new field into a message in acl.api, and check patchset - must fail..."
44sed -i -e 's#vpe_pid;#vpe_pid; u32 sneaky_new_field;#' src/plugins/acl/acl.api
45verify_check_patchset_fails
46
47echo "TEST 5: Rename the changed acl.api file and not add it to git... must fail (due to deletion of the APIs)..."
48mv src/plugins/acl/acl.api src/plugins/acl/acl_new.api
49verify_check_patchset_fails
50
51echo "TEST 6: Add the renamed file to git commit... must fail (due to addition of the fields)..."
52git add src/plugins/acl/acl_new.api
53git commit -m "added acl_new.api"
54verify_check_patchset_fails
55
56echo "TEST 7: Verify we can delete deprecated message"
57git commit -a -m "reset"
Ole Troanab9f5732020-12-15 10:19:25 +010058cat >src/crccheck.api <<EOL
Ole Troan5c318c72020-05-05 12:23:47 +020059option version="1.0.0";
60autoreply define crccheck
61{
Ole Troan68ebcd52020-08-10 17:06:44 +020062 option deprecated;
Ole Troan5c318c72020-05-05 12:23:47 +020063 bool foo;
64};
65EOL
Ole Troanab9f5732020-12-15 10:19:25 +010066git add src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +020067git commit -m "deprecated api";
68# delete API
Ole Troanab9f5732020-12-15 10:19:25 +010069cat >src/crccheck.api <<EOL
Ole Troan5c318c72020-05-05 12:23:47 +020070option version="1.0.0";
71autoreply define crccheck_2
72{
73 bool foo;
74};
75EOL
Ole Troanab9f5732020-12-15 10:19:25 +010076git add src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +020077git commit -m "deprecated api";
78extras/scripts/crcchecker.py --check-patchset
79
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +000080echo "TEST 7.1: Verify we can delete deprecated message (old/confused style)"
Ole Troanab9f5732020-12-15 10:19:25 +010081cat >src/crccheck_dep.api <<EOL
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +000082option version="1.0.0";
83autoreply define crccheck
84{
85 option status="deprecated";
86 bool foo;
87};
88EOL
Ole Troanab9f5732020-12-15 10:19:25 +010089git add src/crccheck_dep.api
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +000090git commit -m "deprecated api";
91# delete API
Ole Troanab9f5732020-12-15 10:19:25 +010092cat >src/crccheck_dep.api <<EOL
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +000093option version="1.0.0";
94autoreply define crccheck_2
95{
96 bool foo;
97};
98EOL
Ole Troanab9f5732020-12-15 10:19:25 +010099git add src/crccheck_dep.api
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +0000100git commit -m "deprecated api";
101extras/scripts/crcchecker.py --check-patchset
102
Ole Troan5c318c72020-05-05 12:23:47 +0200103echo "TEST 8: Verify that we can not rename a non-deprecated message"
Ole Troanab9f5732020-12-15 10:19:25 +0100104sed -i -e 's/crccheck_2/crccheck_3/g' src/crccheck.api
105git add src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +0200106git commit -m "renamed api";
107verify_check_patchset_fails
108# fix it.
Ole Troanab9f5732020-12-15 10:19:25 +0100109sed -i -e 's/crccheck_3/crccheck_2/g' src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +0200110git commit -a --amend -m "empty commit after we renamed api back" --allow-empty
111
112echo "TEST 9: Verify that the check fails if the changes are not committed"
Ole Troanab9f5732020-12-15 10:19:25 +0100113cat >>src/crccheck.api <<EOL
Ole Troan5c318c72020-05-05 12:23:47 +0200114autoreply define crc_new_check_in_progress
115{
116 option status="in_progress";
117 bool foobar;
118};
119EOL
120verify_check_patchset_fails
121
122echo "TEST10: Verify that the in-progress message can be added"
Ole Troanab9f5732020-12-15 10:19:25 +0100123git add src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +0200124git commit -m "added a new in-progress api";
125extras/scripts/crcchecker.py --check-patchset
126
127echo "TEST11: Verify we can rename an in-progress API"
Ole Troanab9f5732020-12-15 10:19:25 +0100128sed -i -e 's/crc_new_check_in_progress/crc_new_check_in_progress_2/g' src/crccheck.api
129git add src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +0200130git commit -m "renamed in-progress api";
131extras/scripts/crcchecker.py --check-patchset
132
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +0000133echo "TEST11.1: Switch to new designation of in-progress API"
Ole Troanab9f5732020-12-15 10:19:25 +0100134sed -i -e 's/status="in_progress"/in_progress/g' src/crccheck.api
135git add src/crccheck.api
Andrew Yourtchenko6a3d4cc2020-09-22 15:11:51 +0000136git commit -m "new designation of in-progress api";
137extras/scripts/crcchecker.py --check-patchset
138
139
Ole Troan5c318c72020-05-05 12:23:47 +0200140echo "TEST12: Verify we can add a field to an in-progress API"
Ole Troanab9f5732020-12-15 10:19:25 +0100141sed -i -e 's/foobar;/foobar; bool new_baz;/g' src/crccheck.api
142git add src/crccheck.api
Ole Troan5c318c72020-05-05 12:23:47 +0200143git commit -m "new field added in in-progress api";
144extras/scripts/crcchecker.py --check-patchset
145
146echo "TEST13: Verify we fail the check if the file can not be compiled"
Ole Troanab9f5732020-12-15 10:19:25 +0100147cat >src/crccheck2.api <<EOL
Ole Troan5c318c72020-05-05 12:23:47 +0200148option version="0.0.1";
149autoreply define spot_the_error
150{
151 option status="in_progress"
152 bool something_important;
153};
154EOL
Ole Troanab9f5732020-12-15 10:19:25 +0100155git add src/crccheck2.api
Ole Troan5c318c72020-05-05 12:23:47 +0200156git commit -m "a new message with a syntax error";
157verify_check_patchset_fails
158
159# get rid of the "erroneous" commit in the previous test
160git reset --hard HEAD~1
161
Ole Troandeecc932020-05-19 12:33:00 +0200162echo "TEST14: Verify we handle new .api file"
Ole Troanab9f5732020-12-15 10:19:25 +0100163cat >src/crccheck3.api <<EOL
Ole Troandeecc932020-05-19 12:33:00 +0200164autoreply define foo
165{
166 bool bar;
167};
168EOL
Ole Troanab9f5732020-12-15 10:19:25 +0100169git add src/crccheck3.api
Ole Troandeecc932020-05-19 12:33:00 +0200170git commit -m "a new message in new file";
171extras/scripts/crcchecker.py --check-patchset
172
Ole Troan5c318c72020-05-05 12:23:47 +0200173echo "TEST: All tests got the expected result, cleaning up."
174
175# done with all the tests - clean up
176cd ${CURR_DIR}
177
178# beware of empty variables, careful with deletion
179rm -rf ${TMPDIR}/vpp-uut
180rm -rf ${TMPDIR}/misc-files
181rmdir ${TMPDIR}