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 java.util.stream.Stream; 20 import org.junit.jupiter.api.extension.ExtensionContext; 21 import org.junit.jupiter.params.provider.Arguments; 22 import org.junit.jupiter.params.provider.ArgumentsProvider; 23 import org.junit.jupiter.params.support.AnnotationConsumer; 24 25 public class AgentConfiguringArgumentsProvider 26 implements ArgumentsProvider, AnnotationConsumer<FuzzTest> { 27 private FuzzTest fuzzTest; 28 29 @Override accept(FuzzTest fuzzTest)30 public void accept(FuzzTest fuzzTest) { 31 this.fuzzTest = fuzzTest; 32 } 33 34 @Override provideArguments(ExtensionContext extensionContext)35 public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) 36 throws Exception { 37 // FIXME(fmeum): Calling this here feels like a hack. There should be a lifecycle hook that runs 38 // before the argument discovery for a ParameterizedTest is kicked off, but I haven't found 39 // one. 40 FuzzTestExecutor.configureAndInstallAgent(extensionContext, fuzzTest.maxDuration()); 41 return Stream.empty(); 42 } 43 } 44