Skip to content

Commit 6f92dc2

Browse files
jmarantzhtuch
authored andcommitted
tools: check_format_test to run under CI under 'format' (envoyproxy#3516)
check_format_test is (I think) hard to run under bazel because it must run under the docker image to get the right clang, but bazel is hermetic and I don't know what it would take to call docker from bazel. But it can easily run under CI. In fact it's fast enough to just run it in front of check_format.py itself. Having it in CI and available to run manually via tools/check_format_test.sh should be sufficient to keep check_format.py sane, once more tests are added. Risk Level: Low Testing: test/check_format_test.sh --loglevel={0,1,2} and observing CI Docs Changes: N/A Release Notes: N/A Signed-off-by: Joshua Marantz <[email protected]>
1 parent 759eacb commit 6f92dc2

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

ci/do_ci.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ elif [[ "$1" == "fix_format" ]]; then
180180
./tools/check_format.py fix
181181
exit 0
182182
elif [[ "$1" == "check_format" ]]; then
183-
echo "check_format..."
184183
cd "${ENVOY_SRCDIR}"
184+
echo "check_format_test..."
185+
./tools/check_format_test_helper.py --log=WARN
186+
echo "check_format..."
185187
./tools/check_format.py check
186188
exit 0
187189
elif [[ "$1" == "docs" ]]; then

tools/check_format.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,5 @@ def checkFormatVisitor(arg, dir_name, names):
327327
print "ERROR: %s" % e
328328
print "ERROR: check format failed. run 'tools/check_format.py fix'"
329329
sys.exit(1)
330+
if operation_type == "check":
331+
print "PASS"

tools/check_format_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ tools=$(dirname $(realpath $0))
44
root=$(realpath $tools/..)
55
ci=$root/ci
66
cd $root
7-
exec ./ci/run_envoy_docker.sh ./tools/check_format_test_run_under_docker.py
7+
exec ./ci/run_envoy_docker.sh ./tools/check_format_test_helper.py "$@"

tools/check_format_test_run_under_docker.py renamed to tools/check_format_test_helper.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env python
22

3-
# Tests check_format.py. This must be run under docker via
4-
# check_format_test.py, or you are liable to get the wrong clang, and
5-
# all kinds of bad results.
3+
# Tests check_format.py. This must be run in a context where the clang
4+
# version and settings are compatible with the one in the Envoy
5+
# docker. Normally this is run via check_format_test.sh, which
6+
# executes it in under docker.
67

8+
import argparse
79
import os
810
import shutil
11+
import logging
912
import subprocess
1013

1114
def getenvFallback(envvar, fallback):
@@ -33,7 +36,7 @@ def runCommand(command):
3336
status = e.returncode
3437
for line in e.output.splitlines():
3538
stdout.append(line)
36-
print("%s" % command)
39+
logging.info("%s" % command)
3740
return status, stdout
3841

3942
# Runs the 'check_format' operation, on the specified file, printing
@@ -79,19 +82,19 @@ def fixFileExpectingNoChange(file):
7982
return 1
8083
return 0
8184

82-
def emitStdout(stdout):
85+
def emitStdoutAsError(stdout):
8386
for line in stdout:
84-
print(" %s" % line)
87+
logging.error(" %s" % line)
8588

8689
def expectError(status, stdout, expected_substring):
8790
if status == 0:
88-
print("Expected failure, but succeeded")
91+
logging.error("Expected failure, but succeeded")
8992
return 1
9093
for line in stdout:
9194
if expected_substring in line:
9295
return 0
93-
print("Could not find '%s' in:\n" % expected_substring)
94-
emitStdout(stdout)
96+
logging.error("Could not find '%s' in:\n" % expected_substring)
97+
emitStdoutAsError(stdout)
9598
return 1
9699

97100
def fixFileExpectingFailure(filename, expected_substring):
@@ -105,11 +108,15 @@ def checkFileExpectingError(filename, expected_substring):
105108
def checkFileExpectingOK(filename):
106109
command, status, stdout = runCheckFormat("check", getInputFile(filename))
107110
if status != 0:
108-
print("status=%d, output:\n" % status)
109-
emitStdout(stdout)
111+
logging.error("status=%d, output:\n" % status)
112+
emitStdoutAsError(stdout)
110113
return 0
111114

112115
if __name__ == "__main__":
116+
parser = argparse.ArgumentParser(description='tester for check_foramt.py.')
117+
parser.add_argument('--log', choices=['INFO', 'WARN', 'ERROR'], default='INFO')
118+
args = parser.parse_args()
119+
logging.basicConfig(format='%(message)s', level=args.log)
113120
errors = 0
114121

115122
# Now create a temp directory to copy the input files, so we can fix them
@@ -128,7 +135,6 @@ def checkFileExpectingOK(filename):
128135
errors += checkFileExpectingOK("ok_file.cc")
129136

130137
if errors != 0:
131-
print("%d FAILURES" % errors)
138+
logging.error("%d FAILURES" % errors)
132139
exit(1)
133-
print("PASS")
134-
exit(0)
140+
logging.warn("PASS")

0 commit comments

Comments
 (0)