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

PS4 has a 100 character limit, causing shcov to fail with deep directories #6

Open
GoogleCodeExporter opened this issue Mar 16, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

I realize that this is really a bash issue, but it showed up when we were 
trying to use shcov, so I'm hoping someone here has a solution.

What steps will reproduce the problem?
1. mkdir -p 
/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/subdir9
2. cd 
/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/subdir9
3. echo "echo Hi" > test2.sh ; chmod +x test2.sh
4. shcov ${PWD}/test2.sh

What is the expected output? 
"Hi"

What do you see instead?
Hi
Traceback (most recent call last):
  File "/ascldap/users/mhamilt/shcov-5/scripts/shcov", line 177, in <module>
    out = sc.parse_output()
  File "/ascldap/users/mhamilt/shcov-5/scripts/shcov", line 118, in parse_output
    self.handle_line(line)
  File "/ascldap/users/mhamilt/shcov-5/scripts/shcov", line 77, in handle_line
    file.add_to_line(line_nr)
  File "/home/mhamilt/shcov-5/shcov/file.py", line 103, in add_to_line
    line_nr = int(line_nr)
ValueError: invalid literal for int() with base 10: '1::echo Hi\n'


What version of the product are you using? On what operating system?
shcov-5 on an RHEL6 machine with Python 2.7.4

Please provide any additional information below.

Taking shcov out of the equation we can demonstrate that bash shortens the 
results of the expansion of PS4 to 100 characters:

% export PS4='SHCOV:::${BASH_SOURCE}:::${LINENO}::: SHCOV:'
% bash -x ${PWD}/test2.sh
SHCOV:::/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/sub
dir9/test2.sh:::1::echo Hi
Hi
%

Counting characters to the 'echo Hi' at the end gives 100.

If I add 'print line' to shcov at line 51 I get this:

SHCOV:::/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/sub
dir9/test2.sh:::1::echo Hi

and since the parser is using ':::' as the separator the last field ends up 
with '1::echo Hi', instead of '1'. (Clearly it gets worse the deeper the 
hierarchy becomes.)

We can't really flatten out our hierarchy, so I'm unsure of how this might be 
corrected.

Mark E. Hamilton





Original issue reported on code.google.com by [email protected] on 4 Feb 2014 at 9:27

@GoogleCodeExporter
Copy link
Author

That would require some thinking. Perhaps it's possible to use some generated 
pattern instead of BASH_SOURCE, but I'm not sure.

As you might have noticed, I'm not very active in updating shcov anymore (to 
say the least). There are some other people that has improved the code a bit at 
github, so I guess I should start merging back that code soon.

Original comment by [email protected] on 8 Feb 2014 at 2:30

@GoogleCodeExporter
Copy link
Author

Good news! Since bash 4.3 this problems is no more as bash changed the 
indirection_string from a static buffer to a dynamic buffer.

from the changelog.
print_cmd.c
    - change indirection_string from a static buffer to a dynamic one
          managed by indirection_level_string(), so we don't end up truncating
      PS4.  Suggested by Dennis Williamson <addresswithheld>

Original comment by [email protected] on 9 Feb 2015 at 3:33

@GoogleCodeExporter
Copy link
Author

Good to hear!

Also good news: I've deprecated shcov in favor of kcov 
(https://github.com/SimonKagstrom/kcov), which has many more features and fixes 
at least a few of the bugs shcov had.

Although I tought it would have had this particular problem as well, but 
apparently that fixed itself! :-)

Original comment by [email protected] on 9 Feb 2015 at 3:36

@GoogleCodeExporter
Copy link
Author

That's great news. Unfortunately, our system admins aren't amenable to 
installing bash/4.3 on all of the RHEL6 machines they support, and there are 
many. (If 4.3 is the default with the next version of RHEL we'll get it, but 
not until then.) I've been testing out kcov recently, and it seems to encounter 
this issue also (with Bash-4.1.2) though the reproduction commands I provided 
with this issue don't seem to cause it. I'll have to investigate some more 
before I submit an issue on the kcov site.

Original comment by [email protected] on 25 Feb 2015 at 8:49

@GoogleCodeExporter
Copy link
Author

I don't know how your test suite looks like, but would it be possible to 
locally build a bash for use in the test suites? In that case, you could use

  kcov --bash-parser=/path/to/bash-4.3 [other args]

(With kcov, that is!)

Original comment by [email protected] on 26 Feb 2015 at 7:11

@GoogleCodeExporter
Copy link
Author

Thanks. That seems work fine (though I had to get the most recent version of 
bash-4.3 (4.3.30, not 4.3.0) for it to work.

Original comment by [email protected] on 26 Feb 2015 at 6:41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant