Langsung ke konten
Skillpedia
Testing25k · #10057

fuzzing

Fungsinya

Skill ini menunjukkan kepada agent Anda cara menulis dan mendaftarkan tes fuzz memakai kerangka FuzzTest. Cocok untuk pengembang yang ingin menguji kode yang membaca input tidak tepercaya.

Kapan dipakai

  • ✓Saat Anda meminta AI menambahkan tes fuzz ke file tes unit C++.
  • ✓Saat Anda ingin memeriksa parser atau penangan data terhadap crash dengan input acak.
  • ✓Saat Anda perlu menyiapkan folder build yang mengaktifkan fuzzing.

Link skill

https://github.com/chromium/chromium/blob/main/agents/skills/fuzzing/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/chromium/chromium/blob/main/agents/skills/fuzzing/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Bisakah Anda menulis tes fuzz untuk parser URL C++ saya agar memeriksa crash dengan input acak?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill memandu AI menulis fungsi properti yang memeriksa aturan tertentu pada kode, lalu mendaftarkannya dengan makro FUZZ_TEST. Fuzzer kemudian mencoba banyak input untuk mencari kegagalan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Fuzzing (Chromium)

1. Setup

Ensure the output directory is configured:

gn gen out/fuzz --args='enable_fuzztest_fuzz=true is_debug=false is_asan=true \
is_component_build=false use_remoteexec=true'

2. Implement the FUZZ_TEST

Add to *_unittest.cc alongside existing tests:

#include "third_party/fuzztest/src/fuzztest/fuzztest.h"
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"

// 1. Define the property function. Use a descriptive name that reflects
// the property being tested (e.g., "ParseFooDoesNotCrash" or "RoundTripIsLossless").
void MyPropertyFunctionDoesNotCrash(int i, const std::string& s) {
  // Call code under test. Focus on functions parsing untrusted input, complex
  // state machines, or data processing.
  bool result = MyComponent::DoSomething(i, s);
  // Add test assertions about invariants (e.g. "roundtrip equality", "valid
  // output structure"). Sanitizers like ASAN catch crashes.
  EXPECT_TRUE(result);
}

// 2. Register with FUZZ_TEST macro
FUZZ_TEST(MyComponentFuzzTest, MyPropertyFunctionDoesNotCrash)
  .WithDomains(
      fuzztest::InRange(0, 100),
      fuzztest::Arbitrary<std::string>()
  );

For complex types:

  • Construct from primitives: If the object has a parsing constructor (e.g. GURL(string)), accept the primitive and construct it inside your test function.
  • Define a local domain: Use fuzztest::Constructor or fuzztest::Map to build valid objects.
    auto ArbitraryFoo() {
      return fuzztest::Constructor<Foo>(fuzztest::InRange(0, 10));
    }
    

3. Register in BUILD.gn

You MUST register the test in the fuzztests list (in alphabetical order) of the executable test target.

Case A: File is in a test() target

test("my_component_unittests") {
  sources = [ "my_component_unittest.cc" ]

  # Format: SuiteName.TestName
  fuzztests = [
    "MyComponentFuzzTest.MyPropertyFunctionDoesNotCrash",
  ]

  # No dependency changes are needed here. The build system
  # automatically adds FuzzTest dependencies for targets
  # with a `fuzztests` list.

}

Case B: File is in a source_set(): Add //third_party/fuzztest:fuzztest to deps.

source_set("tests") {
  sources = [ "my_component_unittest.cc" ]
  deps = [
    "//third_party/fuzztest:fuzztest",
    # ...
  ]
}

Find the executable test() target that depends on this source_set(): gn refs out/fuzz //path/to:source_set --testonly=true --type=executable --all

Then, ensure it lists the fuzz test in its fuzztests variable (in alphabetical order).

4. Mandatory verification workflow

The task is incomplete until you successfully execute this sequence:

  1. Find the target and Build

Find the executable test() target that contains your test file:

gn refs out/fuzz //path/to/my_component_unittest.cc --type=executable --all

Build the identified target (e.g. unit_tests or browser_tests):

autoninja --quiet -C out/fuzz <target_name>

Note: If the build fails with an include not allowed by DEPS error, see the Common Issues & Fixes section below.

  1. Verify unit tests pass
./out/fuzz/<target_name> \
--gtest_filter="MyComponentFuzzTest.MyPropertyFunctionDoesNotCrash"
  1. Verify fuzzing mode doesn't crash
./out/fuzz/<target_name> \
--fuzz="MyComponentFuzzTest.MyPropertyFunctionDoesNotCrash" --fuzz_for=10s

Resources

  • Chromium Guide: testing/libfuzzer/getting_started.md
  • Macro Usage: third_party/fuzztest/src/doc/fuzz-test-macro.md
  • Domains: third_party/fuzztest/src/doc/domains-reference.md
  • Fixtures: third_party/fuzztest/src/doc/fixtures.md

Common Issues & Fixes

Build failure: include not allowed by DEPS

Symptom: Build fails with an error like: ERROR: include not allowed by DEPS: third_party/fuzztest/...

Fix: You must allow the fuzztest include in the nearest DEPS file (usually in the same directory as your test or a parent directory). Add +third_party/fuzztest to specific_include_rules for your test files:

specific_include_rules = {
  ".*_unittest\\.cc": [
    "+third_party/fuzztest",
  ],
}
Pertanyaan umum

Apa itu fuzz testing?

Fuzz testing mengirim banyak input acak atau tidak biasa ke kode untuk menemukan crash atau aturan yang rusak. Metode ini bagus untuk menemukan bug yang terlewat oleh tes biasa.

Apakah saya harus ahli C++ untuk memakai ini?

Anda perlu sedikit pengetahuan C++ agar bisa memakainya dengan baik. Skill membantu AI menulis kode tes dan pengaturan build.

Apakah skill ini bisa dipakai di luar proyek Chromium?

Contohnya berasal dari Chromium, tetapi pola FuzzTest adalah kerangka umum. Langkahnya bisa diterapkan pada proyek C++ lain.

Detail

Deskripsi asli dari pembuat

Implements, registers, and verifies fuzz tests in Chromium. Use when the user asks to add or write fuzzers in C++, or mentions fuzz testing or FUZZ_TEST.

repo: chromium/chromium

Popularitas

Bintang GitHub
25k
Peringkat
#10057
Lisensi
BSD-3-Clause
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa