Skip to content

Instantly share code, notes, and snippets.

@ono-max
Last active August 28, 2021 23:26
Show Gist options
  • Save ono-max/b12ef342d77267c46c5c77a3e3040791 to your computer and use it in GitHub Desktop.
Save ono-max/b12ef342d77267c46c5c77a3e3040791 to your computer and use it in GitHub Desktop.

Google Summer of Code 2021: Tests for debugger

Background and Motivation

Current lib/debug.rb is no longer being maintained and it is not appropriate for current Ruby features. Koichi Sasada started writing new lib/debug.rb (hereinafter referred to as the new debugger) to replace it(For more information, see this article). However, it was hard to write test for it because the test framework have to test the new debugger without interrupting debugger process. That's why we worked on developping the test framework for the new debugger as the part of GSoC 2021 project.

Project Goal

Main goal

  • Implementing the test framework for the new debugger

Advanced goal

The main project goal was to implement test framework for the new debugger. However, we were able to accomplish the goal before first evaluation. Therefore, we re-set our advanced goal as follows.

  • Making the test framework faster with multithreaded programming

    Execution speed of the test framework in the new debugger is slow. As of August 29, 2021, it took over six minutes to finish the test with Github Actions. To make it faster, multithreaded programming is an effective way.

  • Adding Chrome debugging support in the new debugger

    It's sometimes hard for users to see long backtrace informations in the terminal. To solve the problem, Chrome Devtools frontend is one of solution.

Works

In short, what I've done is as shown below. I met the main goal and one extra goal. Although there were many challenges, I was able to overcome with the help of great mentors.

  • Implementing the test framework for the new debugger
  • Making the test framework faster with multithreaded programming
  • Adding Chrome debugging support in the new debugger

Implementing the test framework for the new debugger

The following figure is the structure about the test framework. The parent process run the child process(pseudo terminal) by PTY module. The parent process takes the inputs of the child process and tests them.

Screen Shot 2021-08-20 at 1 44 54 PM This is generated by Typora

  • Test generator

Test generator helps new debugger's contributors to create tests. By running the new debugger and entering debug commands, tests will be created on them(For detailed instructions, see this link).

The structure of test generator is very similar to it of the test framework.

  1. The test generator runs the child process by PTY module and the debugger program is executed in the child process.
  2. The test generator gets standard inputs from an user, and enters them into debugger program(child process). It also generates the method from user's inputs,
  3. The test generator generates assertions from child process's standard output/error. It also outputs standard output/error in the terminal.
  4. Finally, the file is generated.
  • Writing some test cases

Making the test framework faster with multithreaded programming

Multithreaded programming allows us to test concurrently as follows. If a test fails, the current thread will do nonlocal exits and other threads will be killed.

Before

Screen Shot 2021-08-20 at 9 33 18 AM

After

Screen Shot 2021-08-20 at 9 34 08 AM These are generated by Typora

Adding Chrome debugging support in the new debugger

To add Chrome debugging support in the new debugger, I needed to understand Chrome Devtools Protocol. Hence, I created a prototype to comprehend it. Thanks to the great help of the chrome-remote-interface team, I was able to create it in node.js.

https://github.com/ono-max/prototype-chrome-debug

Other

While writing the codes, I encountered some bugs. The following pull requests are patches for fixing them.

Evaluation

  • Implementing the test framework for the new debugger

    All current debug commands have a sufficient level of test coverage and the test framework has no issue so far. The test generator is helpful for writing tests. However it has a problem that the program method can't be added if it already exists.

  • Making the test framework faster with multithreaded programming

    The following table shows the mediums of measured program execution times for the new debugger's tests. Multithreaded testing of the new debugger are run with $ rake test. On the other hand, single-threaded testing of it are run with $ RUBY_DEBUG_TEST_DISABLE_THREADS=1 rake test. All measurements were taken 10 times(For actual datas, see this link) and run times were measured by using the time that test-unit outputs after all tests are completed.

    Comparing the medians, multithreaded programming is about 2.39 faster than single-threaded one.

    Table2: The mediums obtained based on Table1(Unit: seconds)

    Medium
    Multiple threads  56.32
    Single thread 134.40

    The following list is the development information used for the measurements.

    • MacBook Pro (13-inch, 2019, Two Thunderbolt 3 ports)
    • Processor 1.4 GHz Quad-Core Intel Core i5
    • Memory 8 GB 2133 MHz LPDDR3
  • Adding Chrome debugging support in the new debugger

    There are three steps to achieve this goal

    1. Creating a prototype in node.js
    2. Creating a prototype in Ruby
    3. Adding Chrome debuging support in the new debugger

    I only completed the first step. One reason that I'm not able to accomplish is that there are few example. It took a lot of trial and error.

Impact

The new debugger should have been a fascinating project through my project.

  • Implementing the test framework for the new debugger

    New debugger's contributors can create new features without breaking existing ones. They also can write tests easily with the test generator.

  • Making the test framework faster with multithreaded programming

    New debugger's contributors can experiment at shorter intervals. They can wait for the test to finish with less stress.

Future Work

  • Implementing the test framework for the new debugger

    I plan to develop the test generator to solve the problem that the program method can't be added if it already exists. I also maintains the test framework.

  • Adding Chrome debugging support in the new debugger

    I create a prototype in Ruby. After I'm done building it, I will create a pull request to add Chrome debugging support.

Acknowledgement

I am greatful to my mentor Koichi Sasada for guidance and support. Your advice always motivated me! Thank you teaching me a lot of things!

Special thanks to Yusuke Endoh, Kenta Murata, Kazuhiro Nishiyama, Stan Lo, Andrea Cardaci, Geoffrey Litt and all awesome people in Ruby community for making time for me.

Table1: Actual data of execution times(Unit: seconds)

1st measurement 2nd measurement 3rd measurement 4th measurement 5th measurement 6th measurement 7th measurement 8th measurement 9th measurement 10th measurement Arithmetic mean Standard Deviation
Multiple threads  57.46  56.56  55.21  57.94  56.07  55.09  59.63  56.03  56.64  56.01  56.66 1.30
Single thread 132.39 130.07 135.13 136.44 137.30 134.54 134.05 136.42 134.27 131.52 134.21 2.19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment