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

kcov loses accumulated data when ${1:?} used #75

Open
Mark-E-Hamilton opened this issue Mar 13, 2015 · 4 comments
Open

kcov loses accumulated data when ${1:?} used #75

Mark-E-Hamilton opened this issue Mar 13, 2015 · 4 comments
Labels

Comments

@Mark-E-Hamilton
Copy link

Hi, again,
I've got another simple test case.

#!/bin/bash
#echo before
fparam=${1:?}
echo $fparam

When I run it with a parameter I get 100% coverage

% rm -rf kcov_out
% kcov ./kcov_out ./test7.sh something
something

When I run it with no parameter I get 0% coverage.

% rm -rf kcov_out
% kcov ./kcov_out ./test7.sh
./test7.sh: line 3: 1: parameter null or not set

Howwever, when I run them both in sequence I get 100% coverage after the first kcov, and 0% after the second.

% rm -rf kcov_out
% kcov ./kcov_out ./test7.sh
case 1
% kcov ./kcov_out ./test7.sh
./test7.sh: line 3: 1: parameter null or not set

FInally, if I uncomment the 'echo before' statement I get 100% coverage in both cases when I run them in the order above. If I run them in the other order (the failure case first) I get 33% coverage after the failure case, and then 100% coverage after the success case (which seems correct.)

@SimonKagstrom
Copy link
Owner

OK, this is sort of an interesting case. Apparently bash will parse this as a syntax error and return an error code:

ska@localhost:kcov$ bash -x tests/bash/dollar-one-question.sh
tests/bash/dollar-one-question.sh: line 3: 1: parameter null or not set
ska@localhost:kcov$ echo $?
1

adding a parameter sets that right again:

ska@localhost:kcov$ bash -x tests/bash/dollar-one-question.sh 4
+ fparam=4
+ echo 4
4
ska@localhost:kcov$ echo $?
0

and in this case, kcov works as expected. However, as you noted, the real kcov issue here is that accumulation doesn't work as expected. I have to investigate, but my guess is that the reason is that kcov visits files in bash "lazily" the first time they are referenced through PS4. So in the error-case, kcov won't see any files at all. When you added the echo, the file will show up and the accumulation can be done.

@Mark-E-Hamilton
Copy link
Author

Thanks.

I suppose then that I'll have to visit my larger test case. I strip out
code from large scripts to get the smallest possible piece that still
exhibits the problems I see. Occasionally I add statements that might
not have been in the original, so my test cases can be too simple. In
the larger case I'm seeing a similar problem, but your description makes
me think it might actually be something else. I'll have to investigate
it some more.


Mark E. Hamilton
Engineering Sciences Center
Senior Member of Technical Staff
Sandia National Laboratories
505-844-7666

@SimonKagstrom
Copy link
Owner

The smaller tests are quite good to have, so thanks for doing that!

Is your original problem an accumulation problem?

@Mark-E-Hamilton
Copy link
Author

I think so. When I run a single test case the shell lines in question
are covered. When I run all the test cases the previously covered lines
turn red again. I haven't been able to isolate it yet, however.


Mark E. Hamilton
Engineering Sciences Center
Senior Member of Technical Staff
Sandia National Laboratories
505-844-7666

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

No branches or pull requests

2 participants