> For the complete documentation index, see [llms.txt](https://pkuflyingpig.gitbook.io/pintos/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pkuflyingpig.gitbook.io/pintos/getting-started/debug-and-test.md).

# Debug and Test

## Debugging versus Testing

**When you're debugging code, it's useful to be able to run a program twice and have it do exactly the same thing.** On second and later runs, you can make new observations without having to discard or verify your old observations. This property is called **"reproducibility"**.

* One of the simulators that Pintos supports, Bochs, can be set up for reproducibility, and that's the way that `pintos` invokes it by option `--bochs`.

Of course, a simulation can only be reproducible from one run to the next if its input is the same each time. For simulating an entire computer, as we do, this means that every part of the computer must be the same. For example, you must use the same command-line argument, the same disks, the same version of Bochs, and you must not hit any keys on the keyboard (because you could not be sure to hit them at exactly the same point each time) during the runs.

**While reproducibility is useful for debugging, it is a problem for testing thread synchronization, an important part of most of projects.** In particular, when Bochs is set up for reproducibility, the timer interrupts will come at perfectly reproducible points, and therefore so will thread switches. That means that running the same test several times doesn't give you any greater confidence in your code's correctness than does running it only once.

**So, to make your code easier to test, we've added a feature, called "jitter", to Bochs, that makes timer interrupts come at random intervals, but in a perfectly predictable way.**

* In particular, if you invoke `pintos` with the option `-j` seed, timer interrupts will come at **irregularly** spaced intervals. Within a single seed value, execution will still be reproducible, but timer behavior will change as seed is varied.

Thus, for the highest degree of confidence you should test your code with many seed values.

**On the other hand, when Bochs runs in reproducible mode, timings are not realistic, meaning that a "one-second" delay may be much shorter or even much longer than one second.**

* You can invoke `pintos` with a different option, `-r`, to set up Bochs for realistic timings, in which a one-second delay should take approximately one second of real time. Simulation in real-time mode is not reproducible, and options `-j` and `-r` are mutually exclusive.

**The QEMU simulator is available as an alternative to Bochs (use `--qemu` when invoking `pintos`).** The QEMU simulator is much faster than Bochs, but it only supports real-time simulation and does not have a reproducible mode.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pkuflyingpig.gitbook.io/pintos/getting-started/debug-and-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
