Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug29221 draft #742

Closed
wants to merge 13 commits into from
Closed

Bug29221 draft #742

wants to merge 13 commits into from

Conversation

Labels
None yet
Projects
None yet
3 participants
@asn-d6
Copy link
Member

@asn-d6 asn-d6 commented Feb 28, 2019

No description provided.

@asn-d6 asn-d6 force-pushed the bug29221_draft branch from af323ae to d1d6fcb Feb 28, 2019
asn-d6 added 2 commits Feb 28, 2019
- Introduce 'make check-best-practices'.
- Fix up Tor topdir etc to work with the way 'make check-local' gets called.
- Make practracker less likely to print useless stuff.
@asn-d6 asn-d6 force-pushed the bug29221_draft branch from d1d6fcb to ceed830 Feb 28, 2019
@coveralls
Copy link

@coveralls coveralls commented Mar 2, 2019

Pull Request Test Coverage Report for Build 4169

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1026 unchanged lines in 9 files lost coverage.
  • Overall coverage decreased (-0.004%) to 61.719%

Files with Coverage Reduction New Missed Lines %
src/lib/time/compat_time.c 2 92.54%
src/feature/dirauth/shared_random.c 3 85.64%
src/feature/dirauth/dirvote.c 9 64.74%
src/lib/evloop/workqueue.c 11 93.33%
src/core/or/circuitpadding.c 33 94.97%
src/core/mainloop/cpuworker.c 108 0.0%
src/feature/client/transports.c 127 50.68%
src/feature/rend/rendservice.c 346 32.66%
src/core/or/relay.c 387 49.41%
Totals Coverage Status
Change from base Build 4026: -0.004%
Covered Lines: 45346
Relevant Lines: 73472

💛 - Coveralls

asn-d6 added 4 commits Mar 5, 2019
This was causing issues because the exceptions file is written using Posix
paths, whereas practracker in Windows was trying to match Windows paths ("\"
instead of "/").
func_start = lineno
in_function = True
else:
# Fund the end of a function
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

Oops, this is my typo: this function should say "find", not "fund"

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Fixed in ac05cc7.

"""Get number of #include statements in the file"""
include_count = 0
for line in f:
if re.match(r' *# *include', line):
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

Maybe this should be \s* instead of *, since tabs can also appear in this context. On the other hand, Tor doesn't allow tabs, so maybe we don't need to care.

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Included this improvement in the post-merge ticket #29746, since it's a good-to-have but doesn't actually influence results atm. Ideally we would have tests for this change.

super(FunctionSizeProblem, self).__init__("function-size", problem_location, metric_value)

def get_old_problem_from_exception_str(exception_str):
try:
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

I'd suggest that we explicitly allow comments and empty lines in this file, and that we treat other unrecognized lines as errors.

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Included this improvement in the post-merge ticket #29746, since it's a good-to-have but doesn't actually influence results atm. Ideally we would have tests for such change.

elif problem_type == "function-size":
return FunctionSizeProblem(problem_location, metric_value)
else:
print "Unknown exception line %s" % exception_str
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

Using stderr might make sense here; also, this won't work with python3. (Maybe you fix it later in the branch)

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Yep, that line was fixed later in the branch, but I used stderr for another err message in ac05cc7.

"""
Return iterator which iterates over functions and returns (function name, function lines)
"""

# XXX Buggy! Doesn't work with MOCK_IMPL and ENABLE_GCC_WARNINGS
# Skip lines with these terms since they confuse our regexp
REGEXP_CONFUSE_TERMS = ["MOCK_IMPL", "ENABLE_GCC_WARNINGS", "ENABLE_GCC_WARNING", "DUMMY_TYPECHECK_INSTANCE",
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

I'd suggest that you use a set here rather than an array.

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Fixed in ac05cc7.

in_function = False
for lineno, line in enumerate(f):
if any(x in line for x in REGEXP_CONFUSE_TERMS):
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

Instead of checking for the presence of the strings here, I'd suggest checking after we find the start of a function, to see if the function name is in the list of confusing terms.

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Added to post-merge ticket #29746. Ideally we would have tests for this change to make sure that results are not impacted.

Copy link
Contributor

@nmathewson nmathewson Mar 12, 2019

I think this one is actually important for correctness; I'll try a quick fix. See e968b88 in my bug29221_more


def consider_function_size(fname, f):
for name, lines in metrics.function_lines(f):
"""Consider the function sizes for 'f' and return True if a new issue was found"""
found_new_issues = False
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

Suggestion, possibly for a later ticket: use a counter here instead of a boolean. That way you can print the number of new issues on exit.

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Added to post-merge ticket #29746.

@@ -14,7 +18,7 @@ def get_tor_c_files(tor_topdir, exclude_dirs):

# Exclude the excluded paths
full_path = os.path.join(root,filename)
if any(exclude_dir in full_path for exclude_dir in exclude_dirs):
if any(exclude_dir in full_path for exclude_dir in EXCLUDE_SOURCE_DIRS):
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

I don't like looking for the excluded path everywhere in the full_path string; it should only be excluded when it is right under TOP_SRCDIR. In other words, if tor is in ~/tor/, then ~/tor/src/trunnel/ should be excluded, but "~/src/tor/src/lib/handle_trunnel/src/trunnel` shouldn't be excluded

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

I tried to do this, but I think it should be done properly with tests to make sure of it's correctness.
Added to post-merge ticket #29746.

if (found_new_issues):
print("practracker FAILED")
new_issues_str = "practracker FAILED as indicated by the problem lines above. Please use the exceptions file ({}) to find any previous state of these problems. If you are unable to fix the underlying best-practices issue right now then you need to either update the relevant exception line or add a new one.".format(exceptions_file)
Copy link
Contributor

@nmathewson nmathewson Mar 5, 2019

With your permission, I'll tweak this string a little post-merge. The way it is written now, it suggests that the preferred solution to a bad practice is to add an exception, rather than to fix the problem. I think there should be a new section in doc/HACKING about this, with suggestions for how to fix each kind of problem.

Copy link
Member Author

@asn-d6 asn-d6 Mar 12, 2019

Yes, no problem with tweaking that string.

@asn-d6 asn-d6 requested a review from nmathewson Mar 12, 2019
@nmathewson
Copy link
Contributor

@nmathewson nmathewson commented Mar 13, 2019

eventually merged as #787

@nmathewson nmathewson closed this Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment