fuzzing
ما الذي تفعله
تعلّم هذه المهارة وكيلك كيف يكتب اختبارات الفازينغ ويسجلها باستخدام إطار FuzzTest. وهي مخصصة للمطورين الذين يريدون اختبار شيفرة تقرأ مدخلات غير موثوقة.
متى تستخدمها
- ✓عندما تطلب من الذكاء الاصطناعي إضافة اختبار فازينغ إلى ملف اختبار وحدة في C++.
- ✓عندما تريد فحص محلل بيانات أو معالج بيانات بحثًا عن الأعطال بمدخلات عشوائية.
- ✓عندما تحتاج إلى إعداد مجلد مخرجات بناء يفعّل الفازينغ.
رابط المهارة
https://github.com/chromium/chromium/blob/main/agents/skills/fuzzing/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“هل يمكنك كتابة اختبار فازينغ لمحلل عناوين URL في C++ يفحص الأعطال بمدخلات عشوائية؟”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
توجه المهارة الذكاء الاصطناعي لكتابة دالة خاصية تفحص قاعدة ما في الشيفرة، ثم تسجلها بماكرو FUZZ_TEST. بعد ذلك يجرب الفازر مدخلات كثيرة بحثًا عن الإخفاقات.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من 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::Constructororfuzztest::Mapto 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:
- 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.
- Verify unit tests pass
./out/fuzz/<target_name> \
--gtest_filter="MyComponentFuzzTest.MyPropertyFunctionDoesNotCrash"
- 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",
],
}
الأسئلة الشائعة
ما اختبار الفازينغ؟
هو إرسال مدخلات عشوائية أو غير مألوفة كثيرة إلى الشيفرة لاكتشاف الأعطال أو القواعد المكسورة، وهو جيد في إيجاد أخطاء تفوتها الاختبارات العادية.
هل أحتاج إلى أن أكون خبيرًا في C++؟
تحتاج إلى بعض المعرفة بـ C++ لتستفيد منه جيدًا. وتساعد المهارة الذكاء الاصطناعي على كتابة شيفرة الاختبار وإعدادات البناء.
هل تعمل هذه المهارة خارج مشروع Chromium؟
الأمثلة مأخوذة من Chromium، لكن نمط FuzzTest إطار عام، ويمكن تطبيق خطواته على مشاريع C++ أخرى.
التفاصيل
الوصف الأصلي من المؤلف
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
الشعبية
- نجوم GitHub
- 25k
- الترتيب
- #10057
- الترخيص
- BSD-3-Clause
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
gn-deps-debugging
25kيساعد وكيلك على إصلاح أخطاء البناء الناتجة عن تبعيات ناقصة أو خاطئة في ملفات بناء GN، دون إضافة تبعيات واسعة وغير لازمة.
java-memory-leaks
25kيساعد وكيلك على إيجاد تسريبات الذاكرة في تطبيقات Android المكتوبة بـ Java وإصلاحها، عبر قراءة تقارير التسريب من LeakCanary.
jni-type-conversion
25kيساعد وكيلك على استبدال شيفرة التحويل اليدوي بين Java وC++ بتعليقات @JniType أبسط في شيفرة Android.
loadline
25kيساعد وكيلك على تشغيل اختبارات أداء LoadLine التي تقيس سرعة تحميل صفحات الويب على Android وChrome للحاسوب.
مهارات مشابهة
test-driven-development
311kيعلّم وكيلك كتابة اختبار فاشل أولًا، ثم رؤيته يفشل، ثم كتابة أصغر شيفرة تنجحه، قبل بناء أي ميزة أو إصلاح.
verification-before-completion
311kيعلّم وكيلك تشغيل فحوصات حقيقية وقراءة نتائجها قبل أن يقول إن المهمة أو الإصلاح أو البناء مكتمل أو ناجح.
migrate-to-shoehorn
310kيستبدل تأكيدات النوع الخطرة في ملفات الاختبار بمكتبة shoehorn، حتى تتمكن الاختبارات من استخدام بيانات جزئية وتجتاز فحوص الأنواع.