|
2 | 2 | ;; CHECK: ================================================================================
|
3 | 3 | ;; CHECK-NEXT: wasm-reduce INFILE
|
4 | 4 | ;; CHECK-NEXT:
|
5 |
| -;; CHECK-NEXT: Reduce a wasm file to a smaller one that has the same behavior on a given |
6 |
| -;; CHECK-NEXT: command |
| 5 | +;; CHECK-NEXT: Reduce a wasm file to a smaller one with the same behavior on a given command. |
| 6 | +;; CHECK-NEXT: |
| 7 | +;; CHECK-NEXT: Typical usage: |
| 8 | +;; CHECK-NEXT: |
| 9 | +;; CHECK-NEXT: wasm-reduce orig.wasm '--command=bash a.sh' --test t.wasm --working w.wasm |
| 10 | +;; CHECK-NEXT: |
| 11 | +;; CHECK-NEXT: The original file orig.wasm is where we begin. We then repeatedly test a small |
| 12 | +;; CHECK-NEXT: reduction of it by writing that modification to the 'test file' (specified by |
| 13 | +;; CHECK-NEXT: '--test'), and we run the command, in this example 'bash a.sh'. That command |
| 14 | +;; CHECK-NEXT: should use the test file (and not the original file or any other one). Whenever |
| 15 | +;; CHECK-NEXT: the reduction works, we write that new smaller file to the 'working file' |
| 16 | +;; CHECK-NEXT: (specified by '--working'). The reduction 'works' if it correctly preserves the |
| 17 | +;; CHECK-NEXT: behavior of the command on the original input, specifically, that it has the |
| 18 | +;; CHECK-NEXT: same stdout and the result return code. Each time reduction works we continue to |
| 19 | +;; CHECK-NEXT: reduce from that point (and each time it fails, we go back and try something |
| 20 | +;; CHECK-NEXT: else). |
| 21 | +;; CHECK-NEXT: |
| 22 | +;; CHECK-NEXT: As mentioned above, the command should run on the test file. That is, the first |
| 23 | +;; CHECK-NEXT: thing that wasm-reduce does on the example above is, effectively, |
| 24 | +;; CHECK-NEXT: |
| 25 | +;; CHECK-NEXT: cp orig.wasm t.wasm |
| 26 | +;; CHECK-NEXT: bash a.sh |
| 27 | +;; CHECK-NEXT: |
| 28 | +;; CHECK-NEXT: In other words, it copies the original to the test file, and runs the command. |
| 29 | +;; CHECK-NEXT: Whatever the command does, we will preserve as we copy progressively smaller |
| 30 | +;; CHECK-NEXT: files to t.wasm. As we make progress, the smallest file will be written to |
| 31 | +;; CHECK-NEXT: the working file, w.wasm, and when reduction is done you will find the final |
| 32 | +;; CHECK-NEXT: result there. |
| 33 | +;; CHECK-NEXT: |
| 34 | +;; CHECK-NEXT: Comparison to creduce: |
| 35 | +;; CHECK-NEXT: |
| 36 | +;; CHECK-NEXT: 1. creduce requires the command to return 0. wasm-reduce is often used to reduce |
| 37 | +;; CHECK-NEXT: crashes, which have non-zero return codes, so it is natural to allow any |
| 38 | +;; CHECK-NEXT: return code. As mentioned above, we preserve the return code as we reduce. |
| 39 | +;; CHECK-NEXT: 2. creduce ignores stdout. wasm-reduce preserves stdout as it reduces, as part |
| 40 | +;; CHECK-NEXT: of the principle of preserving the original behavior of the command (if your |
| 41 | +;; CHECK-NEXT: stdout varies in uninteresting ways, your command can be a script that runs |
| 42 | +;; CHECK-NEXT: the real command and captures stdout to /dev/null, or filters it). |
| 43 | +;; CHECK-NEXT: 3. creduce tramples the original input file as it reduces. wasm-reduce never |
| 44 | +;; CHECK-NEXT: modifies the input (to avoid mistakes that cause data loss). Instead, |
| 45 | +;; CHECK-NEXT: when reductions work we write to the 'working file' as mentioned above, and |
| 46 | +;; CHECK-NEXT: the final reduction will be there. |
| 47 | +;; CHECK-NEXT: 4. creduce runs the command in a temp directory. That is safer in general, but |
| 48 | +;; CHECK-NEXT: it is not how the original command ran, and in particular forces additional |
| 49 | +;; CHECK-NEXT: work if you have multiple files (which, for wasm-reduce, is common, e.g. if |
| 50 | +;; CHECK-NEXT: the testcase is a combination of JavaScript and wasm). wasm-reduce runs the |
| 51 | +;; CHECK-NEXT: command in the current directory (of course, your command can be a script |
| 52 | +;; CHECK-NEXT: that changes directory to anywhere else). |
| 53 | +;; CHECK-NEXT: |
| 54 | +;; CHECK-NEXT: More documentation can be found at |
| 55 | +;; CHECK-NEXT: |
| 56 | +;; CHECK-NEXT: https://github.com/WebAssembly/binaryen/wiki/Fuzzing#reducing |
| 57 | +;; CHECK-NEXT: |
7 | 58 | ;; CHECK-NEXT: ================================================================================
|
8 | 59 | ;; CHECK-NEXT:
|
9 | 60 | ;; CHECK-NEXT:
|
|
0 commit comments