DeepRNG: Towards Deep Reinforcement Learning-Assisted Generative Testing of Software

Chuan-Yung Tsai, Graham W. TaylorarXiv 2022 · OpenReview

TL;DR

This paper introduces DeepRNG, a novel framework that enhances software testing by integrating a deep reinforcement learning (RL) agent directly into the random number generator (RNG). By using the software's call stack as a state representation, DeepRNG significantly improves test coverage for complex systems like the Cosmos SDK, while also identifying previously unknown bugs.

What Problem Does This Paper Address?

Software testing, particularly for large and complex systems, remains a significant challenge despite the increasing prevalence of software vulnerabilities. Traditional fuzzing techniques often struggle to generate effective test inputs, and while generative testing offers a more targeted approach, it typically relies on manually designed test generators. The authors aim to automate and improve generative testing by leveraging the power of deep reinforcement learning, specifically by making the RNG "smarter" and more adaptive to the software's internal state.

Methods

The core of DeepRNG is its integration of a deep RL agent with the software's RNG. Instead of relying on a fixed, pseudorandom number generation process, DeepRNG augments it with an RL agent.

  • State Representation: A key innovation is the use of the software's full call stack as the state representation for the RL agent. This is automatically extracted and is described as lightweight and effective.
  • RL Agent: The authors employ the IMPALA algorithm, known for its efficiency in distributed deep RL, along with its associated neural network architecture. This architecture can flexibly encode the current state and optionally the history of past states, actions, and rewards.
  • RNG Augmentation: The custom RNG library in DeepRNG routes function calls to an external RL agent. The agent receives the call stack as its state and returns random numbers as actions. These actions are then sampled from a learned distribution designed to maximize expected rewards (e.g., increased test coverage or bug discovery).
  • Gym Wrapper: An OpenAI Gym wrapper facilitates communication between the software and the RL agent, handling the passing of states, rewards, and actions.

Datasets

The paper uses two main testbeds:

  • Binary Search Tree (BST) Generation: A toy problem inspired by previous work, used to evaluate different state-history representations in a controlled environment. This problem involves generating valid BSTs with specific depth and pruning probabilities.
  • Cosmos SDK: A large, real-world software framework (over 350,000 lines of code) used to demonstrate the practical effectiveness of DeepRNG. The authors highlight that the Cosmos SDK's coverage bitmap is too large for efficient processing, necessitating the use of the call stack as the state representation.

Key Insights and Ideas

  • Call Stack as an Effective State: The full call stack proves to be a surprisingly effective and lightweight state representation for the RL agent, outperforming more complex representations like coverage bitmaps in some scenarios.
  • History Matters (Sometimes): While incorporating state, action, and reward history (CSAR) showed the most significant improvement for the Cosmos SDK, the BST experiment suggested that for simpler problems, not using history might even be better. This highlights the nuanced relationship between state representation complexity and RL performance.
  • RL for Adaptive RNG: Directly augmenting the RNG with an RL agent allows for adaptive, state-aware generation of test inputs, moving beyond purely random or pre-programmed generation strategies.
  • Practical Applicability: The framework is designed to be extensible to most programming languages due to the availability of call stack extraction mechanisms.

Key Results

  • Cosmos SDK: DeepRNG achieved a statistically significant improvement in test coverage compared to default random testing. Specifically, the CSAR (Call Stack + State + Action + Reward) configuration showed the most significant improvement based on t-tests.
  • Bug Discovery: The DeepRNG framework successfully identified at least two types of bugs in the Cosmos SDK: invalid initialization and unexpected timeouts.
  • BST Generation: The BST experiment demonstrated that while more information isn't always better, a flexible framework with efficient representations is crucial for effective exploration.

Limitations and Future Work

  • Small Numerical Improvement: For the Cosmos SDK, the authors acknowledge that the numerical increase in test coverage, while statistically significant, is quite small. They attribute this to the fact that many modules within the SDK are not currently reachable by its existing test generator.
  • Future Directions:
    • Filtering Unreachable Modules: To improve coverage further, the authors suggest filtering out unreachable or unimportant modules to simplify the problem.
  • Exploration Phase Optimization: They propose exploring techniques to disregard the "exploitation phase" of the RL algorithm, focusing solely on exploration, as new states are the primary source of rewards.
  • Extensibility: The framework's theoretical extensibility to other languages is noted, implying future work could involve porting and testing it on diverse software systems.

Summary updated

Abstract

Although machine learning (ML) has been successful in automating various software engineering needs, software testing still remains a highly challenging topic. In this paper, we aim to improve the generative testing of software by directly augmenting the random number generator (RNG) with a deep reinforcement learning (RL) agent using an efficient, automatically extractable state representation of the software under test. Using the Cosmos SDK as the testbed, we show that the proposed DeepRNG framework provides a statistically significant improvement to the testing of the highly complex software library with over 350,000 lines of code. The source code of the DeepRNG framework is publicly available online.
BibTeX
@misc{tsai2022deeprng,
  author = {Chuan-Yung Tsai and Graham W. Taylor},
  title = {{DeepRNG: Towards Deep Reinforcement Learning-Assisted Generative Testing of Software}},
  year = {2022},
  eprint = {2201.12602},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2201.12602},
}

Loading related content...

Figure