1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/fuzztest/src/fuzztest/domain.h"
6 #include "third_party/fuzztest/src/fuzztest/fuzztest.h"
7 #include "third_party/libyuv/include/libyuv.h"
8
9 #include "testing/libfuzzer/fuzzers/libyuv_scale_fuzzer.h"
10
11 // FuzzTest norms are to name the function according to the invariant
12 // we're trying to test
ScaleDoesNotCrash(bool is420,int src_width,int src_height,int dst_width,int dst_height,int filter_num,std::string seed_str)13 static void ScaleDoesNotCrash(bool is420,
14 int src_width,
15 int src_height,
16 int dst_width,
17 int dst_height,
18 int filter_num,
19 std::string seed_str) {
20 Scale(is420, src_width, src_height, dst_width, dst_height, filter_num,
21 seed_str);
22 }
23
24 // This happens to be the first FuzzTest fuzzer we've tried to use in Chrome.
25 // In an ideal world, we can skip the whole WithDomains stuff, and simply
26 // declare FUZZ_TEST(ScaleFuzz, ScaleDoesNotCrash).
27 // That will work for some functions which can accept truly arbitrary input.
28 // Domains are necessary in this case because only certain ranges of input
29 // are acceptable to the function.
30
31 FUZZ_TEST(ScaleFuzz, ScaleDoesNotCrash)
32 .WithDomains(
33 fuzztest::Arbitrary<bool>(),
34 fuzztest::InRange(1, 256),
35 fuzztest::InRange(1, 256),
36 fuzztest::InRange(1, 256),
37 fuzztest::InRange(1, 256),
38 fuzztest::InRange(0, static_cast<int>(libyuv::FilterMode::kFilterBox)),
39 fuzztest::Arbitrary<std::string>());
40