执行日志补充
This commit is contained in:
parent
7d6ed60333
commit
d427b94d99
@ -144,6 +144,8 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
||||
// 获取编译后的文文件的inputStream
|
||||
JSch jsch = new JSch();
|
||||
Session session = null;
|
||||
ChannelExec exec = null;
|
||||
ChannelSftp sftp = null;
|
||||
try {
|
||||
session = jsch.getSession(machineInfo.getUsername(),machineInfo.getHostIp(), machineInfo.getSshPort());
|
||||
session.setPassword( CryptogramUtil.doDecrypt(machineInfo.getPassword()));
|
||||
@ -152,13 +154,17 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
session.setConfig(config);
|
||||
session.connect();
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
sftp.connect();
|
||||
String workDir = (String)getGlobalVariable(context,AFL_DOCKER_WORK_DIR_KEY);
|
||||
append(context,"AI测试用例生成开始上传目标文件。。。");
|
||||
String filePath = AFL_DOCKER_BASE_DIR + File.separator + workDir+File.separator+getSourceName(fileName)+File.separator+binaryName;
|
||||
append(context,"读取到目标文件路径:"+filePath);
|
||||
InputStream inputStream = sftp.get(filePath);
|
||||
String targetUploadRes = aiGeneratorService.targetUpload("./" + binaryName, inputStream);
|
||||
append(context,"上传结果:"+targetUploadRes);
|
||||
String binaryId = JSON.parseObject(targetUploadRes).getString("id");
|
||||
append(context,"开始创建测试用例生成task");
|
||||
// 创建task
|
||||
TestCaseAITaskCreateReq req = new TestCaseAITaskCreateReq();
|
||||
req.setBinaryId(binaryId);
|
||||
@ -166,6 +172,7 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
||||
req.setCount(count);
|
||||
String taskCreateRes = aiGeneratorService.taskCreate(req);
|
||||
String taskId = JSON.parseObject(taskCreateRes).getString("task_id");
|
||||
append(context,"创建测试用例生成task成功,开始读取task执行日志");
|
||||
while (true){
|
||||
// 获取状态及日志
|
||||
String taskStatusRes = aiGeneratorService.getTaskStatus(taskId);
|
||||
@ -179,25 +186,51 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
||||
String logStr = JSON.parseObject(logRes).getString("log");
|
||||
append(context,logStr);
|
||||
}
|
||||
append(context,"task当前执行状态"+taskStatusRes);
|
||||
}
|
||||
append(context,"开始下载生成的测试用例文件");
|
||||
File tempFile = File.createTempFile("seed", ".zip");
|
||||
tempFile.deleteOnExit();
|
||||
FileOutputStream fos = new FileOutputStream(tempFile);
|
||||
// 下载生成的种子
|
||||
aiGeneratorService.downloadTestCase(taskId,fos);
|
||||
fos.close();
|
||||
append(context,"下载生成的模糊测试种子文件成功");
|
||||
|
||||
FileInputStream fis = new FileInputStream(tempFile);
|
||||
// 上传种子zip到目标服务器
|
||||
sftp.put(fis,"");
|
||||
sftp.disconnect();
|
||||
String seedPath= workDir+File.separator+ AFL_DOCKER_SEED;
|
||||
String seedTarget = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath+File.separator+"seed.zip";
|
||||
String seedTarget = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath+File.separator+tempFile.getName();
|
||||
String seedDir = AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath;
|
||||
append(context,"上传模糊测试种子压缩包到指定工作目录:"+seedDir);
|
||||
sftp.put(fis,seedDir);
|
||||
sftp.disconnect();
|
||||
append(context,"解压种子到指定工作目录"+seedDir);
|
||||
String cmd = "unzip -o " + seedTarget + " -d " + seedDir;
|
||||
append(context,cmd);
|
||||
// 解压种子zip
|
||||
ChannelExec exec = (ChannelExec)session.openChannel("exec");
|
||||
exec.setCommand("unzip -o "+seedTarget+" -d "+seedDir);
|
||||
exec = (ChannelExec)session.openChannel("exec");
|
||||
exec.setCommand(cmd);
|
||||
|
||||
} catch (Exception e) {
|
||||
append(context,"测试用例生成失败");
|
||||
}finally {
|
||||
if (exec!=null) {
|
||||
if (exec.isConnected()) {
|
||||
exec.disconnect();
|
||||
}
|
||||
}
|
||||
if (sftp!=null) {
|
||||
if (sftp.isConnected()) {
|
||||
sftp.disconnect();
|
||||
}
|
||||
}
|
||||
if (session!=null) {
|
||||
if (session.isConnected()) {
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user