MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Fuzz

Function Fuzz

tensorflow/core/util/example_proto_fast_parsing_test.cc:340–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338}
339
340void Fuzz(random::SimplePhilox* rng) {
341 // Generate keys.
342 auto num_keys = 1 + rng->Rand32() % 100;
343 std::unordered_set<string> unique_keys;
344 for (auto i = 0; i < num_keys; ++i) {
345 unique_keys.emplace(RandStr(rng));
346 }
347
348 // Generate serialized example.
349 Example example;
350 string serialized_example;
351 auto num_concats = 1 + rng->Rand32() % 4;
352 std::vector<Feature::KindCase> feat_types(
353 {Feature::kBytesList, Feature::kFloatList, Feature::kInt64List});
354 std::vector<string> all_keys(unique_keys.begin(), unique_keys.end());
355 while (num_concats--) {
356 example.Clear();
357 auto num_active_keys = 1 + rng->Rand32() % all_keys.size();
358
359 // Generate features.
360 for (auto i = 0; i < num_active_keys; ++i) {
361 auto fkey = all_keys[rng->Rand32() % all_keys.size()];
362 auto ftype_idx = rng->Rand32() % feat_types.size();
363 auto num_features = 1 + rng->Rand32() % 5;
364 switch (static_cast<Feature::KindCase>(feat_types[ftype_idx])) {
365 case Feature::kBytesList: {
366 BytesList* bytes_list =
367 (*example.mutable_features()->mutable_feature())[fkey]
368 .mutable_bytes_list();
369 while (num_features--) {
370 bytes_list->add_value(RandStr(rng));
371 }
372 break;
373 }
374 case Feature::kFloatList: {
375 FloatList* float_list =
376 (*example.mutable_features()->mutable_feature())[fkey]
377 .mutable_float_list();
378 while (num_features--) {
379 float_list->add_value(rng->RandFloat());
380 }
381 break;
382 }
383 case Feature::kInt64List: {
384 Int64List* int64_list =
385 (*example.mutable_features()->mutable_feature())[fkey]
386 .mutable_int64_list();
387 while (num_features--) {
388 int64_list->add_value(rng->Rand64());
389 }
390 break;
391 }
392 default: {
393 LOG(QFATAL);
394 break;
395 }
396 }
397 }

Callers 1

TESTFunction · 0.85

Calls 11

RandStrFunction · 0.85
TestCorrectnessFunction · 0.85
Rand32Method · 0.80
RandFloatMethod · 0.80
Rand64Method · 0.80
emplaceMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ClearMethod · 0.45
sizeMethod · 0.45
SerializeAsStringMethod · 0.45

Tested by

no test coverage detected