se2p/pynguin

Segmantation fault while running mutant

Closed this issue · 3 comments

Hello.

I got an segmentation fault error while trying to generate test cases using pynguin.

Error Message : Running Pynguin...Segmentation fault (core dumped)

After further analysis, I found the cause.
Whenever I use dict.keys() or items() method and the mutant's input to be an empty dictionary({}), the tests fail.

I prepared a sample code below.

class Sample:
    def __init__(self):
        pass

    def get_user_names(self, user_dict: dict):
        headers = []

        for key in user_dict.keys():
            name = user_dict[key]['name']
            headers.append(name)

        print(headers)
        return headers

If I check length of the keys first, then It works fine.

or change line 8 to

for key in list(user_dict.keys()):

, it works too.

I think this is a general case.
I mean, many developers could encounter this kind of situation.
There are too many code lines like this sample in my projects... Hard to fix all of them.

Please fix this bug or let me know another way to avoid this error.
Thanks.

Dear @pjy0121 ,

Thank you for your interest in Pynguin and your report. I've just tried your example snipped using Pynguin 0.16.1 (the latest release) and Python 3.10.0 on macOS 12.2. I was using a more or less default configuration, i.e., --algorithm DYNAMOSA --budget 60 --seed 42, and I did not encounter a segmentation fault.

So, in order to allow a reproduction of the issue, could you please give some more details, i.e., the versions of Pynguin and Python you are using as well as the full command line for Pynguin?

Thank you in advance.

Best,
Stephan

@stephanlukasczyk

Thanks for your reply.
After reading your comment, I upgraded my python to 3.10.0 version and it works fine.
But when I downgrade back to 3.8.0 version, the segmentation fault rises occurs again. It would be good to be aware of this issue with python 3.8.

Thank you so much for your help.

Dear @pjy0121 ,

Thank you for your answer. First of all, I am happy that Pynguin works for you on Python 3.10. Second, I tried to reproduce the issue with Python 3.8. Unfortunately, I have no Python 3.8.0 available, but only 3.8.12. Using Python 3.8.12 I cannot reproduce the issue, i.e., no segmentation fault happens.

Thus, I believe that this might have been a bug in Python 3.8.0 that was fixed with one of its patch releases afterwards. Running Pynguin 0.17.0 on Python 3.8.12 works fine for your example code. Therefore, I am closing this issue.

Best,
Stephan