1 /* 2 * Copyright 2023 Code Intelligence GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.code_intelligence.jazzer.junit; 18 19 import static com.code_intelligence.jazzer.junit.Utils.isFuzzing; 20 21 import java.util.stream.Stream; 22 import org.junit.jupiter.api.extension.ExtensionContext; 23 import org.junit.jupiter.params.provider.Arguments; 24 import org.junit.jupiter.params.provider.ArgumentsProvider; 25 26 class FuzzingArgumentsProvider implements ArgumentsProvider { 27 @Override provideArguments(ExtensionContext extensionContext)28 public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { 29 if (!isFuzzing(extensionContext)) { 30 return Stream.empty(); 31 } 32 33 // When fuzzing, supply a special set of arguments that our InvocationInterceptor uses as a 34 // sign to start fuzzing. 35 // FIXME: This is a hack that is needed only because there does not seem to be a way to 36 // communicate out of band that a certain invocation was triggered by a particular argument 37 // provider. We should get rid of this hack as soon as 38 // https://github.com/junit-team/junit5/issues/3282 has been addressed. 39 return Stream.of( 40 Utils.getMarkedArguments(extensionContext.getRequiredTestMethod(), "Fuzzing...")); 41 } 42 } 43