Commit 9d5c8d46 by 钱炳权

测试监控

parent e8df61c8
......@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@RestController
......@@ -34,7 +35,7 @@ public class FuzzParamsController {
}
/**
* 跟据id获取参数
* 跟据任务id获取参数
*/
@RequestMapping(value = "/getParam/{missionId}", method = RequestMethod.GET)
public AjaxResult getById(@PathVariable("missionId") int missionId) {
......@@ -55,6 +56,7 @@ public class FuzzParamsController {
public AjaxResult editById(@RequestBody FuzzParams fuzzParams) {
boolean flag = false;
try {
fuzzParams.setEditTime(new Date());
flag = fuzzParamsService.editFuzzParams(fuzzParams);
} catch (Exception e) {
log.error("Edit params with id error:{}", e.getMessage());
......
......@@ -15,6 +15,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
/**
* aflnet测试控制
*/
......@@ -38,11 +41,11 @@ public class AlfnetController {
service.testStart(cmdStartParams);
}
});
SystemRunningParams.ThreadState.put(subThread,"start");
SystemRunningParams.ThreadState.put(subThread, "start");
subThread.setUncaughtExceptionHandler(new MyExceptionHandler());
subThread.start();
// subThread.join();
Thread.sleep(1000*10);//暂停3s,让系统运行至指令完全运行 todo跟据系统运行设定时间
Thread.sleep(1000 * 10);//暂停3s,让系统运行至指令完全运行 todo跟据系统运行设定时间
if ("error".equals(SystemRunningParams.ThreadState.get(subThread))) {//使用join串行就无法停止
throw new Exception();
}
......@@ -67,5 +70,20 @@ public class AlfnetController {
}
return AjaxResult.success("测试停止成功!");
}
/**
* 获取测试信息
*/
@RequestMapping(value = "/testProcessInfo", method = RequestMethod.GET)
public AjaxResult getProcessInfo() {
LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
try {
result = service.getProcessInfo();
} catch (AflnetException e) {
log.error(e.getDefaultMessage());
return AjaxResult.error("测试信息获取失败!");
}
return AjaxResult.success(result);
}
}
......@@ -2,10 +2,14 @@ package com.example.fuzzControll.service;
import com.example.fuzzControll.domain.bo.CmdStartParams;
import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
public interface TestService {
void testStart(CmdStartParams cmdStartParams);
void testStop();
LinkedHashMap<String,String> getProcessInfo();
}
......@@ -23,6 +23,8 @@ import org.springframework.stereotype.Service;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
@Service("testService")
@Slf4j
......@@ -69,4 +71,9 @@ public class TestServiceImpl implements TestService {
SystemRunningParams.testTimeMessage.get("aflnet").put("end", System.currentTimeMillis());//指令停止时间
log.info("Aflnet has been stopped ! ");
}
@Override
public LinkedHashMap<String,String> getProcessInfo() {
return SystemRunningParams.TestProgressMap;
}
}
package com.example.fuzzControll.tools.system;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -30,14 +32,47 @@ public class SystemRunningParams {
* kitty运行时数据
*/
public static ConcurrentHashMap<String, String> kittyData = new ConcurrentHashMap<>();//当前kitty任务的数据
public static void init(){
/**
* 测试进度map
*/
public static LinkedHashMap<String, String> TestProgressMap = new LinkedHashMap<>();
public static void init() {
/*初始化aflnet和kitty时间参数*/
testTimeMessage.put("aflnet",new ConcurrentHashMap<>());
testTimeMessage.put("kitty",new ConcurrentHashMap<>());
testTimeMessage.put("aflnet", new ConcurrentHashMap<>());
testTimeMessage.put("kitty", new ConcurrentHashMap<>());
/*初始化两个测试的起止时间*/
testTimeMessage.get("aflnet").put("start", 0L);
testTimeMessage.get("aflnet").put("end", 0L);
testTimeMessage.get("kitty").put("start", 0L);
testTimeMessage.get("kitty").put("end", 0L);
/*初始化测试进度map*/
TestProgressMapInit();
}
/**
* 测试进度初始化
*/
private static void TestProgressMapInit() {
TestProgressMap.put("系统已运行时间", "");
TestProgressMap.put("当前正在执行的变异阶段", "");
TestProgressMap.put("总执行次数", "");
TestProgressMap.put("平均执行速度", "");
TestProgressMap.put("总的崩溃数量", "");
TestProgressMap.put("总的超时数量", "");
TestProgressMap.put("发现的唯一崩溃的总数", "");
TestProgressMap.put("发现的唯一挂起总数", "");
TestProgressMap.put("距上次发现新路径过去多少时间", "");
TestProgressMap.put("据上次发现唯一崩溃过去多少时间", "");
TestProgressMap.put("距上次发现唯一挂起过去多少时间", "");
TestProgressMap.put("队列循环次数", "");
TestProgressMap.put("队列测试用例总数", "");
TestProgressMap.put("队列中待fuzz的用例数量", "");
TestProgressMap.put("添加到队列中的用例数量", "");
TestProgressMap.put("当前正在fuzz队列的第几个测试用例/测试进度", "");
TestProgressMap.put("放弃的用例数量/占总用例的比率", "");
TestProgressMap.put("当前执行次数/该阶段需要执行的次数(执行进度)", "");
}
}
......@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
......@@ -162,6 +163,12 @@ public class TestCmdTools {
if (send) {
String data = JSONObject.toJSONString(returnEntity);
try {
new Thread(new Runnable() {
@Override
public void run() {
dataToMap(data);
}
}).start();
websocketClientServiceImpl.webSocketClient.send(data);
} catch (Exception ignored) {
}
......@@ -169,6 +176,34 @@ public class TestCmdTools {
}
}
private void dataToMap(String data) {
try {
JSONObject dataJson = JSONObject.parseObject(data);
LinkedHashMap<String, String> testProgressMap = SystemRunningParams.TestProgressMap;
testProgressMap.put("系统已运行时间", dataJson.getString("run_time"));
testProgressMap.put("距上次发现新路径过去多少时间", dataJson.getString("last_new_path"));
testProgressMap.put("据上次发现唯一崩溃过去多少时间", dataJson.getString("last_uniq_crash"));
testProgressMap.put("距上次发现唯一挂起过去多少时间", dataJson.getString("last_uniq_hang"));
testProgressMap.put("队列循环次数", dataJson.getString("cycles_done"));
testProgressMap.put("队列测试用例总数", dataJson.getString("total_paths"));
testProgressMap.put("添加到队列中的用例数量", dataJson.getString("own_finds"));
testProgressMap.put("队列中待fuzz的用例数量", dataJson.getString("pending"));
testProgressMap.put("发现的唯一崩溃的总数", dataJson.getString("uniq_crashes"));
testProgressMap.put("发现的唯一挂起总数", dataJson.getString("uniq_hangs"));
testProgressMap.put("当前正在fuzz队列的第几个测试用例/测试进度", dataJson.getString("now_processing"));
testProgressMap.put("放弃的用例数量/占总用例的比率", dataJson.getString("paths_timed_out"));
testProgressMap.put("当前正在执行的变异阶段", dataJson.getString("now_trying"));
testProgressMap.put("当前执行次数/该阶段需要执行的次数(执行进度)", dataJson.getString("stage_execs"));
testProgressMap.put("总执行次数", dataJson.getString("total_crashes"));
testProgressMap.put("平均执行速度", dataJson.getString("exec_speed"));
testProgressMap.put("总的崩溃数量", dataJson.getString("total_crashes"));
testProgressMap.put("总的超时数量", dataJson.getString("total_tmouts"));
} catch (Exception e) {
log.error("There is no key:{}", e.getMessage());
throw new RuntimeException();
}
}
/**
* aflnet模糊测试数据键值对返回
*
......@@ -327,7 +362,7 @@ public class TestCmdTools {
@Transactional(rollbackFor = MysqlException.class)
public void dataBackUpTransaction(String caller, List<String> out, List<String> error, String missionName) {
int missionId =SystemRunningParams.kittyMissionId;
int missionId = SystemRunningParams.kittyMissionId;
try {
/*kitty结果存入数据库*/
KittyResult kittyResult = new KittyResult(missionId, out.toString(), error.toString());
......
......@@ -23,7 +23,7 @@ public class FuzzParamsController {
@RequestMapping(value = "/list", method = RequestMethod.GET)
public AjaxResult list() {
try {
return AjaxResult.success(fuzzIntegrationFileApi.getFuzzParamsList());
return fuzzIntegrationFileApi.getFuzzParamsList();
} catch (Exception e) {
log.error("Get params of fuzz error:{}", e.getMessage());
return AjaxResult.error();
......@@ -37,7 +37,7 @@ public class FuzzParamsController {
public AjaxResult getById(@PathVariable("id") int id) {
FuzzParams result;
try {
return AjaxResult.success(fuzzIntegrationFileApi.getFuzzParamById(id));
return fuzzIntegrationFileApi.getFuzzParamById(id);
} catch (Exception e) {
log.error("Get params of fuzz with id error:{}", e.getMessage());
return AjaxResult.error();
......@@ -50,7 +50,7 @@ public class FuzzParamsController {
@RequestMapping(value = "/editParam", method = RequestMethod.POST)
public AjaxResult editById(@RequestBody FuzzParams fuzzParams) {
try {
return AjaxResult.success(fuzzIntegrationFileApi.editFuzzParams(fuzzParams));
return fuzzIntegrationFileApi.editFuzzParams(fuzzParams);
} catch (Exception e) {
log.error("Edit params with id error:{}", e.getMessage());
return AjaxResult.error();
......
......@@ -38,4 +38,12 @@ public class TestController {
return fuzzIntegrationFileApi.testStop();
}
/**
* 获取测试信息和测试进度
*/
@RequestMapping(value = "/testProcessInfo", method = RequestMethod.GET)
public AjaxResult getTestProcessInfo() {
//停止时就开始关闭
return fuzzIntegrationFileApi.getProcessInfo();
}
}
\ No newline at end of file
......@@ -102,4 +102,10 @@ public interface FuzzIntegrationFileApi {
*/
@RequestMapping(value = "/fuzzParams/editParam", method = RequestMethod.POST)
AjaxResult editFuzzParams(FuzzParams fuzzParams);
/**
* 获取测试过程信息
*/
@RequestMapping(value = "/test/testProcessInfo", method = RequestMethod.GET)
AjaxResult getProcessInfo();
}
......@@ -8,7 +8,7 @@
var ws1 = null;
var ws2 = null;
function myFunction() {
ws1 = new WebSocket("ws://192.168.50.247:8101/websocket/testResult/web");
ws1 = new WebSocket("ws://192.168.50.251:8101/websocket/testResult/web");
ws1.onmessage = function (evt) {
console.log(evt);
var received_msg =JSON.parse(evt.data) ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment