ai测试用例生成接口修改,afl报表信息修改
This commit is contained in:
parent
fe6ca78d74
commit
a3f5c06b46
@ -2,6 +2,7 @@ package cd.casic.ci.process.engine.worker.afl;
|
|||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.common.WorkAtom;
|
import cd.casic.ci.process.common.WorkAtom;
|
||||||
|
import cd.casic.ci.process.constant.CommandConstant;
|
||||||
import cd.casic.ci.process.dto.req.testCase.TestCaseAITaskCreateReq;
|
import cd.casic.ci.process.dto.req.testCase.TestCaseAITaskCreateReq;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceDetailResp;
|
import cd.casic.ci.process.dto.resp.resource.ResourceDetailResp;
|
||||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
@ -129,7 +130,7 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
Map<String, Object> taskProperties = taskDef.getTaskProperties();
|
Map<String, Object> taskProperties = taskDef.getTaskProperties();
|
||||||
String binaryName = taskProperties.get(BINARY_NAME) instanceof String ? ((String) taskProperties.get("binaryName")) : null;
|
String binaryName = taskProperties.get(BINARY_NAME) instanceof String ? ((String) taskProperties.get("binaryName")) : null;
|
||||||
Integer count = taskProperties.get(COUNT) instanceof Integer ? ((Integer) taskProperties.get(COUNT)) : null;
|
Integer count = taskProperties.get(COUNT) instanceof Integer ? ((Integer) taskProperties.get(COUNT)) : null;
|
||||||
String prompt = taskProperties.get(PROMPT) instanceof String ? ((String) taskProperties.get(COUNT)) : null;
|
String prompt = taskProperties.get(PROMPT) instanceof String ? ((String) taskProperties.get(PROMPT)) : null;
|
||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
||||||
String managerId = getVariableNearby(context, AFL_RESOURCE_MANAGER_ID_KEY) instanceof String ? ((String) getVariableNearby(context, AFL_RESOURCE_MANAGER_ID_KEY)) : null;
|
String managerId = getVariableNearby(context, AFL_RESOURCE_MANAGER_ID_KEY) instanceof String ? ((String) getVariableNearby(context, AFL_RESOURCE_MANAGER_ID_KEY)) : null;
|
||||||
@ -160,10 +161,12 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
String filePath = AFL_VOLUME_WORK_DIR_PREFIX + File.separator + workDir+File.separator+getSourceName(fileName)+File.separator+binaryName;
|
String filePath = AFL_VOLUME_WORK_DIR_PREFIX + File.separator + workDir+File.separator+getSourceName(fileName)+File.separator+binaryName;
|
||||||
append(context,"读取到目标文件路径:"+filePath);
|
append(context,"读取到目标文件路径:"+filePath);
|
||||||
InputStream inputStream = sftp.get(filePath);
|
InputStream inputStream = sftp.get(filePath);
|
||||||
|
|
||||||
String targetUploadRes = aiGeneratorService.targetUpload("./" + binaryName, inputStream);
|
String targetUploadRes = aiGeneratorService.targetUpload("./" + binaryName, inputStream);
|
||||||
append(context,"上传结果:"+targetUploadRes);
|
append(context,"上传结果:"+targetUploadRes);
|
||||||
String binaryId = JSON.parseObject(targetUploadRes).getString("id");
|
String binaryId = JSON.parseObject(targetUploadRes).getString("id");
|
||||||
append(context,"开始创建测试用例生成task");
|
append(context,"开始创建测试用例生成task");
|
||||||
|
sftp.disconnect();
|
||||||
// 创建task
|
// 创建task
|
||||||
TestCaseAITaskCreateReq req = new TestCaseAITaskCreateReq();
|
TestCaseAITaskCreateReq req = new TestCaseAITaskCreateReq();
|
||||||
req.setBinaryId(binaryId);
|
req.setBinaryId(binaryId);
|
||||||
@ -185,11 +188,10 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
String logStr = JSON.parseObject(logRes).getString("log");
|
String logStr = JSON.parseObject(logRes).getString("log");
|
||||||
append(context,logStr);
|
append(context,logStr);
|
||||||
}
|
}
|
||||||
append(context,"task当前执行状态"+taskStatusRes);
|
// append(context,"task当前执行状态"+taskStatusRes);
|
||||||
}
|
}
|
||||||
append(context,"开始下载生成的测试用例文件");
|
append(context,"开始下载生成的测试用例文件");
|
||||||
File tempFile = File.createTempFile("seed", ".zip");
|
File tempFile = File.createTempFile("seed", ".zip");
|
||||||
tempFile.deleteOnExit();
|
|
||||||
FileOutputStream fos = new FileOutputStream(tempFile);
|
FileOutputStream fos = new FileOutputStream(tempFile);
|
||||||
// 下载生成的种子
|
// 下载生成的种子
|
||||||
aiGeneratorService.downloadTestCase(taskId,fos);
|
aiGeneratorService.downloadTestCase(taskId,fos);
|
||||||
@ -202,15 +204,38 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
String seedTarget = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath+File.separator+tempFile.getName();
|
String seedTarget = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath+File.separator+tempFile.getName();
|
||||||
String seedDir = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath;
|
String seedDir = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath;
|
||||||
append(context,"上传模糊测试种子压缩包到指定工作目录:"+seedDir);
|
append(context,"上传模糊测试种子压缩包到指定工作目录:"+seedDir);
|
||||||
sftp.put(fis,seedTarget);
|
String cmd = "mkdir -p "+seedDir;
|
||||||
sftp.disconnect();
|
|
||||||
append(context,"解压种子到指定工作目录"+seedDir);
|
|
||||||
String cmd = "unzip -o " + seedTarget + " -d " + seedDir;
|
|
||||||
append(context,cmd);
|
append(context,cmd);
|
||||||
// 解压种子zip
|
// 解压种子zip
|
||||||
exec = (ChannelExec)session.openChannel("exec");
|
exec = (ChannelExec)session.openChannel("exec");
|
||||||
exec.setCommand(cmd);
|
exec.setCommand(cmd);
|
||||||
exec.connect();
|
exec.connect();
|
||||||
|
exec.disconnect();
|
||||||
|
sftp = (ChannelSftp) session.openChannel("sftp");
|
||||||
|
sftp.connect();
|
||||||
|
sftp.put(fis,seedTarget);
|
||||||
|
sftp.disconnect();
|
||||||
|
fis.close();
|
||||||
|
append(context,"解压种子到指定工作目录"+seedDir);
|
||||||
|
|
||||||
|
cmd = "unzip -o " + seedTarget + " -d " + seedDir;
|
||||||
|
append(context,cmd);
|
||||||
|
// 解压种子zip
|
||||||
|
exec = (ChannelExec)session.openChannel("exec");
|
||||||
|
exec.setCommand(cmd);
|
||||||
|
exec.connect();
|
||||||
|
InputStream errStream = exec.getErrStream();
|
||||||
|
InputStream inStream = exec.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
|
||||||
|
BufferedReader errReader = new BufferedReader(new InputStreamReader(errStream));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
append(context, "STDOUT: " + line);
|
||||||
|
}
|
||||||
|
while ((line = errReader.readLine()) != null) {
|
||||||
|
append(context, "STDERR: " + line);
|
||||||
|
}
|
||||||
|
tempFile.deleteOnExit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("ai测试用例生成报错",e);
|
log.error("ai测试用例生成报错",e);
|
||||||
append(context,"测试用例生成失败");
|
append(context,"测试用例生成失败");
|
||||||
@ -230,7 +255,6 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
session.disconnect();
|
session.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ public class AflCrashesInfoServiceImpl extends ServiceImpl<AflCrashesInfoDao, Af
|
|||||||
try {
|
try {
|
||||||
// 查询所有崩溃数
|
// 查询所有崩溃数
|
||||||
List<String> files = SftpUploadUtil.listFilesInRemoteDirectory(
|
List<String> files = SftpUploadUtil.listFilesInRemoteDirectory(
|
||||||
resourceMachine.getHostIp(), resourceMachine.getSshPort(), resourceMachine.getUsername(), resourceMachine.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath);
|
resourceMachine.getHostIp(), resourceMachine.getSshPort(), resourceMachine.getUsername(), CryptogramUtil.doDecrypt(resourceMachine.getPassword()), null, remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath);
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(files)){
|
if (!CollectionUtils.isEmpty(files)){
|
||||||
aflCrashesResp.setImperfectionCount(files.size());
|
aflCrashesResp.setImperfectionCount(files.size());
|
||||||
|
@ -129,7 +129,7 @@ public class AflPlotInfoServiceImpl extends ServiceImpl<AflPlotInfoDao, AflPlotI
|
|||||||
}
|
}
|
||||||
|
|
||||||
MachineInfoDO resourceMachine = resourceById.getMachineInfo();
|
MachineInfoDO resourceMachine = resourceById.getMachineInfo();
|
||||||
AflPlotInfo aflPlotInfo = SftpUploadUtil.downloadFileSftpForLastLineAndSetAflPlotInfo(resourceMachine.getHostIp(), resourceMachine.getSshPort(), resourceMachine.getUsername(), resourceMachine.getPassword(),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/plot_data");
|
AflPlotInfo aflPlotInfo = SftpUploadUtil.downloadFileSftpForLastLineAndSetAflPlotInfo(resourceMachine.getHostIp(), resourceMachine.getSshPort(), resourceMachine.getUsername(), CryptogramUtil.doDecrypt(resourceMachine.getPassword()),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/plot_data");
|
||||||
|
|
||||||
return AflManagerConverter.INSTANCE.toAflPlotInfoResp(aflPlotInfo);
|
return AflManagerConverter.INSTANCE.toAflPlotInfoResp(aflPlotInfo);
|
||||||
}
|
}
|
||||||
|
@ -191,14 +191,6 @@ public class SftpClientUtils implements AutoCloseable {
|
|||||||
return inputStream;
|
return inputStream;
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new SftpUploadUtil.SftpUploadException("获取远程文件流失败: " + fileName, e);
|
throw new SftpUploadUtil.SftpUploadException("获取远程文件流失败: " + fileName, e);
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("关闭 InputStream 时发生异常: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ package cd.casic.ci.process.process.service.sftpFile.impl;
|
|||||||
import cd.casic.ci.process.process.service.sftpFile.SftpClientUtils;
|
import cd.casic.ci.process.process.service.sftpFile.SftpClientUtils;
|
||||||
import cd.casic.ci.process.process.service.sftpFile.SftpFileService;
|
import cd.casic.ci.process.process.service.sftpFile.SftpFileService;
|
||||||
import cd.casic.ci.process.properties.TargetFileUploadProperties;
|
import cd.casic.ci.process.properties.TargetFileUploadProperties;
|
||||||
|
import com.amazonaws.util.IOUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -107,17 +108,20 @@ public class SftpFileServiceImpl implements SftpFileService {
|
|||||||
String fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf("/") + 1);
|
String fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf("/") + 1);
|
||||||
try (InputStream in = client.downloadFileToStream(remoteFilePath)) {
|
try (InputStream in = client.downloadFileToStream(remoteFilePath)) {
|
||||||
zipOut.putNextEntry(new ZipEntry(fileName));
|
zipOut.putNextEntry(new ZipEntry(fileName));
|
||||||
byte[] buffer = new byte[1024];
|
// byte[] buffer = new byte[1024];
|
||||||
int bytesRead;
|
// int bytesRead;
|
||||||
while ((bytesRead = in.read(buffer)) > 0) {
|
// while ((bytesRead = in.read(buffer)) > 0) {
|
||||||
zipOut.write(buffer, 0, bytesRead);
|
// zipOut.write(buffer, 0, bytesRead);
|
||||||
}
|
// }
|
||||||
|
IOUtils.copy(in,zipOut);
|
||||||
|
in.close();
|
||||||
zipOut.closeEntry();
|
zipOut.closeEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("批量下载并打包 ZIP 失败: " + e.getMessage(), e);
|
e.printStackTrace();
|
||||||
|
// throw new RuntimeException("批量下载并打包 ZIP 失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ public class TargetManagerServiceImpl extends ServiceImpl<TargetManagerDao, Targ
|
|||||||
String file = Base64.getEncoder().encodeToString(byteArray);
|
String file = Base64.getEncoder().encodeToString(byteArray);
|
||||||
FileBase64DownloadResp resp = new FileBase64DownloadResp();
|
FileBase64DownloadResp resp = new FileBase64DownloadResp();
|
||||||
resp.setFile(file);
|
resp.setFile(file);
|
||||||
resp.setFileName(targetName);
|
resp.setFileName(targetName+".zip");
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,6 +897,7 @@ public class SftpUploadUtil {
|
|||||||
}
|
}
|
||||||
return fileNames;
|
return fileNames;
|
||||||
} catch (JSchException e) {
|
} catch (JSchException e) {
|
||||||
|
log.error("SFTP 连接或认证失败: " ,e);
|
||||||
throw new SftpUploadException("SFTP 连接或认证失败: " + e.getMessage(), e);
|
throw new SftpUploadException("SFTP 连接或认证失败: " + e.getMessage(), e);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new SftpUploadException("SFTP 操作失败 (如切换目录或上传文件): " + e.getMessage(), e);
|
throw new SftpUploadException("SFTP 操作失败 (如切换目录或上传文件): " + e.getMessage(), e);
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user